changeset 53:28b242612ad7

Re #60: Add UI to add/remove/edit weapons in GTK * Use proper method for making dialog appear Re #306: Combine equipment lists in GTK# * Populate unit equipment lists on unit display widget
author IBBoard <dev@ibboard.co.uk>
date Wed, 25 Aug 2010 15:21:56 +0000
parents 4bad8cb3f889
children f9f6e9db5350
files FrmAddEquipment.cs UIControl/AddEquipmentUIControl.cs Widgets/UnitDisplayWidget.cs gtk-gui/gui.stetic
diffstat 4 files changed, 190 insertions(+), 110 deletions(-) [+]
line diff
     1.1 --- a/FrmAddEquipment.cs	Sun Aug 22 14:32:16 2010 +0000
     1.2 +++ b/FrmAddEquipment.cs	Wed Aug 25 15:21:56 2010 +0000
     1.3 @@ -48,8 +48,15 @@
     1.4  
     1.5  		public void ShowControl()
     1.6  		{
     1.7 -			
     1.8 +			ShowNow();
     1.9  		}
    1.10 +		
    1.11 +		protected virtual void CancelButtonClicked (object sender, System.EventArgs e)
    1.12 +		{
    1.13 +			Respond(ResponseType.Cancel);
    1.14 +		}
    1.15 +		
    1.16 +		
    1.17  	}
    1.18  }
    1.19  
     2.1 --- a/UIControl/AddEquipmentUIControl.cs	Sun Aug 22 14:32:16 2010 +0000
     2.2 +++ b/UIControl/AddEquipmentUIControl.cs	Wed Aug 25 15:21:56 2010 +0000
     2.3 @@ -57,7 +57,7 @@
     2.4  		//TODO Make abstract
     2.5  		public void Show()
     2.6  		{
     2.7 -			((FrmAddEquipment)ui).ShowNow();
     2.8 +			ui.ShowControl();
     2.9  		}
    2.10  	}
    2.11  }
     3.1 --- a/Widgets/UnitDisplayWidget.cs	Sun Aug 22 14:32:16 2010 +0000
     3.2 +++ b/Widgets/UnitDisplayWidget.cs	Wed Aug 25 15:21:56 2010 +0000
     3.3 @@ -7,9 +7,11 @@
     3.4  using IBBoard.Commands;
     3.5  using IBBoard.Lang;
     3.6  using IBBoard.WarFoundry.API;
     3.7 -using IBBoard.WarFoundry.API.Objects;
     3.8 +using WFObjects = IBBoard.WarFoundry.API.Objects;
     3.9  using IBBoard.WarFoundry.API.Commands;
    3.10  using IBBoard.WarFoundry.GUI.GTK.UIControl;
    3.11 +using IBBoard.WarFoundry.API.Objects;
    3.12 +using IBBoard.WarFoundry.API.Util;
    3.13  
    3.14  namespace IBBoard.WarFoundry.GTK.Widgets
    3.15  {
    3.16 @@ -17,10 +19,10 @@
    3.17  	[System.ComponentModel.ToolboxItem(true)]
    3.18  	public partial class UnitDisplayWidget : Gtk.Bin
    3.19  	{		
    3.20 -		private IBBoard.WarFoundry.API.Objects.Unit unit;
    3.21 +		private WFObjects.Unit unit;
    3.22  		private CommandStack stack;
    3.23  		
    3.24 -		public UnitDisplayWidget(IBBoard.WarFoundry.API.Objects.Unit sourceUnit, CommandStack commandStack)
    3.25 +		public UnitDisplayWidget(WFObjects.Unit sourceUnit, CommandStack commandStack)
    3.26  		{
    3.27  			this.Build();
    3.28  			stack = commandStack;
    3.29 @@ -39,12 +41,11 @@
    3.30  			unit.NameChanged+= new StringValChangedDelegate(UnitNameChanged);
    3.31  			unit.UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChanged);
    3.32  			SetStats();
    3.33 +			SetWeapons();
    3.34  		}
    3.35  
    3.36  		private void SetStats()
    3.37  		{
    3.38 -            //GameSystem system = unit.Army.GameSystem;
    3.39 -            //SystemStats stats = system.StandardSystemStats;
    3.40              CellRendererText renderer = new CellRendererText();
    3.41              unitStats.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, new TreeCellDataFunc(RenderUnitName));
    3.42              
    3.43 @@ -58,7 +59,7 @@
    3.44  	            unitStats.AppendColumn(stats[i].ParentSlotName, renderer, statFunc);
    3.45  			}
    3.46  
    3.47 -			TreeStore model = new TreeStore(typeof(IBBoard.WarFoundry.API.Objects.Unit));
    3.48 +			TreeStore model = new TreeStore(typeof(WFObjects.Unit));
    3.49  			model.AppendValues(unit);
    3.50  			unitStats.Model = model;
    3.51  		}
    3.52 @@ -67,9 +68,9 @@
    3.53  		{
    3.54  			object o = model.GetValue(iter, 0);
    3.55  			
    3.56 -			if (o is IBBoard.WarFoundry.API.Objects.Unit)
    3.57 +			if (o is WFObjects.Unit)
    3.58  			{
    3.59 -				IBBoard.WarFoundry.API.Objects.Unit u = (IBBoard.WarFoundry.API.Objects.Unit)o;				
    3.60 +				WFObjects.Unit u = (WFObjects.Unit)o;				
    3.61  				(cell as CellRendererText).Text = u.UnitType.Name;
    3.62  			}
    3.63  		}
    3.64 @@ -78,14 +79,81 @@
    3.65  		{
    3.66  			object o = model.GetValue(iter, 0);
    3.67  			
    3.68 -			if (o is IBBoard.WarFoundry.API.Objects.Unit)
    3.69 +			if (o is WFObjects.Unit)
    3.70  			{
    3.71 -				IBBoard.WarFoundry.API.Objects.Unit u = (IBBoard.WarFoundry.API.Objects.Unit)o;
    3.72 +				WFObjects.Unit u = (WFObjects.Unit)o;
    3.73  				(cell as CellRendererText).Text = u.GetStatValue(column.Title);
    3.74  			}
    3.75  		}
    3.76  
    3.77 -		public IBBoard.WarFoundry.API.Objects.Unit Unit
    3.78 +		private void SetWeapons()
    3.79 +		{
    3.80 +			CellRendererText renderer = new CellRendererText();
    3.81 +			equipmentList.AppendColumn("", renderer, new TreeCellDataFunc(RenderEquipmentLine));
    3.82 +			
    3.83 +			
    3.84 +			TreeStore model = new TreeStore(typeof(UnitEquipmentItem));
    3.85 +			model.AppendValues(unit.GetEquipment());
    3.86 +			equipmentList.Model = model;
    3.87 +		}
    3.88 +		
    3.89 +		public void RenderEquipmentLine(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
    3.90 +		{
    3.91 +			object o = model.GetValue(iter, 0);
    3.92 +			
    3.93 +			if (o is UnitEquipmentItem)
    3.94 +			{
    3.95 +				UnitEquipmentItem item = (UnitEquipmentItem)o;
    3.96 +				(cell as CellRendererText).Text = GetUnitEquipmentText(item);
    3.97 +			}			
    3.98 +						
    3.99 +		}
   3.100 +		
   3.101 +		private string GetUnitEquipmentText(UnitEquipmentItem item)
   3.102 +		{
   3.103 +			string translation = "";
   3.104 +
   3.105 +			if (item.Cost == 0)
   3.106 +			{
   3.107 +				translation = Translation.GetTranslation("equipmentAmountWithZeroCost", "{0} ({1} - free)", item.Name, GetAmountString(item));
   3.108 +			}
   3.109 +			else
   3.110 +			{
   3.111 +				translation = Translation.GetTranslation("equipmentAmountWithCost", "{0} ({1} at {2}pts each)", item.Name, GetAmountString(item), item.Cost);
   3.112 +			}
   3.113 +
   3.114 +			return translation;
   3.115 +		}
   3.116 +
   3.117 +		private string GetAmountString(UnitEquipmentItem item)
   3.118 +		{
   3.119 +			double amount = UnitEquipmentUtil.GetEquipmentAmount(unit, item);
   3.120 +			string amountString = "";
   3.121 +			
   3.122 +			if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, item))
   3.123 +			{
   3.124 +				int number = UnitEquipmentUtil.GetEquipmentAmountTaken(unit, item);
   3.125 +				
   3.126 +				if (amount == 100)
   3.127 +				{
   3.128 +					amountString = Translation.GetTranslation("equipmentChoiceAmountAll", "all ({1})", amount, number);
   3.129 +				}
   3.130 +
   3.131 +				else
   3.132 +				{
   3.133 +					amountString = Translation.GetTranslation("equipmentChoiceAmountPercentage", "{0}% ({1})", amount, number);
   3.134 +				}
   3.135 +			}
   3.136 +
   3.137 +			else
   3.138 +			{
   3.139 +				amountString = Translation.GetTranslation("equipmentChoiceAmountNumber", "{0}", amount);
   3.140 +			}
   3.141 +			
   3.142 +			return amountString;
   3.143 +		}
   3.144 +
   3.145 +		public WFObjects.Unit Unit
   3.146  		{
   3.147  			get { return unit; }
   3.148  		}
     4.1 --- a/gtk-gui/gui.stetic	Sun Aug 22 14:32:16 2010 +0000
     4.2 +++ b/gtk-gui/gui.stetic	Wed Aug 25 15:21:56 2010 +0000
     4.3 @@ -764,103 +764,111 @@
     4.4            </packing>
     4.5          </child>
     4.6          <child>
     4.7 -          <widget class="Gtk.Table" id="table1">
     4.8 +          <widget class="Gtk.HBox" id="hbox2">
     4.9              <property name="MemberName" />
    4.10 -            <property name="NRows">2</property>
    4.11 -            <property name="NColumns">3</property>
    4.12 -            <property name="RowSpacing">6</property>
    4.13 -            <property name="ColumnSpacing">6</property>
    4.14 +            <property name="Spacing">6</property>
    4.15              <child>
    4.16 -              <placeholder />
    4.17 -            </child>
    4.18 -            <child>
    4.19 -              <widget class="Gtk.Label" id="equipmentLabel">
    4.20 +              <widget class="Gtk.Table" id="table1">
    4.21                  <property name="MemberName" />
    4.22 -                <property name="LabelProp" translatable="yes">equipment:</property>
    4.23 -              </widget>
    4.24 -              <packing>
    4.25 -                <property name="AutoSize">True</property>
    4.26 -                <property name="XOptions">Fill</property>
    4.27 -                <property name="YOptions">Fill</property>
    4.28 -                <property name="XExpand">False</property>
    4.29 -                <property name="XFill">True</property>
    4.30 -                <property name="XShrink">False</property>
    4.31 -                <property name="YExpand">False</property>
    4.32 -                <property name="YFill">True</property>
    4.33 -                <property name="YShrink">False</property>
    4.34 -              </packing>
    4.35 -            </child>
    4.36 -            <child>
    4.37 -              <widget class="Gtk.ScrolledWindow" id="GtkScrolledWindow2">
    4.38 -                <property name="MemberName" />
    4.39 -                <property name="ShadowType">In</property>
    4.40 +                <property name="NRows">2</property>
    4.41 +                <property name="NColumns">2</property>
    4.42 +                <property name="RowSpacing">6</property>
    4.43 +                <property name="ColumnSpacing">6</property>
    4.44                  <child>
    4.45 -                  <widget class="Gtk.NodeView" id="equipmentList">
    4.46 +                  <widget class="Gtk.Label" id="equipmentLabel">
    4.47                      <property name="MemberName" />
    4.48 -                    <property name="CanFocus">True</property>
    4.49 -                    <property name="ShowScrollbars">True</property>
    4.50 +                    <property name="LabelProp" translatable="yes">equipment:</property>
    4.51                    </widget>
    4.52 +                  <packing>
    4.53 +                    <property name="AutoSize">True</property>
    4.54 +                    <property name="XOptions">Fill</property>
    4.55 +                    <property name="YOptions">Fill</property>
    4.56 +                    <property name="XExpand">False</property>
    4.57 +                    <property name="XFill">True</property>
    4.58 +                    <property name="XShrink">False</property>
    4.59 +                    <property name="YExpand">False</property>
    4.60 +                    <property name="YFill">True</property>
    4.61 +                    <property name="YShrink">False</property>
    4.62 +                  </packing>
    4.63 +                </child>
    4.64 +                <child>
    4.65 +                  <widget class="Gtk.ScrolledWindow" id="GtkScrolledWindow2">
    4.66 +                    <property name="MemberName" />
    4.67 +                    <property name="ShadowType">In</property>
    4.68 +                    <child>
    4.69 +                      <widget class="Gtk.NodeView" id="equipmentList">
    4.70 +                        <property name="MemberName" />
    4.71 +                        <property name="CanFocus">True</property>
    4.72 +                        <property name="ShowScrollbars">True</property>
    4.73 +                        <property name="HeadersVisible">False</property>
    4.74 +                      </widget>
    4.75 +                    </child>
    4.76 +                  </widget>
    4.77 +                  <packing>
    4.78 +                    <property name="LeftAttach">1</property>
    4.79 +                    <property name="RightAttach">2</property>
    4.80 +                    <property name="AutoSize">True</property>
    4.81 +                    <property name="YOptions">Fill</property>
    4.82 +                    <property name="XExpand">True</property>
    4.83 +                    <property name="XFill">True</property>
    4.84 +                    <property name="XShrink">False</property>
    4.85 +                    <property name="YExpand">False</property>
    4.86 +                    <property name="YFill">True</property>
    4.87 +                    <property name="YShrink">False</property>
    4.88 +                  </packing>
    4.89 +                </child>
    4.90 +                <child>
    4.91 +                  <widget class="Gtk.ScrolledWindow" id="GtkScrolledWindow3">
    4.92 +                    <property name="MemberName" />
    4.93 +                    <property name="ShadowType">In</property>
    4.94 +                    <child>
    4.95 +                      <widget class="Gtk.TextView" id="notesView">
    4.96 +                        <property name="MemberName" />
    4.97 +                        <property name="CanFocus">True</property>
    4.98 +                        <property name="ShowScrollbars">True</property>
    4.99 +                        <property name="Editable">False</property>
   4.100 +                        <property name="Text" translatable="yes" />
   4.101 +                      </widget>
   4.102 +                    </child>
   4.103 +                  </widget>
   4.104 +                  <packing>
   4.105 +                    <property name="TopAttach">1</property>
   4.106 +                    <property name="BottomAttach">2</property>
   4.107 +                    <property name="LeftAttach">1</property>
   4.108 +                    <property name="RightAttach">2</property>
   4.109 +                    <property name="AutoSize">True</property>
   4.110 +                    <property name="YOptions">Fill</property>
   4.111 +                    <property name="XExpand">True</property>
   4.112 +                    <property name="XFill">True</property>
   4.113 +                    <property name="XShrink">False</property>
   4.114 +                    <property name="YExpand">False</property>
   4.115 +                    <property name="YFill">True</property>
   4.116 +                    <property name="YShrink">False</property>
   4.117 +                  </packing>
   4.118 +                </child>
   4.119 +                <child>
   4.120 +                  <widget class="Gtk.Label" id="lblNotes">
   4.121 +                    <property name="MemberName" />
   4.122 +                    <property name="LabelProp" translatable="yes">notes:</property>
   4.123 +                  </widget>
   4.124 +                  <packing>
   4.125 +                    <property name="TopAttach">1</property>
   4.126 +                    <property name="BottomAttach">2</property>
   4.127 +                    <property name="AutoSize">True</property>
   4.128 +                    <property name="XOptions">Fill</property>
   4.129 +                    <property name="YOptions">Fill</property>
   4.130 +                    <property name="XExpand">False</property>
   4.131 +                    <property name="XFill">True</property>
   4.132 +                    <property name="XShrink">False</property>
   4.133 +                    <property name="YExpand">False</property>
   4.134 +                    <property name="YFill">True</property>
   4.135 +                    <property name="YShrink">False</property>
   4.136 +                  </packing>
   4.137                  </child>
   4.138                </widget>
   4.139                <packing>
   4.140 -                <property name="LeftAttach">1</property>
   4.141 -                <property name="RightAttach">2</property>
   4.142 +                <property name="Position">0</property>
   4.143                  <property name="AutoSize">True</property>
   4.144 -                <property name="YOptions">Fill</property>
   4.145 -                <property name="XExpand">True</property>
   4.146 -                <property name="XFill">True</property>
   4.147 -                <property name="XShrink">False</property>
   4.148 -                <property name="YExpand">False</property>
   4.149 -                <property name="YFill">True</property>
   4.150 -                <property name="YShrink">False</property>
   4.151 -              </packing>
   4.152 -            </child>
   4.153 -            <child>
   4.154 -              <widget class="Gtk.ScrolledWindow" id="GtkScrolledWindow3">
   4.155 -                <property name="MemberName" />
   4.156 -                <property name="ShadowType">In</property>
   4.157 -                <child>
   4.158 -                  <widget class="Gtk.TextView" id="notesView">
   4.159 -                    <property name="MemberName" />
   4.160 -                    <property name="CanFocus">True</property>
   4.161 -                    <property name="ShowScrollbars">True</property>
   4.162 -                    <property name="Editable">False</property>
   4.163 -                    <property name="Text" translatable="yes" />
   4.164 -                  </widget>
   4.165 -                </child>
   4.166 -              </widget>
   4.167 -              <packing>
   4.168 -                <property name="TopAttach">1</property>
   4.169 -                <property name="BottomAttach">2</property>
   4.170 -                <property name="LeftAttach">1</property>
   4.171 -                <property name="RightAttach">2</property>
   4.172 -                <property name="AutoSize">True</property>
   4.173 -                <property name="YOptions">Fill</property>
   4.174 -                <property name="XExpand">True</property>
   4.175 -                <property name="XFill">True</property>
   4.176 -                <property name="XShrink">False</property>
   4.177 -                <property name="YExpand">False</property>
   4.178 -                <property name="YFill">True</property>
   4.179 -                <property name="YShrink">False</property>
   4.180 -              </packing>
   4.181 -            </child>
   4.182 -            <child>
   4.183 -              <widget class="Gtk.Label" id="lblNotes">
   4.184 -                <property name="MemberName" />
   4.185 -                <property name="LabelProp" translatable="yes">notes:</property>
   4.186 -              </widget>
   4.187 -              <packing>
   4.188 -                <property name="TopAttach">1</property>
   4.189 -                <property name="BottomAttach">2</property>
   4.190 -                <property name="AutoSize">True</property>
   4.191 -                <property name="XOptions">Fill</property>
   4.192 -                <property name="YOptions">Fill</property>
   4.193 -                <property name="XExpand">False</property>
   4.194 -                <property name="XFill">True</property>
   4.195 -                <property name="XShrink">False</property>
   4.196 -                <property name="YExpand">False</property>
   4.197 -                <property name="YFill">True</property>
   4.198 -                <property name="YShrink">False</property>
   4.199                </packing>
   4.200              </child>
   4.201              <child>
   4.202 @@ -930,17 +938,10 @@
   4.203                  </child>
   4.204                </widget>
   4.205                <packing>
   4.206 -                <property name="LeftAttach">2</property>
   4.207 -                <property name="RightAttach">3</property>
   4.208 +                <property name="Position">1</property>
   4.209                  <property name="AutoSize">True</property>
   4.210 -                <property name="XOptions">Fill</property>
   4.211 -                <property name="YOptions">Fill</property>
   4.212 -                <property name="XExpand">False</property>
   4.213 -                <property name="XFill">True</property>
   4.214 -                <property name="XShrink">False</property>
   4.215 -                <property name="YExpand">False</property>
   4.216 -                <property name="YFill">True</property>
   4.217 -                <property name="YShrink">False</property>
   4.218 +                <property name="Expand">False</property>
   4.219 +                <property name="Fill">False</property>
   4.220                </packing>
   4.221              </child>
   4.222            </widget>
   4.223 @@ -954,6 +955,9 @@
   4.224          <child>
   4.225            <placeholder />
   4.226          </child>
   4.227 +        <child>
   4.228 +          <placeholder />
   4.229 +        </child>
   4.230        </widget>
   4.231      </child>
   4.232    </widget>
   4.233 @@ -1268,6 +1272,7 @@
   4.234              <property name="Type">StockItem</property>
   4.235              <property name="StockId">gtk-cancel</property>
   4.236              <property name="ResponseId">-6</property>
   4.237 +            <signal name="Clicked" handler="CancelButtonClicked" />
   4.238              <property name="label">gtk-cancel</property>
   4.239            </widget>
   4.240            <packing>