# HG changeset patch # User IBBoard # Date 1274904320 0 # Node ID fcd90498d9a2af9daa73395902ec831a904d2983 # Parent 4b96e6a6c999095fd070f438521956e5cda785cf Re #269: Handle multiple stat lines * Improve rendering of stats * Fix column widths * Set width and height based on content Also: * Make FrmUnit title contain unit type as we're using it more now Still needs more testing and fixing diff -r 4b96e6a6c999 -r fcd90498d9a2 FrmUnit.cs --- a/FrmUnit.cs Fri May 14 19:46:29 2010 +0000 +++ b/FrmUnit.cs Wed May 26 20:05:20 2010 +0000 @@ -25,6 +25,8 @@ /// public class FrmUnit : IBBoard.Windows.Forms.IBBForm { + private static readonly int COLUMN_WIDTH = 40; + private static readonly int BORDER_WIDTH = 1; private Unit unit; private Dictionary equipmentChoices = new Dictionary(); private Dictionary DataGridViews = new Dictionary(); @@ -80,9 +82,14 @@ private void TranslateForm() { ControlTranslator.TranslateControl(this); + SetUnitName(); + RefreshUnitEquipment(); + } + + private void SetUnitName() + { tbUnitName.Text = unit.Name; - Text = Translation.GetTranslation("FrmUnit", "{0}", unit.Name); - RefreshUnitEquipment(); + Text = Translation.GetTranslation("FrmUnit", "{0} ({1})", unit.Name, unit.UnitType.Name); } void unit_PointsValueChanged(WarFoundryObject obj, double oldValue, double newValue) @@ -108,6 +115,7 @@ DataRow dr = dt.NewRow(); dr.ItemArray = stats[i]; dt.Rows.Add(dr); + statsGrid.SelectedCells[0].Selected = false; } } @@ -135,23 +143,22 @@ StatSlot[] statsWithName = new StatSlot[sysStatSlots.Length + 1]; statsWithName[0] = new StatSlot("Name"); sysStatSlots.CopyTo(statsWithName, 1); - DataColumn[] dc = new DataColumn[statsWithName.Length]; DataTable dt = new DataTable(); int statsCount = statsWithName.Length; + DataGridView statsGrid = CreateDataGridView(); + statsGrid.DataSource = dt; for (int i = 0; i < statsCount; i++) { StatSlot stat = statsWithName[i]; string slotName = stat.Name; - dc[i] = CreateDataColumn(slotName); + dt.Columns.Add(CreateDataColumn(slotName)); + statsGrid.Columns[i].Width = COLUMN_WIDTH; } - DataGridView statsGrid = CreateDataGridView(); - - dt.Columns.AddRange(dc); - statsGrid.DataSource = dt; - statsGrid.Columns[0].Name = Translation.GetTranslation("UnitName", "Name"); - statsGrid.Columns[0].Width = statsGrid.ClientSize.Width - ((sysStatSlots.Length) * 40) - 4; + DataGridViewColumn nameColumn = statsGrid.Columns[0]; + nameColumn.Name = Translation.GetTranslation("UnitName", "Name"); + nameColumn.Width = statsGrid.ClientSize.Width - (sysStatSlots.Length * (COLUMN_WIDTH + BORDER_WIDTH)); for (int i = 0; i < statsCount; i++) { @@ -177,11 +184,31 @@ statsGrid.RowHeadersVisible = false; statsGrid.Size = new System.Drawing.Size(600, 88); statsGrid.TabStop = false; + statsGrid.AllowUserToAddRows = false; + statsGrid.ScrollBars = ScrollBars.None; + statsGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + statsGrid.BorderStyle = BorderStyle.None; + statsGrid.BackgroundColor = SystemColors.Control; + statsGrid.RowsAdded += new DataGridViewRowsAddedEventHandler(statsGrid_RowsAdded); statsPanel.Controls.Add(statsGrid); statsGrid.Width = statsPanel.Width; return statsGrid; } + private void statsGrid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) + { + if (sender is DataGridView) + { + SetGridHeight((DataGridView)sender); + } + } + + private static void SetGridHeight(DataGridView statsGrid) + { + DataGridViewRowCollection rows = statsGrid.Rows; + statsGrid.Height = statsGrid.Columns[0].HeaderCell.Size.Height + (rows.Count * rows[0].Height); + } + private void SetWeapons() { foreach (UnitEquipmentItem item in unit.GetEquipment()) @@ -483,9 +510,7 @@ { if (obj is Unit && obj.Equals(unit)) { - Unit u = (Unit) obj; - tbUnitName.Text = obj.Name; - Text = obj.Name; + SetUnitName(); } } @@ -494,7 +519,6 @@ if (obj is Unit && obj.Equals(unit)) { unitSize.Value = newValue; - RefreshUnitEquipment(); } } diff -r 4b96e6a6c999 -r fcd90498d9a2 translations/en.translation --- a/translations/en.translation Fri May 14 19:46:29 2010 +0000 +++ b/translations/en.translation Wed May 26 20:05:20 2010 +0000 @@ -58,7 +58,7 @@ Version: {0} Developers: Thanks to: - {0} + {0} ({1}) Unit size: Equipment: Add