changeset 91:986fc923c0fa

Fixes #331: Equipment buttons should be disabled when options aren't available * Edit was already handled via UnitEquipmentUtil call * Added enabling/disabling for Add via extracted methods on AddEquipmentUIControl
author IBBoard <dev@ibboard.co.uk>
date Fri, 31 Dec 2010 11:36:06 +0000
parents a754a2d1881c
children 58779fcd0166
files UIControl/AddEquipmentUIControl.cs Widgets/UnitDisplayWidget.cs
diffstat 2 files changed, 31 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/UIControl/AddEquipmentUIControl.cs	Fri Dec 31 10:54:42 2010 +0000
+++ b/UIControl/AddEquipmentUIControl.cs	Fri Dec 31 11:36:06 2010 +0000
@@ -26,12 +26,21 @@
 		}
 
 		protected override void CompleteUISetup()
-		{			
-			UnitEquipmentItem[] items = Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment());
-			ui.SetUnitEquipmentItems(items);
+		{
+			ui.SetUnitEquipmentItems(GetEquipmentItems(unit));
 			ui.UnitEquipmentItemChoiceChanged += HandleUiUnitEquipmentItemChoiceChanged;
 		}
 
+		public static UnitEquipmentItem[] GetEquipmentItems(Unit unit)
+		{
+			return Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment());
+		}
+
+		public static bool HasEquipmentToAdd(Unit unit)
+		{
+			return GetEquipmentItems(unit).Length > 0;
+		}
+
 		private void HandleUiUnitEquipmentItemChoiceChanged(UnitEquipmentItem equip)
 		{
 			equipItem = equip;
--- a/Widgets/UnitDisplayWidget.cs	Fri Dec 31 10:54:42 2010 +0000
+++ b/Widgets/UnitDisplayWidget.cs	Fri Dec 31 11:36:06 2010 +0000
@@ -45,6 +45,7 @@
 			SetAbilities ();
 			SetStats ();
 			SetWeapons ();
+			SetAddButtonEnabledState();
 		}
 
 		private void HandleEquipmentListSelectionChanged (object sender, EventArgs e)
@@ -60,6 +61,11 @@
 			bttnRemoveEquipment.Sensitive = (equipItem != null && !equipItem.IsRequired);
 		}
 
+		private void SetAddButtonEnabledState()
+		{
+			bttnAddEquipment.Sensitive = AddEquipmentUIControl.HasEquipmentToAdd(unit);
+		}
+
 		private UnitEquipmentItem GetSelectedEquipmentItem ()
 		{
 			return (UnitEquipmentItem)TreeUtils.GetSelectedItem (equipmentList);
@@ -247,16 +253,21 @@
 
 		private void HandleUnitUnitEquipmentAmountChanged (WarFoundryObject obj, double oldValue, double newValue)
 		{
-			if (oldValue == 0) {
-				((ListStore)equipmentList.Model).AppendValues (obj);
-			} else {
-				if (newValue == 0) {
-					TreeIter treeIter = TreeUtils.GetItemIter (equipmentList, obj);
-					((ListStore)equipmentList.Model).Remove (ref treeIter);
+			if (oldValue == 0)
+			{
+				((ListStore)equipmentList.Model).AppendValues(obj);
+			}
+			else
+			{
+				if (newValue == 0)
+				{
+					TreeIter treeIter = TreeUtils.GetItemIter(equipmentList, obj);
+					((ListStore)equipmentList.Model).Remove(ref treeIter);
 				}
+			}
 
-			}			
-			equipmentList.QueueDraw ();
+			SetAddButtonEnabledState();
+			equipmentList.QueueDraw();
 		}
 
 		protected virtual void OnUnitSizeFocusOut (object o, Gtk.FocusOutEventArgs args)