changeset 73:19e7123aafd5

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
author IBBoard <dev@ibboard.co.uk>
date Tue, 09 Nov 2010 20:54:38 +0000
parents f0cc295e883c
children 52b731576845
files Widgets/UnitDisplayWidget.cs
diffstat 1 files changed, 23 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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()
 		{