diff FrmAddEquipment.cs @ 57:293d204e40db

Re #60: Add UI to add/remove/edit weapons in GTK * Make enabling/disabling fit the values passed (copied from existing WinForms checks) * Add extra interface methods and properties to get necessary values from UI to use in command * Implement new interface methods * Implement command execution * Make use of IDisposable interface instead of defining Dispose ourselves Also: * Use existing method of printing exception stack traces in main window
author IBBoard <dev@ibboard.co.uk>
date Thu, 26 Aug 2010 19:30:22 +0000
parents 0c5fbb54bfb0
children e7ad676a7344
line wrap: on
line diff
--- a/FrmAddEquipment.cs	Wed Aug 25 20:04:27 2010 +0000
+++ b/FrmAddEquipment.cs	Thu Aug 26 19:30:22 2010 +0000
@@ -36,7 +36,7 @@
 		{
 			if (UnitEquipmentItemChoiceChanged!=null)
 			{
-				UnitEquipmentItemChoiceChanged((UnitEquipmentItem)TreeUtils.GetSelectedItem(lstEquipment));
+				UnitEquipmentItemChoiceChanged(SelectedUnitEquipmentItem);
 			}
 		}
 
@@ -69,12 +69,28 @@
 		
 		private void SetEnabledState()
 		{
-			rbEquipNumeric.Sensitive = (limitsEnabled && ratioLimited);
-			numericAmount.Sensitive = (limitsEnabled && ratioLimited);
-			rbEquipPercent.Sensitive = limitsEnabled;
-			percentageAmount.Sensitive = limitsEnabled;
-			rbEquipAll.Sensitive = limitsEnabled;
-			lblEquipAll.Sensitive = limitsEnabled;
+			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 && maxPercentage == 100;
+			lblEquipAll.Sensitive = limitsEnabled && 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;
 		}
 
 		public bool ShowControl()
@@ -96,6 +112,52 @@
 			log.Debug("Okay clicked");
 			Respond(ResponseType.Ok);
 		}		
+		
+		public UnitEquipmentItem SelectedUnitEquipmentItem
+		{
+			get
+			{
+				return (UnitEquipmentItem)TreeUtils.GetSelectedItem(lstEquipment);
+			}
+		}
+		
+		
+		public bool IsRatioEquipmentAmount
+		{
+			get
+			{
+				return !rbEquipNumeric.Active;
+			}
+		}
+		
+		
+		public int EquipmentNumericAmount
+		{
+			get
+			{
+				return (int)numericAmount.Value;
+			}
+		}
+		
+		
+		public double EquipmentPercentageAmount
+		{
+			get
+			{
+				double percent;
+				
+				if (rbEquipAll.Active)
+				{
+					percent = 100;
+				}
+				else
+				{
+					percent = percentageAmount.Value;
+				}
+				
+				return percent;
+			}
+		}
 	}
 }