view FrmNewArmy.cs @ 112:9a93ae9ad956

* Add simple shell script to make sure that we run through Mono and not Wine (Not necessary, but useful to save confusion) no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sun, 07 Aug 2011 19:36:54 +0000
parents 9515b57ba752
children 3b4863c61db8
line source
1 // This file (FrmNewArmy.cs) is a part of the IBBoard.WarFoundry.GTK project and is copyright 2008, 2009 IBBoard.
2 //
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
5 using System;
6 using Gtk;
7 using IBBoard.Lang;
8 using IBBoard.WarFoundry.API;
9 using IBBoard.WarFoundry.API.Objects;
10 using IBBoard.GtkSharp;
11 using log4net;
12 using IBBoard.WarFoundry.GUI.GTK.Util;
13 using IBBoard.GtkSharp.Translatable;
15 namespace IBBoard.WarFoundry.GUI.GTK
16 {
17 public partial class FrmNewArmy : TranslatableDialog, ITranslatable
18 {
19 private ILog logger = LogManager.GetLogger(typeof(FrmNewArmy));
20 private Race race;
21 private string armyName;
22 private int pointsValue;
24 public FrmNewArmy(GameSystem gameSystem)
25 {
26 this.Build();
28 GameSystem[] gameSystems = WarFoundryLoader.GetDefault().GetGameSystems();
29 ComboBoxUtils.FillCombo(systemCombo, gameSystems, delegate(GameSystem sys){return sys.Name;});
31 lstRaces.Selection.Changed += new EventHandler(OnSelectionChanged);
33 TreeViewColumn raceColumn = new TreeViewColumn();
34 raceColumn.Title = Translation.GetTranslation("frmNewArmyRaceColumn", "race");
35 CellRendererText raceCell = new CellRendererText();
36 raceColumn.PackStart(raceCell, true);
37 lstRaces.AppendColumn(raceColumn);
38 raceColumn.SetCellDataFunc(raceCell, GtkWarFoundryUtil.RenderWarFoundryObjectName);
40 if (gameSystem != null)
41 {
42 ComboBoxUtils.SelectItem(systemCombo, gameSystem);
43 }
44 else if (gameSystems.Length == 1)
45 {
46 ComboBoxUtils.SelectIndex(systemCombo, 0);
47 }
49 Translation.TranslationChanged += Retranslate;
50 Translate();
51 }
53 private void Retranslate()
54 {
55 Translate();
56 }
58 public override void Dispose()
59 {
60 Translation.TranslationChanged -= Retranslate;
61 base.Dispose();
62 }
64 protected override void Translate()
65 {
66 base.Translate();
67 ControlTranslator.TranslateButtons(bttnCreate, bttnCancel);
68 }
70 protected virtual void OnSelectionChanged(object o, EventArgs e)
71 {
72 logger.Debug("Race selection changed");
73 SetOkayButtonState();
74 }
76 private void SetOkayButtonState()
77 {
78 bttnCreate.Sensitive = (lstRaces.Selection.CountSelectedRows() == 1 && txtArmyName.Text != "" && sbPointsValue.Value > 0);
79 }
81 protected virtual void OnCreateClicked(object sender, System.EventArgs e)
82 {
83 TreeModel model;
84 TreeIter iter;
85 lstRaces.Selection.GetSelected(out model, out iter);
86 race = (Race)model.GetValue(iter, 0);
87 armyName = txtArmyName.Text;
88 pointsValue = (int)sbPointsValue.Value;
89 Respond(ResponseType.Ok);
90 }
92 protected virtual void OnCancelClicked(object sender, System.EventArgs e)
93 {
94 Respond(ResponseType.Cancel);
95 }
97 protected virtual void OnTextChanged(object sender, System.EventArgs e)
98 {
99 SetOkayButtonState();
100 }
102 protected virtual void OnSpinChangeValue(object o, Gtk.ChangeValueArgs args)
103 {
104 SetOkayButtonState();
105 }
107 protected virtual void OnSpinValueChanged(object sender, System.EventArgs e)
108 {
109 SetOkayButtonState();
110 }
112 protected virtual void OnSystemComboChanged(object sender, System.EventArgs e)
113 {
114 GameSystem system = ComboBoxUtils.GetSelectedItem<GameSystem>(systemCombo);
115 SetRaces(system);
116 ListStore model = (ListStore)lstRaces.Model;
118 if (model.IterNChildren() == 1)
119 {
120 TreeIter iter;
121 model.GetIterFirst(out iter);
122 lstRaces.Selection.SelectIter(iter);
123 }
125 logger.Debug("System selection changed: " + (system == null ? "null" : system.Name));
126 SetOkayButtonState();
127 }
129 private void SetRaces(GameSystem system)
130 {
131 ListStore store = new ListStore(typeof(Race));
133 if (system != null)
134 {
135 foreach (Race race in WarFoundryLoader.GetDefault().GetRaces(system))
136 {
137 store.AppendValues(race);
138 }
139 }
141 lstRaces.Model = store;
142 }
144 public Race SelectedRace
145 {
146 get { return race; }
147 }
149 public string ArmyName
150 {
151 get { return armyName; }
152 }
154 public int ArmySize
155 {
156 get { return pointsValue; }
157 }
158 }
159 }