Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
diff Widgets/UnitDisplayWidget.cs @ 72:f0cc295e883c
Re #307: Add support for multiple stat lines
* Implement starts of multiple stat lines, based on WinForms method
* Replace existing NodeView with a VBox for repeat widgets
* Create NodeViews for each stat line type and append stats
Currently fails to show stats.
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 09 Nov 2010 20:29:50 +0000 |
parents | 91354245218a |
children | 19e7123aafd5 |
line wrap: on
line diff
--- a/Widgets/UnitDisplayWidget.cs Sat Nov 06 20:22:19 2010 +0000 +++ b/Widgets/UnitDisplayWidget.cs Tue Nov 09 20:29:50 2010 +0000 @@ -14,6 +14,7 @@ using IBBoard.WarFoundry.GUI.GTK.UIControl; using log4net; using WFObjects = IBBoard.WarFoundry.API.Objects; +using System.Collections.Generic; namespace IBBoard.WarFoundry.GTK.Widgets { @@ -24,6 +25,7 @@ private static ILog log = LogManager.GetLogger(typeof(UnitDisplayWidget)); private WFObjects.Unit unit; private CommandStack stack; + private Dictionary<string, NodeView> statsViews = new Dictionary<string, NodeView>(); public UnitDisplayWidget(WFObjects.Unit sourceUnit, CommandStack commandStack) { @@ -93,22 +95,64 @@ private void SetStats() { - CellRendererText renderer = new CellRendererText(); - unitStats.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, new TreeCellDataFunc(RenderUnitName)); - - TreeCellDataFunc statFunc = new TreeCellDataFunc(RenderUnitStat); - Stat[] stats = unit.UnitStatsArray; - - int length = stats.Length; + Stat[][] stats = unit.UnitStatsArraysWithName; + string[] statsIDs = unit.UnitStatsArrayIDs; + int statsCount = stats.Length; + log.DebugFormat("Unit {0} has {1} stats arrays", unit.UnitType.Name, statsCount); - for (int i = 0; i < length; i++) + for (int i = 0; i < statsCount; i++) { - unitStats.AppendColumn(stats[i].ParentSlotName, renderer, statFunc); + NodeView statsGrid = GetStatsView(statsIDs[i]); + TreeStore model = (TreeStore)statsGrid.Model; + log.DebugFormat("Adding row to data table for {0}", statsIDs[i]); + log.DebugFormat("TreeStore supports {0} columns", model.NColumns); + model.AppendValues(stats[i]); + } + } + + private NodeView GetStatsView(string statsID) + { + NodeView statsView; + + if (statsViews.ContainsKey(statsID)) + { + statsView = DictionaryUtils.GetValue(statsViews, statsID); + } + else + { + statsView = CreateStatsView(statsID); + statsViews[statsID] = statsView; } - TreeStore model = new TreeStore(typeof(WFObjects.Unit)); - model.AppendValues(unit); - unitStats.Model = model; + return statsView; + } + + private NodeView CreateStatsView(string statsID) + { + log.DebugFormat("Create NodeView for stats ID {0}", statsID); + SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID); + StatSlot[] sysStatSlots = sysStats.StatSlots; + int statsCount = sysStatSlots.Length; + NodeView statsGrid = CreateNodeView(); + CellRendererText renderer = new CellRendererText(); + statsGrid.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, RenderUnitName); + + for (int i = 0; i < statsCount; i++) + { + StatSlot stat = sysStatSlots[i]; + string slotName = stat.Name; + statsGrid.AppendColumn(slotName, renderer, RenderUnitStat); + } + + statsGrid.Model = new TreeStore(typeof(Stat[])); + return statsGrid; + } + + private NodeView CreateNodeView() + { + NodeView nodeView = new NodeView(); + statsRepeatBox.Add(nodeView); + return nodeView; } private void RenderUnitName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) @@ -328,9 +372,6 @@ ReplaceEquipmentUIControl addEquipment = new ReplaceEquipmentUIControl(unit, item, stack); addEquipment.Show(); } - } - - - + } } -} +} \ No newline at end of file