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 wrap: on
line diff
--- a/API/Objects/Army.cs	Wed Oct 12 20:39:28 2011 +0100
+++ b/API/Objects/Army.cs	Sat Oct 15 16:03:22 2011 +0100
@@ -35,6 +35,7 @@
 		public event ObjectRemoveDelegate UnitRemoved;
 		public event IntValChangedDelegate MaxPointsValueChanged;
 		public event DoubleValChangedDelegate PointsValueChanged;
+		public event MethodInvoker ArmyCompositionChanged;
 		private DoubleValChangedDelegate PointsValueChangedMethod;
 		
 		public Army(Race race, string armyName, int maxArmyPoints) : this(race, armyName, maxArmyPoints, null)
@@ -240,17 +241,43 @@
 
 		private void Army_UnitAdded(WarFoundryObject val)
 		{
-			OnUnitAdded((Unit)val);
+			Unit unit = (Unit)val;
+			OnUnitAdded(unit);
+			OnArmyCompositionChanged();
+			unit.UnitEquipmentAmountChanged += HandleUnitUnitEquipmentAmountChanged;
+			unit.UnitSizeChanged += HandleUnitUnitSizeChanged;
 		}
 
 		private void Army_UnitRemoved(WarFoundryObject val)
 		{
-			OnUnitRemoved((Unit)val);
+			Unit unit = (Unit)val;
+			OnUnitRemoved(unit);
+			OnArmyCompositionChanged();
+			unit.UnitEquipmentAmountChanged -= HandleUnitUnitEquipmentAmountChanged;
+			unit.UnitSizeChanged -= HandleUnitUnitSizeChanged;
+		}
+
+		private void HandleUnitUnitEquipmentAmountChanged (WarFoundryObject obj, double oldValue, double newValue)
+		{
+			OnArmyCompositionChanged();
+		}
+
+		private void HandleUnitUnitSizeChanged (WarFoundryObject obj, int oldValue, int newValue)
+		{
+			OnArmyCompositionChanged();
 		}
 
 		public ICollection<IRequirement> GetRequirements ()
 		{
 			return Race.GetRequirements();
 		}
+
+		internal void OnArmyCompositionChanged()
+		{
+			if (ArmyCompositionChanged != null)
+			{
+				ArmyCompositionChanged();
+			}
+		}
 	}
 }