changeset 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
files Widgets/UnitDisplayWidget.cs gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs gtk-gui/gui.stetic
diffstat 3 files changed, 147 insertions(+), 94 deletions(-) [+]
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
--- a/gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs	Sat Nov 06 20:22:19 2010 +0000
+++ b/gtk-gui/IBBoard.WarFoundry.GTK.Widgets.UnitDisplayWidget.cs	Tue Nov 09 20:29:50 2010 +0000
@@ -8,8 +8,8 @@
 				private global::Gtk.HBox hbox1;
 				private global::Gtk.Entry unitName;
 				private global::Gtk.SpinButton unitSize;
-				private global::Gtk.ScrolledWindow GtkScrolledWindow;
-				private global::Gtk.NodeView unitStats;
+				private global::Gtk.ScrolledWindow statsScrollPanel;
+				private global::Gtk.VBox statsRepeatBox;
 				private global::Gtk.HSeparator hseparator1;
 				private global::Gtk.HBox hbox2;
 				private global::Gtk.Table table1;
@@ -69,26 +69,30 @@
 			w3.Expand = false;
 			w3.Fill = false;
 			// Container child vbox1.Gtk.Box+BoxChild
-			this.GtkScrolledWindow = new global::Gtk.ScrolledWindow();
-			this.GtkScrolledWindow.Name = "GtkScrolledWindow";
-			this.GtkScrolledWindow.ShadowType = ((global::Gtk.ShadowType)(1));
-			// Container child GtkScrolledWindow.Gtk.Container+ContainerChild
-			this.unitStats = new global::Gtk.NodeView();
-			this.unitStats.HeightRequest = 75;
-			this.unitStats.CanFocus = true;
-			this.unitStats.Name = "unitStats";
-			this.GtkScrolledWindow.Add(this.unitStats);
-			this.vbox1.Add(this.GtkScrolledWindow);
-			global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.GtkScrolledWindow]));
-			w5.Position = 1;
+			this.statsScrollPanel = new global::Gtk.ScrolledWindow();
+			this.statsScrollPanel.CanFocus = true;
+			this.statsScrollPanel.Name = "statsScrollPanel";
+			this.statsScrollPanel.ShadowType = ((global::Gtk.ShadowType)(1));
+			// Container child statsScrollPanel.Gtk.Container+ContainerChild
+			global::Gtk.Viewport w4 = new global::Gtk.Viewport();
+			w4.ShadowType = ((global::Gtk.ShadowType)(0));
+			// Container child GtkViewport.Gtk.Container+ContainerChild
+			this.statsRepeatBox = new global::Gtk.VBox();
+			this.statsRepeatBox.Name = "statsRepeatBox";
+			this.statsRepeatBox.Spacing = 6;
+			w4.Add(this.statsRepeatBox);
+			this.statsScrollPanel.Add(w4);
+			this.vbox1.Add(this.statsScrollPanel);
+			global::Gtk.Box.BoxChild w7 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.statsScrollPanel]));
+			w7.Position = 1;
 			// Container child vbox1.Gtk.Box+BoxChild
 			this.hseparator1 = new global::Gtk.HSeparator();
 			this.hseparator1.Name = "hseparator1";
 			this.vbox1.Add(this.hseparator1);
-			global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.hseparator1]));
-			w6.Position = 2;
-			w6.Expand = false;
-			w6.Fill = false;
+			global::Gtk.Box.BoxChild w8 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.hseparator1]));
+			w8.Position = 2;
+			w8.Expand = false;
+			w8.Fill = false;
 			// Container child vbox1.Gtk.Box+BoxChild
 			this.hbox2 = new global::Gtk.HBox();
 			this.hbox2.Name = "hbox2";
@@ -103,9 +107,9 @@
 			this.equipmentLabel.Name = "equipmentLabel";
 			this.equipmentLabel.LabelProp = global::Mono.Unix.Catalog.GetString("equipment:");
 			this.table1.Add(this.equipmentLabel);
