diff FrmNewArmy.cs @ 200:d084446348f5 default-army-size

RRe #97: Default army size issues
author snowblizz
date Wed, 01 Dec 2010 20:00:07 +0000
parents 0e39412353c4
children ec2b73de16ba
line wrap: on
line diff
--- a/FrmNewArmy.cs	Tue Nov 02 20:28:00 2010 +0000
+++ b/FrmNewArmy.cs	Wed Dec 01 20:00:07 2010 +0000
@@ -19,7 +19,8 @@
 	/// Summary description for FrmNewArmy.
 	/// </summary>
 	public class FrmNewArmy : IBBForm
-	{
+    {
+        private static int SYSTEM_DEFAULT_ARMY_SIZE = 1000; 
 		private IContainer components;
 		private IBBoard.Windows.Forms.IBBButton bttnCancel;
 		private IBBoard.Windows.Forms.IBBLabel lblRaceList;
@@ -35,6 +36,7 @@
 		private GameSystem system;
 		private Race race;
 		private string armyName;
+        public bool isDefaultArmyName;
 		private ToolTip gameSystemToolTip;
 		private int maxPoints;
 
@@ -209,11 +211,12 @@
 			this.armySize.TabIndex = 11;
 			this.armySize.ThousandsSeparator = true;
 			this.armySize.Value = new decimal(new int[] {
-            2000,
+            SYSTEM_DEFAULT_ARMY_SIZE,
             0,
             0,
             0});
-			//
+            this.armySize.ValueChanged += new System.EventHandler(this.armySize_ValueChanged);
+            //
 			// gameSystems
 			//
 			this.gameSystems.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
@@ -307,38 +310,65 @@
 			maxPoints = (int) armySize.Value;
 		}
 
-		private GameSystem GetSelectedGameSystem()
+        private void armySize_ValueChanged(object sender, System.EventArgs e)
+		{
+            if (txtArmyName.Enabled && isDefaultArmyName)
+            {
+                setTxtArmyNameVal();
+            }
+		}
+        
+        private GameSystem GetSelectedGameSystem()
 		{
 			return (GameSystem) gameSystems.SelectedItem;
 		}
 
 		private void txtArmyName_TextChanged(object sender, System.EventArgs e)
 		{
-			setSelectRaceEnabledVal();
+			isDefaultArmyName = false ;
+            setSelectRaceEnabledVal();
 		}
 
 		private void setSelectRaceEnabledVal()
-		{
+        {
 			bttnSelectRace.Enabled = (lstRaces.SelectedIndex>-1 && txtArmyName.Text.Trim()!="" && armySize.Value > 0);
 		}
 
-		private void lstRaces_SelectedIndexChanged(object sender, System.EventArgs e)
+        private void setTxtArmyNameVal()
+        {
+            txtArmyName.Text = String.Format(race.ArmyDefaultName, Translation.GetTranslation("armySizePts", "{0}pt", armySize.Value));
+            isDefaultArmyName = true;
+        }
+
+        private void lstRaces_SelectedIndexChanged(object sender, System.EventArgs e)
 		{
 			setSelectRaceEnabledVal();
 			bool raceSelected = lstRaces.SelectedItem != null;
 			txtArmyName.Enabled = raceSelected;
 			armySize.Enabled = raceSelected;
 			race = (Race)lstRaces.SelectedItem;
-			txtArmyName.Text = String.Format(race.ArmyDefaultName, Translation.GetTranslation("armySizePts", "{0}pt", armySize.Value));
+            setTxtArmyNameVal();
 		}
 
 		private void gameSystems_SelectedValueChanged(object sender, EventArgs e)
 		{
-			GameSystem selected = GetSelectedGameSystem();
-			lstRaces.Items.Clear();
+			
+            GameSystem selected = GetSelectedGameSystem();
+			txtArmyName.Text = "";
+            txtArmyName.Enabled = false;
+            lstRaces.Items.Clear();
+            
+ 
+			if (selected != null)
+            {
 
-			if (selected != null)
-			{
+                if (selected.SystemArmyDefaultSize != 1)
+                {
+                    System.Diagnostics.Debug.WriteLine("defaultSize:" + selected.SystemArmyDefaultSize);
+                    System.Diagnostics.Debug.WriteLine("system:" + selected.ID);
+                armySize.Value = (decimal) selected.SystemArmyDefaultSize;//}
+                }
+                
 				SetRaces(selected);
 
 				if (lstRaces.Items.Count == 1)
@@ -348,6 +378,8 @@
 			}
 
 			lstRaces.Enabled = lstRaces.Items.Count > 0;
+            
+            
 		}
 	}
 }