Building.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 System;
  16. using System.Collections.Generic;
  17. using System.ComponentModel;
  18. using System.Drawing;
  19. using System.Runtime.CompilerServices;
  20. namespace MobiusEditor.Model
  21. {
  22. public class Building : ICellOverlapper, ICellOccupier, INotifyPropertyChanged, ICloneable
  23. {
  24. public event PropertyChangedEventHandler PropertyChanged;
  25. private BuildingType type;
  26. public BuildingType Type { get => type; set => SetField(ref type, value); }
  27. public Rectangle OverlapBounds => Type.OverlapBounds;
  28. public bool[,] OccupyMask => Type.OccupyMask;
  29. private HouseType house;
  30. public HouseType House { get => house; set => SetField(ref house, value); }
  31. private int strength;
  32. public int Strength { get => strength; set => SetField(ref strength, value); }
  33. private DirectionType direction;
  34. public DirectionType Direction { get => direction; set => SetField(ref direction, value); }
  35. private string trigger = Model.Trigger.None;
  36. public string Trigger { get => trigger; set => SetField(ref trigger, value); }
  37. private int basePriority = -1;
  38. public int BasePriority { get => basePriority; set => SetField(ref basePriority, value); }
  39. private bool isPrebuilt = true;
  40. public bool IsPrebuilt { get => isPrebuilt; set => SetField(ref isPrebuilt, value); }
  41. private bool sellable;
  42. public bool Sellable { get => sellable; set => SetField(ref sellable, value); }
  43. private bool rebuild;
  44. public bool Rebuild { get => rebuild; set => SetField(ref rebuild, value); }
  45. public ISet<int> BibCells { get; private set; } = new HashSet<int>();
  46. private Color tint = Color.White;
  47. public Color Tint
  48. {
  49. get => IsPrebuilt ? tint : Color.FromArgb((int)(tint.A * 0.75f), tint.R, tint.G, tint.B);
  50. set => tint = value;
  51. }
  52. public Building Clone()
  53. {
  54. return new Building()
  55. {
  56. Type = Type,
  57. House = House,
  58. Strength = Strength,
  59. Direction = Direction,
  60. Trigger = Trigger,
  61. BasePriority = BasePriority,
  62. IsPrebuilt = IsPrebuilt,
  63. Sellable = Sellable,
  64. Rebuild = Rebuild,
  65. Tint = Tint
  66. };
  67. }
  68. protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
  69. {
  70. if (EqualityComparer<T>.Default.Equals(field, value))
  71. {
  72. return false;
  73. }
  74. field = value;
  75. OnPropertyChanged(propertyName);
  76. return true;
  77. }
  78. protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  79. object ICloneable.Clone()
  80. {
  81. return Clone();
  82. }
  83. }
  84. }