CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

Building.cs (3833B)


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