comparison Widgets/UnitDisplayWidget.cs @ 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
comparison
equal deleted inserted replaced
58:7bba99c368c8 59:c3415c6df551
10 using WFObjects = IBBoard.WarFoundry.API.Objects; 10 using WFObjects = IBBoard.WarFoundry.API.Objects;
11 using IBBoard.WarFoundry.API.Commands; 11 using IBBoard.WarFoundry.API.Commands;
12 using IBBoard.WarFoundry.GUI.GTK.UIControl; 12 using IBBoard.WarFoundry.GUI.GTK.UIControl;
13 using IBBoard.WarFoundry.API.Objects; 13 using IBBoard.WarFoundry.API.Objects;
14 using IBBoard.WarFoundry.API.Util; 14 using IBBoard.WarFoundry.API.Util;
15 using IBBoard.GtkSharp;
15 16
16 namespace IBBoard.WarFoundry.GTK.Widgets 17 namespace IBBoard.WarFoundry.GTK.Widgets
17 { 18 {
18 [System.ComponentModel.Category("WarFoundry GTK# GUI")] 19 [System.ComponentModel.Category("WarFoundry GTK# GUI")]
19 [System.ComponentModel.ToolboxItem(true)] 20 [System.ComponentModel.ToolboxItem(true)]
36 { 37 {
37 max = double.MaxValue; 38 max = double.MaxValue;
38 } 39 }
39 40
40 unitSize.SetRange(unit.UnitType.MinSize, max); 41 unitSize.SetRange(unit.UnitType.MinSize, max);
41 unit.NameChanged+= new StringValChangedDelegate(UnitNameChanged); 42 unit.NameChanged += new StringValChangedDelegate(UnitNameChanged);
42 unit.UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChanged); 43 unit.UnitSizeChanged += new IntValChangedDelegate(UnitSizeChanged);
44 unit.UnitEquipmentAmountChanged += HandleUnitUnitEquipmentAmountChanged;
43 SetStats(); 45 SetStats();
44 SetWeapons(); 46 SetWeapons();
45 } 47 }
46 48
47 private void SetStats() 49 private void SetStats()
89 private void SetWeapons() 91 private void SetWeapons()
90 { 92 {
91 CellRendererText renderer = new CellRendererText(); 93 CellRendererText renderer = new CellRendererText();
92 equipmentList.AppendColumn("", renderer, new TreeCellDataFunc(RenderEquipmentLine)); 94 equipmentList.AppendColumn("", renderer, new TreeCellDataFunc(RenderEquipmentLine));
93 95
94 96 ListStore model = new ListStore(typeof(UnitEquipmentItem));
95 TreeStore model = new TreeStore(typeof(UnitEquipmentItem)); 97
96 foreach (UnitEquipmentItem item in unit.GetEquipment()) 98 foreach (UnitEquipmentItem item in unit.GetEquipment())
97 { 99 {
98 model.AppendValues(item); 100 model.AppendValues(item);
99 } 101 }
100 102
146 else 148 else
147 { 149 {
148 amountString = Translation.GetTranslation("equipmentChoiceAmountPercentage", "{0}% ({1})", amount, number); 150 amountString = Translation.GetTranslation("equipmentChoiceAmountPercentage", "{0}% ({1})", amount, number);
149 } 151 }
150 } 152 }
151
152 else 153 else
153 { 154 {
154 amountString = Translation.GetTranslation("equipmentChoiceAmountNumber", "{0}", amount); 155 amountString = Translation.GetTranslation("equipmentChoiceAmountNumber", "{0}", amount);
155 } 156 }
156 157
168 } 169 }
169 170
170 private void UnitSizeChanged(WarFoundryObject obj, int oldValue, int newValue) 171 private void UnitSizeChanged(WarFoundryObject obj, int oldValue, int newValue)
171 { 172 {
172 unitSize.Value = newValue; 173 unitSize.Value = newValue;
174 }
175
176 private void HandleUnitUnitEquipmentAmountChanged(WarFoundryObject obj, double oldValue, double newValue)
177 {
178 if (oldValue == 0)
179 {
180 ((ListStore)equipmentList.Model).AppendValues(obj);
181 }
182 else if (newValue == 0)
183 {
184 TreeIter treeIter = TreeUtils.GetItemIter(equipmentList, obj);
185 ((ListStore)equipmentList.Model).Remove(ref treeIter);
186 }
187
188 equipmentList.QueueDraw();
173 } 189 }
174 190
175 protected virtual void OnUnitSizeFocusOut (object o, Gtk.FocusOutEventArgs args) 191 protected virtual void OnUnitSizeFocusOut (object o, Gtk.FocusOutEventArgs args)
176 { 192 {
177 SetNewUnitSize(); 193 SetNewUnitSize();