Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
annotate FrmNewArmy.cs @ 97:6d2c8ad0d8f1
Re #308: Make GTK# UI translatable
* More standardisation of widget names with WinForms
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 02 Jan 2011 15:50:29 +0000 |
parents | b4416ca69153 |
children | 3b4863c61db8 |
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(); |
84
9db2112b31d7
Fixes #333: GTK interface doesn't auto-select race if only one exists
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
34 raceColumn.Title = Translation.GetTranslation("frmNewArmyRaceColumn", "race"); |
75
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 } |
96
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
48 |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
49 Translation.TranslationChanged += Retranslate; |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
50 Translate(); |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
51 } |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
52 |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
53 private void Retranslate() |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
54 { |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
55 Translate(); |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
56 } |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
57 |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
58 public override void Dispose() |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
59 { |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
60 Translation.TranslationChanged -= Retranslate; |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
61 base.Dispose(); |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
62 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
63 |
85
bfb29a60b802
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
84
diff
changeset
|
64 protected override void Translate() |
bfb29a60b802
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
84
diff
changeset
|
65 { |
bfb29a60b802
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
84
diff
changeset
|
66 base.Translate(); |
86
9515b57ba752
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
67 ControlTranslator.TranslateButtons(bttnCreate, bttnCancel); |
85
bfb29a60b802
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
84
diff
changeset
|
68 } |
bfb29a60b802
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
84
diff
changeset
|
69 |
0 | 70 protected virtual void OnSelectionChanged(object o, EventArgs e) |
71 { | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
72 logger.Debug("Race selection changed"); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
73 SetOkayButtonState(); |
0 | 74 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
75 |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
76 private void SetOkayButtonState() |
0 | 77 { |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
78 bttnCreate.Sensitive = (lstRaces.Selection.CountSelectedRows() == 1 && txtArmyName.Text != "" && sbPointsValue.Value > 0); |
0 | 79 } |
80 | |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
81 protected virtual void OnCreateClicked(object sender, System.EventArgs e) |
0 | 82 { |
83 TreeModel model; | |
84 TreeIter iter; | |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
85 lstRaces.Selection.GetSelected(out model, out iter); |
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
86 race = (Race)model.GetValue(iter, 0); |
0 | 87 armyName = txtArmyName.Text; |
88 pointsValue = (int)sbPointsValue.Value; | |
89 Respond(ResponseType.Ok); | |
90 } | |
91 | |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
92 protected virtual void OnCancelClicked(object sender, System.EventArgs e) |
0 | 93 { |
94 Respond(ResponseType.Cancel); | |
95 } | |
96 | |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
97 protected virtual void OnTextChanged(object sender, System.EventArgs e) |
0 | 98 { |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
99 SetOkayButtonState(); |
0 | 100 } |
101 | |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
102 protected virtual void OnSpinChangeValue(object o, Gtk.ChangeValueArgs args) |
0 | 103 { |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
104 SetOkayButtonState(); |
0 | 105 } |
106 | |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
107 protected virtual void OnSpinValueChanged(object sender, System.EventArgs e) |
0 | 108 { |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
109 SetOkayButtonState(); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
110 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
111 |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
112 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
|
113 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
114 GameSystem system = ComboBoxUtils.GetSelectedItem<GameSystem>(systemCombo); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
115 SetRaces(system); |
84
9db2112b31d7
Fixes #333: GTK interface doesn't auto-select race if only one exists
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
116 ListStore model = (ListStore)lstRaces.Model; |
9db2112b31d7
Fixes #333: GTK interface doesn't auto-select race if only one exists
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
117 |
9db2112b31d7
Fixes #333: GTK interface doesn't auto-select race if only one exists
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
118 if (model.IterNChildren() == 1) |
9db2112b31d7
Fixes #333: GTK interface doesn't auto-select race if only one exists
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
119 { |
9db2112b31d7
Fixes #333: GTK interface doesn't auto-select race if only one exists
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
120 TreeIter iter; |
9db2112b31d7
Fixes #333: GTK interface doesn't auto-select race if only one exists
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
121 model.GetIterFirst(out iter); |
9db2112b31d7
Fixes #333: GTK interface doesn't auto-select race if only one exists
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
122 lstRaces.Selection.SelectIter(iter); |
9db2112b31d7
Fixes #333: GTK interface doesn't auto-select race if only one exists
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
123 } |
9db2112b31d7
Fixes #333: GTK interface doesn't auto-select race if only one exists
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
124 |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
125 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
|
126 SetOkayButtonState(); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
127 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
128 |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
129 private void SetRaces(GameSystem system) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
130 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
131 ListStore store = new ListStore(typeof(Race)); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
132 |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
133 if (system != null) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
134 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
135 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
|
136 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
137 store.AppendValues(race); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
138 } |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
139 } |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
140 |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
141 lstRaces.Model = store; |
0 | 142 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
143 |
0 | 144 public Race SelectedRace |
145 { | |
146 get { return race; } | |
147 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
148 |
0 | 149 public string ArmyName |
150 { | |
151 get { return armyName; } | |
152 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
153 |
75
2ceae5d685d8
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
154 public int ArmySize |
0 | 155 { |
156 get { return pointsValue; } | |
157 } | |
158 } | |
159 } |