Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
diff Widgets/UnitDisplayWidget.cs @ 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 | 7bba99c368c8 |
line wrap: on
line diff
--- 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; } }