SmudgeType.cs 3.5 KB

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