Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
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 wrap: on
line diff
--- a/FrmAddEquipment.cs Sun Aug 22 14:32:16 2010 +0000 +++ b/FrmAddEquipment.cs Wed Aug 25 15:21:56 2010 +0000 @@ -48,8 +48,15 @@ public void ShowControl() { - + ShowNow(); } + + protected virtual void CancelButtonClicked (object sender, System.EventArgs e) + { + Respond(ResponseType.Cancel); + } + + } }
--- a/UIControl/AddEquipmentUIControl.cs Sun Aug 22 14:32:16 2010 +0000 +++ b/UIControl/AddEquipmentUIControl.cs Wed Aug 25 15:21:56 2010 +0000 @@ -57,7 +57,7 @@ //TODO Make abstract public void Show() { - ((FrmAddEquipment)ui).ShowNow(); + ui.ShowControl(); } } }
--- a/Widgets/UnitDisplayWidget.cs Sun Aug 22 14:32:16 2010 +0000 +++ b/Widgets/UnitDisplayWidget.cs Wed Aug 25 15:21:56 2010 +0000 @@ -7,9 +7,11 @@ using IBBoard.Commands; using IBBoard.Lang; using IBBoard.WarFoundry.API; -using IBBoard.WarFoundry.API.Objects; +using WFObjects = IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Commands; using IBBoard.WarFoundry.GUI.GTK.UIControl; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.WarFoundry.API.Util; namespace IBBoard.WarFoundry.GTK.Widgets { @@ -17,10 +19,10 @@ [System.ComponentModel.ToolboxItem(true)] public partial class UnitDisplayWidget : Gtk.Bin { - private IBBoard.WarFoundry.API.Objects.Unit unit; + private WFObjects.Unit unit; private CommandStack stack; - public UnitDisplayWidget(IBBoard.WarFoundry.API.Objects.Unit sourceUnit, CommandStack commandStack) + public UnitDisplayWidget(WFObjects.Unit sourceUnit, CommandStack commandStack) { this.Build(); stack = commandStack; @@ -39,12 +41,11 @@ unit.NameChanged+= new StringValChangedDelegate(UnitNameChanged); unit.UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChanged); SetStats(); + SetWeapons(); } private void SetStats() { - //GameSystem system = unit.Army.GameSystem; - //SystemStats stats = system.StandardSystemStats; CellRendererText renderer = new CellRendererText(); unitStats.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, new TreeCellDataFunc(RenderUnitName)); @@ -58,7 +59,7 @@ unitStats.AppendColumn(stats[i].ParentSlotName, renderer, statFunc); } - TreeStore model = new TreeStore(typeof(IBBoard.WarFoundry.API.Objects.Unit)); + TreeStore model = new TreeStore(typeof(WFObjects.Unit)); model.AppendValues(unit); unitStats.Model = model; } @@ -67,9 +68,9 @@ { object o = model.GetValue(iter, 0); - if (o is IBBoard.WarFoundry.API.Objects.Unit) + if (o is WFObjects.Unit) { - IBBoard.WarFoundry.API.Objects.Unit u = (IBBoard.WarFoundry.API.Objects.Unit)o; + WFObjects.Unit u = (WFObjects.Unit)o; (cell as CellRendererText).Text = u.UnitType.Name; } } @@ -78,14 +79,81 @@ { object o = model.GetValue(iter, 0); - if (o is IBBoard.WarFoundry.API.Objects.Unit) + if (o is WFObjects.Unit) { - IBBoard.WarFoundry.API.Objects.Unit u = (IBBoard.WarFoundry.API.Objects.Unit)o; + WFObjects.Unit u = (WFObjects.Unit)o; (cell as CellRendererText).Text = u.GetStatValue(column.Title); } } - public IBBoard.WarFoundry.API.Objects.Unit Unit + private void SetWeapons() + { + CellRendererText renderer = new CellRendererText(); + equipmentList.AppendColumn("", renderer, new TreeCellDataFunc(RenderEquipmentLine)); + + + TreeStore model = new TreeStore(typeof(UnitEquipmentItem)); + model.AppendValues(unit.GetEquipment()); + equipmentList.Model = model; + } + + public void RenderEquipmentLine(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) + { + object o = model.GetValue(iter, 0); + + if (o is UnitEquipmentItem) + { + UnitEquipmentItem item = (UnitEquipmentItem)o; + (cell as CellRendererText).Text = GetUnitEquipmentText(item); + } + + } + + private string GetUnitEquipmentText(UnitEquipmentItem item) + { + string translation = ""; + + if (item.Cost == 0) + { + translation = Translation.GetTranslation("equipmentAmountWithZeroCost", "{0} ({1} - free)", item.Name, GetAmountString(item)); + } + else + { + translation = Translation.GetTranslation("equipmentAmountWithCost", "{0} ({1} at {2}pts each)", item.Name, GetAmountString(item), item.Cost); + } + + return translation; + } + + private string GetAmountString(UnitEquipmentItem item) + { + double amount = UnitEquipmentUtil.GetEquipmentAmount(unit, item); + string amountString = ""; + + if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, item)) + { + int number = UnitEquipmentUtil.GetEquipmentAmountTaken(unit, item); + + if (amount == 100) + { + amountString = Translation.GetTranslation("equipmentChoiceAmountAll", "all ({1})", amount, number); + } + + else + { + amountString = Translation.GetTranslation("equipmentChoiceAmountPercentage", "{0}% ({1})", amount, number); + } + } + + else + { + amountString = Translation.GetTranslation("equipmentChoiceAmountNumber", "{0}", amount); + } + + return amountString; + } + + public WFObjects.Unit Unit { get { return unit; } }
--- a/gtk-gui/gui.stetic Sun Aug 22 14:32:16 2010 +0000 +++ b/gtk-gui/gui.stetic Wed Aug 25 15:21:56 2010 +0000 @@ -764,103 +764,111 @@ </packing> </child> <child> - <widget class="Gtk.Table" id="table1"> + <widget class="Gtk.HBox" id="hbox2"> <property name="MemberName" /> - <property name="NRows">2</property> - <property name="NColumns">3</property> - <property name="RowSpacing">6</property> - <property name="ColumnSpacing">6</property> + <property name="Spacing">6</property> <child> - <placeholder /> - </child> - <child> - <widget class="Gtk.Label" id="equipmentLabel"> + <widget class="Gtk.Table" id="table1"> <property name="MemberName" /> - <property name="LabelProp" translatable="yes">equipment:</property> - </widget> - <packing> - <property name="AutoSize">True</property> - <property name="XOptions">Fill</property> - <property name="YOptions">Fill</property> - <property name="XExpand">False</property> - <property name="XFill">True</property> - <property name="XShrink">False</property> - <property name="YExpand">False</property> - <property name="YFill">True</property> - <property name="YShrink">False</property> - </packing> - </child> - <child> - <widget class="Gtk.ScrolledWindow" id="GtkScrolledWindow2"> - <property name="MemberName" /> - <property name="ShadowType">In</property> + <property name="NRows">2</property> + <property name="NColumns">2</property> + <property name="RowSpacing">6</property> + <property name="ColumnSpacing">6</property> + <child> + <widget class="Gtk.Label" id="equipmentLabel"> + <property name="MemberName" /> + <property name="LabelProp" translatable="yes">equipment:</property> + </widget> + <packing> + <property name="AutoSize">True</property> + <property name="XOptions">Fill</property> + <property name="YOptions">Fill</property> + <property name="XExpand">False</property> + <property name="XFill">True</property> + <property name="XShrink">False</property> + <property name="YExpand">False</property> + <property name="YFill">True</property> + <property name="YShrink">False</property> + </packing> + </child> <child> - <widget class="Gtk.NodeView" id="equipmentList"> + <widget class="Gtk.ScrolledWindow" id="GtkScrolledWindow2"> + <property name="MemberName" /> + <property name="ShadowType">In</property> + <child> + <widget class="Gtk.NodeView" id="equipmentList"> + <property name="MemberName" /> + <property name="CanFocus">True</property> + <property name="ShowScrollbars">True</property> + <property name="HeadersVisible">False</property> + </widget> + </child> + </widget> + <packing> + <property name="LeftAttach">1</property> + <property name="RightAttach">2</property> + <property name="AutoSize">True</property> + <property name="YOptions">Fill</property> + <property name="XExpand">True</property> + <property name="XFill">True</property> + <property name="XShrink">False</property> + <property name="YExpand">False</property> + <property name="YFill">True</property> + <property name="YShrink">False</property> + </packing> + </child> + <child> + <widget class="Gtk.ScrolledWindow" id="GtkScrolledWindow3"> <property name="MemberName" /> - <property name="CanFocus">True</property> - <property name="ShowScrollbars">True</property> + <property name="ShadowType">In</property> + <child> + <widget class="Gtk.TextView" id="notesView"> + <property name="MemberName" /> + <property name="CanFocus">True</property> + <property name="ShowScrollbars">True</property> + <property name="Editable">False</property> + <property name="Text" translatable="yes" /> + </widget> + </child> </widget> + <packing> + <property name="TopAttach">1</property> + <property name="BottomAttach">2</property> + <property name="LeftAttach">1</property> + <property name="RightAttach">2</property> + <property name="AutoSize">True</property> + <property name="YOptions">Fill</property> + <property name="XExpand">True</property> + <property name="XFill">True</property> + <property name="XShrink">False</property> + <property name="YExpand">False</property> + <property name="YFill">True</property> + <property name="YShrink">False</property> + </packing> + </child> + <child> + <widget class="Gtk.Label" id="lblNotes"> + <property name="MemberName" /> + <property name="LabelProp" translatable="yes">notes:</property> + </widget> + <packing> + <property name="TopAttach">1</property> + <property name="BottomAttach">2</property> + <property name="AutoSize">True</property> + <property name="XOptions">Fill</property> + <property name="YOptions">Fill</property> + <property name="XExpand">False</property> + <property name="XFill">True</property> + <property name="XShrink">False</property> + <property name="YExpand">False</property> + <property name="YFill">True</property> + <property name="YShrink">False</property> + </packing> </child> </widget> <packing> - <property name="LeftAttach">1</property> - <property name="RightAttach">2</property> + <property name="Position">0</property> <property name="AutoSize">True</property> - <property name="YOptions">Fill</property> - <property name="XExpand">True</property> - <property name="XFill">True</property> - <property name="XShrink">False</property> - <property name="YExpand">False</property> - <property name="YFill">True</property> - <property name="YShrink">False</property> - </packing> - </child> - <child> - <widget class="Gtk.ScrolledWindow" id="GtkScrolledWindow3"> - <property name="MemberName" /> - <property name="ShadowType">In</property> - <child> - <widget class="Gtk.TextView" id="notesView"> - <property name="MemberName" /> - <property name="CanFocus">True</property> - <property name="ShowScrollbars">True</property> - <property name="Editable">False</property> - <property name="Text" translatable="yes" /> - </widget> - </child> - </widget> - <packing> - <property name="TopAttach">1</property> - <property name="BottomAttach">2</property> - <property name="LeftAttach">1</property> - <property name="RightAttach">2</property> - <property name="AutoSize">True</property> - <property name="YOptions">Fill</property> - <property name="XExpand">True</property> - <property name="XFill">True</property> - <property name="XShrink">False</property> - <property name="YExpand">False</property> - <property name="YFill">True</property> - <property name="YShrink">False</property> - </packing> - </child> - <child> - <widget class="Gtk.Label" id="lblNotes"> - <property name="MemberName" /> - <property name="LabelProp" translatable="yes">notes:</property> - </widget> - <packing> - <property name="TopAttach">1</property> - <property name="BottomAttach">2</property> - <property name="AutoSize">True</property> - <property name="XOptions">Fill</property> - <property name="YOptions">Fill</property> - <property name="XExpand">False</property> - <property name="XFill">True</property> - <property name="XShrink">False</property> - <property name="YExpand">False</property> - <property name="YFill">True</property> - <property name="YShrink">False</property> </packing> </child> <child> @@ -930,17 +938,10 @@ </child> </widget> <packing> - <property name="LeftAttach">2</property> - <property name="RightAttach">3</property> + <property name="Position">1</property> <property name="AutoSize">True</property> - <property name="XOptions">Fill</property> - <property name="YOptions">Fill</property> - <property name="XExpand">False</property> - <property name="XFill">True</property> - <property name="XShrink">False</property> - <property name="YExpand">False</property> - <property name="YFill">True</property> - <property name="YShrink">False</property> + <property name="Expand">False</property> + <property name="Fill">False</property> </packing> </child> </widget> @@ -954,6 +955,9 @@ <child> <placeholder /> </child> + <child> + <placeholder /> + </child> </widget> </child> </widget> @@ -1268,6 +1272,7 @@ <property name="Type">StockItem</property> <property name="StockId">gtk-cancel</property> <property name="ResponseId">-6</property> + <signal name="Clicked" handler="CancelButtonClicked" /> <property name="label">gtk-cancel</property> </widget> <packing>