InfantryType.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // The Command & Conquer Map Editor and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // The Command & Conquer Map Editor and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. using MobiusEditor.Interface;
  15. using MobiusEditor.Render;
  16. using MobiusEditor.Utility;
  17. using System;
  18. using System.Drawing;
  19. namespace MobiusEditor.Model
  20. {
  21. public class InfantryType : ITechnoType, IBrowsableType
  22. {
  23. public sbyte ID { get; private set; }
  24. public string Name { get; private set; }
  25. public string DisplayName { get; private set; }
  26. public string OwnerHouse { get; private set; }
  27. public Size RenderSize { get; set; }
  28. public Image Thumbnail { get; set; }
  29. public InfantryType(sbyte id, string name, string textId, string ownerHouse)
  30. {
  31. ID = id;
  32. Name = name;
  33. DisplayName = Globals.TheGameTextManager[textId];
  34. OwnerHouse = ownerHouse;
  35. }
  36. public InfantryType(sbyte id, string name, string textId)
  37. : this(id, name, textId, null)
  38. {
  39. }
  40. public override bool Equals(object obj)
  41. {
  42. if (obj is InfantryType)
  43. {
  44. return this == obj;
  45. }
  46. else if (obj is sbyte)
  47. {
  48. return ID == (sbyte)obj;
  49. }
  50. else if (obj is string)
  51. {
  52. return string.Equals(Name, obj as string, StringComparison.OrdinalIgnoreCase);
  53. }
  54. return base.Equals(obj);
  55. }
  56. public override int GetHashCode()
  57. {
  58. return ID.GetHashCode();
  59. }
  60. public override string ToString()
  61. {
  62. return Name;
  63. }
  64. public void Init(GameType gameType, TheaterType theater, HouseType house, DirectionType direction)
  65. {
  66. if (Globals.TheTilesetManager.GetTileData(theater.Tilesets, Name, 4, out Tile tile))
  67. {
  68. RenderSize = new Size(tile.Image.Width / Globals.TileScale, tile.Image.Height / Globals.TileScale);
  69. }
  70. var mockInfantry = new Infantry(null)
  71. {
  72. Type = this,
  73. House = house,
  74. Strength = 256,
  75. Direction = direction
  76. };
  77. var infantryThumbnail = new Bitmap(Globals.TileWidth, Globals.TileHeight);
  78. using (var g = Graphics.FromImage(infantryThumbnail))
  79. {
  80. MapRenderer.Render(theater, Point.Empty, Globals.TileSize, mockInfantry, InfantryStoppingType.Center).Item2(g);
  81. }
  82. Thumbnail = infantryThumbnail;
  83. }
  84. }
  85. }