# HG changeset patch # User IBBoard # Date 1272815184 0 # Node ID 0e38371706379917bb10807ea2ac4454cf18e04f # Parent def0c33a662c1ad53c007367438a30f2a4b40b90 Re #269: Handle multiple stat lines * Add initial rebuild with multiple possible statlines - only tested with one stat line type diff -r def0c33a662c -r 0e3837170637 FrmUnit.cs --- a/FrmUnit.cs Sat Apr 24 10:56:40 2010 +0000 +++ b/FrmUnit.cs Sun May 02 15:46:24 2010 +0000 @@ -27,8 +27,8 @@ { private Unit unit; private Dictionary equipmentChoices = new Dictionary(); + private Dictionary dataGrids = new Dictionary(); private CommandStack commandStack; - private System.Windows.Forms.DataGrid statsGrid; private System.Windows.Forms.TextBox tbUnitName; private System.Windows.Forms.NumericUpDown unitSize; private IBBLabel lblUnitSize; @@ -43,6 +43,7 @@ private TextBox notes; private ListBox abilitiesList; private IBBLabel lblAbilities; + private Panel statsPanel; /// /// Required designer variable. /// @@ -96,45 +97,105 @@ private void SetStats() { - DataTable dt = new DataTable(); - Stat[] stats = unit.UnitStatsArrayWithName; + Stat[][] stats = unit.UnitStatsArraysWithName; + string[] statsIDs = unit.UnitStatsArrayIDs; int statsCount = stats.Length; - DataColumn[] dc = new DataColumn[statsCount]; - - DataGridTableStyle dgStyle = new DataGridTableStyle(); - dgStyle.RowHeadersVisible = false; - - Stat stat = stats[0]; - DataColumn tempCol = new DataColumn(stat.ParentSlotName); - tempCol.DataType = stat.GetType(); for (int i = 0; i < statsCount; i++) { - stat = stats[i]; - tempCol = new DataColumn(stat.ParentSlotName); - tempCol.DataType = stat.GetType(); - dc[i] = tempCol; - DataGridColumnStyle colStyle = new StatColumnStyle(); - colStyle.Width = 40; - colStyle.MappingName = stat.ParentSlotName; - colStyle.HeaderText = stat.ParentSlotName; - colStyle.Alignment = HorizontalAlignment.Center; - colStyle.ReadOnly = true; - dgStyle.GridColumnStyles.Add(colStyle); + DataGrid statsGrid = GetDataGrid(statsIDs[i]); + DataTable dt = (DataTable)statsGrid.DataSource; + DataRow dr = dt.NewRow(); + dr.ItemArray = stats[i]; + dt.Rows.Add(dr); + } + } + + private DataGrid GetDataGrid(string statsID) + { + DataGrid grid; + + if (dataGrids.ContainsKey(statsID)) + { + grid = DictionaryUtils.GetValue(dataGrids, statsID); + } + else + { + grid = CreateDataGrid(statsID); + dataGrids[statsID] = grid; + } + + return grid; + } + + private DataGrid CreateDataGrid(string statsID) + { + SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID); + StatSlot[] sysStatSlots = sysStats.StatSlots; + StatSlot[] stats = new StatSlot[sysStatSlots.Length + 1]; + stats[0] = new StatSlot("Name"); + sysStatSlots.CopyTo(stats, 1); + DataColumn[] dc = new DataColumn[stats.Length]; + DataGridTableStyle dgStyle = new DataGridTableStyle(); + dgStyle.RowHeadersVisible = false; + DataTable dt = new DataTable(); + int statsCount = stats.Length; + + for (int i = 0; i < statsCount; i++) + { + StatSlot stat = stats[i]; + string slotName = stat.Name; + dc[i] = CreateDataColumn(slotName); + dgStyle.GridColumnStyles.Add(CreateColumnStyle(slotName)); } DataGridColumnStyle nameColStyle = dgStyle.GridColumnStyles[0]; nameColStyle.HeaderText = Translation.GetTranslation("UnitName", "Name"); nameColStyle.Alignment = HorizontalAlignment.Left; - nameColStyle.Width = statsGrid.ClientSize.Width - ((stats.Length - 1) * 40) - 4; + DataGrid statsGrid = CreateDataGrid(); + nameColStyle.Width = statsGrid.ClientSize.Width - ((stats.Length) * 40) - 4; dt.Columns.AddRange(dc); - - DataRow dr = dt.NewRow(); - dr.ItemArray = stats; - dt.Rows.Add(dr); statsGrid.DataSource = dt; statsGrid.TableStyles.Add(dgStyle); + return statsGrid; + } + + private static DataColumn CreateDataColumn(string slotName) + { + DataColumn tempCol = new DataColumn(slotName); + tempCol.DataType = typeof(Stat); + return tempCol; + } + + private static DataGridColumnStyle CreateColumnStyle(string slotName) + { + DataGridColumnStyle colStyle = new StatColumnStyle(); + colStyle.Width = 40; + colStyle.MappingName = slotName; + colStyle.HeaderText = slotName; + colStyle.Alignment = HorizontalAlignment.Center; + colStyle.ReadOnly = true; + return colStyle; + } + + public DataGrid CreateDataGrid() + { + DataGrid statsGrid = new DataGrid(); + statsGrid.AllowNavigation = false; + statsGrid.AllowSorting = false; + statsGrid.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + statsGrid.CaptionVisible = false; + statsGrid.CausesValidation = false; + statsGrid.PreferredColumnWidth = 40; + statsGrid.ReadOnly = true; + statsGrid.RowHeadersVisible = false; + statsGrid.Size = new System.Drawing.Size(600, 88); + statsGrid.TabStop = false; + statsPanel.Controls.Add(statsGrid); + statsGrid.Width = statsPanel.Width; + return statsGrid; } private void SetWeapons() @@ -185,7 +246,6 @@ /// private void InitializeComponent() { - this.statsGrid = new System.Windows.Forms.DataGrid(); this.tbUnitName = new System.Windows.Forms.TextBox(); this.unitSize = new System.Windows.Forms.NumericUpDown(); this.lblUnitSize = new IBBoard.Windows.Forms.IBBLabel(); @@ -200,46 +260,22 @@ this.notes = new System.Windows.Forms.TextBox(); this.abilitiesList = new System.Windows.Forms.ListBox(); this.lblAbilities = new IBBoard.Windows.Forms.IBBLabel(); - ((System.ComponentModel.ISupportInitialize) (this.statsGrid)).BeginInit(); - ((System.ComponentModel.ISupportInitialize) (this.unitSize)).BeginInit(); + this.statsPanel = new System.Windows.Forms.Panel(); + ((System.ComponentModel.ISupportInitialize)(this.unitSize)).BeginInit(); this.SuspendLayout(); // - // statsGrid - // - this.statsGrid.AllowNavigation = false; - this.statsGrid.AllowSorting = false; - this.statsGrid.AlternatingBackColor = System.Drawing.SystemColors.Control; - this.statsGrid.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.statsGrid.BackgroundColor = System.Drawing.SystemColors.Control; - this.statsGrid.CaptionVisible = false; - this.statsGrid.CausesValidation = false; - this.statsGrid.DataMember = ""; - this.statsGrid.GridLineColor = System.Drawing.SystemColors.ControlDarkDark; - this.statsGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText; - this.statsGrid.Location = new System.Drawing.Point(8, 32); - this.statsGrid.Name = "statsGrid"; - this.statsGrid.PreferredColumnWidth = 40; - this.statsGrid.ReadOnly = true; - this.statsGrid.RowHeadersVisible = false; - this.statsGrid.SelectionBackColor = System.Drawing.SystemColors.Control; - this.statsGrid.SelectionForeColor = System.Drawing.SystemColors.WindowText; - this.statsGrid.Size = new System.Drawing.Size(600, 88); - this.statsGrid.TabIndex = 0; - this.statsGrid.TabStop = false; - // // tbUnitName // this.tbUnitName.Location = new System.Drawing.Point(8, 8); this.tbUnitName.Name = "tbUnitName"; this.tbUnitName.Size = new System.Drawing.Size(344, 20); this.tbUnitName.TabIndex = 1; + this.tbUnitName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbUnitName_KeyDown); this.tbUnitName.Leave += new System.EventHandler(this.tbUnitName_Leave); - this.tbUnitName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbUnitName_KeyDown); // // unitSize // - this.unitSize.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.unitSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.unitSize.Location = new System.Drawing.Point(528, 8); this.unitSize.Name = "unitSize"; this.unitSize.Size = new System.Drawing.Size(80, 20); @@ -255,7 +291,7 @@ // // lblUnitSize // - this.lblUnitSize.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.lblUnitSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.lblUnitSize.Location = new System.Drawing.Point(426, 8); this.lblUnitSize.Name = "lblUnitSize"; this.lblUnitSize.Size = new System.Drawing.Size(98, 23); @@ -274,7 +310,7 @@ // // bttnAddWeapon // - this.bttnAddWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.bttnAddWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.bttnAddWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; this.bttnAddWeapon.Location = new System.Drawing.Point(516, 126); this.bttnAddWeapon.Name = "bttnAddWeapon"; @@ -285,7 +321,7 @@ // // bttnRemoveWeapon // - this.bttnRemoveWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.bttnRemoveWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.bttnRemoveWeapon.Enabled = false; this.bttnRemoveWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; this.bttnRemoveWeapon.Location = new System.Drawing.Point(516, 210); @@ -297,18 +333,18 @@ // // equipmentList // - this.equipmentList.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.equipmentList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.equipmentList.Location = new System.Drawing.Point(102, 126); this.equipmentList.Name = "equipmentList"; this.equipmentList.Size = new System.Drawing.Size(408, 108); this.equipmentList.TabIndex = 6; + this.equipmentList.SelectedIndexChanged += new System.EventHandler(this.equipmentList_SelectedIndexChanged); this.equipmentList.DoubleClick += new System.EventHandler(this.equipmentList_DoubleClick); - this.equipmentList.SelectedIndexChanged += new System.EventHandler(this.equipmentList_SelectedIndexChanged); // // bttnReplaceWeapon // - this.bttnReplaceWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.bttnReplaceWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.bttnReplaceWeapon.Enabled = false; this.bttnReplaceWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; this.bttnReplaceWeapon.Location = new System.Drawing.Point(516, 182); @@ -320,7 +356,7 @@ // // bttnEditWeapon // - this.bttnEditWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.bttnEditWeapon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.bttnEditWeapon.Enabled = false; this.bttnEditWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; this.bttnEditWeapon.Location = new System.Drawing.Point(516, 154); @@ -373,10 +409,19 @@ this.lblAbilities.Text = "abilities"; this.lblAbilities.TextAlign = System.Drawing.ContentAlignment.TopRight; // + // statsPanel + // + this.statsPanel.AutoScroll = true; + this.statsPanel.Location = new System.Drawing.Point(8, 35); + this.statsPanel.Name = "statsPanel"; + this.statsPanel.Size = new System.Drawing.Size(600, 85); + this.statsPanel.TabIndex = 17; + // // FrmUnit // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(616, 391); + this.Controls.Add(this.statsPanel); this.Controls.Add(this.lblAbilities); this.Controls.Add(this.abilitiesList); this.Controls.Add(this.notes); @@ -391,14 +436,12 @@ this.Controls.Add(this.lblUnitSize); this.Controls.Add(this.unitSize); this.Controls.Add(this.tbUnitName); - this.Controls.Add(this.statsGrid); this.Name = "FrmUnit"; this.ShowIcon = false; this.ShowInTaskbar = false; this.Text = "FrmUnit"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmUnit_FormClosing); - ((System.ComponentModel.ISupportInitialize) (this.statsGrid)).EndInit(); - ((System.ComponentModel.ISupportInitialize) (this.unitSize)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.unitSize)).EndInit(); this.ResumeLayout(false); this.PerformLayout();