Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
changeset 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 | e7ad676a7344 |
files | Widgets/UnitDisplayWidget.cs gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs gtk-gui/gui.stetic |
diffstat | 3 files changed, 45 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/Widgets/UnitDisplayWidget.cs Fri Aug 27 10:55:58 2010 +0000 +++ b/Widgets/UnitDisplayWidget.cs Fri Aug 27 14:44:48 2010 +0000 @@ -13,13 +13,16 @@ using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Util; using IBBoard.GtkSharp; +using log4net; namespace IBBoard.WarFoundry.GTK.Widgets { [System.ComponentModel.Category("WarFoundry GTK# GUI")] [System.ComponentModel.ToolboxItem(true)] public partial class UnitDisplayWidget : Gtk.Bin - { + { + private static ILog log = LogManager.GetLogger(typeof(UnitDisplayWidget)); + private WFObjects.Unit unit; private CommandStack stack; @@ -30,22 +33,35 @@ unit = sourceUnit; unitName.Text = unit.Name; unitSize.Value = unit.Size; + int maxSize = (unit.UnitType.MaxSize == WarFoundryCore.INFINITY ? int.MaxValue : unit.UnitType.MaxSize); + int minSize = unit.UnitType.MinSize; + unitSize.SetRange(minSize, maxSize); + unitSize.Sensitive = (maxSize != minSize); notesView.Buffer.Text = unit.UnitType.Notes; - double max = unit.UnitType.MaxSize; - - if (max == -1) - { - max = double.MaxValue; - } - - unitSize.SetRange(unit.UnitType.MinSize, max); - unit.NameChanged += new StringValChangedDelegate(UnitNameChanged); - unit.UnitSizeChanged += new IntValChangedDelegate(UnitSizeChanged); + unit.NameChanged += UnitNameChanged; + unit.UnitSizeChanged += UnitSizeChanged; unit.UnitEquipmentAmountChanged += HandleUnitUnitEquipmentAmountChanged; + equipmentList.Selection.Changed += HandleEquipmentListSelectionChanged; SetStats(); SetWeapons(); } + private void HandleEquipmentListSelectionChanged (object sender, EventArgs e) + { + SetButtonsEnabledState(); + } + private void SetButtonsEnabledState() + { + UnitEquipmentItem equipItem = GetSelectedEquipmentItem(); + bttnReplaceEquipment.Sensitive = (equipItem != null && equipItem.HasAlternatives()); + bttnEditEquipment.Sensitive = (equipItem != null); + bttnRemoveEquipment.Sensitive = (equipItem != null && !equipItem.IsRequired); + } + private UnitEquipmentItem GetSelectedEquipmentItem() + { + return (UnitEquipmentItem)TreeUtils.GetSelectedItem(equipmentList); + } + private void SetStats() { CellRendererText renderer = new CellRendererText(); @@ -244,5 +260,17 @@ AddEquipmentUIControl addEquipment = new AddEquipmentUIControl(unit, stack); addEquipment.Show(); } + + protected virtual void HandleRemoveButtonActivated(object sender, System.EventArgs e) + { + UnitEquipmentItem item = GetSelectedEquipmentItem(); + log.Debug("Remove "+item); + + if (item != null) + { + SetUnitEquipmentNumericAmountCommand cmd = new SetUnitEquipmentNumericAmountCommand(unit, item, 0); + stack.Execute(cmd); + } + } } }
--- a/gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs Fri Aug 27 10:55:58 2010 +0000 +++ b/gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs Fri Aug 27 14:44:48 2010 +0000 @@ -124,6 +124,7 @@ this.equipmentList = new global::Gtk.NodeView(); this.equipmentList.CanFocus = true; this.equipmentList.Name = "equipmentList"; + this.equipmentList.HeadersVisible = false; this.GtkScrolledWindow2.Add(this.equipmentList); this.table1.Add(this.GtkScrolledWindow2); global::Gtk.Table.TableChild w9 = ((global::Gtk.Table.TableChild)(this.table1[this.GtkScrolledWindow2])); @@ -227,6 +228,7 @@ this.unitSize.FocusOutEvent += new global::Gtk.FocusOutEventHandler(this.OnUnitSizeFocusOut); this.unitSize.KeyPressEvent += new global::Gtk.KeyPressEventHandler(this.OnUnitSizeKeyPress); this.bttnAddEquipment.Clicked += new global::System.EventHandler(this.OnBttnAddEquipmentClicked); + this.bttnRemoveEquipment.Clicked += new global::System.EventHandler(this.HandleRemoveButtonActivated); } } }
--- a/gtk-gui/gui.stetic Fri Aug 27 10:55:58 2010 +0000 +++ b/gtk-gui/gui.stetic Fri Aug 27 14:44:48 2010 +0000 @@ -894,6 +894,7 @@ <child> <widget class="Gtk.Button" id="bttnEditEquipment"> <property name="MemberName" /> + <property name="Sensitive">False</property> <property name="CanFocus">True</property> <property name="Type">TextOnly</property> <property name="Label" translatable="yes">Edit</property> @@ -909,6 +910,7 @@ <child> <widget class="Gtk.Button" id="bttnReplaceEquipment"> <property name="MemberName" /> + <property name="Sensitive">False</property> <property name="CanFocus">True</property> <property name="Type">TextOnly</property> <property name="Label" translatable="yes">Replace</property> @@ -924,10 +926,12 @@ <child> <widget class="Gtk.Button" id="bttnRemoveEquipment"> <property name="MemberName" /> + <property name="Sensitive">False</property> <property name="CanFocus">True</property> <property name="Type">TextOnly</property> <property name="Label" translatable="yes">Remove</property> <property name="UseUnderline">True</property> + <signal name="Clicked" handler="HandleRemoveButtonActivated" /> </widget> <packing> <property name="Position">3</property> @@ -1117,7 +1121,6 @@ <property name="MemberName" /> <property name="CanFocus">True</property> <property name="Label" translatable="yes" /> - <property name="Active">True</property> <property name="DrawIndicator">True</property> <property name="HasLabel">True</property> <property name="UseUnderline">True</property>