TerrainType.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.Utility;
  16. using System;
  17. using System.Drawing;
  18. namespace MobiusEditor.Model
  19. {
  20. public class TerrainType : ICellOverlapper, ICellOccupier, IBrowsableType
  21. {
  22. public sbyte ID { get; private set; }
  23. public string Name { get; private set; }
  24. public string DisplayName => Name;
  25. public Rectangle OverlapBounds => new Rectangle(
  26. Point.Empty,
  27. new Size(((RenderSize.Width + Globals.TileWidth - 1) / Globals.TileWidth), ((RenderSize.Height + Globals.TileHeight - 1) / Globals.TileHeight))
  28. );
  29. public bool[,] OccupyMask { get; private set; }
  30. public Size Size => new Size(OccupyMask.GetLength(1), OccupyMask.GetLength(0));
  31. public TheaterType[] Theaters { get; private set; }
  32. public bool IsTransformable { get; private set; }
  33. public TemplateTypeFlag TemplateType { get; private set; }
  34. public Size RenderSize { get; set; }
  35. public Image Thumbnail { get; set; }
  36. public TerrainType(sbyte id, string name, TheaterType[] theaters, bool[,] occupyMask, bool isTransformable, TemplateTypeFlag templateType)
  37. {
  38. ID = id;
  39. Name = name;
  40. Theaters = theaters;
  41. OccupyMask = occupyMask;
  42. IsTransformable = isTransformable;
  43. TemplateType = templateType;
  44. }
  45. public TerrainType(sbyte id, string name, TheaterType[] theaters, bool[,] occupyMask, bool isTransformable)
  46. : this(id, name, theaters, occupyMask, isTransformable, TemplateTypeFlag.None)
  47. {
  48. }
  49. public TerrainType(sbyte id, string name, TheaterType[] theaters, bool[,] occupyMask, TemplateTypeFlag templateType)
  50. : this(id, name, theaters, occupyMask, false, templateType)
  51. {
  52. }
  53. public TerrainType(sbyte id, string name, TheaterType[] theaters, bool[,] occupyMask)
  54. : this(id, name, theaters, occupyMask, false, TemplateTypeFlag.None)
  55. {
  56. }
  57. public override bool Equals(object obj)
  58. {
  59. if (obj is TerrainType)
  60. {
  61. return this == obj;
  62. }
  63. else if (obj is sbyte)
  64. {
  65. return ID == (sbyte)obj;
  66. }
  67. else if (obj is string)
  68. {
  69. return string.Equals(Name, obj as string, StringComparison.OrdinalIgnoreCase);
  70. }
  71. return base.Equals(obj);
  72. }
  73. public override int GetHashCode()
  74. {
  75. return ID.GetHashCode();
  76. }
  77. public override string ToString()
  78. {
  79. return Name;
  80. }
  81. public void Init(TheaterType theater)
  82. {
  83. string tileName = Name;
  84. if ((TemplateType & TemplateTypeFlag.OreMine) != TemplateTypeFlag.None)
  85. {
  86. tileName = "OREMINE";
  87. }
  88. if (Globals.TheTilesetManager.GetTileData(theater.Tilesets, tileName, IsTransformable ? 22 : 0, out Tile tile))
  89. {
  90. RenderSize = new Size(tile.Image.Width / Globals.TileScale, tile.Image.Height / Globals.TileScale);
  91. Thumbnail = new Bitmap(tile.Image, tile.Image.Width / 2, tile.Image.Height / 2);
  92. }
  93. }
  94. }
  95. }