Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
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 wrap: on
line diff
--- a/FrmNewArmy.cs Sat Oct 08 20:56:37 2011 +0100 +++ b/FrmNewArmy.cs Sun Oct 09 20:37:53 2011 +0100 @@ -20,6 +20,7 @@ private Race race; private string armyName; private int pointsValue; + private bool isDefaultArmyName = true; public FrmNewArmy(GameSystem gameSystem) { @@ -70,6 +71,7 @@ protected virtual void OnSelectionChanged(object o, EventArgs e) { logger.Debug("Race selection changed"); + SetArmyName(); SetOkayButtonState(); } @@ -80,13 +82,18 @@ protected virtual void OnCreateClicked(object sender, System.EventArgs e) { + race = GetSelectedRace(); + armyName = txtArmyName.Text; + pointsValue = (int)sbPointsValue.Value; + Respond(ResponseType.Ok); + } + + private Race GetSelectedRace() + { TreeModel model; TreeIter iter; lstRaces.Selection.GetSelected(out model, out iter); - race = (Race)model.GetValue(iter, 0); - armyName = txtArmyName.Text; - pointsValue = (int)sbPointsValue.Value; - Respond(ResponseType.Ok); + return (Race)model.GetValue(iter, 0); } protected virtual void OnCancelClicked(object sender, System.EventArgs e) @@ -97,15 +104,18 @@ protected virtual void OnTextChanged(object sender, System.EventArgs e) { SetOkayButtonState(); + isDefaultArmyName = false; } protected virtual void OnSpinChangeValue(object o, Gtk.ChangeValueArgs args) { + SetArmyName(); SetOkayButtonState(); } protected virtual void OnSpinValueChanged(object sender, System.EventArgs e) { + SetArmyName(); SetOkayButtonState(); } @@ -113,6 +123,7 @@ { GameSystem system = ComboBoxUtils.GetSelectedItem<GameSystem>(systemCombo); SetRaces(system); + sbPointsValue.Value = system.SystemArmyDefaultSize; ListStore model = (ListStore)lstRaces.Model; if (model.IterNChildren() == 1) @@ -120,9 +131,9 @@ TreeIter iter; model.GetIterFirst(out iter); lstRaces.Selection.SelectIter(iter); + SetArmyName(); } - sbPointsValue.Value = system.SystemArmyDefaultSize; logger.Debug("System selection changed: " + (system == null ? "null" : system.Name)); SetOkayButtonState(); } @@ -142,6 +153,23 @@ lstRaces.Model = store; } + private void SetArmyName() + { + if (isDefaultArmyName || txtArmyName.Text == "") + { + if (lstRaces.Selection.CountSelectedRows() == 1) + { + GameSystem currSystem = SelectedGameSystem; + txtArmyName.Text = String.Format(GetSelectedRace().ArmyDefaultName, Translation.GetTranslation("armySizePts", "{0}{1}", sbPointsValue.Value, currSystem.SystemPtsAbbrevSingle)); + } + else { + txtArmyName.Text = ""; + } + + isDefaultArmyName = true; + } + } + public Race SelectedRace { get { return race; } @@ -156,5 +184,10 @@ { get { return pointsValue; } } + + private GameSystem SelectedGameSystem + { + get { return ComboBoxUtils.GetSelectedItem<GameSystem>(systemCombo); } + } } }