diff FrmAddEquipment.cs @ 63:c2d79b4209e3

* FrmAddEquipment.cs: Re #60: Add UI to add/remove/edit weapons in GTK * Cache more values in the controller so that we don't rely on the UI as a the model/data store * Move enable/disable of amount controls to controller (assumes minimum numeric and percentage, so implementation has its own custom implementation to handle "Equip All") * AddEquipmentUIControl.cs: * IAddEquipmentUI.cs:
author IBBoard <dev@ibboard.co.uk>
date Mon, 30 Aug 2010 19:44:35 +0000
parents f733073967a2
children 4b82515586ac
line wrap: on
line diff
--- a/FrmAddEquipment.cs	Sun Aug 29 15:44:20 2010 +0000
+++ b/FrmAddEquipment.cs	Mon Aug 30 19:44:35 2010 +0000
@@ -92,40 +92,12 @@
 			{
 				rbEquipNumeric.Active = true;
 			}
-			
-			SetEnabledState();
 		}
 
 		public void SetUnitEquipmentLimitsEnabled(bool isEnabled)
 		{
-			limitsEnabled = isEnabled;
-			SetEnabledState();
-		}
-		
-		private void SetEnabledState()
-		{
-			rbEquipNumeric.Sensitive = (limitsEnabled && !ratioLimited);
-			numericAmount.Sensitive = (limitsEnabled && !ratioLimited);
-			double minPercentage = GetMinPercentage();
-			rbEquipPercent.Sensitive = limitsEnabled && minPercentage != 100;
-			percentageAmount.Sensitive = limitsEnabled && minPercentage != 100;
-			double maxPercentage = GetMaxPercentage();
-			rbEquipAll.Sensitive = limitsEnabled && ratioLimited && maxPercentage == 100;
-			lblEquipAll.Sensitive = limitsEnabled && ratioLimited && maxPercentage == 100;
-		}
-		
-		private double GetMaxPercentage()
-		{
-			double min, max;
-			percentageAmount.GetRange(out min, out max);
-			return max;
-		}
-
-		private double GetMinPercentage()
-		{
-			double min, max;
-			percentageAmount.GetRange(out min, out max);
-			return min;
+			SetNumericAmountEnabledState(isEnabled);
+			SetPercentageAmountEnabledState(isEnabled);
 		}
 
 		public bool ShowControl()
@@ -163,6 +135,45 @@
 			OnUnitEquipmentAmountTypeChanged();
 		}
 		
+		public void SetNumericAmountEnabledState (bool enabled)
+		{
+			rbEquipNumeric.Sensitive = enabled;
+			numericAmount.Sensitive = enabled;
+		}		
+		
+		public void SetPercentageAmountEnabledState(bool enabled)
+		{
+			if (enabled)
+			{
+				double minPercentage = GetMinPercentage();
+				rbEquipPercent.Sensitive = minPercentage != 100;
+				percentageAmount.Sensitive = minPercentage != 100;
+				double maxPercentage = GetMaxPercentage();
+				rbEquipAll.Sensitive = ratioLimited && maxPercentage == 100;
+				lblEquipAll.Sensitive = ratioLimited && maxPercentage == 100;
+			}
+			else
+			{
+				rbEquipPercent.Sensitive = false;
+				percentageAmount.Sensitive = false;
+				rbEquipAll.Sensitive = false;
+				lblEquipAll.Sensitive = false;
+			}
+		}
+
+		private double GetMaxPercentage()
+		{
+			double min, max;
+			percentageAmount.GetRange(out min, out max);
+			return max;
+		}
+
+		private double GetMinPercentage()
+		{
+			double min, max;
+			percentageAmount.GetRange(out min, out max);
+			return min;
+		}
 		
 		public UnitEquipmentItem SelectedUnitEquipmentItem
 		{