SmudgeType.cs (3570B)
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 SmudgeTypeFlag 24 { 25 None = 0, 26 Bib = 1, 27 Bib1 = 3, 28 Bib2 = 5, 29 Bib3 = 9, 30 } 31 32 public class SmudgeType : IBrowsableType 33 { 34 public sbyte ID { get; private set; } 35 36 public string Name { get; private set; } 37 38 public string DisplayName => Name; 39 40 public Size Size { get; set; } 41 42 public SmudgeTypeFlag Flag { get; private set; } 43 44 public Size RenderSize { get; set; } 45 46 public Image Thumbnail { get; set; } 47 48 public SmudgeType(sbyte id, string name, Size size, SmudgeTypeFlag flag) 49 { 50 ID = id; 51 Name = name; 52 Size = size; 53 Flag = flag; 54 } 55 56 public SmudgeType(sbyte id, string name, Size size) 57 : this(id, name, size, SmudgeTypeFlag.None) 58 { 59 } 60 61 public SmudgeType(sbyte id, string name) 62 : this(id, name, new Size(1, 1), SmudgeTypeFlag.None) 63 { 64 } 65 66 public override bool Equals(object obj) 67 { 68 if (obj is SmudgeType) 69 { 70 return this == obj; 71 } 72 else if (obj is sbyte) 73 { 74 return ID == (sbyte)obj; 75 } 76 else if (obj is string) 77 { 78 return string.Equals(Name, obj as string, StringComparison.OrdinalIgnoreCase); 79 } 80 81 return base.Equals(obj); 82 } 83 84 public override int GetHashCode() 85 { 86 return ID.GetHashCode(); 87 } 88 89 public override string ToString() 90 { 91 return Name; 92 } 93 94 public void Init(TheaterType theater) 95 { 96 if (Globals.TheTilesetManager.GetTileData(theater.Tilesets, Name, 0, out Tile tile)) 97 { 98 if ((tile.Image.Width * Globals.TileHeight) > (tile.Image.Height * Globals.TileWidth)) 99 { 100 RenderSize = new Size( 101 tile.Image.Width * Globals.TileWidth / tile.Image.Width, 102 tile.Image.Height * Globals.TileWidth / tile.Image.Width 103 ); 104 } 105 else 106 { 107 RenderSize = new Size( 108 tile.Image.Width * Globals.TileHeight / tile.Image.Height, 109 tile.Image.Height * Globals.TileHeight / tile.Image.Height 110 ); 111 } 112 Thumbnail = new Bitmap(tile.Image, tile.Image.Width, tile.Image.Height); 113 } 114 } 115 } 116 }