OverlayType.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. [Flags]
  21. public enum OverlayTypeFlag
  22. {
  23. None = 0,
  24. TiberiumOrGold = (1 << 0),
  25. Gems = (1 << 1),
  26. Wall = (1 << 2),
  27. Crate = (1 << 3),
  28. Flag = (1 << 4),
  29. }
  30. public class OverlayType : ICellOccupier, IBrowsableType
  31. {
  32. public sbyte ID { get; private set; }
  33. public string Name { get; private set; }
  34. public string DisplayName { get; private set; }
  35. public TheaterType[] Theaters { get; private set; }
  36. public OverlayTypeFlag Flag { get; private set; }
  37. public Image Thumbnail { get; set; }
  38. public bool[,] OccupyMask => new bool[1, 1] { { true } };
  39. public bool IsResource => (Flag & (OverlayTypeFlag.TiberiumOrGold | OverlayTypeFlag.Gems)) != OverlayTypeFlag.None;
  40. public bool IsTiberiumOrGold => (Flag & OverlayTypeFlag.TiberiumOrGold) != OverlayTypeFlag.None;
  41. public bool IsGem => (Flag & OverlayTypeFlag.Gems) != OverlayTypeFlag.None;
  42. public bool IsWall => (Flag & OverlayTypeFlag.Wall) != OverlayTypeFlag.None;
  43. public bool IsCrate => (Flag & OverlayTypeFlag.Crate) != OverlayTypeFlag.None;
  44. public bool IsFlag => (Flag & OverlayTypeFlag.Flag) != OverlayTypeFlag.None;
  45. public bool IsPlaceable => (Flag & ~OverlayTypeFlag.Crate) == OverlayTypeFlag.None;
  46. public OverlayType(sbyte id, string name, string textId, TheaterType[] theaters, OverlayTypeFlag flag)
  47. {
  48. ID = id;
  49. Name = name;
  50. DisplayName = Globals.TheGameTextManager[textId];
  51. Theaters = theaters;
  52. Flag = flag;
  53. }
  54. public OverlayType(sbyte id, string name, string textId, OverlayTypeFlag flag)
  55. : this(id, name, textId, null, flag)
  56. {
  57. }
  58. public OverlayType(sbyte id, string name, string textId, TheaterType[] theaters)
  59. : this(id, name, textId, theaters, OverlayTypeFlag.None)
  60. {
  61. }
  62. public OverlayType(sbyte id, string name, OverlayTypeFlag flag)
  63. : this(id, name, name, null, flag)
  64. {
  65. }
  66. public OverlayType(sbyte id, string name, string textId)
  67. : this(id, name, textId, null, OverlayTypeFlag.None)
  68. {
  69. }
  70. public override bool Equals(object obj)
  71. {
  72. if (obj is OverlayType)
  73. {
  74. return this == obj;
  75. }
  76. else if (obj is sbyte)
  77. {
  78. return ID == (sbyte)obj;
  79. }
  80. else if (obj is string)
  81. {
  82. return string.Equals(Name, obj as string, StringComparison.OrdinalIgnoreCase);
  83. }
  84. return base.Equals(obj);
  85. }
  86. public override int GetHashCode()
  87. {
  88. return ID.GetHashCode();
  89. }
  90. public override string ToString()
  91. {
  92. return Name;
  93. }
  94. public void Init(TheaterType theater)
  95. {
  96. if (Globals.TheTilesetManager.GetTileData(theater.Tilesets, Name, 0, out Tile tile))
  97. {
  98. Thumbnail = new Bitmap(tile.Image, tile.Image.Width, tile.Image.Height);
  99. }
  100. }
  101. }
  102. }