changeset 153:fcd90498d9a2

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
author IBBoard <dev@ibboard.co.uk>
date Wed, 26 May 2010 20:05:20 +0000
parents 4b96e6a6c999
children 24d0cfaa95da
files FrmUnit.cs translations/en.translation
diffstat 2 files changed, 39 insertions(+), 15 deletions(-) [+]
line diff
     1.1 --- a/FrmUnit.cs	Fri May 14 19:46:29 2010 +0000
     1.2 +++ b/FrmUnit.cs	Wed May 26 20:05:20 2010 +0000
     1.3 @@ -25,6 +25,8 @@
     1.4  	/// </summary>
     1.5  	public class FrmUnit : IBBoard.Windows.Forms.IBBForm
     1.6  	{
     1.7 +		private static readonly int COLUMN_WIDTH = 40;
     1.8 +		private static readonly int BORDER_WIDTH = 1;
     1.9  		private Unit unit;
    1.10  		private Dictionary<UnitEquipmentItem, UnitEquipmentChoice> equipmentChoices = new Dictionary<UnitEquipmentItem, UnitEquipmentChoice>();
    1.11  		private Dictionary<string, DataGridView> DataGridViews = new Dictionary<string, DataGridView>();
    1.12 @@ -80,9 +82,14 @@
    1.13  		private void TranslateForm()
    1.14  		{
    1.15  			ControlTranslator.TranslateControl(this);
    1.16 +			SetUnitName();
    1.17 +			RefreshUnitEquipment();
    1.18 +		}
    1.19 +
    1.20 +		private void SetUnitName()
    1.21 +		{
    1.22  			tbUnitName.Text = unit.Name;
    1.23 -			Text = Translation.GetTranslation("FrmUnit", "{0}", unit.Name);
    1.24 -			RefreshUnitEquipment();
    1.25 +			Text = Translation.GetTranslation("FrmUnit", "{0} ({1})", unit.Name, unit.UnitType.Name);
    1.26  		}
    1.27  
    1.28  		void unit_PointsValueChanged(WarFoundryObject obj, double oldValue, double newValue)
    1.29 @@ -108,6 +115,7 @@
    1.30  				DataRow dr = dt.NewRow();
    1.31  				dr.ItemArray = stats[i];
    1.32  				dt.Rows.Add(dr);
    1.33 +				statsGrid.SelectedCells[0].Selected = false;
    1.34  			}
    1.35  		}
    1.36  
    1.37 @@ -135,23 +143,22 @@
    1.38  			StatSlot[] statsWithName = new StatSlot[sysStatSlots.Length + 1];
    1.39  			statsWithName[0] = new StatSlot("Name");
    1.40  			sysStatSlots.CopyTo(statsWithName, 1);
    1.41 -			DataColumn[] dc = new DataColumn[statsWithName.Length];
    1.42  			DataTable dt = new DataTable();
    1.43  			int statsCount = statsWithName.Length;
    1.44 +			DataGridView statsGrid = CreateDataGridView();
    1.45 +			statsGrid.DataSource = dt;
    1.46  
    1.47  			for (int i = 0; i < statsCount; i++)
    1.48  			{
    1.49  				StatSlot stat = statsWithName[i];
    1.50  				string slotName = stat.Name;
    1.51 -				dc[i] = CreateDataColumn(slotName);
    1.52 +				dt.Columns.Add(CreateDataColumn(slotName));
    1.53 +				statsGrid.Columns[i].Width = COLUMN_WIDTH;
    1.54  			}
    1.55  
    1.56 -			DataGridView statsGrid = CreateDataGridView();
    1.57 -
    1.58 -			dt.Columns.AddRange(dc);
    1.59 -			statsGrid.DataSource = dt;
    1.60 -			statsGrid.Columns[0].Name = Translation.GetTranslation("UnitName", "Name");
    1.61 -			statsGrid.Columns[0].Width = statsGrid.ClientSize.Width - ((sysStatSlots.Length) * 40) - 4;
    1.62 +			DataGridViewColumn nameColumn = statsGrid.Columns[0];
    1.63 +			nameColumn.Name = Translation.GetTranslation("UnitName", "Name");
    1.64 +			nameColumn.Width = statsGrid.ClientSize.Width - (sysStatSlots.Length * (COLUMN_WIDTH + BORDER_WIDTH));
    1.65  
    1.66  			for (int i = 0; i < statsCount; i++)
    1.67  			{
    1.68 @@ -177,11 +184,31 @@
    1.69  			statsGrid.RowHeadersVisible = false;
    1.70  			statsGrid.Size = new System.Drawing.Size(600, 88);
    1.71  			statsGrid.TabStop = false;
    1.72 +			statsGrid.AllowUserToAddRows = false;
    1.73 +			statsGrid.ScrollBars = ScrollBars.None;
    1.74 +			statsGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
    1.75 +			statsGrid.BorderStyle = BorderStyle.None;
    1.76 +			statsGrid.BackgroundColor = SystemColors.Control;
    1.77 +			statsGrid.RowsAdded += new DataGridViewRowsAddedEventHandler(statsGrid_RowsAdded);
    1.78  			statsPanel.Controls.Add(statsGrid);
    1.79  			statsGrid.Width = statsPanel.Width;
    1.80  			return statsGrid;
    1.81  		}
    1.82  
    1.83 +		private void statsGrid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
    1.84 +		{
    1.85 +			if (sender is DataGridView)
    1.86 +			{
    1.87 +				SetGridHeight((DataGridView)sender);
    1.88 +			}
    1.89 +		}
    1.90 +
    1.91 +		private static void SetGridHeight(DataGridView statsGrid)
    1.92 +		{
    1.93 +			DataGridViewRowCollection rows = statsGrid.Rows;
    1.94 +			statsGrid.Height = statsGrid.Columns[0].HeaderCell.Size.Height + (rows.Count * rows[0].Height);
    1.95 +		}
    1.96 +
    1.97  		private void SetWeapons()
    1.98  		{
    1.99  			foreach (UnitEquipmentItem item in unit.GetEquipment())
   1.100 @@ -483,9 +510,7 @@
   1.101  		{
   1.102  			if (obj is Unit && obj.Equals(unit))
   1.103  			{
   1.104 -				Unit u = (Unit) obj;
   1.105 -				tbUnitName.Text = obj.Name;
   1.106 -				Text = obj.Name;
   1.107 +				SetUnitName();
   1.108  			}
   1.109  		}
   1.110  
   1.111 @@ -494,7 +519,6 @@
   1.112  			if (obj is Unit && obj.Equals(unit))
   1.113  			{
   1.114  				unitSize.Value = newValue;
   1.115 -
   1.116  				RefreshUnitEquipment();
   1.117  			}
   1.118  		}
     2.1 --- a/translations/en.translation	Fri May 14 19:46:29 2010 +0000
     2.2 +++ b/translations/en.translation	Wed May 26 20:05:20 2010 +0000
     2.3 @@ -58,7 +58,7 @@
     2.4  	<translation id="lblVersion">Version: {0}</translation>
     2.5  	<translation id="lblDevelopers">Developers:</translation>
     2.6  	<translation id="lblThanks">Thanks to:</translation>
     2.7 -	<translation id="FrmUnit">{0}</translation>
     2.8 +	<translation id="FrmUnit">{0} ({1})</translation>
     2.9  	<translation id="lblUnitSize">Unit size:</translation>
    2.10  	<translation id="lblEquip">Equipment:</translation>
    2.11  	<translation id="bttnAddWeapon">Add</translation>