OverlayType.cs (4231B)
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 9 // The Command & Conquer Map Editor and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 using MobiusEditor.Interface; 16 using MobiusEditor.Utility; 17 using System; 18 using System.Drawing; 19 20 namespace MobiusEditor.Model 21 { 22 [Flags] 23 public enum OverlayTypeFlag 24 { 25 None = 0, 26 TiberiumOrGold = (1 << 0), 27 Gems = (1 << 1), 28 Wall = (1 << 2), 29 Crate = (1 << 3), 30 Flag = (1 << 4), 31 } 32 33 public class OverlayType : ICellOccupier, IBrowsableType 34 { 35 public sbyte ID { get; private set; } 36 37 public string Name { get; private set; } 38 39 public string DisplayName { get; private set; } 40 41 public TheaterType[] Theaters { get; private set; } 42 43 public OverlayTypeFlag Flag { get; private set; } 44 45 public Image Thumbnail { get; set; } 46 47 public bool[,] OccupyMask => new bool[1, 1] { { true } }; 48 49 public bool IsResource => (Flag & (OverlayTypeFlag.TiberiumOrGold | OverlayTypeFlag.Gems)) != OverlayTypeFlag.None; 50 51 public bool IsTiberiumOrGold => (Flag & OverlayTypeFlag.TiberiumOrGold) != OverlayTypeFlag.None; 52 53 public bool IsGem => (Flag & OverlayTypeFlag.Gems) != OverlayTypeFlag.None; 54 55 public bool IsWall => (Flag & OverlayTypeFlag.Wall) != OverlayTypeFlag.None; 56 57 public bool IsCrate => (Flag & OverlayTypeFlag.Crate) != OverlayTypeFlag.None; 58 59 public bool IsFlag => (Flag & OverlayTypeFlag.Flag) != OverlayTypeFlag.None; 60 61 public bool IsPlaceable => (Flag & ~OverlayTypeFlag.Crate) == OverlayTypeFlag.None; 62 63 public OverlayType(sbyte id, string name, string textId, TheaterType[] theaters, OverlayTypeFlag flag) 64 { 65 ID = id; 66 Name = name; 67 DisplayName = Globals.TheGameTextManager[textId]; 68 Theaters = theaters; 69 Flag = flag; 70 } 71 72 public OverlayType(sbyte id, string name, string textId, OverlayTypeFlag flag) 73 : this(id, name, textId, null, flag) 74 { 75 } 76 77 public OverlayType(sbyte id, string name, string textId, TheaterType[] theaters) 78 : this(id, name, textId, theaters, OverlayTypeFlag.None) 79 { 80 } 81 82 public OverlayType(sbyte id, string name, OverlayTypeFlag flag) 83 : this(id, name, name, null, flag) 84 { 85 } 86 87 public OverlayType(sbyte id, string name, string textId) 88 : this(id, name, textId, null, OverlayTypeFlag.None) 89 { 90 } 91 92 public override bool Equals(object obj) 93 { 94 if (obj is OverlayType) 95 { 96 return this == obj; 97 } 98 else if (obj is sbyte) 99 { 100 return ID == (sbyte)obj; 101 } 102 else if (obj is string) 103 { 104 return string.Equals(Name, obj as string, StringComparison.OrdinalIgnoreCase); 105 } 106 107 return base.Equals(obj); 108 } 109 110 public override int GetHashCode() 111 { 112 return ID.GetHashCode(); 113 } 114 115 public override string ToString() 116 { 117 return Name; 118 } 119 120 public void Init(TheaterType theater) 121 { 122 if (Globals.TheTilesetManager.GetTileData(theater.Tilesets, Name, 0, out Tile tile)) 123 { 124 Thumbnail = new Bitmap(tile.Image, tile.Image.Width, tile.Image.Height); 125 } 126 } 127 } 128 }