changeset 424:d992758b0150

Re #344: Show unit requirement failures * Add event to Army so we can see when anything that might affect validation changes
author IBBoard <dev@ibboard.co.uk>
date Sat, 15 Oct 2011 16:03:22 +0100
parents 314b8b8bf4f1
children 5b3e3fb11de9
files API/Objects/Army.cs
diffstat 1 files changed, 29 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Army.cs	Wed Oct 12 20:39:28 2011 +0100
     1.2 +++ b/API/Objects/Army.cs	Sat Oct 15 16:03:22 2011 +0100
     1.3 @@ -35,6 +35,7 @@
     1.4  		public event ObjectRemoveDelegate UnitRemoved;
     1.5  		public event IntValChangedDelegate MaxPointsValueChanged;
     1.6  		public event DoubleValChangedDelegate PointsValueChanged;
     1.7 +		public event MethodInvoker ArmyCompositionChanged;
     1.8  		private DoubleValChangedDelegate PointsValueChangedMethod;
     1.9  		
    1.10  		public Army(Race race, string armyName, int maxArmyPoints) : this(race, armyName, maxArmyPoints, null)
    1.11 @@ -240,17 +241,43 @@
    1.12  
    1.13  		private void Army_UnitAdded(WarFoundryObject val)
    1.14  		{
    1.15 -			OnUnitAdded((Unit)val);
    1.16 +			Unit unit = (Unit)val;
    1.17 +			OnUnitAdded(unit);
    1.18 +			OnArmyCompositionChanged();
    1.19 +			unit.UnitEquipmentAmountChanged += HandleUnitUnitEquipmentAmountChanged;
    1.20 +			unit.UnitSizeChanged += HandleUnitUnitSizeChanged;
    1.21  		}
    1.22  
    1.23  		private void Army_UnitRemoved(WarFoundryObject val)
    1.24  		{
    1.25 -			OnUnitRemoved((Unit)val);
    1.26 +			Unit unit = (Unit)val;
    1.27 +			OnUnitRemoved(unit);
    1.28 +			OnArmyCompositionChanged();
    1.29 +			unit.UnitEquipmentAmountChanged -= HandleUnitUnitEquipmentAmountChanged;
    1.30 +			unit.UnitSizeChanged -= HandleUnitUnitSizeChanged;
    1.31 +		}
    1.32 +
    1.33 +		private void HandleUnitUnitEquipmentAmountChanged (WarFoundryObject obj, double oldValue, double newValue)
    1.34 +		{
    1.35 +			OnArmyCompositionChanged();
    1.36 +		}
    1.37 +
    1.38 +		private void HandleUnitUnitSizeChanged (WarFoundryObject obj, int oldValue, int newValue)
    1.39 +		{
    1.40 +			OnArmyCompositionChanged();
    1.41  		}
    1.42  
    1.43  		public ICollection<IRequirement> GetRequirements ()
    1.44  		{
    1.45  			return Race.GetRequirements();
    1.46  		}
    1.47 +
    1.48 +		internal void OnArmyCompositionChanged()
    1.49 +		{
    1.50 +			if (ArmyCompositionChanged != null)
    1.51 +			{
    1.52 +				ArmyCompositionChanged();
    1.53 +			}
    1.54 +		}
    1.55  	}
    1.56  }