# HG changeset patch # User IBBoard # Date 1289336078 0 # Node ID 19e7123aafd5b188d4cccc0cbd2b4219a48801ec # Parent f0cc295e883cf577140e44418d0f007c340cfef5 Re #307: Add support for multiple stat lines * Fix GTK assert by casting array of stats to an object * Fix stat rendering by checking for Stat[] type instead of old Unit check diff -r f0cc295e883c -r 19e7123aafd5 Widgets/UnitDisplayWidget.cs --- a/Widgets/UnitDisplayWidget.cs Tue Nov 09 20:29:50 2010 +0000 +++ b/Widgets/UnitDisplayWidget.cs Tue Nov 09 20:54:38 2010 +0000 @@ -106,7 +106,7 @@ 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]); + model.AppendValues((object)stats[i]); } } @@ -135,7 +135,7 @@ int statsCount = sysStatSlots.Length; NodeView statsGrid = CreateNodeView(); CellRendererText renderer = new CellRendererText(); - statsGrid.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, RenderUnitName); + statsGrid.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, RenderUnitStat); for (int i = 0; i < statsCount; i++) { @@ -155,27 +155,34 @@ return nodeView; } - private void RenderUnitName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) - { - object o = model.GetValue(iter, 0); - - if (o is WFObjects.Unit) - { - WFObjects.Unit u = (WFObjects.Unit)o; - (cell as CellRendererText).Text = u.UnitType.Name; - } - } - private void RenderUnitStat(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) { object o = model.GetValue(iter, 0); - if (o is WFObjects.Unit) + if (o is Stat[]) { - WFObjects.Unit u = (WFObjects.Unit)o; - (cell as CellRendererText).Text = u.GetStatValue(column.Title); + Stat[] stats = (Stat[])o; + (cell as CellRendererText).Text = stats[GetStatColumnIndex(column)].SlotValueString; } } + + private int GetStatColumnIndex(TreeViewColumn column) + { + int idx = -1; + TreeViewColumn[] cols = ((TreeView)column.TreeView).Columns; + int colCount = cols.Length; + + for (int i = 0; i < colCount; i++) + { + if (cols[i] == column) + { + idx = i; + break; + } + } + + return idx; + } private void SetWeapons() {