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 diff
     1.1 --- a/Widgets/UnitDisplayWidget.cs	Thu Aug 26 19:34:57 2010 +0000
     1.2 +++ b/Widgets/UnitDisplayWidget.cs	Fri Aug 27 10:55:58 2010 +0000
     1.3 @@ -12,6 +12,7 @@
     1.4  using IBBoard.WarFoundry.GUI.GTK.UIControl;
     1.5  using IBBoard.WarFoundry.API.Objects;
     1.6  using IBBoard.WarFoundry.API.Util;
     1.7 +using IBBoard.GtkSharp;
     1.8  
     1.9  namespace IBBoard.WarFoundry.GTK.Widgets
    1.10  {
    1.11 @@ -38,8 +39,9 @@
    1.12  			}
    1.13  			
    1.14  			unitSize.SetRange(unit.UnitType.MinSize, max);
    1.15 -			unit.NameChanged+= new StringValChangedDelegate(UnitNameChanged);
    1.16 -			unit.UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChanged);
    1.17 +			unit.NameChanged += new StringValChangedDelegate(UnitNameChanged);
    1.18 +			unit.UnitSizeChanged += new IntValChangedDelegate(UnitSizeChanged);
    1.19 +			unit.UnitEquipmentAmountChanged += HandleUnitUnitEquipmentAmountChanged;
    1.20  			SetStats();
    1.21  			SetWeapons();
    1.22  		}
    1.23 @@ -91,8 +93,8 @@
    1.24  			CellRendererText renderer = new CellRendererText();
    1.25  			equipmentList.AppendColumn("", renderer, new TreeCellDataFunc(RenderEquipmentLine));
    1.26  			
    1.27 +			ListStore model = new ListStore(typeof(UnitEquipmentItem));
    1.28  			
    1.29 -			TreeStore model = new TreeStore(typeof(UnitEquipmentItem));
    1.30  			foreach (UnitEquipmentItem item in unit.GetEquipment())
    1.31  			{
    1.32  				model.AppendValues(item);
    1.33 @@ -148,7 +150,6 @@
    1.34  					amountString = Translation.GetTranslation("equipmentChoiceAmountPercentage", "{0}% ({1})", amount, number);
    1.35  				}
    1.36  			}
    1.37 -
    1.38  			else
    1.39  			{
    1.40  				amountString = Translation.GetTranslation("equipmentChoiceAmountNumber", "{0}", amount);
    1.41 @@ -172,6 +173,21 @@
    1.42  			unitSize.Value = newValue;
    1.43  		}
    1.44  
    1.45 +		private void HandleUnitUnitEquipmentAmountChanged(WarFoundryObject obj, double oldValue, double newValue)
    1.46 +		{
    1.47 +			if (oldValue == 0)
    1.48 +			{
    1.49 +				((ListStore)equipmentList.Model).AppendValues(obj);
    1.50 +			}
    1.51 +			else if (newValue == 0)
    1.52 +			{
    1.53 +				TreeIter treeIter = TreeUtils.GetItemIter(equipmentList, obj);
    1.54 +				((ListStore)equipmentList.Model).Remove(ref treeIter);
    1.55 +			}
    1.56 +			
    1.57 +			equipmentList.QueueDraw();
    1.58 +		}
    1.59 +
    1.60  		protected virtual void OnUnitSizeFocusOut (object o, Gtk.FocusOutEventArgs args)
    1.61  		{
    1.62  			SetNewUnitSize();