Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
comparison Widgets/UnitDisplayWidget.cs @ 60:04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
* Implement Remove button
* Hack "code-behind" file again to make things work, until MD bug is fixed
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 27 Aug 2010 14:44:48 +0000 |
parents | c3415c6df551 |
children | e3fe48c4d794 |
comparison
equal
deleted
inserted
replaced
59:c3415c6df551 | 60:04c0f6a7625c |
---|---|
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 using IBBoard.GtkSharp; |
16 using log4net; | |
16 | 17 |
17 namespace IBBoard.WarFoundry.GTK.Widgets | 18 namespace IBBoard.WarFoundry.GTK.Widgets |
18 { | 19 { |
19 [System.ComponentModel.Category("WarFoundry GTK# GUI")] | 20 [System.ComponentModel.Category("WarFoundry GTK# GUI")] |
20 [System.ComponentModel.ToolboxItem(true)] | 21 [System.ComponentModel.ToolboxItem(true)] |
21 public partial class UnitDisplayWidget : Gtk.Bin | 22 public partial class UnitDisplayWidget : Gtk.Bin |
22 { | 23 { |
24 private static ILog log = LogManager.GetLogger(typeof(UnitDisplayWidget)); | |
25 | |
23 private WFObjects.Unit unit; | 26 private WFObjects.Unit unit; |
24 private CommandStack stack; | 27 private CommandStack stack; |
25 | 28 |
26 public UnitDisplayWidget(WFObjects.Unit sourceUnit, CommandStack commandStack) | 29 public UnitDisplayWidget(WFObjects.Unit sourceUnit, CommandStack commandStack) |
27 { | 30 { |
28 this.Build(); | 31 this.Build(); |
29 stack = commandStack; | 32 stack = commandStack; |
30 unit = sourceUnit; | 33 unit = sourceUnit; |
31 unitName.Text = unit.Name; | 34 unitName.Text = unit.Name; |
32 unitSize.Value = unit.Size; | 35 unitSize.Value = unit.Size; |
36 int maxSize = (unit.UnitType.MaxSize == WarFoundryCore.INFINITY ? int.MaxValue : unit.UnitType.MaxSize); | |
37 int minSize = unit.UnitType.MinSize; | |
38 unitSize.SetRange(minSize, maxSize); | |
39 unitSize.Sensitive = (maxSize != minSize); | |
33 notesView.Buffer.Text = unit.UnitType.Notes; | 40 notesView.Buffer.Text = unit.UnitType.Notes; |
34 double max = unit.UnitType.MaxSize; | 41 unit.NameChanged += UnitNameChanged; |
35 | 42 unit.UnitSizeChanged += UnitSizeChanged; |
36 if (max == -1) | |
37 { | |
38 max = double.MaxValue; | |
39 } | |
40 | |
41 unitSize.SetRange(unit.UnitType.MinSize, max); | |
42 unit.NameChanged += new StringValChangedDelegate(UnitNameChanged); | |
43 unit.UnitSizeChanged += new IntValChangedDelegate(UnitSizeChanged); | |
44 unit.UnitEquipmentAmountChanged += HandleUnitUnitEquipmentAmountChanged; | 43 unit.UnitEquipmentAmountChanged += HandleUnitUnitEquipmentAmountChanged; |
44 equipmentList.Selection.Changed += HandleEquipmentListSelectionChanged; | |
45 SetStats(); | 45 SetStats(); |
46 SetWeapons(); | 46 SetWeapons(); |
47 } | |
48 | |
49 private void HandleEquipmentListSelectionChanged (object sender, EventArgs e) | |
50 { | |
51 SetButtonsEnabledState(); | |
52 } | |
53 private void SetButtonsEnabledState() | |
54 { | |
55 UnitEquipmentItem equipItem = GetSelectedEquipmentItem(); | |
56 bttnReplaceEquipment.Sensitive = (equipItem != null && equipItem.HasAlternatives()); | |
57 bttnEditEquipment.Sensitive = (equipItem != null); | |
58 bttnRemoveEquipment.Sensitive = (equipItem != null && !equipItem.IsRequired); | |
59 } | |
60 private UnitEquipmentItem GetSelectedEquipmentItem() | |
61 { | |
62 return (UnitEquipmentItem)TreeUtils.GetSelectedItem(equipmentList); | |
47 } | 63 } |
48 | 64 |
49 private void SetStats() | 65 private void SetStats() |
50 { | 66 { |
51 CellRendererText renderer = new CellRendererText(); | 67 CellRendererText renderer = new CellRendererText(); |
242 private void AddEquipment() | 258 private void AddEquipment() |
243 { | 259 { |
244 AddEquipmentUIControl addEquipment = new AddEquipmentUIControl(unit, stack); | 260 AddEquipmentUIControl addEquipment = new AddEquipmentUIControl(unit, stack); |
245 addEquipment.Show(); | 261 addEquipment.Show(); |
246 } | 262 } |
263 | |
264 protected virtual void HandleRemoveButtonActivated(object sender, System.EventArgs e) | |
265 { | |
266 UnitEquipmentItem item = GetSelectedEquipmentItem(); | |
267 log.Debug("Remove "+item); | |
268 | |
269 if (item != null) | |
270 { | |
271 SetUnitEquipmentNumericAmountCommand cmd = new SetUnitEquipmentNumericAmountCommand(unit, item, 0); | |
272 stack.Execute(cmd); | |
273 } | |
274 } | |
247 } | 275 } |
248 } | 276 } |