# HG changeset patch # User Tsudico # Date 1292727891 21600 # Node ID 26f7f6d2b4f80900931b337c6eb56a5441abd482 # Parent 372f921c20fcd182b61ae1f0edca0c242810b53d Implement most of the buttons on the stats tab and adjust button enabling on category tab. diff -r 372f921c20fc -r 26f7f6d2b4f8 FrmSystem.Designer.cs --- a/FrmSystem.Designer.cs Sat Dec 18 13:20:18 2010 -0600 +++ b/FrmSystem.Designer.cs Sat Dec 18 21:04:51 2010 -0600 @@ -71,10 +71,10 @@ this.btnCategoryRemove = new System.Windows.Forms.Button(); this.btnCategoryApply = new System.Windows.Forms.Button(); this.tabStats = new System.Windows.Forms.TabPage(); - this.btnMoveStatDown = new System.Windows.Forms.Button(); - this.btnMoveStatUp = new System.Windows.Forms.Button(); - this.btnRemoveStat = new System.Windows.Forms.Button(); - this.btnAddStat = new System.Windows.Forms.Button(); + this.btnStatListDown = new System.Windows.Forms.Button(); + this.btnStatListUp = new System.Windows.Forms.Button(); + this.btnStatListRemove = new System.Windows.Forms.Button(); + this.btnStatListAdd = new System.Windows.Forms.Button(); this.gbStats = new System.Windows.Forms.GroupBox(); this.listStatNames = new System.Windows.Forms.ListBox(); this.txtStatName = new System.Windows.Forms.TextBox(); @@ -558,6 +558,7 @@ // // btnCategoryAdd // + this.btnCategoryAdd.Enabled = false; this.btnCategoryAdd.Location = new System.Drawing.Point(216, 5); this.btnCategoryAdd.Name = "btnCategoryAdd"; this.btnCategoryAdd.Size = new System.Drawing.Size(62, 23); @@ -568,6 +569,7 @@ // // btnCategoryRemove // + this.btnCategoryRemove.Enabled = false; this.btnCategoryRemove.Location = new System.Drawing.Point(216, 34); this.btnCategoryRemove.Name = "btnCategoryRemove"; this.btnCategoryRemove.Size = new System.Drawing.Size(62, 23); @@ -585,13 +587,14 @@ this.btnCategoryApply.TabIndex = 14; this.btnCategoryApply.Text = "Apply"; this.btnCategoryApply.UseVisualStyleBackColor = true; + this.btnCategoryApply.Click += new System.EventHandler(this.btnCategoryApply_Click); // // tabStats // - this.tabStats.Controls.Add(this.btnMoveStatDown); - this.tabStats.Controls.Add(this.btnMoveStatUp); - this.tabStats.Controls.Add(this.btnRemoveStat); - this.tabStats.Controls.Add(this.btnAddStat); + this.tabStats.Controls.Add(this.btnStatListDown); + this.tabStats.Controls.Add(this.btnStatListUp); + this.tabStats.Controls.Add(this.btnStatListRemove); + this.tabStats.Controls.Add(this.btnStatListAdd); this.tabStats.Controls.Add(this.gbStats); this.tabStats.Controls.Add(this.txtStatName); this.tabStats.Controls.Add(this.label1); @@ -612,45 +615,49 @@ this.tabStats.Text = "Stat Lines"; this.tabStats.UseVisualStyleBackColor = true; // - // btnMoveStatDown + // btnStatListDown // - this.btnMoveStatDown.Enabled = false; - this.btnMoveStatDown.Location = new System.Drawing.Point(500, 205); - this.btnMoveStatDown.Name = "btnMoveStatDown"; - this.btnMoveStatDown.Size = new System.Drawing.Size(76, 23); - this.btnMoveStatDown.TabIndex = 25; - this.btnMoveStatDown.Text = "Down"; - this.btnMoveStatDown.UseVisualStyleBackColor = true; + this.btnStatListDown.Enabled = false; + this.btnStatListDown.Location = new System.Drawing.Point(500, 205); + this.btnStatListDown.Name = "btnStatListDown"; + this.btnStatListDown.Size = new System.Drawing.Size(76, 23); + this.btnStatListDown.TabIndex = 25; + this.btnStatListDown.Text = "Down"; + this.btnStatListDown.UseVisualStyleBackColor = true; + this.btnStatListDown.Click += new System.EventHandler(this.btnStatListDown_Click); // - // btnMoveStatUp + // btnStatListUp // - this.btnMoveStatUp.Enabled = false; - this.btnMoveStatUp.Location = new System.Drawing.Point(500, 176); - this.btnMoveStatUp.Name = "btnMoveStatUp"; - this.btnMoveStatUp.Size = new System.Drawing.Size(76, 23); - this.btnMoveStatUp.TabIndex = 24; - this.btnMoveStatUp.Text = "Up"; - this.btnMoveStatUp.UseVisualStyleBackColor = true; + this.btnStatListUp.Enabled = false; + this.btnStatListUp.Location = new System.Drawing.Point(500, 176); + this.btnStatListUp.Name = "btnStatListUp"; + this.btnStatListUp.Size = new System.Drawing.Size(76, 23); + this.btnStatListUp.TabIndex = 24; + this.btnStatListUp.Text = "Up"; + this.btnStatListUp.UseVisualStyleBackColor = true; + this.btnStatListUp.Click += new System.EventHandler(this.btnStatListUp_Click); // - // btnRemoveStat + // btnStatListRemove // - this.btnRemoveStat.Enabled = false; - this.btnRemoveStat.Location = new System.Drawing.Point(500, 147); - this.btnRemoveStat.Name = "btnRemoveStat"; - this.btnRemoveStat.Size = new System.Drawing.Size(76, 23); - this.btnRemoveStat.TabIndex = 23; - this.btnRemoveStat.Text = "Remove"; - this.btnRemoveStat.UseVisualStyleBackColor = true; + this.btnStatListRemove.Enabled = false; + this.btnStatListRemove.Location = new System.Drawing.Point(500, 147); + this.btnStatListRemove.Name = "btnStatListRemove"; + this.btnStatListRemove.Size = new System.Drawing.Size(76, 23); + this.btnStatListRemove.TabIndex = 23; + this.btnStatListRemove.Text = "Remove"; + this.btnStatListRemove.UseVisualStyleBackColor = true; + this.btnStatListRemove.Click += new System.EventHandler(this.btnStatListRemove_Click); // - // btnAddStat + // btnStatListAdd // - this.btnAddStat.Enabled = false; - this.btnAddStat.Location = new System.Drawing.Point(500, 118); - this.btnAddStat.Name = "btnAddStat"; - this.btnAddStat.Size = new System.Drawing.Size(76, 23); - this.btnAddStat.TabIndex = 22; - this.btnAddStat.Text = "Add"; - this.btnAddStat.UseVisualStyleBackColor = true; + this.btnStatListAdd.Enabled = false; + this.btnStatListAdd.Location = new System.Drawing.Point(500, 118); + this.btnStatListAdd.Name = "btnStatListAdd"; + this.btnStatListAdd.Size = new System.Drawing.Size(76, 23); + this.btnStatListAdd.TabIndex = 22; + this.btnStatListAdd.Text = "Add"; + this.btnStatListAdd.UseVisualStyleBackColor = true; + this.btnStatListAdd.Click += new System.EventHandler(this.btnStatListAdd_Click); // // gbStats // @@ -660,7 +667,7 @@ this.gbStats.Size = new System.Drawing.Size(204, 103); this.gbStats.TabIndex = 21; this.gbStats.TabStop = false; - this.gbStats.Text = "Stat List"; + this.gbStats.Text = "Stat Names"; // // listStatNames // @@ -669,6 +676,7 @@ this.listStatNames.Name = "listStatNames"; this.listStatNames.Size = new System.Drawing.Size(191, 69); this.listStatNames.TabIndex = 0; + this.listStatNames.SelectedIndexChanged += new System.EventHandler(this.listStatNames_SelectedIndexChanged); // // txtStatName // @@ -676,6 +684,7 @@ this.txtStatName.Name = "txtStatName"; this.txtStatName.Size = new System.Drawing.Size(126, 20); this.txtStatName.TabIndex = 20; + this.txtStatName.TextChanged += new System.EventHandler(this.txtStatName_TextChanged); // // label1 // @@ -692,6 +701,7 @@ this.txtStatLineID.Name = "txtStatLineID"; this.txtStatLineID.Size = new System.Drawing.Size(126, 20); this.txtStatLineID.TabIndex = 18; + this.txtStatLineID.TextChanged += new System.EventHandler(this.txtStatLineID_TextChanged); // // lblStatLineID // @@ -723,6 +733,7 @@ this.btnStatLineApply.TabIndex = 15; this.btnStatLineApply.Text = "Apply"; this.btnStatLineApply.UseVisualStyleBackColor = true; + this.btnStatLineApply.Click += new System.EventHandler(this.btnStatLineApply_Click); // // lblStatLinePreview // @@ -735,6 +746,7 @@ // // btnStatsDefault // + this.btnStatsDefault.Enabled = false; this.btnStatsDefault.Location = new System.Drawing.Point(203, 64); this.btnStatsDefault.Name = "btnStatsDefault"; this.btnStatsDefault.Size = new System.Drawing.Size(81, 23); @@ -774,15 +786,18 @@ // // btnStatsRemove // + this.btnStatsRemove.Enabled = false; this.btnStatsRemove.Location = new System.Drawing.Point(203, 35); this.btnStatsRemove.Name = "btnStatsRemove"; this.btnStatsRemove.Size = new System.Drawing.Size(81, 23); this.btnStatsRemove.TabIndex = 9; this.btnStatsRemove.Text = "Remove"; this.btnStatsRemove.UseVisualStyleBackColor = true; + this.btnStatsRemove.Click += new System.EventHandler(this.btnStatsRemove_Click); // // btnStatsAdd // + this.btnStatsAdd.Enabled = false; this.btnStatsAdd.Location = new System.Drawing.Point(203, 6); this.btnStatsAdd.Name = "btnStatsAdd"; this.btnStatsAdd.Size = new System.Drawing.Size(81, 23); @@ -879,11 +894,11 @@ private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox txtStatLineID; private System.Windows.Forms.Label lblStatLineID; - private System.Windows.Forms.Button btnRemoveStat; - private System.Windows.Forms.Button btnAddStat; + private System.Windows.Forms.Button btnStatListRemove; + private System.Windows.Forms.Button btnStatListAdd; private System.Windows.Forms.GroupBox gbStats; - private System.Windows.Forms.Button btnMoveStatDown; - private System.Windows.Forms.Button btnMoveStatUp; + private System.Windows.Forms.Button btnStatListDown; + private System.Windows.Forms.Button btnStatListUp; private System.Windows.Forms.ListBox listStatNames; } diff -r 372f921c20fc -r 26f7f6d2b4f8 FrmSystem.cs --- a/FrmSystem.cs Sat Dec 18 13:20:18 2010 -0600 +++ b/FrmSystem.cs Sat Dec 18 21:04:51 2010 -0600 @@ -15,58 +15,60 @@ public partial class FrmSystem : IBBoard.Windows.Forms.IBBForm { private IBBoard.WarFoundry.API.Objects.GameSystem system; + private IBBoard.WarFoundry.API.Objects.Category currentCategory; + private IBBoard.WarFoundry.API.Objects.SystemStats currentStats; private bool UpdateCategory { get { - if(this.listCategories.SelectedIndex >= 0) + if(currentCategory == null) + { + return false; + } + if (currentCategory.Name == (string)this.listCategories.SelectedItem) { - foreach(IBBoard.WarFoundry.API.Objects.Category cat in system.Categories) + if (currentCategory.Name != this.txtCategoryName.Text) + { + return true; + } + if (currentCategory.ID != this.txtCategoryID.Text) + { + return true; + } + if (currentCategory.MinimumPoints > 0 && !this.cbPointMin.Checked) + { + return true; + } + else if (currentCategory.MinimumPoints != this.numPointMin.Value) { - if(cat.Name == this.listCategories.SelectedItem) - { - if(cat.Name != this.txtCategoryName.Text) - { - return true; - } - if(cat.ID != this.txtCategoryID.Text) - { - return true; - } - if(cat.MinimumPoints > 0 && !this.cbPointMin.Checked) - { - return true; - } - else if(cat.MinimumPoints != this.numPointMin.Value) - { - return true; - } - if(cat.MaximumPoints < this.numPointMax.Maximum && !this.cbPointMax.Checked) - { - return true; - } - else if(cat.MaximumPoints != this.numPointMax.Value) - { - return true; - } - if(cat.MinimumPercentage > 0 && !this.cbPercentMin.Checked) - { - return true; - } - else if(cat.MinimumPercentage != this.numPercentMin.Value) - { - return true; - } - if(cat.MaximumPercentage < this.numPercentMax.Maximum && !this.cbPercentMax.Checked) - { - return true; - } - else if(cat.MaximumPercentage != this.numPercentMax.Value) - { - return true; - } - } + return true; + } + if (currentCategory.MaximumPoints < this.numPointMax.Maximum + && !this.cbPointMax.Checked) + { + return true; + } + else if (currentCategory.MaximumPoints != this.numPointMax.Value) + { + return true; + } + if (currentCategory.MinimumPercentage > 0 && !this.cbPercentMin.Checked) + { + return true; + } + else if (currentCategory.MinimumPercentage != this.numPercentMin.Value) + { + return true; + } + if (currentCategory.MaximumPercentage < this.numPercentMax.Maximum + && !this.cbPercentMax.Checked) + { + return true; + } + else if (currentCategory.MaximumPercentage != this.numPercentMax.Value) + { + return true; } } return false; @@ -135,6 +137,7 @@ this.numPercentMin.Enabled = false; this.numPercentMax.Value = 100; this.numPercentMax.Enabled = false; + currentCategory = null; } private void updateCategoryList() @@ -147,6 +150,10 @@ this.listCategories.Items.Add(system.Categories[i].Name); } } + else + { + this.btnCategoryRemove.Enabled = false; + } } private void updateSystemStatsList() @@ -165,6 +172,8 @@ this.lviewStats.Items.Add(item); } } + this.lviewStats.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent); + this.lviewStats.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.HeaderSize); } private void updateStatLinePreview(IBBoard.WarFoundry.API.Objects.SystemStats stats) @@ -181,10 +190,7 @@ column.TextAlign = HorizontalAlignment.Center; this.lviewStatPreview.Columns.Add(column); } - for(int i = 0; i < this.lviewStatPreview.Columns.Count; i++) - { - this.lviewStatPreview.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); - } + this.lviewStatPreview.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); this.lviewStatPreview.Items.Add(" "); } } @@ -213,53 +219,61 @@ private void listCategories_SelectedIndexChanged(object sender, EventArgs e) { + currentCategory = null; foreach (IBBoard.WarFoundry.API.Objects.Category cat in system.Categories) { if (cat.Name == this.listCategories.SelectedItem) { - this.txtCategoryName.Text = cat.Name; - this.txtCategoryID.Text = cat.ID; - if (cat.MinimumPoints > 0) + currentCategory = cat; + this.txtCategoryName.Text = currentCategory.Name; + this.txtCategoryID.Text = currentCategory.ID; + if (currentCategory.MinimumPoints > 0) { - this.numPointMin.Value = cat.MinimumPoints; + this.numPointMin.Value = currentCategory.MinimumPoints; this.cbPointMin.Checked = true; this.numPointMin.Enabled = true; } else { + this.cbPointMin.Checked = false; this.numPointMin.Enabled = false; } - if (cat.MaximumPoints > 0 && cat.MaximumPoints < this.numPercentMax.Maximum) + if (currentCategory.MaximumPoints > 0 + && currentCategory.MaximumPoints < this.numPercentMax.Maximum) { - this.numPointMax.Value = cat.MaximumPoints; + this.numPointMax.Value = currentCategory.MaximumPoints; this.cbPointMax.Checked = true; this.numPointMax.Enabled = true; } else { this.numPointMax.Value = this.numDefaultSize.Value; + this.cbPointMax.Checked = false; this.numPointMax.Enabled = false; } - if (cat.MinimumPercentage > 0) + if (currentCategory.MinimumPercentage > 0) { - this.numPercentMin.Value = cat.MinimumPercentage; + this.numPercentMin.Value = currentCategory.MinimumPercentage; this.cbPercentMin.Checked = true; this.numPercentMin.Enabled = true; } else { + this.cbPercentMin.Checked = false; this.numPercentMin.Enabled = false; } - if (cat.MaximumPercentage < 100) + if (currentCategory.MaximumPercentage < 100) { - this.numPercentMax.Value = cat.MaximumPercentage; + this.numPercentMax.Value = currentCategory.MaximumPercentage; this.cbPercentMax.Checked = true; this.numPercentMax.Enabled = true; } else { + this.cbPercentMax.Checked = false; this.numPercentMax.Enabled = false; } + this.btnCategoryRemove.Enabled = true; this.btnCategoryApply.Enabled = false; break; } @@ -317,6 +331,7 @@ { system.RemoveCategory(cat.ID); this.listCategories.ClearSelected(); + this.btnCategoryRemove.Enabled = false; break; } } @@ -387,6 +402,14 @@ { this.btnCategoryApply.Enabled = false; } + if(this.txtCategoryName.Text != string.Empty && this.txtCategoryID.Text != string.Empty) + { + this.btnCategoryAdd.Enabled = true; + } + else + { + this.btnCategoryAdd.Enabled = false; + } } private void txtCategoryID_TextChanged(object sender, EventArgs e) @@ -534,27 +557,221 @@ } } + private void btnCategoryApply_Click(object sender, EventArgs e) + { + currentCategory.Name = this.txtCategoryName.Text; + currentCategory.ID = this.txtCategoryID.Text; + if(this.cbPointMin.Checked) + { + currentCategory.MinimumPoints = (int)this.numPointMin.Value; + } + else + { + currentCategory.MinimumPoints = 0; + } + if (this.cbPointMax.Checked) + { + currentCategory.MaximumPoints = (int)this.numPointMax.Value; + } + else + { + currentCategory.MaximumPoints = IBBoard.WarFoundry.API.WarFoundryCore.INFINITY; + } + if (this.cbPercentMin.Checked) + { + currentCategory.MinimumPercentage = (int)this.numPercentMin.Value; + } + else + { + currentCategory.MinimumPercentage = 0; + } + if (this.cbPercentMax.Checked) + { + currentCategory.MinimumPercentage = (int)this.numPercentMax.Value; + } + else + { + currentCategory.MaximumPercentage = 100; + } + system.SetCategory(currentCategory); + updateCategoryList(); + this.listCategories.ClearSelected(); + } + void lviewStats_SelectedIndexChanged(object sender, System.EventArgs e) { + currentStats = null; foreach(IBBoard.WarFoundry.API.Objects.SystemStats stat in system.SystemStats) { ListView.SelectedListViewItemCollection items = this.lviewStats.SelectedItems; + if(items.Count > 0) + { + this.btnStatsRemove.Enabled = true; + } foreach(ListViewItem item in items) { if(stat.ID == item.Text) { - this.txtStatLineID.Text = stat.ID; - updateStatNames(stat); - updateStatLinePreview(stat); + currentStats = stat; + if(currentStats.ID.Equals(system.StandardSystemStatsID)) + { + this.btnStatsDefault.Enabled = false; + } + else + { + this.btnStatsDefault.Enabled = true; + } + this.txtStatLineID.Text = currentStats.ID; + updateStatNames(currentStats); + updateStatLinePreview(currentStats); } } } } + private void btnStatsRemove_Click(object sender, EventArgs e) + { + system.RemoveSystemStats(currentStats.ID); + this.btnStatsRemove.Enabled = false; + updateSystemStatsList(); + } + private void btnStatsDefault_Click(object sender, EventArgs e) { system.StandardSystemStatsID = this.lviewStats.SelectedItems[0].Text; updateSystemStatsList(); } + + private void txtStatLineID_TextChanged(object sender, EventArgs e) + { + if(this.txtStatLineID.Text != string.Empty) + { + this.btnStatsAdd.Enabled = true; + } + else + { + this.btnStatsAdd.Enabled = false; + } + } + + private void txtStatName_TextChanged(object sender, EventArgs e) + { + if(this.txtStatName.Text != string.Empty) + { + this.btnStatListAdd.Enabled = true; + } + else + { + this.btnStatListAdd.Enabled = false; + } + } + + private void btnStatListAdd_Click(object sender, EventArgs e) + { + if(this.txtStatName.Text != string.Empty) + { + currentStats.AddStatSlot(this.txtStatName.Text); + } + updateStatNames(currentStats); + updateStatLinePreview(currentStats); + } + + private void listStatNames_SelectedIndexChanged(object sender, EventArgs e) + { + if(this.listStatNames.SelectedIndex >= 0) + { + this.btnStatListRemove.Enabled = true; + if(this.listStatNames.SelectedIndex == 0) + { + this.btnStatListUp.Enabled = false; + } + else + { + this.btnStatListUp.Enabled = true; + } + if(this.listStatNames.SelectedIndex == this.listStatNames.Items.Count - 1) + { + this.btnStatListDown.Enabled = false; + } + else + { + this.btnStatListDown.Enabled = true; + } + } + else + { + this.btnStatListRemove.Enabled = false; + this.btnStatListUp.Enabled = false; + this.btnStatListDown.Enabled = false; + } + } + + private void btnStatListRemove_Click(object sender, EventArgs e) + { + currentStats.RemoveStatSlot((string)this.listStatNames.SelectedItem); + updateStatNames(currentStats); + updateStatLinePreview(currentStats); + } + + private void btnStatListUp_Click(object sender, EventArgs e) + { + int index = this.listStatNames.SelectedIndex; + string[] slotList = new string[this.listStatNames.Items.Count]; + + for (int i = 0; i < currentStats.SlotCount; i++) + { + slotList[i] = currentStats.StatSlots[i].Name; + } + for (int i = 0; i < slotList.Length; i++) + { + currentStats.RemoveStatSlot(slotList[i]); + } + + string temp = slotList[index]; + slotList[index] = slotList[index - 1]; + slotList[index - 1] = temp; + + for (int i = 0; i < slotList.Length; i++) + { + currentStats.AddStatSlot(slotList[i]); + } + + updateStatNames(currentStats); + updateStatLinePreview(currentStats); + this.listStatNames.SelectedIndex = index - 1; + } + + private void btnStatListDown_Click(object sender, EventArgs e) + { + int index = this.listStatNames.SelectedIndex; + string[] slotList = new string[this.listStatNames.Items.Count]; + + for (int i = 0; i < currentStats.SlotCount; i++) + { + slotList[i] = currentStats.StatSlots[i].Name; + } + for (int i = 0; i < slotList.Length; i++) + { + currentStats.RemoveStatSlot(slotList[i]); + } + + string temp = slotList[index]; + slotList[index] = slotList[index + 1]; + slotList[index + 1] = temp; + + for (int i = 0; i < slotList.Length; i++) + { + currentStats.AddStatSlot(slotList[i]); + } + + updateStatNames(currentStats); + updateStatLinePreview(currentStats); + this.listStatNames.SelectedIndex = index + 1; + } + + private void btnStatLineApply_Click(object sender, EventArgs e) + { + system.SetSystemStats(currentStats); + } } }