changeset 134:7e77e79e5fdd

Fixes #325: Use default army size when creating armies * Update name where it hasn't been changed, using template values from data file
author IBBoard <dev@ibboard.co.uk>
date Sun, 09 Oct 2011 20:37:53 +0100
parents 3b4863c61db8
children fda46380dd68
files FrmNewArmy.cs
diffstat 1 files changed, 38 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/FrmNewArmy.cs	Sat Oct 08 20:56:37 2011 +0100
     1.2 +++ b/FrmNewArmy.cs	Sun Oct 09 20:37:53 2011 +0100
     1.3 @@ -20,6 +20,7 @@
     1.4  		private Race race;
     1.5  		private string armyName;
     1.6  		private int pointsValue;
     1.7 +		private bool isDefaultArmyName = true;
     1.8  
     1.9  		public FrmNewArmy(GameSystem gameSystem)
    1.10  		{
    1.11 @@ -70,6 +71,7 @@
    1.12  		protected virtual void OnSelectionChanged(object o, EventArgs e)
    1.13  		{
    1.14  			logger.Debug("Race selection changed");
    1.15 +			SetArmyName();
    1.16  			SetOkayButtonState();
    1.17  		}
    1.18  
    1.19 @@ -80,13 +82,18 @@
    1.20  
    1.21  		protected virtual void OnCreateClicked(object sender, System.EventArgs e)
    1.22  		{
    1.23 +			race = GetSelectedRace();
    1.24 +			armyName = txtArmyName.Text;
    1.25 +			pointsValue = (int)sbPointsValue.Value;
    1.26 +			Respond(ResponseType.Ok);
    1.27 +		}
    1.28 +
    1.29 +		private Race GetSelectedRace()
    1.30 +		{
    1.31  			TreeModel model;
    1.32  			TreeIter iter;
    1.33  			lstRaces.Selection.GetSelected(out model, out iter);
    1.34 -			race = (Race)model.GetValue(iter, 0);
    1.35 -			armyName = txtArmyName.Text;
    1.36 -			pointsValue = (int)sbPointsValue.Value;
    1.37 -			Respond(ResponseType.Ok);
    1.38 +			return (Race)model.GetValue(iter, 0);
    1.39  		}
    1.40  
    1.41  		protected virtual void OnCancelClicked(object sender, System.EventArgs e)
    1.42 @@ -97,15 +104,18 @@
    1.43  		protected virtual void OnTextChanged(object sender, System.EventArgs e)
    1.44  		{
    1.45  			SetOkayButtonState();
    1.46 +			isDefaultArmyName = false;
    1.47  		}
    1.48  
    1.49  		protected virtual void OnSpinChangeValue(object o, Gtk.ChangeValueArgs args)
    1.50  		{
    1.51 +			SetArmyName();
    1.52  			SetOkayButtonState();
    1.53  		}
    1.54  
    1.55  		protected virtual void OnSpinValueChanged(object sender, System.EventArgs e)
    1.56  		{
    1.57 +			SetArmyName();
    1.58  			SetOkayButtonState();
    1.59  		}
    1.60  
    1.61 @@ -113,6 +123,7 @@
    1.62  		{
    1.63  			GameSystem system = ComboBoxUtils.GetSelectedItem<GameSystem>(systemCombo);
    1.64  			SetRaces(system);
    1.65 +			sbPointsValue.Value = system.SystemArmyDefaultSize;
    1.66  			ListStore model = (ListStore)lstRaces.Model;
    1.67  
    1.68  			if (model.IterNChildren() == 1)
    1.69 @@ -120,9 +131,9 @@
    1.70  				TreeIter iter;
    1.71  				model.GetIterFirst(out iter);
    1.72  				lstRaces.Selection.SelectIter(iter);
    1.73 +				SetArmyName();
    1.74  			}
    1.75  
    1.76 -			sbPointsValue.Value = system.SystemArmyDefaultSize;
    1.77  			logger.Debug("System selection changed: " + (system == null ? "null" : system.Name));
    1.78  			SetOkayButtonState();
    1.79  		}
    1.80 @@ -142,6 +153,23 @@
    1.81  			lstRaces.Model = store;
    1.82  		}
    1.83  
    1.84 +		private void SetArmyName()
    1.85 +        {
    1.86 +			if (isDefaultArmyName || txtArmyName.Text == "")
    1.87 +			{
    1.88 +				if (lstRaces.Selection.CountSelectedRows() == 1)
    1.89 +		        {
    1.90 +	                GameSystem currSystem = SelectedGameSystem;
    1.91 +	                txtArmyName.Text = String.Format(GetSelectedRace().ArmyDefaultName, Translation.GetTranslation("armySizePts", "{0}{1}", sbPointsValue.Value, currSystem.SystemPtsAbbrevSingle));
    1.92 +				}
    1.93 +				else {
    1.94 +					txtArmyName.Text = "";
    1.95 +				}
    1.96 +
    1.97 +				isDefaultArmyName = true;
    1.98 +			}
    1.99 +        }
   1.100 +
   1.101  		public Race SelectedRace
   1.102  		{
   1.103  			get { return race; }
   1.104 @@ -156,5 +184,10 @@
   1.105  		{
   1.106  			get { return pointsValue; }
   1.107  		}
   1.108 +
   1.109 +		private GameSystem SelectedGameSystem
   1.110 +		{
   1.111 +			get { return ComboBoxUtils.GetSelectedItem<GameSystem>(systemCombo); }
   1.112 +		}
   1.113  	}
   1.114  }