-			global::Gtk.Table.TableChild w7 = ((global::Gtk.Table.TableChild)(this.table1[this.equipmentLabel]));
-			w7.XOptions = ((global::Gtk.AttachOptions)(4));
-			w7.YOptions = ((global::Gtk.AttachOptions)(4));
+			global::Gtk.Table.TableChild w9 = ((global::Gtk.Table.TableChild)(this.table1[this.equipmentLabel]));
+			w9.XOptions = ((global::Gtk.AttachOptions)(4));
+			w9.YOptions = ((global::Gtk.AttachOptions)(4));
 			// Container child table1.Gtk.Table+TableChild
 			this.GtkScrolledWindow2 = new global::Gtk.ScrolledWindow();
 			this.GtkScrolledWindow2.Name = "GtkScrolledWindow2";
@@ -117,10 +121,10 @@
 			this.equipmentList.HeadersVisible = false;
 			this.GtkScrolledWindow2.Add(this.equipmentList);
 			this.table1.Add(this.GtkScrolledWindow2);
-			global::Gtk.Table.TableChild w9 = ((global::Gtk.Table.TableChild)(this.table1[this.GtkScrolledWindow2]));
-			w9.LeftAttach = ((uint)(1));
-			w9.RightAttach = ((uint)(2));
-			w9.YOptions = ((global::Gtk.AttachOptions)(4));
+			global::Gtk.Table.TableChild w11 = ((global::Gtk.Table.TableChild)(this.table1[this.GtkScrolledWindow2]));
+			w11.LeftAttach = ((uint)(1));
+			w11.RightAttach = ((uint)(2));
+			w11.YOptions = ((global::Gtk.AttachOptions)(4));
 			// Container child table1.Gtk.Table+TableChild
 			this.GtkScrolledWindow3 = new global::Gtk.ScrolledWindow();
 			this.GtkScrolledWindow3.Name = "GtkScrolledWindow3";
@@ -132,12 +136,12 @@
 			this.notesView.Editable = false;
 			this.GtkScrolledWindow3.Add(this.notesView);
 			this.table1.Add(this.GtkScrolledWindow3);
-			global::Gtk.Table.TableChild w11 = ((global::Gtk.Table.TableChild)(this.table1[this.GtkScrolledWindow3]));
-			w11.TopAttach = ((uint)(2));
-			w11.BottomAttach = ((uint)(3));
-			w11.LeftAttach = ((uint)(1));
-			w11.RightAttach = ((uint)(2));
-			w11.YOptions = ((global::Gtk.AttachOptions)(4));
+			global::Gtk.Table.TableChild w13 = ((global::Gtk.Table.TableChild)(this.table1[this.GtkScrolledWindow3]));
+			w13.TopAttach = ((uint)(2));
+			w13.BottomAttach = ((uint)(3));
+			w13.LeftAttach = ((uint)(1));
+			w13.RightAttach = ((uint)(2));
+			w13.YOptions = ((global::Gtk.AttachOptions)(4));
 			// Container child table1.Gtk.Table+TableChild
 			this.GtkScrolledWindow4 = new global::Gtk.ScrolledWindow();
 			this.GtkScrolledWindow4.Name = "GtkScrolledWindow4";
@@ -149,35 +153,35 @@
 			this.abilitiesList.HeadersVisible = false;
 			this.GtkScrolledWindow4.Add(this.abilitiesList);
 			this.table1.Add(this.GtkScrolledWindow4);
-			global::Gtk.Table.TableChild w13 = ((global::Gtk.Table.TableChild)(this.table1[this.GtkScrolledWindow4]));
-			w13.TopAttach = ((uint)(1));
-			w13.BottomAttach = ((uint)(2));
-			w13.LeftAttach = ((uint)(1));
-			w13.RightAttach = ((uint)(2));
-			w13.YOptions = ((global::Gtk.AttachOptions)(4));
+			global::Gtk.Table.TableChild w15 = ((global::Gtk.Table.TableChild)(this.table1[this.GtkScrolledWindow4]));
+			w15.TopAttach = ((uint)(1));
+			w15.BottomAttach = ((uint)(2));
+			w15.LeftAttach = ((uint)(1));
+			w15.RightAttach = ((uint)(2));
+			w15.YOptions = ((global::Gtk.AttachOptions)(4));
 			// Container child table1.Gtk.Table+TableChild
 			this.lblAbilities = new global::Gtk.Label();
 			this.lblAbilities.Name = "lblAbilities";
 			this.lblAbilities.LabelProp = global::Mono.Unix.Catalog.GetString("abilities:");
 			this.table1.Add(this.lblAbilities);
