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 diff
     1.1 --- a/Widgets/UnitDisplayWidget.cs	Fri Aug 27 10:55:58 2010 +0000
     1.2 +++ b/Widgets/UnitDisplayWidget.cs	Fri Aug 27 14:44:48 2010 +0000
     1.3 @@ -13,13 +13,16 @@
     1.4  using IBBoard.WarFoundry.API.Objects;
     1.5  using IBBoard.WarFoundry.API.Util;
     1.6  using IBBoard.GtkSharp;
     1.7 +using log4net;
     1.8  
     1.9  namespace IBBoard.WarFoundry.GTK.Widgets
    1.10  {
    1.11  	[System.ComponentModel.Category("WarFoundry GTK# GUI")]
    1.12  	[System.ComponentModel.ToolboxItem(true)]
    1.13  	public partial class UnitDisplayWidget : Gtk.Bin
    1.14 -	{		
    1.15 +	{
    1.16 +		private static ILog log = LogManager.GetLogger(typeof(UnitDisplayWidget));
    1.17 +		
    1.18  		private WFObjects.Unit unit;
    1.19  		private CommandStack stack;
    1.20  		
    1.21 @@ -30,22 +33,35 @@
    1.22  			unit = sourceUnit;
    1.23  			unitName.Text = unit.Name;
    1.24  			unitSize.Value = unit.Size;
    1.25 +			int maxSize = (unit.UnitType.MaxSize == WarFoundryCore.INFINITY ? int.MaxValue : unit.UnitType.MaxSize);
    1.26 +			int minSize = unit.UnitType.MinSize;
    1.27 +			unitSize.SetRange(minSize, maxSize);
    1.28 +			unitSize.Sensitive = (maxSize != minSize);
    1.29  			notesView.Buffer.Text = unit.UnitType.Notes;
    1.30 -			double max = unit.UnitType.MaxSize;
    1.31 -			
    1.32 -			if (max == -1)
    1.33 -			{
    1.34 -				max = double.MaxValue;
    1.35 -			}
    1.36 -			
    1.37 -			unitSize.SetRange(unit.UnitType.MinSize, max);
    1.38 -			unit.NameChanged += new StringValChangedDelegate(UnitNameChanged);
    1.39 -			unit.UnitSizeChanged += new IntValChangedDelegate(UnitSizeChanged);
    1.40 +			unit.NameChanged += UnitNameChanged;
    1.41 +			unit.UnitSizeChanged += UnitSizeChanged;
    1.42  			unit.UnitEquipmentAmountChanged += HandleUnitUnitEquipmentAmountChanged;
    1.43 +			equipmentList.Selection.Changed += HandleEquipmentListSelectionChanged;
    1.44  			SetStats();
    1.45  			SetWeapons();
    1.46  		}
    1.47  
    1.48 +		private void HandleEquipmentListSelectionChanged (object sender, EventArgs e)
    1.49 +		{
    1.50 +			SetButtonsEnabledState();	
    1.51 +		}
    1.52 +		private void SetButtonsEnabledState()
    1.53 +		{			
    1.54 +			UnitEquipmentItem equipItem = GetSelectedEquipmentItem();
    1.55 +			bttnReplaceEquipment.Sensitive = (equipItem != null && equipItem.HasAlternatives());
    1.56 +			bttnEditEquipment.Sensitive = (equipItem != null);
    1.57 +			bttnRemoveEquipment.Sensitive = (equipItem != null && !equipItem.IsRequired);
    1.58 +		}
    1.59 +		private UnitEquipmentItem GetSelectedEquipmentItem()
    1.60 +		{
    1.61 +			return (UnitEquipmentItem)TreeUtils.GetSelectedItem(equipmentList);
    1.62 +		}
    1.63 +
    1.64  		private void SetStats()
    1.65  		{
    1.66              CellRendererText renderer = new CellRendererText();
    1.67 @@ -244,5 +260,17 @@
    1.68  			AddEquipmentUIControl addEquipment = new AddEquipmentUIControl(unit, stack);
    1.69  			addEquipment.Show();
    1.70  		}
    1.71 +		
    1.72 +		protected virtual void HandleRemoveButtonActivated(object sender, System.EventArgs e)
    1.73 +		{
    1.74 +			UnitEquipmentItem item = GetSelectedEquipmentItem();
    1.75 +			log.Debug("Remove "+item);
    1.76 +				
    1.77 +			if (item != null)
    1.78 +			{
    1.79 +				SetUnitEquipmentNumericAmountCommand cmd = new SetUnitEquipmentNumericAmountCommand(unit, item, 0);
    1.80 +				stack.Execute(cmd);
    1.81 +			}
    1.82 +		}		
    1.83  	}
    1.84  }
     2.1 --- a/gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs	Fri Aug 27 10:55:58 2010 +0000
     2.2 +++ b/gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs	Fri Aug 27 14:44:48 2010 +0000
     2.3 @@ -124,6 +124,7 @@
     2.4  			this.equipmentList = new global::Gtk.NodeView();
     2.5  			this.equipmentList.CanFocus = true;
     2.6  			this.equipmentList.Name = "equipmentList";
     2.7 +			this.equipmentList.HeadersVisible = false;
     2.8  			this.GtkScrolledWindow2.Add(this.equipmentList);
     2.9  			this.table1.Add(this.GtkScrolledWindow2);
    2.10  			global::Gtk.Table.TableChild w9 = ((global::Gtk.Table.TableChild)(this.table1[this.GtkScrolledWindow2]));
    2.11 @@ -227,6 +228,7 @@
    2.12  			this.unitSize.FocusOutEvent += new global::Gtk.FocusOutEventHandler(this.OnUnitSizeFocusOut);
    2.13  			this.unitSize.KeyPressEvent += new global::Gtk.KeyPressEventHandler(this.OnUnitSizeKeyPress);
    2.14  			this.bttnAddEquipment.Clicked += new global::System.EventHandler(this.OnBttnAddEquipmentClicked);
    2.15 +			this.bttnRemoveEquipment.Clicked += new global::System.EventHandler(this.HandleRemoveButtonActivated);
    2.16  		}
    2.17  	}
    2.18  }
     3.1 --- a/gtk-gui/gui.stetic	Fri Aug 27 10:55:58 2010 +0000
     3.2 +++ b/gtk-gui/gui.stetic	Fri Aug 27 14:44:48 2010 +0000
     3.3 @@ -894,6 +894,7 @@
     3.4                  <child>
     3.5                    <widget class="Gtk.Button" id="bttnEditEquipment">
     3.6                      <property name="MemberName" />
     3.7 +                    <property name="Sensitive">False</property>
     3.8                      <property name="CanFocus">True</property>
     3.9                      <property name="Type">TextOnly</property>
    3.10                      <property name="Label" translatable="yes">Edit</property>
    3.11 @@ -909,6 +910,7 @@
    3.12                  <child>
    3.13                    <widget class="Gtk.Button" id="bttnReplaceEquipment">
    3.14                      <property name="MemberName" />
    3.15 +                    <property name="Sensitive">False</property>
    3.16                      <property name="CanFocus">True</property>
    3.17                      <property name="Type">TextOnly</property>
    3.18                      <property name="Label" translatable="yes">Replace</property>
    3.19 @@ -924,10 +926,12 @@
    3.20                  <child>
    3.21                    <widget class="Gtk.Button" id="bttnRemoveEquipment">
    3.22                      <property name="MemberName" />
    3.23 +                    <property name="Sensitive">False</property>
    3.24                      <property name="CanFocus">True</property>
    3.25                      <property name="Type">TextOnly</property>
    3.26                      <property name="Label" translatable="yes">Remove</property>
    3.27                      <property name="UseUnderline">True</property>
    3.28 +                    <signal name="Clicked" handler="HandleRemoveButtonActivated" />
    3.29                    </widget>
    3.30                    <packing>
    3.31                      <property name="Position">3</property>
    3.32 @@ -1117,7 +1121,6 @@
    3.33                          <property name="MemberName" />
    3.34                          <property name="CanFocus">True</property>
    3.35                          <property name="Label" translatable="yes" />
    3.36 -                        <property name="Active">True</property>
    3.37                          <property name="DrawIndicator">True</property>
    3.38                          <property name="HasLabel">True</property>
    3.39                          <property name="UseUnderline">True</property>