Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
comparison 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 |
comparison
equal
deleted
inserted
replaced
71:91354245218a | 72:f0cc295e883c |
---|---|
12 using IBBoard.WarFoundry.API.Objects; | 12 using IBBoard.WarFoundry.API.Objects; |
13 using IBBoard.WarFoundry.API.Util; | 13 using IBBoard.WarFoundry.API.Util; |
14 using IBBoard.WarFoundry.GUI.GTK.UIControl; | 14 using IBBoard.WarFoundry.GUI.GTK.UIControl; |
15 using log4net; | 15 using log4net; |
16 using WFObjects = IBBoard.WarFoundry.API.Objects; | 16 using WFObjects = IBBoard.WarFoundry.API.Objects; |
17 using System.Collections.Generic; | |
17 | 18 |
18 namespace IBBoard.WarFoundry.GTK.Widgets | 19 namespace IBBoard.WarFoundry.GTK.Widgets |
19 { | 20 { |
20 [System.ComponentModel.Category("WarFoundry GTK# GUI")] | 21 [System.ComponentModel.Category("WarFoundry GTK# GUI")] |
21 [System.ComponentModel.ToolboxItem(true)] | 22 [System.ComponentModel.ToolboxItem(true)] |
22 public partial class UnitDisplayWidget : Gtk.Bin | 23 public partial class UnitDisplayWidget : Gtk.Bin |
23 { | 24 { |
24 private static ILog log = LogManager.GetLogger(typeof(UnitDisplayWidget)); | 25 private static ILog log = LogManager.GetLogger(typeof(UnitDisplayWidget)); |
25 private WFObjects.Unit unit; | 26 private WFObjects.Unit unit; |
26 private CommandStack stack; | 27 private CommandStack stack; |
28 private Dictionary<string, NodeView> statsViews = new Dictionary<string, NodeView>(); | |
27 | 29 |
28 public UnitDisplayWidget(WFObjects.Unit sourceUnit, CommandStack commandStack) | 30 public UnitDisplayWidget(WFObjects.Unit sourceUnit, CommandStack commandStack) |
29 { | 31 { |
30 this.Build(); | 32 this.Build(); |
31 stack = commandStack; | 33 stack = commandStack; |
91 | 93 |
92 } | 94 } |
93 | 95 |
94 private void SetStats() | 96 private void SetStats() |
95 { | 97 { |
98 Stat[][] stats = unit.UnitStatsArraysWithName; | |
99 string[] statsIDs = unit.UnitStatsArrayIDs; | |
100 int statsCount = stats.Length; | |
101 log.DebugFormat("Unit {0} has {1} stats arrays", unit.UnitType.Name, statsCount); | |
102 | |
103 for (int i = 0; i < statsCount; i++) | |
104 { | |
105 NodeView statsGrid = GetStatsView(statsIDs[i]); | |
106 TreeStore model = (TreeStore)statsGrid.Model; | |
107 log.DebugFormat("Adding row to data table for {0}", statsIDs[i]); | |
108 log.DebugFormat("TreeStore supports {0} columns", model.NColumns); | |
109 model.AppendValues(stats[i]); | |
110 } | |
111 } | |
112 | |
113 private NodeView GetStatsView(string statsID) | |
114 { | |
115 NodeView statsView; | |
116 | |
117 if (statsViews.ContainsKey(statsID)) | |
118 { | |
119 statsView = DictionaryUtils.GetValue(statsViews, statsID); | |
120 } | |
121 else | |
122 { | |
123 statsView = CreateStatsView(statsID); | |
124 statsViews[statsID] = statsView; | |
125 } | |
126 | |
127 return statsView; | |
128 } | |
129 | |
130 private NodeView CreateStatsView(string statsID) | |
131 { | |
132 log.DebugFormat("Create NodeView for stats ID {0}", statsID); | |
133 SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID); | |
134 StatSlot[] sysStatSlots = sysStats.StatSlots; | |
135 int statsCount = sysStatSlots.Length; | |
136 NodeView statsGrid = CreateNodeView(); | |
96 CellRendererText renderer = new CellRendererText(); | 137 CellRendererText renderer = new CellRendererText(); |
97 unitStats.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, new TreeCellDataFunc(RenderUnitName)); | 138 statsGrid.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, RenderUnitName); |
98 | 139 |
99 TreeCellDataFunc statFunc = new TreeCellDataFunc(RenderUnitStat); | 140 for (int i = 0; i < statsCount; i++) |
100 Stat[] stats = unit.UnitStatsArray; | 141 { |
101 | 142 StatSlot stat = sysStatSlots[i]; |
102 int length = stats.Length; | 143 string slotName = stat.Name; |
103 | 144 statsGrid.AppendColumn(slotName, renderer, RenderUnitStat); |
104 for (int i = 0; i < length; i++) | 145 } |
105 { | 146 |
106 unitStats.AppendColumn(stats[i].ParentSlotName, renderer, statFunc); | 147 statsGrid.Model = new TreeStore(typeof(Stat[])); |
107 } | 148 return statsGrid; |
108 | 149 } |
109 TreeStore model = new TreeStore(typeof(WFObjects.Unit)); | 150 |
110 model.AppendValues(unit); | 151 private NodeView CreateNodeView() |
111 unitStats.Model = model; | 152 { |
153 NodeView nodeView = new NodeView(); | |
154 statsRepeatBox.Add(nodeView); | |
155 return nodeView; | |
112 } | 156 } |
113 | 157 |
114 private void RenderUnitName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | 158 private void RenderUnitName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
115 { | 159 { |
116 object o = model.GetValue(iter, 0); | 160 object o = model.GetValue(iter, 0); |
326 if (item != null) | 370 if (item != null) |
327 { | 371 { |
328 ReplaceEquipmentUIControl addEquipment = new ReplaceEquipmentUIControl(unit, item, stack); | 372 ReplaceEquipmentUIControl addEquipment = new ReplaceEquipmentUIControl(unit, item, stack); |
329 addEquipment.Show(); | 373 addEquipment.Show(); |
330 } | 374 } |
331 } | 375 } |
332 | |
333 | |
334 | |
335 } | 376 } |
336 } | 377 } |