-			global::Gtk.Table.TableChild w14 = ((global::Gtk.Table.TableChild)(this.table1[this.lblAbilities]));
-			w14.TopAttach = ((uint)(1));
-			w14.BottomAttach = ((uint)(2));
-			w14.XOptions = ((global::Gtk.AttachOptions)(4));
-			w14.YOptions = ((global::Gtk.AttachOptions)(4));
+			global::Gtk.Table.TableChild w16 = ((global::Gtk.Table.TableChild)(this.table1[this.lblAbilities]));
+			w16.TopAttach = ((uint)(1));
+			w16.BottomAttach = ((uint)(2));
+			w16.XOptions = ((global::Gtk.AttachOptions)(4));
+			w16.YOptions = ((global::Gtk.AttachOptions)(4));
 			// Container child table1.Gtk.Table+TableChild
 			this.lblNotes = new global::Gtk.Label();
 			this.lblNotes.Name = "lblNotes";
 			this.lblNotes.LabelProp = global::Mono.Unix.Catalog.GetString("notes:");
 			this.table1.Add(this.lblNotes);
-			global::Gtk.Table.TableChild w15 = ((global::Gtk.Table.TableChild)(this.table1[this.lblNotes]));
-			w15.TopAttach = ((uint)(2));
-			w15.BottomAttach = ((uint)(3));
-			w15.XOptions = ((global::Gtk.AttachOptions)(4));
-			w15.YOptions = ((global::Gtk.AttachOptions)(4));
+			global::Gtk.Table.TableChild w17 = ((global::Gtk.Table.TableChild)(this.table1[this.lblNotes]));
+			w17.TopAttach = ((uint)(2));
+			w17.BottomAttach = ((uint)(3));
+			w17.XOptions = ((global::Gtk.AttachOptions)(4));
+			w17.YOptions = ((global::Gtk.AttachOptions)(4));
 			this.hbox2.Add(this.table1);
-			global::Gtk.Box.BoxChild w16 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.table1]));
-			w16.Position = 0;
+			global::Gtk.Box.BoxChild w18 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.table1]));
+			w18.Position = 0;
 			// Container child hbox2.Gtk.Box+BoxChild
 			this.vbox3 = new global::Gtk.VBox();
 			this.vbox3.Name = "vbox3";
@@ -189,10 +193,10 @@
 			this.bttnAddEquipment.UseUnderline = true;
 			this.bttnAddEquipment.Label = global::Mono.Unix.Catalog.GetString("Add");
 			this.vbox3.Add(this.bttnAddEquipment);
-			global::Gtk.Box.BoxChild w17 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnAddEquipment]));
-			w17.Position = 0;
-			w17.Expand = false;
-			w17.Fill = false;
+			global::Gtk.Box.BoxChild w19 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnAddEquipment]));
+			w19.Position = 0;
+			w19.Expand = false;
+			w19.Fill = false;
 			// Container child vbox3.Gtk.Box+BoxChild
 			this.bttnEditEquipment = new global::Gtk.Button();
 			this.bttnEditEquipment.Sensitive = false;
@@ -201,10 +205,10 @@
 			this.bttnEditEquipment.UseUnderline = true;
 			this.bttnEditEquipment.Label = global::Mono.Unix.Catalog.GetString("Edit");
 			this.vbox3.Add(this.bttnEditEquipment);
