Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate FrmNewArmy.cs @ 82:fb16ca1cb52b
Re #308: Make GTK# UI translatable
* Match button names to WinForms for consistency
* Translate army column title
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 28 Dec 2010 20:20:16 +0000 |
parents | 68804784bf6f |
children | 9db2112b31d7 |
rev | line source |
---|---|
19 | 1 // This file (FrmNewArmy.cs) is a part of the IBBoard.WarFoundry.GTK project and is copyright 2008, 2009 IBBoard. |
0 | 2 // |
19 | 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. |
0 | 4 |
5 using System; | |
6 using Gtk; | |
7 using IBBoard.Lang; | |
8 using IBBoard.WarFoundry.API; | |
9 using IBBoard.WarFoundry.API.Objects; | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
10 using IBBoard.GtkSharp; |
0 | 11 using log4net; |
52
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
12 using IBBoard.WarFoundry.GUI.GTK.Util; |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
75
diff
changeset
|
13 using IBBoard.GtkSharp.Translatable; |
0 | 14 |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
15 namespace IBBoard.WarFoundry.GUI.GTK |
0 | 16 { |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
75
diff
changeset
|
17 public partial class FrmNewArmy : TranslatableDialog, ITranslatable |
0 | 18 { |
19 private ILog logger = LogManager.GetLogger(typeof(FrmNewArmy)); | |
20 private Race race; | |
21 private string armyName; | |
22 private int pointsValue; | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
23 |
0 | 24 public FrmNewArmy(GameSystem gameSystem) |
25 { | |
26 this.Build(); | |
27 | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
28 GameSystem[] gameSystems = WarFoundryLoader.GetDefault().GetGameSystems(); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
29 ComboBoxUtils.FillCombo(systemCombo, gameSystems, delegate(GameSystem sys){return sys.Name;}); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
30 |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
31 lstRaces.Selection.Changed += new EventHandler(OnSelectionChanged); |
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
32 |
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
33 TreeViewColumn raceColumn = new TreeViewColumn(); |
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
34 raceColumn.Title = "Race"; |
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
35 CellRendererText raceCell = new CellRendererText(); |
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
36 raceColumn.PackStart(raceCell, true); |
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
37 lstRaces.AppendColumn(raceColumn); |
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
38 raceColumn.SetCellDataFunc(raceCell, GtkWarFoundryUtil.RenderWarFoundryObjectName); |
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
39 |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
40 if (gameSystem != null) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
41 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
42 ComboBoxUtils.SelectItem(systemCombo, gameSystem); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
43 } |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
44 else if (gameSystems.Length == 1) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
45 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
46 ComboBoxUtils.SelectIndex(systemCombo, 0); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
47 } |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
48 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
49 |
0 | 50 protected virtual void OnSelectionChanged(object o, EventArgs e) |
51 { | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
52 logger.Debug("Race selection changed"); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
53 SetOkayButtonState(); |
0 | 54 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
55 |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
56 private void SetOkayButtonState() |
0 | 57 { |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
58 bttnCreate.Sensitive = (lstRaces.Selection.CountSelectedRows() == 1 && txtArmyName.Text != "" && sbPointsValue.Value > 0); |
0 | 59 } |
60 | |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
61 protected virtual void OnCreateClicked(object sender, System.EventArgs e) |
0 | 62 { |
63 TreeModel model; | |
64 TreeIter iter; | |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
65 lstRaces.Selection.GetSelected(out model, out iter); |
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
66 race = (Race)model.GetValue(iter, 0); |
0 | 67 armyName = txtArmyName.Text; |
68 pointsValue = (int)sbPointsValue.Value; | |
69 Respond(ResponseType.Ok); | |
70 } | |
71 | |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
72 protected virtual void OnCancelClicked(object sender, System.EventArgs e) |
0 | 73 { |
74 Respond(ResponseType.Cancel); | |
75 } | |
76 | |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
77 protected virtual void OnTextChanged(object sender, System.EventArgs e) |
0 | 78 { |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
79 SetOkayButtonState(); |
0 | 80 } |
81 | |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
82 protected virtual void OnSpinChangeValue(object o, Gtk.ChangeValueArgs args) |
0 | 83 { |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
84 SetOkayButtonState(); |
0 | 85 } |
86 | |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
87 protected virtual void OnSpinValueChanged(object sender, System.EventArgs e) |
0 | 88 { |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
89 SetOkayButtonState(); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
90 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
91 |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
92 protected virtual void OnSystemComboChanged(object sender, System.EventArgs e) |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
93 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
94 GameSystem system = ComboBoxUtils.GetSelectedItem<GameSystem>(systemCombo); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
95 SetRaces(system); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
96 logger.Debug("System selection changed: " + (system == null ? "null" : system.Name)); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
97 SetOkayButtonState(); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
98 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
99 |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
100 private void SetRaces(GameSystem system) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
101 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
102 ListStore store = new ListStore(typeof(Race)); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
103 |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
104 if (system != null) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
105 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
106 foreach (Race race in WarFoundryLoader.GetDefault().GetRaces(system)) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
107 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
108 store.AppendValues(race); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
109 } |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
110 } |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
111 |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
112 lstRaces.Model = store; |
0 | 113 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
114 |
0 | 115 public Race SelectedRace |
116 { | |
117 get { return race; } | |
118 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
119 |
0 | 120 public string ArmyName |
121 { | |
122 get { return armyName; } | |
123 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
124 |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
125 public int ArmySize |
0 | 126 { |
127 get { return pointsValue; } | |
128 } | |
129 } | |
130 } |