changeset 15:3a347947ecea

Updates to Categories and Stat Lines Categories Adjusted some things behind the scenes. Stat Lines Added functionality of already existing buttons.
author Tsudico
date Wed, 22 Dec 2010 18:35:52 -0600
parents 26f7f6d2b4f8
children 489d36b167a6
files FrmSystem.Designer.cs FrmSystem.cs
diffstat 2 files changed, 104 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/FrmSystem.Designer.cs	Sat Dec 18 21:04:51 2010 -0600
+++ b/FrmSystem.Designer.cs	Wed Dec 22 18:35:52 2010 -0600
@@ -680,6 +680,7 @@
 			// 
 			// txtStatName
 			// 
+			this.txtStatName.Enabled = false;
 			this.txtStatName.Location = new System.Drawing.Point(368, 120);
 			this.txtStatName.Name = "txtStatName";
 			this.txtStatName.Size = new System.Drawing.Size(126, 20);
@@ -804,6 +805,7 @@
 			this.btnStatsAdd.TabIndex = 7;
 			this.btnStatsAdd.Text = "Add";
 			this.btnStatsAdd.UseVisualStyleBackColor = true;
+			this.btnStatsAdd.Click += new System.EventHandler(this.btnStatsAdd_Click);
 			// 
 			// FrmSystem
 			// 
--- a/FrmSystem.cs	Sat Dec 18 21:04:51 2010 -0600
+++ b/FrmSystem.cs	Wed Dec 22 18:35:52 2010 -0600
@@ -75,6 +75,37 @@
 			}
 		}
 		
+		private bool UpdateSystemStats
+		{
+			get
+			{
+				if(currentStats == null)
+				{
+					return false;
+				}
+				if(currentStats.ID != this.txtStatLineID.Text)
+				{
+					return true;
+				}
+				if(currentStats.SlotCount != this.listCategories.Items.Count)
+				{
+					return true;
+				}
+				if(system.GetSystemStatsForID(currentStats.ID).SlotCount != currentStats.SlotCount)
+				{
+					return true;
+				}
+				for(int i = 0; i < currentStats.SlotCount; i++)
+				{
+					if(system.GetSystemStatsForID(currentStats.ID).StatSlots[i].Name == currentStats.StatSlots[i].Name)
+					{
+						return true;
+					}
+				}
+				return false;
+			}
+		}
+		
 		public FrmSystem(IBBoard.WarFoundry.API.Objects.GameSystem loadSystem)
 		{
 			InitializeComponent();
@@ -140,6 +171,16 @@
 			currentCategory = null;
 		}
 		
