Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
comparison FrmUnit.cs @ 155:67b4b84f5674
Fixes #269: Handle multiple stat lines
* Reduce the width of the tables to only show a vertical scrollbar
* Make the width of the columns more proportional to how many there are
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 28 May 2010 19:49:34 +0000 |
parents | 24d0cfaa95da |
children | 08271d6569fa |
comparison
equal
deleted
inserted
replaced
154:24d0cfaa95da | 155:67b4b84f5674 |
---|---|
25 /// Summary description for FrmUnit. | 25 /// Summary description for FrmUnit. |
26 /// </summary> | 26 /// </summary> |
27 public class FrmUnit : IBBoard.Windows.Forms.IBBForm | 27 public class FrmUnit : IBBoard.Windows.Forms.IBBForm |
28 { | 28 { |
29 private static readonly ILog log = LogManager.GetLogger(typeof(FrmUnit)); | 29 private static readonly ILog log = LogManager.GetLogger(typeof(FrmUnit)); |
30 private static readonly int COLUMN_WIDTH = 40; | |
31 private static readonly int BORDER_WIDTH = 1; | 30 private static readonly int BORDER_WIDTH = 1; |
31 private static readonly int NAME_COL_WIDTH_MULTIPLIER = 3; | |
32 private Unit unit; | 32 private Unit unit; |
33 private Dictionary<UnitEquipmentItem, UnitEquipmentChoice> equipmentChoices = new Dictionary<UnitEquipmentItem, UnitEquipmentChoice>(); | 33 private Dictionary<UnitEquipmentItem, UnitEquipmentChoice> equipmentChoices = new Dictionary<UnitEquipmentItem, UnitEquipmentChoice>(); |
34 private Dictionary<string, DataGridView> DataGridViews = new Dictionary<string, DataGridView>(); | 34 private Dictionary<string, DataGridView> DataGridViews = new Dictionary<string, DataGridView>(); |
35 private CommandStack commandStack; | 35 private CommandStack commandStack; |
36 private System.Windows.Forms.TextBox tbUnitName; | 36 private System.Windows.Forms.TextBox tbUnitName; |
143 private DataGridView CreateDataGridView(string statsID) | 143 private DataGridView CreateDataGridView(string statsID) |
144 { | 144 { |
145 log.DebugFormat("Create DataGridView for stats ID {0}", statsID); | 145 log.DebugFormat("Create DataGridView for stats ID {0}", statsID); |
146 SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID); | 146 SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID); |
147 StatSlot[] sysStatSlots = sysStats.StatSlots; | 147 StatSlot[] sysStatSlots = sysStats.StatSlots; |
148 StatSlot[] statsWithName = new StatSlot[sysStatSlots.Length + 1]; | 148 int statsCount = sysStatSlots.Length; |
149 int statsWithNameCount = statsCount + 1; | |
150 StatSlot[] statsWithName = new StatSlot[statsWithNameCount]; | |
149 statsWithName[0] = new StatSlot("Name"); | 151 statsWithName[0] = new StatSlot("Name"); |
150 sysStatSlots.CopyTo(statsWithName, 1); | 152 sysStatSlots.CopyTo(statsWithName, 1); |
151 DataTable dt = new DataTable(); | 153 DataTable dt = new DataTable(); |
152 int statsCount = statsWithName.Length; | |
153 DataGridView statsGrid = CreateDataGridView(); | 154 DataGridView statsGrid = CreateDataGridView(); |
154 statsGrid.DataSource = dt; | 155 statsGrid.DataSource = dt; |
155 | 156 int columnWidth = statsGrid.Width / (statsCount + NAME_COL_WIDTH_MULTIPLIER); |
156 for (int i = 0; i < statsCount; i++) | 157 |
158 for (int i = 0; i < statsWithNameCount; i++) | |
157 { | 159 { |
158 StatSlot stat = statsWithName[i]; | 160 StatSlot stat = statsWithName[i]; |
159 string slotName = stat.Name; | 161 string slotName = stat.Name; |
160 dt.Columns.Add(CreateDataColumn(slotName)); | 162 dt.Columns.Add(CreateDataColumn(slotName)); |
161 statsGrid.Columns[i].Width = COLUMN_WIDTH; | 163 DataGridViewColumn col = statsGrid.Columns[i]; |
164 col.Width = columnWidth; | |
165 col.CellTemplate = new StatsDataGridViewCell(); | |
162 } | 166 } |
163 | 167 |
164 DataGridViewColumn nameColumn = statsGrid.Columns[0]; | 168 DataGridViewColumn nameColumn = statsGrid.Columns[0]; |
165 nameColumn.Name = Translation.GetTranslation("UnitName", "Name"); | 169 nameColumn.Name = Translation.GetTranslation("UnitName", "Name"); |
166 nameColumn.Width = statsGrid.ClientSize.Width - (sysStatSlots.Length * (COLUMN_WIDTH + BORDER_WIDTH)); | 170 nameColumn.Width = statsGrid.Width - (statsCount * columnWidth); |
167 | |
168 for (int i = 0; i < statsCount; i++) | |
169 { | |
170 statsGrid.Columns[i].CellTemplate = new StatsDataGridViewCell(); | |
171 } | |
172 | 171 |
173 return statsGrid; | 172 return statsGrid; |
174 } | 173 } |
175 | 174 |
176 private static DataColumn CreateDataColumn(string slotName) | 175 private static DataColumn CreateDataColumn(string slotName) |
196 statsGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; | 195 statsGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; |
197 statsGrid.BorderStyle = BorderStyle.None; | 196 statsGrid.BorderStyle = BorderStyle.None; |
198 statsGrid.BackgroundColor = SystemColors.Control; | 197 statsGrid.BackgroundColor = SystemColors.Control; |
199 statsGrid.RowsAdded += new DataGridViewRowsAddedEventHandler(statsGrid_RowsAdded); | 198 statsGrid.RowsAdded += new DataGridViewRowsAddedEventHandler(statsGrid_RowsAdded); |
200 statsPanel.Controls.Add(statsGrid); | 199 statsPanel.Controls.Add(statsGrid); |
201 statsGrid.Width = statsPanel.Width; | 200 statsGrid.Width = statsPanel.Width - (int)Math.Round(SystemInformation.VerticalScrollBarWidth * 1.4); |
202 return statsGrid; | 201 return statsGrid; |
203 } | 202 } |
204 | 203 |
205 private void statsGrid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) | 204 private void statsGrid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) |
206 { | 205 { |