diff FrmSystem.cs @ 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 d63df495cf5a
children 43d88f50c712
line wrap: on
line diff
--- 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;
+			}
+		}
 	}
 }