+		private void clearStatLine()
+		{
+			this.txtStatName.Clear();
+			this.txtStatLineID.Clear();
+			this.listStatNames.Items.Clear();
+			this.lviewStatPreview.Columns.Clear();
+			this.lviewStatPreview.Items.Clear();
+			currentStats = null;
+		}
+		
 		private void updateCategoryList()
 		{
 			if (system.Categories.Length > 0)
@@ -178,10 +219,10 @@
 		
 		private void updateStatLinePreview(IBBoard.WarFoundry.API.Objects.SystemStats stats)
 		{
+			this.lviewStatPreview.Items.Clear();
+			this.lviewStatPreview.Columns.Clear();
 			if(stats.SlotCount > 0)
 			{
-				this.lviewStatPreview.Items.Clear();
-				this.lviewStatPreview.Columns.Clear();
 				for(int i = 0; i < stats.SlotCount; i++)
 				{
 					System.Windows.Forms.ColumnHeader column = new ColumnHeader();
@@ -193,13 +234,14 @@
 				this.lviewStatPreview.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
 				this.lviewStatPreview.Items.Add(" ");
 			}
+			this.btnStatLineApply.Enabled = this.UpdateSystemStats;
 		}
 		
 		private void updateStatNames(IBBoard.WarFoundry.API.Objects.SystemStats stats)
 		{
+			this.listStatNames.Items.Clear();
 			if (stats.SlotCount > 0)
 			{
-				this.listStatNames.Items.Clear();
 				for (int i = 0; i < stats.SlotCount; i++)
 				{
 					this.listStatNames.Items.Add(stats.StatSlots[i].Name);
@@ -222,7 +264,7 @@
 			currentCategory = null;
 			foreach (IBBoard.WarFoundry.API.Objects.Category cat in system.Categories)
 			{
-				if (cat.Name == this.listCategories.SelectedItem)
+				if (cat.Name == (string)this.listCategories.SelectedItem)
 				{
 					currentCategory = cat;
 					this.txtCategoryName.Text = currentCategory.Name;
@@ -239,7 +281,7 @@
 						this.numPointMin.Enabled = false;
 					}
 					if (currentCategory.MaximumPoints > 0
-						&& currentCategory.MaximumPoints < this.numPercentMax.Maximum)
+						&& currentCategory.MaximumPoints < this.numPointMax.Maximum)
 					{
 						this.numPointMax.Value = currentCategory.MaximumPoints;
 						this.cbPointMax.Checked = true;
@@ -327,7 +369,7 @@
 		{
 			foreach(IBBoard.WarFoundry.API.Objects.Category cat in system.Categories)
 			{
-				if(cat.Name == this.listCategories.SelectedItem)
+				if(cat.Name == (string)this.listCategories.SelectedItem)
 				{
 					system.RemoveCategory(cat.ID);
 					this.listCategories.ClearSelected();
@@ -394,14 +436,8 @@
 
 		private void txtCategoryName_TextChanged(object sender, EventArgs e)
 		{
-			if (this.UpdateCategory)
-			{
-				this.btnCategoryApply.Enabled = true;
-			}
-			else
-			{
-				this.btnCategoryApply.Enabled = false;
-			}
+			this.btnCategoryApply.Enabled = this.UpdateCategory;
+			
 			if(this.txtCategoryName.Text != string.Empty && this.txtCategoryID.Text != string.Empty)
 			{
 				this.btnCategoryAdd.Enabled = true;
@@ -414,14 +450,7 @@
 
 		private void txtCategoryID_TextChanged(object sender, EventArgs e)
 		{
-			if (this.UpdateCategory)
-			{
-				this.btnCategoryApply.Enabled = true;
-			}
-			else
-			{
-				this.btnCategoryApply.Enabled = false;
-			}
+			this.btnCategoryApply.Enabled = this.UpdateCategory;
 		}
 
 		private void btnGenerateCatID_Click(object sender, EventArgs e)
@@ -439,14 +468,7 @@
 			{
 				this.numPointMin.Enabled = false;
 			}
-			if(this.UpdateCategory)
-			{
-				this.btnCategoryApply.Enabled = true;
-			}
-			else
-			{
-				this.btnCategoryApply.Enabled = false;
-			}
+			this.btnCategoryApply.Enabled = this.UpdateCategory;
 		}
 
 		private void cbPointMax_CheckedChanged(object sender, EventArgs e)
@@ -459,14 +481,7 @@
 			{
 				this.numPointMax.Enabled = false;
 			}
-			if (this.UpdateCategory)
-			{
-				this.btnCategoryApply.Enabled = true;
-			}
-			else
-			{
-				this.btnCategoryApply.Enabled = false;
-			}
+			this.btnCategoryApply.Enabled = this.UpdateCategory;
 		}
 
 		private void cbPercentMin_CheckedChanged(object sender, EventArgs e)
@@ -479,14 +494,7 @@
 			{
 				this.numPercentMin.Enabled = false;
 			}
-			if (this.UpdateCategory)
-			{
-				this.btnCategoryApply.Enabled = true;
-			}
-			else
-			{
-				this.btnCategoryApply.Enabled = false;
-			}
+			this.btnCategoryApply.Enabled = this.UpdateCategory;
 		}
 
 		private void cbPercentMax_CheckedChanged(object sender, EventArgs e)
@@ -499,62 +507,27 @@
 			{
 				this.numPercentMax.Enabled = false;
 			}
-			if (this.UpdateCategory)
-			{
-				this.btnCategoryApply.Enabled = true;
-			}
-			else
-			{
-				this.btnCategoryApply.Enabled = false;
-			}
+			this.btnCategoryApply.Enabled = this.UpdateCategory;
 		}
 
 		private void numPointMin_ValueChanged(object sender, EventArgs e)
 		{
-			if (this.UpdateCategory)
-			{
-				this.btnCategoryApply.Enabled = true;
-			}
-			else
-			{
-				this.btnCategoryApply.Enabled = false;
-			}
+			this.btnCategoryApply.Enabled = this.UpdateCategory;
 		}
 
 		private void numPointMax_ValueChanged(object sender, EventArgs e)
 		{
-			if (this.UpdateCategory)
-			{
-				this.btnCategoryApply.Enabled = true;
-			}
-			else
-			{
-				this.btnCategoryApply.Enabled = false;
-			}
+			this.btnCategoryApply.Enabled = this.UpdateCategory;
 		}
 
 		private void numPercentMin_ValueChanged(object sender, EventArgs e)
 		{
-			if (this.UpdateCategory)
-			{
-				this.btnCategoryApply.Enabled = true;
-			}
-			else
-			{
-				this.btnCategoryApply.Enabled = false;
-			}
+			this.btnCategoryApply.Enabled = this.UpdateCategory;
 		}
 
 		private void numPercentMax_ValueChanged(object sender, EventArgs e)
 		{
-			if (this.UpdateCategory)
-			{
-				this.btnCategoryApply.Enabled = true;
-			}
-			else
-			{
-				this.btnCategoryApply.Enabled = false;
-			}
+			this.btnCategoryApply.Enabled = this.UpdateCategory;
 		}
 
 		private void btnCategoryApply_Click(object sender, EventArgs e)
@@ -612,7 +585,11 @@
 				{
 					if(stat.ID == item.Text)
 					{
-						currentStats = stat;
+						currentStats = new IBBoard.WarFoundry.API.Objects.SystemStats(stat.ID);
+						foreach(IBBoard.WarFoundry.API.Objects.StatSlot slot in stat.StatSlots)
+						{
+							currentStats.AddStatSlot(slot.Name);
+						}
 						if(currentStats.ID.Equals(system.StandardSystemStatsID))
 						{
 							this.btnStatsDefault.Enabled = false;
@@ -622,11 +599,32 @@
 							this.btnStatsDefault.Enabled = true;
 						}
 						this.txtStatLineID.Text = currentStats.ID;
+						this.txtStatName.Enabled = true;
 						updateStatNames(currentStats);
 						updateStatLinePreview(currentStats);
 					}
 				}
 			}
+			if(this.txtStatLineID.Text == string.Empty)
+			{
+				this.txtStatName.Enabled = false;
+			}
+		}
+
+		private void btnStatsAdd_Click(object sender, EventArgs e)
+		{
+			if(this.txtStatLineID.Text == string.Empty)
+			{
+				MessageBox.Show("You must enter an ID!", "Create Stat Line Error");
+				return;
+			}
+			if (currentStats == null)
+			{
+				currentStats = new IBBoard.WarFoundry.API.Objects.SystemStats(this.txtStatLineID.Text);
+			}
+			system.AddSystemStats(currentStats);
+			clearStatLine();
+			updateSystemStatsList();
 		}
 
 		private void btnStatsRemove_Click(object sender, EventArgs e)
@@ -647,10 +645,13 @@
 			if(this.txtStatLineID.Text != string.Empty)
 			{
 				this.btnStatsAdd.Enabled = true;
+				this.txtStatName.Enabled = true;
 			}
 			else
 			{
 				this.btnStatsAdd.Enabled = false;
+				this.txtStatName.Enabled = false;
+				this.btnStatListAdd.Enabled = false;
 			}
 		}
 
@@ -668,10 +669,23 @@
 
 		private void btnStatListAdd_Click(object sender, EventArgs e)
 		{
+			if(currentStats == null)
+			{
+				if(this.txtStatLineID.Text != string.Empty)
+				{
+					currentStats = new IBBoard.WarFoundry.API.Objects.SystemStats(this.txtStatLineID.Text);				
+				}
+				else
+				{
+					MessageBox.Show("You must first define an ID for the stat line.", "No ID Error");
+					return;
+				}
+			}
 			if(this.txtStatName.Text != string.Empty)
 			{
 				currentStats.AddStatSlot(this.txtStatName.Text);
 			}
+			this.txtStatName.Clear();
 			updateStatNames(currentStats);
 			updateStatLinePreview(currentStats);
 		}
@@ -772,6 +786,7 @@
 		private void btnStatLineApply_Click(object sender, EventArgs e)
 		{
 			system.SetSystemStats(currentStats);
+			clearStatLine();
 		}
 	}
 }