changeset 8:0dadaa315430

Category Tab Updates: Remove 'Edit' Button, clicking on the list will populate the category fields Add 'Apply' Button, make it so changes to the category enable it Max points for category set to default army size(disabled)
author Tsudico
date Thu, 16 Dec 2010 18:52:30 -0600
parents d4c03cc5bfb7
children b42ba80ec613 43d88f50c712
files .hgignore FrmSystem.Designer.cs FrmSystem.cs
diffstat 3 files changed, 346 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Thu Dec 16 16:14:46 2010 -0600
+++ b/.hgignore	Thu Dec 16 18:52:30 2010 -0600
@@ -1,6 +1,7 @@
 syntax:glob
 bin/*
 obj/*
+bin/Debug/*
 *.orig
 *.user
 *.userprefs
--- a/FrmSystem.Designer.cs	Thu Dec 16 16:14:46 2010 -0600
+++ b/FrmSystem.Designer.cs	Thu Dec 16 18:52:30 2010 -0600
@@ -69,7 +69,7 @@
 			this.btnCategoryDown = new System.Windows.Forms.Button();
 			this.btnCategoryAdd = new System.Windows.Forms.Button();
 			this.btnCategoryRemove = new System.Windows.Forms.Button();
-			this.btnCategoryEdit = new System.Windows.Forms.Button();
+			this.btnCategoryApply = new System.Windows.Forms.Button();
 			this.tabStats = new System.Windows.Forms.TabPage();
 			this.btnStatsDefault = new System.Windows.Forms.Button();
 			this.lvStats = new System.Windows.Forms.ListView();
@@ -92,18 +92,18 @@
 			// 
 			// btnSystemSave
 			// 
-			this.btnSystemSave.Location = new System.Drawing.Point(527, 328);
+			this.btnSystemSave.Location = new System.Drawing.Point(517, 328);
 			this.btnSystemSave.Name = "btnSystemSave";
-			this.btnSystemSave.Size = new System.Drawing.Size(75, 23);
+			this.btnSystemSave.Size = new System.Drawing.Size(85, 23);
 			this.btnSystemSave.TabIndex = 2;
 			this.btnSystemSave.Text = "Save";
 			this.btnSystemSave.UseVisualStyleBackColor = true;
 			// 
 			// btnSystemClose
 			// 
-			this.btnSystemClose.Location = new System.Drawing.Point(446, 328);
+			this.btnSystemClose.Location = new System.Drawing.Point(426, 328);
 			this.btnSystemClose.Name = "btnSystemClose";
-			this.btnSystemClose.Size = new System.Drawing.Size(75, 23);
+			this.btnSystemClose.Size = new System.Drawing.Size(85, 23);
 			this.btnSystemClose.TabIndex = 3;
 			this.btnSystemClose.Text = "Close";
 			this.btnSystemClose.UseVisualStyleBackColor = true;
@@ -303,7 +303,7 @@
 			this.tabCategories.Controls.Add(this.btnCategoryDown);
 			this.tabCategories.Controls.Add(this.btnCategoryAdd);
 			this.tabCategories.Controls.Add(this.btnCategoryRemove);
-			this.tabCategories.Controls.Add(this.btnCategoryEdit);
+			this.tabCategories.Controls.Add(this.btnCategoryApply);
 			this.tabCategories.Location = new System.Drawing.Point(4, 22);
 			this.tabCategories.Name = "tabCategories";
 			this.tabCategories.Padding = new System.Windows.Forms.Padding(3);
@@ -326,7 +326,7 @@
 			this.gbCategoryLimits.Controls.Add(this.lblPointLimit);
 			this.gbCategoryLimits.Location = new System.Drawing.Point(298, 63);
 			this.gbCategoryLimits.Name = "gbCategoryLimits";
-			this.gbCategoryLimits.Size = new System.Drawing.Size(277, 207);
+			this.gbCategoryLimits.Size = new System.Drawing.Size(277, 130);
 			this.gbCategoryLimits.TabIndex = 23;
 			this.gbCategoryLimits.TabStop = false;
 			this.gbCategoryLimits.Text = "Category Limits";
@@ -349,9 +349,11 @@
 			this.cbPercentMax.TabIndex = 10;
 			this.cbPercentMax.Text = "Maximum:";
 			this.cbPercentMax.UseVisualStyleBackColor = true;
+			this.cbPercentMax.CheckedChanged += new System.EventHandler(this.cbPercentMax_CheckedChanged);
 			// 
 			// numPercentMax
 			// 
+			this.numPercentMax.Enabled = false;
 			this.numPercentMax.Increment = new decimal(new int[] {
             5,
             0,
@@ -362,6 +364,12 @@
 			this.numPercentMax.Size = new System.Drawing.Size(42, 20);
 			this.numPercentMax.TabIndex = 9;
 			this.numPercentMax.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+			this.numPercentMax.Value = new decimal(new int[] {
+            100,
+            0,
+            0,
+            0});
+			this.numPercentMax.ValueChanged += new System.EventHandler(this.numPercentMax_ValueChanged);
 			// 
 			// cbPercentMin
 			// 
@@ -372,9 +380,11 @@
 			this.cbPercentMin.TabIndex = 8;
 			this.cbPercentMin.Text = "Minimum:";
 			this.cbPercentMin.UseVisualStyleBackColor = true;
+			this.cbPercentMin.CheckedChanged += new System.EventHandler(this.cbPercentMin_CheckedChanged);
 			// 
 			// numPercentMin
 			// 
+			this.numPercentMin.Enabled = false;
 			this.numPercentMin.Increment = new decimal(new int[] {
             5,
             0,
@@ -385,6 +395,7 @@
 			this.numPercentMin.Size = new System.Drawing.Size(42, 20);
 			this.numPercentMin.TabIndex = 7;
 			this.numPercentMin.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+			this.numPercentMin.ValueChanged += new System.EventHandler(this.numPercentMin_ValueChanged);
 			// 
 			// cbPointMax
 			// 
@@ -395,9 +406,11 @@
 			this.cbPointMax.TabIndex = 6;
 			this.cbPointMax.Text = "Maximum:";
 			this.cbPointMax.UseVisualStyleBackColor = true;
+			this.cbPointMax.CheckedChanged += new System.EventHandler(this.cbPointMax_CheckedChanged);
 			// 
 			// numPointMax
 			// 
+			this.numPointMax.Enabled = false;
 			this.numPointMax.Increment = new decimal(new int[] {
             50,
             0,
@@ -405,7 +418,7 @@
             0});
 			this.numPointMax.Location = new System.Drawing.Point(202, 45);
 			this.numPointMax.Maximum = new decimal(new int[] {
-            1000000,
+            2147483647,
             0,
             0,
             0});
@@ -413,6 +426,7 @@
 			this.numPointMax.Size = new System.Drawing.Size(69, 20);
 			this.numPointMax.TabIndex = 5;
 			this.numPointMax.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+			this.numPointMax.ValueChanged += new System.EventHandler(this.numPointMax_ValueChanged);
 			// 
 			// cbPointMin
 			// 
@@ -423,9 +437,11 @@
 			this.cbPointMin.TabIndex = 4;
 			this.cbPointMin.Text = "Minimum:";
 			this.cbPointMin.UseVisualStyleBackColor = true;
+			this.cbPointMin.CheckedChanged += new System.EventHandler(this.cbPointMin_CheckedChanged);
 			// 
 			// numPointMin
 			// 
+			this.numPointMin.Enabled = false;
 			this.numPointMin.Increment = new decimal(new int[] {
             50,
             0,
@@ -441,6 +457,7 @@
 			this.numPointMin.Size = new System.Drawing.Size(69, 20);
 			this.numPointMin.TabIndex = 2;
 			this.numPointMin.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
+			this.numPointMin.ValueChanged += new System.EventHandler(this.numPointMin_ValueChanged);
 			// 
 			// lblPointLimit
 			// 
@@ -467,6 +484,7 @@
 			this.txtCategoryID.Name = "txtCategoryID";
 			this.txtCategoryID.Size = new System.Drawing.Size(99, 20);
 			this.txtCategoryID.TabIndex = 21;
+			this.txtCategoryID.TextChanged += new System.EventHandler(this.txtCategoryID_TextChanged);
 			// 
 			// lblCategoryID
 			// 
@@ -483,6 +501,7 @@
 			this.txtCategoryName.Name = "txtCategoryName";
 			this.txtCategoryName.Size = new System.Drawing.Size(182, 20);
 			this.txtCategoryName.TabIndex = 19;
+			this.txtCategoryName.TextChanged += new System.EventHandler(this.txtCategoryName_TextChanged);
 			// 
 			// lblCategoryName
 			// 
@@ -495,7 +514,7 @@
 			// 
 			// btnCategoryUp
 			// 
-			this.btnCategoryUp.Location = new System.Drawing.Point(216, 121);
+			this.btnCategoryUp.Location = new System.Drawing.Point(216, 92);
 			this.btnCategoryUp.Name = "btnCategoryUp";
 			this.btnCategoryUp.Size = new System.Drawing.Size(62, 23);
 			this.btnCategoryUp.TabIndex = 17;
@@ -509,10 +528,11 @@
 			this.listCategories.Name = "listCategories";
 			this.listCategories.Size = new System.Drawing.Size(207, 264);
 			this.listCategories.TabIndex = 12;
+			this.listCategories.SelectedIndexChanged += new System.EventHandler(this.listCategories_SelectedIndexChanged);
 			// 
 			// btnCategoryDown
 			// 
-			this.btnCategoryDown.Location = new System.Drawing.Point(216, 150);
+			this.btnCategoryDown.Location = new System.Drawing.Point(216, 121);
 			this.btnCategoryDown.Name = "btnCategoryDown";
 			this.btnCategoryDown.Size = new System.Drawing.Size(62, 23);
 			this.btnCategoryDown.TabIndex = 16;
@@ -531,22 +551,23 @@
 			// 
 			// btnCategoryRemove
 			// 
-			this.btnCategoryRemove.Location = new System.Drawing.Point(216, 63);
+			this.btnCategoryRemove.Location = new System.Drawing.Point(216, 34);
 			this.btnCategoryRemove.Name = "btnCategoryRemove";
 			this.btnCategoryRemove.Size = new System.Drawing.Size(62, 23);
 			this.btnCategoryRemove.TabIndex = 15;
 			this.btnCategoryRemove.Text = "Remove";
 			this.btnCategoryRemove.UseVisualStyleBackColor = true;
+			this.btnCategoryRemove.Click += new System.EventHandler(this.btnCategoryRemove_Click);
 			// 
-			// btnCategoryEdit
+			// btnCategoryApply
 			// 
-			this.btnCategoryEdit.Location = new System.Drawing.Point(216, 34);
-			this.btnCategoryEdit.Name = "btnCategoryEdit";
-			this.btnCategoryEdit.Size = new System.Drawing.Size(62, 23);
-			this.btnCategoryEdit.TabIndex = 14;
-			this.btnCategoryEdit.Text = "Edit";
-			this.btnCategoryEdit.UseVisualStyleBackColor = true;
-			this.btnCategoryEdit.Click += new System.EventHandler(this.btnCategoryEdit_Click);
+			this.btnCategoryApply.Enabled = false;
+			this.btnCategoryApply.Location = new System.Drawing.Point(500, 199);
+			this.btnCategoryApply.Name = "btnCategoryApply";
+			this.btnCategoryApply.Size = new System.Drawing.Size(76, 23);
+			this.btnCategoryApply.TabIndex = 14;
+			this.btnCategoryApply.Text = "Apply";
+			this.btnCategoryApply.UseVisualStyleBackColor = true;
 			// 
 			// tabStats
 			// 
@@ -661,7 +682,7 @@
 		private System.Windows.Forms.Button btnCategoryDown;
 		private System.Windows.Forms.Button btnCategoryAdd;
 		private System.Windows.Forms.Button btnCategoryRemove;
-		private System.Windows.Forms.Button btnCategoryEdit;
+		private System.Windows.Forms.Button btnCategoryApply;
 		private System.Windows.Forms.TabPage tabStats;
 		private System.Windows.Forms.Button btnStatsDefault;
 		private System.Windows.Forms.ListView lvStats;
--- a/FrmSystem.cs	Thu Dec 16 16:14:46 2010 -0600
+++ b/FrmSystem.cs	Thu Dec 16 18:52:30 2010 -0600
@@ -16,12 +16,71 @@
 	{
 		private IBBoard.WarFoundry.API.Objects.GameSystem system;
 		
+		private bool UpdateCategory
+		{
+			get
+			{
+				if(this.listCategories.SelectedIndex >= 0)
+				{
+					foreach(IBBoard.WarFoundry.API.Objects.Category cat in system.Categories)
+					{
+						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 false;
+			}
+		}
+		
 		public FrmSystem(IBBoard.WarFoundry.API.Objects.GameSystem loadSystem)
 		{
 			InitializeComponent();
 			system = loadSystem;
 			this.txtSystemName.Text = system.Name;
 			this.txtSystemId.Text = system.ID;
+			this.numDefaultSize.Value = system.SystemArmyDefaultSize;
+			this.numPointMax.Value = this.numDefaultSize.Value;
 			if(system.AllowAllies)
 			{
 				this.radSystemAlliesYes.Checked = true;
@@ -38,14 +97,7 @@
 			{
 				this.radSystemWarnNo.Checked = true;
 			}
-			if(system.Categories.Length > 0)
-			{
-				this.listCategories.Items.Clear();
-				for(int i = 0; i < system.Categories.Length; i++)
-				{
-					this.listCategories.Items.Add(system.Categories[i].Name);
-				}
-			}
+			updateCategoryList();
 		}
 		
 		private string generateID(string name)
@@ -65,6 +117,36 @@
 
 			return newId.ToLower();
 		}
+		
+		private void clearCategory()
+		{
+			this.txtCategoryName.Text = string.Empty;
+			this.txtCategoryID.Text = string.Empty;
+			this.cbPointMin.Checked = false;
+			this.cbPointMax.Checked = false;
+			this.cbPercentMin.Checked = false;
+			this.cbPercentMax.Checked = false;
+			this.numPointMin.Value = 0;
+			this.numPointMin.Enabled = false;
+			this.numPointMax.Value = this.numDefaultSize.Value;
+			this.numPointMax.Enabled = false;
+			this.numPercentMin.Value = 0;
+			this.numPercentMin.Enabled = false;
+			this.numPercentMax.Value = 100;
+			this.numPercentMax.Enabled = false;
+		}
+		
+		private void updateCategoryList()
+		{
+			if (system.Categories.Length > 0)
+			{
+				this.listCategories.Items.Clear();
+				for (int i = 0; i < system.Categories.Length; i++)
+				{
+					this.listCategories.Items.Add(system.Categories[i].Name);
+				}
+			}
+		}
 
 		private void btnSystemClose_Click(object sender, EventArgs e)
 		{
@@ -76,6 +158,61 @@
 			this.txtSystemId.Text = generateID(this.txtSystemName.Text);
 		}
 
+		private void listCategories_SelectedIndexChanged(object sender, EventArgs e)
+		{
+			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)
+					{
+						this.numPointMin.Value = cat.MinimumPoints;
+						this.cbPointMin.Checked = true;
+						this.numPointMin.Enabled = true;
+					}
+					else
+					{
+						this.numPointMin.Enabled = false;
+					}
+					if (cat.MaximumPoints > 0 && cat.MaximumPoints < this.numPercentMax.Maximum)
+					{
+						this.numPointMax.Value = cat.MaximumPoints;
+						this.cbPointMax.Checked = true;
+						this.numPointMax.Enabled = true;
+					}
+					else
+					{
+						this.numPointMax.Value = this.numDefaultSize.Value;
+						this.numPointMax.Enabled = false;
+					}
+					if (cat.MinimumPercentage > 0)
+					{
+						this.numPercentMin.Value = cat.MinimumPercentage;
+						this.cbPercentMin.Checked = true;
+						this.numPercentMin.Enabled = true;
+					}
+					else
+					{
+						this.numPercentMin.Enabled = false;
+					}
+					if (cat.MaximumPercentage < 100)
+					{
+						this.numPercentMax.Value = cat.MaximumPercentage;
+						this.cbPercentMax.Checked = true;
+						this.numPercentMax.Enabled = true;
+					}
+					else
+					{
+						this.numPercentMax.Enabled = false;
+					}
+					this.btnCategoryApply.Enabled = false;
+					break;
+				}
+			}
+		}
+
 		private void btnCategoryAdd_Click(object sender, EventArgs e)
 		{
 			if(this.txtCategoryName.Text == string.Empty)
@@ -99,48 +236,179 @@
 			cat.MaximumPercentage = (int)this.numPercentMax.Value;
 			
 			system.AddCategory(cat);
-
-			if (system.Categories.Length > 0)
-			{
-				this.listCategories.Items.Clear();
-				for (int i = 0; i < system.Categories.Length; i++)
-				{
-					this.listCategories.Items.Add(system.Categories[i].Name);
-				}
-			}
+			updateCategoryList();
+			clearCategory();
 		}
 
-		private void btnCategoryEdit_Click(object sender, EventArgs e)
+		private void btnCategoryRemove_Click(object sender, EventArgs e)
 		{
 			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)
-					{
-						this.numPointMin.Value = cat.MinimumPoints;
-					}
-					if(cat.MaximumPoints > 0 && cat.MaximumPoints < this.numPointMax.Maximum)
-					{	
-						this.numPointMax.Value = cat.MaximumPoints;
-					}
-					if(cat.MinimumPercentage >= 0)
-					{
-						this.numPercentMin.Value = cat.MinimumPercentage;
-					}
-					if(cat.MaximumPercentage <= 100)
-					{
-						this.numPercentMax.Value = cat.MaximumPercentage;
-					}
+					system.RemoveCategory(cat.ID);
+					this.listCategories.ClearSelected();
+					break;
 				}
 			}
+			updateCategoryList();
+		}
+
+		private void txtCategoryName_TextChanged(object sender, EventArgs e)
+		{
+			if (this.UpdateCategory)
+			{
+				this.btnCategoryApply.Enabled = true;
+			}
+			else
+			{
+				this.btnCategoryApply.Enabled = false;
+			}
+		}
+
+		private void txtCategoryID_TextChanged(object sender, EventArgs e)
+		{
+			if (this.UpdateCategory)
+			{
+				this.btnCategoryApply.Enabled = true;
+			}
+			else
+			{
+				this.btnCategoryApply.Enabled = false;
+			}
 		}
 
 		private void btnGenerateCatID_Click(object sender, EventArgs e)
 		{
 			this.txtCategoryID.Text = generateID(this.txtCategoryName.Text);
 		}
+
+		private void cbPointMin_CheckedChanged(object sender, EventArgs e)
+		{
+			if(this.cbPointMin.Checked)
+			{
+				this.numPointMin.Enabled = true;
+			}
+			else
+			{
+				this.numPointMin.Enabled = false;
+			}
+			if(this.UpdateCategory)
+			{
+				this.btnCategoryApply.Enabled = true;
+			}
+			else
+			{
+				this.btnCategoryApply.Enabled = false;
+			}
+		}
+
+		private void cbPointMax_CheckedChanged(object sender, EventArgs e)
+		{
+			if (this.cbPointMax.Checked)
+			{
+				this.numPointMax.Enabled = true;
+			}
+			else
+			{
+				this.numPointMax.Enabled = false;
+			}
+			if (this.UpdateCategory)
+			{
+				this.btnCategoryApply.Enabled = true;
+			}
+			else
+			{
+				this.btnCategoryApply.Enabled = false;
+			}
+		}
+
+		private void cbPercentMin_CheckedChanged(object sender, EventArgs e)
+		{
+			if (this.cbPercentMin.Checked)
+			{
+				this.numPercentMin.Enabled = true;
+			}
+			else
+			{
+				this.numPercentMin.Enabled = false;
+			}
+			if (this.UpdateCategory)
+			{
+				this.btnCategoryApply.Enabled = true;
+			}
+			else
+			{
+				this.btnCategoryApply.Enabled = false;
+			}
+		}
+
+		private void cbPercentMax_CheckedChanged(object sender, EventArgs e)
+		{
+			if (this.cbPercentMax.Checked)
+			{
+				this.numPercentMax.Enabled = true;
+			}
+			else
+			{
+				this.numPercentMax.Enabled = false;
+			}
+			if (this.UpdateCategory)
+			{
+				this.btnCategoryApply.Enabled = true;
+			}
+			else
+			{
+				this.btnCategoryApply.Enabled = false;
+			}
+		}
+
+		private void numPointMin_ValueChanged(object sender, EventArgs e)
+		{
+			if (this.UpdateCategory)
+			{
+				this.btnCategoryApply.Enabled = true;
+			}
+			else
+			{
+				this.btnCategoryApply.Enabled = false;
+			}
+		}
+
+		private void numPointMax_ValueChanged(object sender, EventArgs e)
+		{
+			if (this.UpdateCategory)
+			{
+				this.btnCategoryApply.Enabled = true;
+			}
+			else
+			{
+				this.btnCategoryApply.Enabled = false;
+			}
+		}
+
+		private void numPercentMin_ValueChanged(object sender, EventArgs e)
+		{
+			if (this.UpdateCategory)
+			{
+				this.btnCategoryApply.Enabled = true;
+			}
+			else
+			{
+				this.btnCategoryApply.Enabled = false;
+			}
+		}
+
+		private void numPercentMax_ValueChanged(object sender, EventArgs e)
+		{
+			if (this.UpdateCategory)
+			{
+				this.btnCategoryApply.Enabled = true;
+			}
+			else
+			{
+				this.btnCategoryApply.Enabled = false;
+			}
+		}
 	}
 }