changeset 188:bbf391b31b3e

Re #98: Default army size papercut Updated Winforms to use the default army size.
author snowblizz
date Sun, 12 Dec 2010 15:37:07 +0000
parents 3a561c3751f5
children cb86380cbf61
files FrmNewArmy.cs
diffstat 1 files changed, 30 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/FrmNewArmy.cs	Sun Nov 21 21:51:28 2010 +0000
+++ b/FrmNewArmy.cs	Sun Dec 12 15:37:07 2010 +0000
@@ -20,6 +20,7 @@
 	/// </summary>
 	public class FrmNewArmy : IBBForm
 	{
+
 		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;
 
@@ -213,7 +215,8 @@
             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,14 +310,23 @@
 			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()
@@ -322,21 +334,31 @@
 			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 = race.Name + " " + 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();
+            armySize.Value = (decimal)selected.SystemArmyDefaultSize;
+ 
 			if (selected != null)
 			{
 				SetRaces(selected);