changeset 6:d63df495cf5a

Implemented initial support for adding and editing categories.
author Tsudico
date Mon, 13 Dec 2010 22:38:01 -0600
parents 387f17b36f52
children d4c03cc5bfb7
files FrmMain.cs FrmSystem.Designer.cs FrmSystem.cs IBBoard.WarFoundry.Forge.WinForms.suo
diffstat 4 files changed, 114 insertions(+), 34 deletions(-) [+]
line diff
     1.1 --- a/FrmMain.cs	Mon Dec 13 21:07:20 2010 -0600
     1.2 +++ b/FrmMain.cs	Mon Dec 13 22:38:01 2010 -0600
     1.3 @@ -306,9 +306,11 @@
     1.4  
     1.5  		private void miOpenSystem_Click(object sender, System.EventArgs e)
     1.6  		{
     1.7 -			OpenFile();
     1.8 -			FrmSystem system = new FrmSystem(CurrentGameSystem);
     1.9 -			system.ShowDialog(this);
    1.10 +			if(OpenFile())
    1.11 +			{
    1.12 +				FrmSystem system = new FrmSystem(CurrentGameSystem);
    1.13 +				system.ShowDialog(this);
    1.14 +			}
    1.15  		}
    1.16  		
    1.17  		private bool OpenFile()
     2.1 --- a/FrmSystem.Designer.cs	Mon Dec 13 21:07:20 2010 -0600
     2.2 +++ b/FrmSystem.Designer.cs	Mon Dec 13 22:38:01 2010 -0600
     2.3 @@ -352,15 +352,14 @@
     2.4  			// 
     2.5  			// numPercentMax
     2.6  			// 
     2.7 -			this.numPercentMax.DecimalPlaces = 4;
     2.8  			this.numPercentMax.Increment = new decimal(new int[] {
     2.9              5,
    2.10              0,
    2.11              0,
    2.12              0});
    2.13 -			this.numPercentMax.Location = new System.Drawing.Point(202, 97);
    2.14 +			this.numPercentMax.Location = new System.Drawing.Point(229, 97);
    2.15  			this.numPercentMax.Name = "numPercentMax";
    2.16 -			this.numPercentMax.Size = new System.Drawing.Size(69, 20);
    2.17 +			this.numPercentMax.Size = new System.Drawing.Size(42, 20);
    2.18  			this.numPercentMax.TabIndex = 9;
    2.19  			this.numPercentMax.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
    2.20  			// 
    2.21 @@ -376,15 +375,14 @@
    2.22  			// 
    2.23  			// numPercentMin
    2.24  			// 
    2.25 -			this.numPercentMin.DecimalPlaces = 4;
    2.26  			this.numPercentMin.Increment = new decimal(new int[] {
    2.27              5,
    2.28              0,
    2.29              0,
    2.30              0});
    2.31 -			this.numPercentMin.Location = new System.Drawing.Point(202, 71);
    2.32 +			this.numPercentMin.Location = new System.Drawing.Point(229, 71);
    2.33  			this.numPercentMin.Name = "numPercentMin";
    2.34 -			this.numPercentMin.Size = new System.Drawing.Size(69, 20);
    2.35 +			this.numPercentMin.Size = new System.Drawing.Size(42, 20);
    2.36  			this.numPercentMin.TabIndex = 7;
    2.37  			this.numPercentMin.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
    2.38  			// 
    2.39 @@ -461,6 +459,7 @@
    2.40  			this.btnGenerateCatID.TabIndex = 22;
    2.41  			this.btnGenerateCatID.Text = "Generate ID";
    2.42  			this.btnGenerateCatID.UseVisualStyleBackColor = true;
    2.43 +			this.btnGenerateCatID.Click += new System.EventHandler(this.btnGenerateCatID_Click);
    2.44  			// 
    2.45  			// txtCategoryID
    2.46  			// 
    2.47 @@ -528,6 +527,7 @@
    2.48  			this.btnCategoryAdd.TabIndex = 13;
    2.49  			this.btnCategoryAdd.Text = "Add";
    2.50  			this.btnCategoryAdd.UseVisualStyleBackColor = true;
    2.51 +			this.btnCategoryAdd.Click += new System.EventHandler(this.btnCategoryAdd_Click);
    2.52  			// 
    2.53  			// btnCategoryRemove
    2.54  			// 
    2.55 @@ -546,6 +546,7 @@
    2.56  			this.btnCategoryEdit.TabIndex = 14;
    2.57  			this.btnCategoryEdit.Text = "Edit";
    2.58  			this.btnCategoryEdit.UseVisualStyleBackColor = true;
    2.59 +			this.btnCategoryEdit.Click += new System.EventHandler(this.btnCategoryEdit_Click);
    2.60  			// 
    2.61  			// tabStats
    2.62  			// 
     3.1 --- a/FrmSystem.cs	Mon Dec 13 21:07:20 2010 -0600
     3.2 +++ b/FrmSystem.cs	Mon Dec 13 22:38:01 2010 -0600
     3.3 @@ -20,28 +20,51 @@
     3.4  		{
     3.5  			InitializeComponent();
     3.6  			system = loadSystem;
     3.7 -			if(loadSystem.IsFullyLoaded)
     3.8 +			this.txtSystemName.Text = system.Name;
     3.9 +			this.txtSystemId.Text = system.ID;
    3.10 +			if(system.AllowAllies)
    3.11  			{
    3.12 -				this.txtSystemName.Text = system.Name;
    3.13 -				this.txtSystemId.Text = system.ID;
    3.14 -				if(system.AllowAllies)
    3.15 +				this.radSystemAlliesYes.Checked = true;
    3.16 +			}
    3.17 +			else
    3.18 +			{
    3.19 +				this.radSystemAlliesNo.Checked = true;
    3.20 +			}
    3.21 +			if (system.WarnOnError)
    3.22 +			{
    3.23 +				this.radSystemWarnYes.Checked = true;
    3.24 +			}
    3.25 +			else
    3.26 +			{
    3.27 +				this.radSystemWarnNo.Checked = true;
    3.28 +			}
    3.29 +			if(system.Categories.Length > 0)
    3.30 +			{
    3.31 +				this.listCategories.Items.Clear();
    3.32 +				for(int i = 0; i < system.Categories.Length; i++)
    3.33  				{
    3.34 -					this.radSystemAlliesYes.Checked = true;
    3.35 -				}
    3.36 -				else
    3.37 -				{
    3.38 -					this.radSystemAlliesNo.Checked = true;
    3.39 -				}
    3.40 -				if (system.WarnOnError)
    3.41 -				{
    3.42 -					this.radSystemWarnYes.Checked = true;
    3.43 -				}
    3.44 -				else
    3.45 -				{
    3.46 -					this.radSystemWarnNo.Checked = true;
    3.47 +					this.listCategories.Items.Add(system.Categories[i].Name);
    3.48  				}
    3.49  			}
    3.50  		}
    3.51 +		
    3.52 +		private string generateID(string name)
    3.53 +		{
    3.54 +			string newId = String.Empty;
    3.55 +
    3.56 +			MatchCollection id_parts = Regex.Matches(name, @"[A-Z\d]");
    3.57 +			foreach (Match part in id_parts)
    3.58 +			{
    3.59 +				newId += part.ToString();
    3.60 +			}
    3.61 +
    3.62 +			if (newId.Length < 3)
    3.63 +			{
    3.64 +				newId = name.ToLower().Replace(" ", "");
    3.65 +			}
    3.66 +
    3.67 +			return newId.ToLower();
    3.68 +		}
    3.69  
    3.70  		private void btnSystemClose_Click(object sender, EventArgs e)
    3.71  		{
    3.72 @@ -50,20 +73,74 @@
    3.73  
    3.74  		private void btnGenerateSysId_Click(object sender, EventArgs e)
    3.75  		{
    3.76 -			string newId = String.Empty;
    3.77 +			this.txtSystemId.Text = generateID(this.txtSystemName.Text);
    3.78 +		}
    3.79  
    3.80 -			MatchCollection id_parts = Regex.Matches(this.txtSystemName.Text, @"[A-Z\d]");
    3.81 -			foreach(Match part in id_parts)
    3.82 +		private void btnCategoryAdd_Click(object sender, EventArgs e)
    3.83 +		{
    3.84 +			if(this.txtCategoryName.Text == string.Empty)
    3.85  			{
    3.86 -				newId += part.ToString();
    3.87 +				MessageBox.Show("Category must have a name", "Category Error");
    3.88 +				return;
    3.89  			}
    3.90 +			if (this.txtCategoryID.Text == string.Empty)
    3.91 +			{
    3.92 +				MessageBox.Show("Category must have an ID", "Category Error");
    3.93 +				return;
    3.94 +			}
    3.95 +			IBBoard.WarFoundry.API.Objects.Category cat = new IBBoard.WarFoundry.API.Objects.Category(
    3.96 +					this.txtCategoryID.Text,
    3.97 +					this.txtCategoryName.Text
    3.98 +					);
    3.99  			
   3.100 -			if(newId.Length < 3)
   3.101 +			cat.MinimumPoints = (int)this.numPointMin.Value;
   3.102 +			cat.MaximumPoints = (int)this.numPointMax.Value;
   3.103 +			cat.MinimumPercentage = (int)this.numPercentMin.Value;
   3.104 +			cat.MaximumPercentage = (int)this.numPercentMax.Value;
   3.105 +			
   3.106 +			system.AddCategory(cat);
   3.107 +
   3.108 +			if (system.Categories.Length > 0)
   3.109  			{
   3.110 -				newId = this.txtSystemName.Text.ToLower().Replace(" ", "");
   3.111 +				this.listCategories.Items.Clear();
   3.112 +				for (int i = 0; i < system.Categories.Length; i++)
   3.113 +				{
   3.114 +					this.listCategories.Items.Add(system.Categories[i].Name);
   3.115 +				}
   3.116  			}
   3.117 -			
   3.118 -			this.txtSystemId.Text = newId.ToLower();
   3.119 +		}
   3.120 +
   3.121 +		private void btnCategoryEdit_Click(object sender, EventArgs e)
   3.122 +		{
   3.123 +			foreach(IBBoard.WarFoundry.API.Objects.Category cat in system.Categories)
   3.124 +			{
   3.125 +				if(cat.Name == this.listCategories.SelectedItem)
   3.126 +				{
   3.127 +					this.txtCategoryName.Text = cat.Name;
   3.128 +					this.txtCategoryID.Text = cat.ID;
   3.129 +					if(cat.MinimumPoints >= 0)
   3.130 +					{
   3.131 +						this.numPointMin.Value = cat.MinimumPoints;
   3.132 +					}
   3.133 +					if(cat.MaximumPoints > 0 && cat.MaximumPoints < this.numPointMax.Maximum)
   3.134 +					{	
   3.135 +						this.numPointMax.Value = cat.MaximumPoints;
   3.136 +					}
   3.137 +					if(cat.MinimumPercentage >= 0)
   3.138 +					{
   3.139 +						this.numPercentMin.Value = cat.MinimumPercentage;
   3.140 +					}
   3.141 +					if(cat.MaximumPercentage <= 100)
   3.142 +					{
   3.143 +						this.numPercentMax.Value = cat.MaximumPercentage;
   3.144 +					}
   3.145 +				}
   3.146 +			}
   3.147 +		}
   3.148 +
   3.149 +		private void btnGenerateCatID_Click(object sender, EventArgs e)
   3.150 +		{
   3.151 +			this.txtCategoryID.Text = generateID(this.txtCategoryName.Text);
   3.152  		}
   3.153  	}
   3.154  }
     4.1 Binary file IBBoard.WarFoundry.Forge.WinForms.suo has changed