Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
comparison FrmUnit.cs @ 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 |
comparison
equal
deleted
inserted
replaced
153:fcd90498d9a2 | 154:24d0cfaa95da |
---|---|
15 using IBBoard.WarFoundry.API; | 15 using IBBoard.WarFoundry.API; |
16 using IBBoard.WarFoundry.API.Commands; | 16 using IBBoard.WarFoundry.API.Commands; |
17 using IBBoard.WarFoundry.API.Objects; | 17 using IBBoard.WarFoundry.API.Objects; |
18 using IBBoard.WarFoundry.GUI.WinForms.UI; | 18 using IBBoard.WarFoundry.GUI.WinForms.UI; |
19 using IBBoard.WarFoundry.GUI.WinForms.Util; | 19 using IBBoard.WarFoundry.GUI.WinForms.Util; |
20 using log4net; | |
20 | 21 |
21 namespace IBBoard.WarFoundry.GUI.WinForms | 22 namespace IBBoard.WarFoundry.GUI.WinForms |
22 { | 23 { |
23 /// <summary> | 24 /// <summary> |
24 /// Summary description for FrmUnit. | 25 /// Summary description for FrmUnit. |
25 /// </summary> | 26 /// </summary> |
26 public class FrmUnit : IBBoard.Windows.Forms.IBBForm | 27 public class FrmUnit : IBBoard.Windows.Forms.IBBForm |
27 { | 28 { |
29 private static readonly ILog log = LogManager.GetLogger(typeof(FrmUnit)); | |
28 private static readonly int COLUMN_WIDTH = 40; | 30 private static readonly int COLUMN_WIDTH = 40; |
29 private static readonly int BORDER_WIDTH = 1; | 31 private static readonly int BORDER_WIDTH = 1; |
30 private Unit unit; | 32 private Unit unit; |
31 private Dictionary<UnitEquipmentItem, UnitEquipmentChoice> equipmentChoices = new Dictionary<UnitEquipmentItem, UnitEquipmentChoice>(); | 33 private Dictionary<UnitEquipmentItem, UnitEquipmentChoice> equipmentChoices = new Dictionary<UnitEquipmentItem, UnitEquipmentChoice>(); |
32 private Dictionary<string, DataGridView> DataGridViews = new Dictionary<string, DataGridView>(); | 34 private Dictionary<string, DataGridView> DataGridViews = new Dictionary<string, DataGridView>(); |
43 private Label lblPoints; | 45 private Label lblPoints; |
44 private IBBLabel lblNotes; | 46 private IBBLabel lblNotes; |
45 private TextBox notes; | 47 private TextBox notes; |
46 private ListBox abilitiesList; | 48 private ListBox abilitiesList; |
47 private IBBLabel lblAbilities; | 49 private IBBLabel lblAbilities; |
48 private Panel statsPanel; | 50 private FlowLayoutPanel statsPanel; |
49 /// <summary> | 51 /// <summary> |
50 /// Required designer variable. | 52 /// Required designer variable. |
51 /// </summary> | 53 /// </summary> |
52 private System.ComponentModel.Container components = null; | 54 private System.ComponentModel.Container components = null; |
53 | 55 |
105 private void SetStats() | 107 private void SetStats() |
106 { | 108 { |
107 Stat[][] stats = unit.UnitStatsArraysWithName; | 109 Stat[][] stats = unit.UnitStatsArraysWithName; |
108 string[] statsIDs = unit.UnitStatsArrayIDs; | 110 string[] statsIDs = unit.UnitStatsArrayIDs; |
109 int statsCount = stats.Length; | 111 int statsCount = stats.Length; |
112 log.DebugFormat("Unit {0} has {1} stats arrays", unit.UnitType.Name, statsCount); | |
110 | 113 |
111 for (int i = 0; i < statsCount; i++) | 114 for (int i = 0; i < statsCount; i++) |
112 { | 115 { |
113 DataGridView statsGrid = GetDataGridView(statsIDs[i]); | 116 DataGridView statsGrid = GetDataGridView(statsIDs[i]); |
114 DataTable dt = (DataTable)statsGrid.DataSource; | 117 DataTable dt = (DataTable)statsGrid.DataSource; |
115 DataRow dr = dt.NewRow(); | 118 DataRow dr = dt.NewRow(); |
116 dr.ItemArray = stats[i]; | 119 dr.ItemArray = stats[i]; |
120 log.DebugFormat("Add row to data table for {0}", statsIDs[i]); | |
117 dt.Rows.Add(dr); | 121 dt.Rows.Add(dr); |
118 statsGrid.SelectedCells[0].Selected = false; | 122 statsGrid.ClearSelection(); |
119 } | 123 } |
120 } | 124 } |
121 | 125 |
122 private DataGridView GetDataGridView(string statsID) | 126 private DataGridView GetDataGridView(string statsID) |
123 { | 127 { |
136 return grid; | 140 return grid; |
137 } | 141 } |
138 | 142 |
139 private DataGridView CreateDataGridView(string statsID) | 143 private DataGridView CreateDataGridView(string statsID) |
140 { | 144 { |
145 log.DebugFormat("Create DataGridView for stats ID {0}", statsID); | |
141 SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID); | 146 SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID); |
142 StatSlot[] sysStatSlots = sysStats.StatSlots; | 147 StatSlot[] sysStatSlots = sysStats.StatSlots; |
143 StatSlot[] statsWithName = new StatSlot[sysStatSlots.Length + 1]; | 148 StatSlot[] statsWithName = new StatSlot[sysStatSlots.Length + 1]; |
144 statsWithName[0] = new StatSlot("Name"); | 149 statsWithName[0] = new StatSlot("Name"); |
145 sysStatSlots.CopyTo(statsWithName, 1); | 150 sysStatSlots.CopyTo(statsWithName, 1); |
168 return statsGrid; | 173 return statsGrid; |
169 } | 174 } |
170 | 175 |
171 private static DataColumn CreateDataColumn(string slotName) | 176 private static DataColumn CreateDataColumn(string slotName) |
172 { | 177 { |
178 log.DebugFormat("Create column {0}", slotName); | |
173 DataColumn tempCol = new DataColumn(slotName, typeof(Stat)); | 179 DataColumn tempCol = new DataColumn(slotName, typeof(Stat)); |
174 return tempCol; | 180 return tempCol; |
175 } | 181 } |
176 | 182 |
177 public DataGridView CreateDataGridView() | 183 public DataGridView CreateDataGridView() |
178 { | 184 { |
185 log.Debug("Create DataGridView widget"); | |
179 DataGridView statsGrid = new DataGridView(); | 186 DataGridView statsGrid = new DataGridView(); |
180 statsGrid.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | 187 statsGrid.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
181 | System.Windows.Forms.AnchorStyles.Right))); | 188 | System.Windows.Forms.AnchorStyles.Right))); |
182 statsGrid.CausesValidation = false; | 189 statsGrid.CausesValidation = false; |
183 statsGrid.ReadOnly = true; | 190 statsGrid.ReadOnly = true; |
205 | 212 |
206 private static void SetGridHeight(DataGridView statsGrid) | 213 private static void SetGridHeight(DataGridView statsGrid) |
207 { | 214 { |
208 DataGridViewRowCollection rows = statsGrid.Rows; | 215 DataGridViewRowCollection rows = statsGrid.Rows; |
209 statsGrid.Height = statsGrid.Columns[0].HeaderCell.Size.Height + (rows.Count * rows[0].Height); | 216 statsGrid.Height = statsGrid.Columns[0].HeaderCell.Size.Height + (rows.Count * rows[0].Height); |
217 log.DebugFormat("Set height to {0} for grid of {1} rows", statsGrid.Height, rows.Count); | |
210 } | 218 } |
211 | 219 |
212 private void SetWeapons() | 220 private void SetWeapons() |
213 { | 221 { |
214 foreach (UnitEquipmentItem item in unit.GetEquipment()) | 222 foreach (UnitEquipmentItem item in unit.GetEquipment()) |
269 this.lblPoints = new System.Windows.Forms.Label(); | 277 this.lblPoints = new System.Windows.Forms.Label(); |
270 this.lblNotes = new IBBoard.Windows.Forms.IBBLabel(); | 278 this.lblNotes = new IBBoard.Windows.Forms.IBBLabel(); |
271 this.notes = new System.Windows.Forms.TextBox(); | 279 this.notes = new System.Windows.Forms.TextBox(); |
272 this.abilitiesList = new System.Windows.Forms.ListBox(); | 280 this.abilitiesList = new System.Windows.Forms.ListBox(); |
273 this.lblAbilities = new IBBoard.Windows.Forms.IBBLabel(); | 281 this.lblAbilities = new IBBoard.Windows.Forms.IBBLabel(); |
274 this.statsPanel = new System.Windows.Forms.Panel(); | 282 this.statsPanel = new System.Windows.Forms.FlowLayoutPanel(); |
275 ((System.ComponentModel.ISupportInitialize)(this.unitSize)).BeginInit(); | 283 ((System.ComponentModel.ISupportInitialize)(this.unitSize)).BeginInit(); |
276 this.SuspendLayout(); | 284 this.SuspendLayout(); |
277 // | 285 // |
278 // tbUnitName | 286 // tbUnitName |
279 // | 287 // |
420 this.lblAbilities.Text = "abilities"; | 428 this.lblAbilities.Text = "abilities"; |
421 this.lblAbilities.TextAlign = System.Drawing.ContentAlignment.TopRight; | 429 this.lblAbilities.TextAlign = System.Drawing.ContentAlignment.TopRight; |
422 // | 430 // |
423 // statsPanel | 431 // statsPanel |
424 // | 432 // |
433 this.statsPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | |
434 | System.Windows.Forms.AnchorStyles.Right))); | |
425 this.statsPanel.AutoScroll = true; | 435 this.statsPanel.AutoScroll = true; |
426 this.statsPanel.Location = new System.Drawing.Point(8, 35); | 436 this.statsPanel.Location = new System.Drawing.Point(8, 35); |
427 this.statsPanel.Name = "statsPanel"; | 437 this.statsPanel.Name = "statsPanel"; |
428 this.statsPanel.Size = new System.Drawing.Size(600, 85); | 438 this.statsPanel.Size = new System.Drawing.Size(600, 85); |
429 this.statsPanel.TabIndex = 17; | 439 this.statsPanel.TabIndex = 17; |