Unit.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 Unit : ICellOverlapper, ICellOccupier, INotifyPropertyChanged, ICloneable
  23. {
  24. public event PropertyChangedEventHandler PropertyChanged;
  25. private UnitType type;
  26. public UnitType 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 mission;
  36. public string Mission { get => mission; set => SetField(ref mission, value); }
  37. private string trigger = Model.Trigger.None;
  38. public string Trigger { get => trigger; set => SetField(ref trigger, value); }
  39. public Color Tint { get; set; } = Color.White;
  40. public Unit Clone()
  41. {
  42. return new Unit()
  43. {
  44. Type = Type,
  45. House = House,
  46. Strength = Strength,
  47. Direction = Direction,
  48. Mission = Mission,
  49. Trigger = Trigger
  50. };
  51. }
  52. protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
  53. {
  54. if (EqualityComparer<T>.Default.Equals(field, value))
  55. {
  56. return false;
  57. }
  58. field = value;
  59. OnPropertyChanged(propertyName);
  60. return true;
  61. }
  62. protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  63. object ICloneable.Clone()
  64. {
  65. return Clone();
  66. }
  67. }
  68. }