# HG changeset patch # User IBBoard # Date 1282749716 0 # Node ID 28b242612ad760d8627a57f4a70a68775db18131 # Parent 4bad8cb3f889e449250341418349c7e2cb730455 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 diff -r 4bad8cb3f889 -r 28b242612ad7 FrmAddEquipment.cs --- 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); + } + + } } diff -r 4bad8cb3f889 -r 28b242612ad7 UIControl/AddEquipmentUIControl.cs --- 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(); } } } diff -r 4bad8cb3f889 -r 28b242612ad7 Widgets/UnitDisplayWidget.cs --- 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; } } diff -r 4bad8cb3f889 -r 28b242612ad7 gtk-gui/gui.stetic --- 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 @@ - + - 2 - 3 - 6 - 6 + 6 - - - - + - equipment: - - - True - Fill - Fill - False - True - False - False - True - False - - - - - - In + 2 + 2 + 6 + 6 + + + + equipment: + + + True + Fill + Fill + False + True + False + False + True + False + + - + + + In + + + + True + True + False + + + + + 1 + 2 + True + Fill + True + True + False + False + True + False + + + + - True - True + In + + + + True + True + False + + + + + 1 + 2 + 1 + 2 + True + Fill + True + True + False + False + True + False + + + + + + notes: + + + 1 + 2 + True + Fill + Fill + False + True + False + False + True + False + - 1 - 2 + 0 True - Fill - True - True - False - False - True - False - - - - - - In - - - - True - True - False - - - - - - 1 - 2 - 1 - 2 - True - Fill - True - True - False - False - True - False - - - - - - notes: - - - 1 - 2 - True - Fill - Fill - False - True - False - False - True - False @@ -930,17 +938,10 @@ - 2 - 3 + 1 True - Fill - Fill - False - True - False - False - True - False + False + False @@ -954,6 +955,9 @@ + + + @@ -1268,6 +1272,7 @@ StockItem gtk-cancel -6 + gtk-cancel