changeset 150:0e3837170637

Re #269: Handle multiple stat lines * Add initial rebuild with multiple possible statlines - only tested with one stat line type
author IBBoard <dev@ibboard.co.uk>
date Sun, 02 May 2010 15:46:24 +0000
parents def0c33a662c
children 540c8aa6e565
files FrmUnit.cs
diffstat 1 files changed, 109 insertions(+), 66 deletions(-) [+]
line diff
     1.1 --- a/FrmUnit.cs	Sat Apr 24 10:56:40 2010 +0000
     1.2 +++ b/FrmUnit.cs	Sun May 02 15:46:24 2010 +0000
     1.3 @@ -27,8 +27,8 @@
     1.4  	{
     1.5  		private Unit unit;
     1.6  		private Dictionary<UnitEquipmentItem, UnitEquipmentChoice> equipmentChoices = new Dictionary<UnitEquipmentItem, UnitEquipmentChoice>();
     1.7 +		private Dictionary<string, DataGrid> dataGrids = new Dictionary<string, DataGrid>();
     1.8  		private CommandStack commandStack;
     1.9 -		private System.Windows.Forms.DataGrid statsGrid;
    1.10  		private System.Windows.Forms.TextBox tbUnitName;
    1.11  		private System.Windows.Forms.NumericUpDown unitSize;
    1.12  		private IBBLabel lblUnitSize;
    1.13 @@ -43,6 +43,7 @@
    1.14  		private TextBox notes;
    1.15  		private ListBox abilitiesList;
    1.16  		private IBBLabel lblAbilities;
    1.17 +		private Panel statsPanel;
    1.18  		/// <summary>
    1.19  		/// Required designer variable.
    1.20  		/// </summary>
    1.21 @@ -96,45 +97,105 @@
    1.22  
    1.23  		private void SetStats()
    1.24  		{
    1.25 -			DataTable dt = new DataTable();
    1.26 -			Stat[] stats = unit.UnitStatsArrayWithName;
    1.27 +			Stat[][] stats = unit.UnitStatsArraysWithName;
    1.28 +			string[] statsIDs = unit.UnitStatsArrayIDs;
    1.29  			int statsCount = stats.Length;
    1.30 -			DataColumn[] dc = new DataColumn[statsCount];
    1.31 -
    1.32 -			DataGridTableStyle dgStyle = new DataGridTableStyle();
    1.33 -			dgStyle.RowHeadersVisible = false;
    1.34 -
    1.35 -			Stat stat = stats[0];
    1.36 -			DataColumn tempCol = new DataColumn(stat.ParentSlotName);
    1.37 -			tempCol.DataType = stat.GetType();
    1.38  
    1.39  			for (int i = 0; i < statsCount; i++)
    1.40  			{
    1.41 -				stat = stats[i];
    1.42 -				tempCol = new DataColumn(stat.ParentSlotName);
    1.43 -				tempCol.DataType = stat.GetType();
    1.44 -				dc[i] = tempCol;
    1.45 -				DataGridColumnStyle colStyle = new StatColumnStyle();
    1.46 -				colStyle.Width = 40;
    1.47 -				colStyle.MappingName = stat.ParentSlotName;
    1.48 -				colStyle.HeaderText = stat.ParentSlotName;
    1.49 -				colStyle.Alignment = HorizontalAlignment.Center;
    1.50 -				colStyle.ReadOnly = true;
    1.51 -				dgStyle.GridColumnStyles.Add(colStyle);
    1.52 +				DataGrid statsGrid = GetDataGrid(statsIDs[i]);
    1.53 +				DataTable dt = (DataTable)statsGrid.DataSource;
    1.54 +				DataRow dr = dt.NewRow();
    1.55 +				dr.ItemArray = stats[i];
    1.56 +				dt.Rows.Add(dr);
    1.57 +			}
    1.58 +		}
    1.59 +
    1.60 +		private DataGrid GetDataGrid(string statsID)
    1.61 +		{
    1.62 +			DataGrid grid;
    1.63 +
    1.64 +			if (dataGrids.ContainsKey(statsID))
    1.65 +			{
    1.66 +				grid = DictionaryUtils.GetValue(dataGrids, statsID);
    1.67 +			}
    1.68 +			else
    1.69 +			{
    1.70 +				grid = CreateDataGrid(statsID);
    1.71 +				dataGrids[statsID] = grid;
    1.72 +			}
    1.73 +
    1.74 +			return grid;
    1.75 +		}
    1.76 +
    1.77 +		private DataGrid CreateDataGrid(string statsID)
    1.78 +		{
    1.79 +			SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID);
    1.80 +			StatSlot[] sysStatSlots = sysStats.StatSlots;
    1.81 +			StatSlot[] stats = new StatSlot[sysStatSlots.Length + 1];
    1.82 +			stats[0] = new StatSlot("Name");
    1.83 +			sysStatSlots.CopyTo(stats, 1);
    1.84 +			DataColumn[] dc = new DataColumn[stats.Length];
    1.85 +			DataGridTableStyle dgStyle = new DataGridTableStyle();
    1.86 +			dgStyle.RowHeadersVisible = false;
    1.87 +			DataTable dt = new DataTable();
    1.88 +			int statsCount = stats.Length;
    1.89 +
    1.90 +			for (int i = 0; i < statsCount; i++)
    1.91 +			{
    1.92 +				StatSlot stat = stats[i];
    1.93 +				string slotName = stat.Name;
    1.94 +				dc[i] = CreateDataColumn(slotName);
    1.95 +				dgStyle.GridColumnStyles.Add(CreateColumnStyle(slotName));
    1.96  			}
    1.97  
    1.98  			DataGridColumnStyle nameColStyle = dgStyle.GridColumnStyles[0];
    1.99  			nameColStyle.HeaderText = Translation.GetTranslation("UnitName", "Name");
   1.100  			nameColStyle.Alignment = HorizontalAlignment.Left;
   1.101 -			nameColStyle.Width = statsGrid.ClientSize.Width - ((stats.Length - 1) * 40) - 4;
   1.102 +			DataGrid statsGrid = CreateDataGrid();
   1.103 +			nameColStyle.Width = statsGrid.ClientSize.Width - ((stats.Length) * 40) - 4;
   1.104  
   1.105  			dt.Columns.AddRange(dc);
   1.106 -
   1.107 -			DataRow dr = dt.NewRow();
   1.108 -			dr.ItemArray = stats;
   1.109 -			dt.Rows.Add(dr);
   1.110  			statsGrid.DataSource = dt;
   1.111  			statsGrid.TableStyles.Add(dgStyle);
   1.112 +			return statsGrid;
   1.113 +		}
   1.114 +
   1.115 +		private static DataColumn CreateDataColumn(string slotName)
   1.116 +		{
   1.117 +			DataColumn tempCol = new DataColumn(slotName);
   1.118 +			tempCol.DataType = typeof(Stat);
   1.119 +			return tempCol;
   1.120 +		}
   1.121 +
   1.122 +		private static DataGridColumnStyle CreateColumnStyle(string slotName)
   1.123 +		{
   1.124 +			DataGridColumnStyle colStyle = new StatColumnStyle();
   1.125 +			colStyle.Width = 40;
   1.126 +			colStyle.MappingName = slotName;
   1.127 +			colStyle.HeaderText = slotName;
   1.128 +			colStyle.Alignment = HorizontalAlignment.Center;
   1.129 +			colStyle.ReadOnly = true;
   1.130 +			return colStyle;
   1.131 +		}
   1.132 +
   1.133 +		public DataGrid CreateDataGrid()
   1.134 +		{
   1.135 +			DataGrid statsGrid = new DataGrid();
   1.136 +			statsGrid.AllowNavigation = false;
   1.137 +			statsGrid.AllowSorting = false;
   1.138 +			statsGrid.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
   1.139 +						| System.Windows.Forms.AnchorStyles.Right)));
   1.140 +			statsGrid.CaptionVisible = false;
   1.141 +			statsGrid.CausesValidation = false;
   1.142 +			statsGrid.PreferredColumnWidth = 40;
   1.143 +			statsGrid.ReadOnly = true;
   1.144 +			statsGrid.RowHeadersVisible = false;
   1.145 +			statsGrid.Size = new System.Drawing.Size(600, 88);
   1.146 +			statsGrid.TabStop = false;
   1.147 +			statsPanel.Controls.Add(statsGrid);
   1.148 +			statsGrid.Width = statsPanel.Width;
   1.149 +			return statsGrid;
   1.150  		}
   1.151  
   1.152  		private void SetWeapons()
   1.153 @@ -185,7 +246,6 @@
   1.154  		/// </summary>
   1.155  		private void InitializeComponent()
   1.156  		{
   1.157 -			this.statsGrid = new System.Windows.Forms.DataGrid();
   1.158  			this.tbUnitName = new System.Windows.Forms.TextBox();
   1.159  			this.unitSize = new System.Windows.Forms.NumericUpDown();
   1.160  			this.lblUnitSize = new IBBoard.Windows.Forms.IBBLabel();
   1.161 @@ -200,46 +260,22 @@
   1.162  			this.notes = new System.Windows.Forms.TextBox();
   1.163  			this.abilitiesList = new System.Windows.Forms.ListBox();
   1.164  			this.lblAbilities = new IBBoard.Windows.Forms.IBBLabel();
   1.165 -			((System.ComponentModel.ISupportInitialize) (this.statsGrid)).BeginInit();
   1.166 -			((System.ComponentModel.ISupportInitialize) (this.unitSize)).BeginInit();
   1.167 +			this.statsPanel = new System.Windows.Forms.Panel();
   1.168 +			((System.ComponentModel.ISupportInitialize)(this.unitSize)).BeginInit();
   1.169  			this.SuspendLayout();
   1.170  			// 
   1.171 -			// statsGrid
   1.172 -			// 
   1.173 -			this.statsGrid.AllowNavigation = false;
   1.174 -			this.statsGrid.AllowSorting = false;
   1.175 -			this.statsGrid.AlternatingBackColor = System.Drawing.SystemColors.Control;
   1.176 -			this.statsGrid.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
   1.177 -						| System.Windows.Forms.AnchorStyles.Right)));
   1.178 -			this.statsGrid.BackgroundColor = System.Drawing.SystemColors.Control;
   1.179 -			this.statsGrid.CaptionVisible = false;
   1.180 -			this.statsGrid.CausesValidation = false;
   1.181 -			this.statsGrid.DataMember = "";
   1.182 -			this.statsGrid.GridLineColor = System.Drawing.SystemColors.ControlDarkDark;
   1.183 -			this.statsGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
   1.184 -			this.statsGrid.Location = new System.Drawing.Point(8, 32);
   1.185 -			this.statsGrid.Name = "statsGrid";
   1.186 -			this.statsGrid.PreferredColumnWidth = 40;
   1.187 -			this.statsGrid.ReadOnly = true;
   1.188 -			this.statsGrid.RowHeadersVisible = false;
   1.189 -			this.statsGrid.SelectionBackColor = System.Drawing.SystemColors.Control;
   1.190 -			this.statsGrid.SelectionForeColor = System.Drawing.SystemColors.WindowText;
   1.191 -			this.statsGrid.Size = new System.Drawing.Size(600, 88);
   1.192 -			this.statsGrid.TabIndex = 0;
   1.193 -			this.statsGrid.TabStop = false;
   1.194 -			// 
   1.195  			// tbUnitName
   1.196  			// 
   1.197  			this.tbUnitName.Location = new System.Drawing.Point(8, 8);
   1.198  			this.tbUnitName.Name = "tbUnitName";
   1.199  			this.tbUnitName.Size = new System.Drawing.Size(344, 20);
   1.200  			this.tbUnitName.TabIndex = 1;
   1.201 +			this.tbUnitName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbUnitName_KeyDown);
   1.202  			this.tbUnitName.Leave += new System.EventHandler(this.tbUnitName_Leave);
   1.203 -			this.tbUnitName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbUnitName_KeyDown);
   1.204  			// 
   1.205  			// unitSize
   1.206  			// 
   1.207 -			this.unitSize.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.208 +			this.unitSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.209  			this.unitSize.Location = new System.Drawing.Point(528, 8);
   1.210  			this.unitSize.Name = "unitSize";
   1.211  			this.unitSize.Size = new System.Drawing.Size(80, 20);
   1.212 @@ -255,7 +291,7 @@
   1.213  			// 
   1.214  			// lblUnitSize
   1.215  			// 
   1.216 -			this.lblUnitSize.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.217 +			this.lblUnitSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.218  			this.lblUnitSize.Location = new System.Drawing.Point(426, 8);
   1.219  			this.lblUnitSize.Name = "lblUnitSize";
   1.220  			this.lblUnitSize.Size = new System.Drawing.Size(98, 23);
   1.221 @@ -274,7 +310,7 @@
   1.222  			// 
   1.223  			// bttnAddWeapon
   1.224  			// 
   1.225 -			this.bttnAddWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.226 +			this.bttnAddWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.227  			this.bttnAddWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System;
   1.228  			this.bttnAddWeapon.Location = new System.Drawing.Point(516, 126);
   1.229  			this.bttnAddWeapon.Name = "bttnAddWeapon";
   1.230 @@ -285,7 +321,7 @@
   1.231  			// 
   1.232  			// bttnRemoveWeapon
   1.233  			// 
   1.234 -			this.bttnRemoveWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.235 +			this.bttnRemoveWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.236  			this.bttnRemoveWeapon.Enabled = false;
   1.237  			this.bttnRemoveWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System;
   1.238  			this.bttnRemoveWeapon.Location = new System.Drawing.Point(516, 210);
   1.239 @@ -297,18 +333,18 @@
   1.240  			// 
   1.241  			// equipmentList
   1.242  			// 
   1.243 -			this.equipmentList.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
   1.244 +			this.equipmentList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
   1.245  						| System.Windows.Forms.AnchorStyles.Right)));
   1.246  			this.equipmentList.Location = new System.Drawing.Point(102, 126);
   1.247  			this.equipmentList.Name = "equipmentList";
   1.248  			this.equipmentList.Size = new System.Drawing.Size(408, 108);
   1.249  			this.equipmentList.TabIndex = 6;
   1.250 +			this.equipmentList.SelectedIndexChanged += new System.EventHandler(this.equipmentList_SelectedIndexChanged);
   1.251  			this.equipmentList.DoubleClick += new System.EventHandler(this.equipmentList_DoubleClick);
   1.252 -			this.equipmentList.SelectedIndexChanged += new System.EventHandler(this.equipmentList_SelectedIndexChanged);
   1.253  			// 
   1.254  			// bttnReplaceWeapon
   1.255  			// 
   1.256 -			this.bttnReplaceWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.257 +			this.bttnReplaceWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.258  			this.bttnReplaceWeapon.Enabled = false;
   1.259  			this.bttnReplaceWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System;
   1.260  			this.bttnReplaceWeapon.Location = new System.Drawing.Point(516, 182);
   1.261 @@ -320,7 +356,7 @@
   1.262  			// 
   1.263  			// bttnEditWeapon
   1.264  			// 
   1.265 -			this.bttnEditWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.266 +			this.bttnEditWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
   1.267  			this.bttnEditWeapon.Enabled = false;
   1.268  			this.bttnEditWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System;
   1.269  			this.bttnEditWeapon.Location = new System.Drawing.Point(516, 154);
   1.270 @@ -373,10 +409,19 @@
   1.271  			this.lblAbilities.Text = "abilities";
   1.272  			this.lblAbilities.TextAlign = System.Drawing.ContentAlignment.TopRight;
   1.273  			// 
   1.274 +			// statsPanel
   1.275 +			// 
   1.276 +			this.statsPanel.AutoScroll = true;
   1.277 +			this.statsPanel.Location = new System.Drawing.Point(8, 35);
   1.278 +			this.statsPanel.Name = "statsPanel";
   1.279 +			this.statsPanel.Size = new System.Drawing.Size(600, 85);
   1.280 +			this.statsPanel.TabIndex = 17;
   1.281 +			// 
   1.282  			// FrmUnit
   1.283  			// 
   1.284  			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   1.285  			this.ClientSize = new System.Drawing.Size(616, 391);
   1.286 +			this.Controls.Add(this.statsPanel);
   1.287  			this.Controls.Add(this.lblAbilities);
   1.288  			this.Controls.Add(this.abilitiesList);
   1.289  			this.Controls.Add(this.notes);
   1.290 @@ -391,14 +436,12 @@
   1.291  			this.Controls.Add(this.lblUnitSize);
   1.292  			this.Controls.Add(this.unitSize);
   1.293  			this.Controls.Add(this.tbUnitName);
   1.294 -			this.Controls.Add(this.statsGrid);
   1.295  			this.Name = "FrmUnit";
   1.296  			this.ShowIcon = false;
   1.297  			this.ShowInTaskbar = false;
   1.298  			this.Text = "FrmUnit";
   1.299  			this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmUnit_FormClosing);
   1.300 -			((System.ComponentModel.ISupportInitialize) (this.statsGrid)).EndInit();
   1.301 -			((System.ComponentModel.ISupportInitialize) (this.unitSize)).EndInit();
   1.302 +			((System.ComponentModel.ISupportInitialize)(this.unitSize)).EndInit();
   1.303  			this.ResumeLayout(false);
   1.304  			this.PerformLayout();
   1.305