-			global::Gtk.Box.BoxChild w18 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnEditEquipment]));
-			w18.Position = 1;
-			w18.Expand = false;
-			w18.Fill = false;
+			global::Gtk.Box.BoxChild w20 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnEditEquipment]));
+			w20.Position = 1;
+			w20.Expand = false;
+			w20.Fill = false;
 			// Container child vbox3.Gtk.Box+BoxChild
 			this.bttnReplaceEquipment = new global::Gtk.Button();
 			this.bttnReplaceEquipment.Sensitive = false;
@@ -213,10 +217,10 @@
 			this.bttnReplaceEquipment.UseUnderline = true;
 			this.bttnReplaceEquipment.Label = global::Mono.Unix.Catalog.GetString("Replace");
 			this.vbox3.Add(this.bttnReplaceEquipment);
-			global::Gtk.Box.BoxChild w19 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnReplaceEquipment]));
-			w19.Position = 2;
-			w19.Expand = false;
-			w19.Fill = false;
+			global::Gtk.Box.BoxChild w21 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnReplaceEquipment]));
+			w21.Position = 2;
+			w21.Expand = false;
+			w21.Fill = false;
 			// Container child vbox3.Gtk.Box+BoxChild
 			this.bttnRemoveEquipment = new global::Gtk.Button();
 			this.bttnRemoveEquipment.Sensitive = false;
@@ -225,20 +229,20 @@
 			this.bttnRemoveEquipment.UseUnderline = true;
 			this.bttnRemoveEquipment.Label = global::Mono.Unix.Catalog.GetString("Remove");
 			this.vbox3.Add(this.bttnRemoveEquipment);
-			global::Gtk.Box.BoxChild w20 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnRemoveEquipment]));
-			w20.Position = 3;
-			w20.Expand = false;
-			w20.Fill = false;
-			this.hbox2.Add(this.vbox3);
-			global::Gtk.Box.BoxChild w21 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.vbox3]));
-			w21.Position = 1;
-			w21.Expand = false;
-			w21.Fill = false;
-			this.vbox1.Add(this.hbox2);
-			global::Gtk.Box.BoxChild w22 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.hbox2]));
+			global::Gtk.Box.BoxChild w22 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.bttnRemoveEquipment]));
 			w22.Position = 3;
 			w22.Expand = false;
 			w22.Fill = false;
+			this.hbox2.Add(this.vbox3);
+			global::Gtk.Box.BoxChild w23 = ((global::Gtk.Box.BoxChild)(this.hbox2[this.vbox3]));
+			w23.Position = 1;
+			w23.Expand = false;
+			w23.Fill = false;
+			this.vbox1.Add(this.hbox2);
+			global::Gtk.Box.BoxChild w24 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.hbox2]));
+			w24.Position = 3;
+			w24.Expand = false;
+			w24.Fill = false;
 			this.Add(this.vbox1);
 			if ((this.Child != null))
 			{
--- a/gtk-gui/gui.stetic	Sat Nov 06 20:22:19 2010 +0000
+++ b/gtk-gui/gui.stetic	Tue Nov 09 20:29:50 2010 +0000
@@ -735,15 +735,23 @@
           </packing>
         </child>
         <child>
-          <widget class="Gtk.ScrolledWindow" id="GtkScrolledWindow">
+          <widget class="Gtk.ScrolledWindow" id="statsScrollPanel">
             <property name="MemberName" />
+            <property name="CanFocus">True</property>
             <property name="ShadowType">In</property>
             <child>
-              <widget class="Gtk.NodeView" id="unitStats">
+              <widget class="Gtk.Viewport" id="GtkViewport">
                 <property name="MemberName" />
-                <property name="HeightRequest">75</property>
-                <property name="CanFocus">True</property>
-                <property name="ShowScrollbars">True</property>
+                <property name="ShadowType">None</property>
+                <child>
+                  <widget class="Gtk.VBox" id="statsRepeatBox">
+                    <property name="MemberName" />
+                    <property name="Spacing">6</property>
+                    <child>
+                      <placeholder />
+                    </child>
+                  </widget>
+                </child>
               </widget>
             </child>
           </widget>