changeset 59:c3415c6df551

Re #60: Add UI to add/remove/edit weapons in GTK * Handle updating of the equipment list on add/remove * Move to a ListStore so that we don't get indentation
author IBBoard <dev@ibboard.co.uk>
date Fri, 27 Aug 2010 10:55:58 +0000
parents 7bba99c368c8
children 04c0f6a7625c
files Widgets/UnitDisplayWidget.cs
diffstat 1 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Widgets/UnitDisplayWidget.cs	Thu Aug 26 19:34:57 2010 +0000
+++ b/Widgets/UnitDisplayWidget.cs	Fri Aug 27 10:55:58 2010 +0000
@@ -12,6 +12,7 @@
 using IBBoard.WarFoundry.GUI.GTK.UIControl;
 using IBBoard.WarFoundry.API.Objects;
 using IBBoard.WarFoundry.API.Util;
+using IBBoard.GtkSharp;
 
 namespace IBBoard.WarFoundry.GTK.Widgets
 {
@@ -38,8 +39,9 @@
 			}
 			
 			unitSize.SetRange(unit.UnitType.MinSize, max);
-			unit.NameChanged+= new StringValChangedDelegate(UnitNameChanged);
-			unit.UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChanged);
+			unit.NameChanged += new StringValChangedDelegate(UnitNameChanged);
+			unit.UnitSizeChanged += new IntValChangedDelegate(UnitSizeChanged);
+			unit.UnitEquipmentAmountChanged += HandleUnitUnitEquipmentAmountChanged;
 			SetStats();
 			SetWeapons();
 		}
@@ -91,8 +93,8 @@
 			CellRendererText renderer = new CellRendererText();
 			equipmentList.AppendColumn("", renderer, new TreeCellDataFunc(RenderEquipmentLine));
 			
+			ListStore model = new ListStore(typeof(UnitEquipmentItem));
 			
-			TreeStore model = new TreeStore(typeof(UnitEquipmentItem));
 			foreach (UnitEquipmentItem item in unit.GetEquipment())
 			{
 				model.AppendValues(item);
@@ -148,7 +150,6 @@
 					amountString = Translation.GetTranslation("equipmentChoiceAmountPercentage", "{0}% ({1})", amount, number);
 				}
 			}
-
 			else
 			{
 				amountString = Translation.GetTranslation("equipmentChoiceAmountNumber", "{0}", amount);
@@ -172,6 +173,21 @@
 			unitSize.Value = newValue;
 		}
 
+		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);
+			}
+			
+			equipmentList.QueueDraw();
+		}
+
 		protected virtual void OnUnitSizeFocusOut (object o, Gtk.FocusOutEventArgs args)
 		{
 			SetNewUnitSize();