changeset 154:24d0cfaa95da

Re #269: Handle multiple stat lines * Add debug logging to work out what was going on * Migrate to using a FlowLayoutPanel Previous problem fixed - test data file had stats override, which stopped multiple stat lines showing TODO: Reduce the width of the stats a bit so that we only get vertical scrollbars
author IBBoard <dev@ibboard.co.uk>
date Thu, 27 May 2010 20:01:07 +0000
parents fcd90498d9a2
children 67b4b84f5674
files FrmUnit.cs
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/FrmUnit.cs	Wed May 26 20:05:20 2010 +0000
+++ b/FrmUnit.cs	Thu May 27 20:01:07 2010 +0000
@@ -17,6 +17,7 @@
 using IBBoard.WarFoundry.API.Objects;
 using IBBoard.WarFoundry.GUI.WinForms.UI;
 using IBBoard.WarFoundry.GUI.WinForms.Util;
+using log4net;
 
 namespace IBBoard.WarFoundry.GUI.WinForms
 {
@@ -25,6 +26,7 @@
 	/// </summary>
 	public class FrmUnit : IBBoard.Windows.Forms.IBBForm
 	{
+		private static readonly ILog log = LogManager.GetLogger(typeof(FrmUnit));
 		private static readonly int COLUMN_WIDTH = 40;
 		private static readonly int BORDER_WIDTH = 1;
 		private Unit unit;
@@ -45,7 +47,7 @@
 		private TextBox notes;
 		private ListBox abilitiesList;
 		private IBBLabel lblAbilities;
-		private Panel statsPanel;
+		private FlowLayoutPanel statsPanel;
 		/// <summary>
 		/// Required designer variable.
 		/// </summary>
@@ -107,6 +109,7 @@
 			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 < statsCount; i++)
 			{
@@ -114,8 +117,9 @@
 				DataTable dt = (DataTable)statsGrid.DataSource;
 				DataRow dr = dt.NewRow();
 				dr.ItemArray = stats[i];
+				log.DebugFormat("Add row to data table for {0}", statsIDs[i]);
 				dt.Rows.Add(dr);
-				statsGrid.SelectedCells[0].Selected = false;
+				statsGrid.ClearSelection();
 			}
 		}
 
@@ -138,6 +142,7 @@
 
 		private DataGridView CreateDataGridView(string statsID)
 		{
+			log.DebugFormat("Create DataGridView for stats ID {0}", statsID);
 			SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID);
 			StatSlot[] sysStatSlots = sysStats.StatSlots;
 			StatSlot[] statsWithName = new StatSlot[sysStatSlots.Length + 1];
@@ -170,12 +175,14 @@
 
 		private static DataColumn CreateDataColumn(string slotName)
 		{
+			log.DebugFormat("Create column {0}", slotName);
 			DataColumn tempCol = new DataColumn(slotName,  typeof(Stat));
 			return tempCol;
 		}
 
 		public DataGridView CreateDataGridView()
 		{
+			log.Debug("Create DataGridView widget");
 			DataGridView statsGrid = new DataGridView();
 			statsGrid.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
 						| System.Windows.Forms.AnchorStyles.Right)));
@@ -207,6 +214,7 @@
 		{
 			DataGridViewRowCollection rows = statsGrid.Rows;
 			statsGrid.Height = statsGrid.Columns[0].HeaderCell.Size.Height + (rows.Count * rows[0].Height);
+			log.DebugFormat("Set height to {0} for grid of {1} rows", statsGrid.Height, rows.Count);
 		}
 
 		private void SetWeapons()
@@ -271,7 +279,7 @@
 			this.notes = new System.Windows.Forms.TextBox();
 			this.abilitiesList = new System.Windows.Forms.ListBox();
 			this.lblAbilities = new IBBoard.Windows.Forms.IBBLabel();
-			this.statsPanel = new System.Windows.Forms.Panel();
+			this.statsPanel = new System.Windows.Forms.FlowLayoutPanel();
 			((System.ComponentModel.ISupportInitialize)(this.unitSize)).BeginInit();
 			this.SuspendLayout();
 			// 
@@ -422,6 +430,8 @@
 			// 
 			// statsPanel
 			// 
+			this.statsPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+						| System.Windows.Forms.AnchorStyles.Right)));
 			this.statsPanel.AutoScroll = true;
 			this.statsPanel.Location = new System.Drawing.Point(8, 35);
 			this.statsPanel.Name = "statsPanel";