Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate FrmNewArmy.cs @ 69:3b4a646b4054
Re #60: Add UI to add/remove/edit weapons in GTK
* Fix errors in replace dialog (move UI setup to just before we show)
Also:
* Fix missing refresh of army tree on equipment/points value change
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 06 Nov 2010 11:44:26 +0000 |
parents | 4bad8cb3f889 |
children | 2ceae5d685d8 |
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; |
0 | 13 |
5 | 14 namespace IBBoard.WarFoundry.GTK |
0 | 15 { |
16 public partial class FrmNewArmy : Dialog, ITranslatable | |
17 { | |
18 private ILog logger = LogManager.GetLogger(typeof(FrmNewArmy)); | |
19 private Race race; | |
20 private string armyName; | |
21 private int pointsValue; | |
22 | |
23 public FrmNewArmy(GameSystem gameSystem) | |
24 { | |
25 this.Build(); | |
26 | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
27 GameSystem[] gameSystems = WarFoundryLoader.GetDefault().GetGameSystems(); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
28 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
|
29 |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
30 if (gameSystem != null) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
31 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
32 ComboBoxUtils.SelectItem(systemCombo, gameSystem); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
33 } |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
34 else if (gameSystems.Length == 1) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
35 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
36 ComboBoxUtils.SelectIndex(systemCombo, 0); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
37 } |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
38 |
0 | 39 lstRaces.Selection.Changed+= new EventHandler(OnSelectionChanged); |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
40 |
0 | 41 TreeViewColumn raceColumn = new TreeViewColumn (); |
42 raceColumn.Title = "Race"; | |
43 CellRendererText raceCell = new CellRendererText (); | |
44 raceColumn.PackStart (raceCell, true); | |
45 lstRaces.AppendColumn(raceColumn); | |
52
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
46 raceColumn.SetCellDataFunc(raceCell, GtkWarFoundryUtil.RenderWarFoundryObjectName); |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
47 |
0 | 48 |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
49 if (gameSystem!=null) |
0 | 50 { |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
51 SetRaces(gameSystem); |
0 | 52 } |
53 } | |
54 | |
55 public string Text | |
56 { | |
57 get { return Title; } | |
58 set { Title = value; } | |
59 } | |
60 | |
61 protected virtual void OnSelectionChanged(object o, EventArgs e) | |
62 { | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
63 logger.Debug("Race selection changed"); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
64 SetOkayButtonState(); |
0 | 65 } |
66 | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
67 private void SetOkayButtonState() |
0 | 68 { |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
69 bttnCreate.Sensitive = (lstRaces.Selection.CountSelectedRows() == 1 && txtArmyName.Text!="" && sbPointsValue.Value > 0); |
0 | 70 } |
71 | |
72 protected virtual void OnCreateClicked (object sender, System.EventArgs e) | |
73 { | |
74 TreeModel model; | |
75 TreeIter iter; | |
76 lstRaces.Selection.GetSelected (out model, out iter); | |
77 race = (Race) model.GetValue(iter, 0); | |
78 armyName = txtArmyName.Text; | |
79 pointsValue = (int)sbPointsValue.Value; | |
80 Respond(ResponseType.Ok); | |
81 } | |
82 | |
83 protected virtual void OnCancelClicked (object sender, System.EventArgs e) | |
84 { | |
85 Respond(ResponseType.Cancel); | |
86 } | |
87 | |
88 protected virtual void OnTextChanged (object sender, System.EventArgs e) | |
89 { | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
90 SetOkayButtonState(); |
0 | 91 } |
92 | |
93 protected virtual void OnSpinChangeValue (object o, Gtk.ChangeValueArgs args) | |
94 { | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
95 SetOkayButtonState(); |
0 | 96 } |
97 | |
98 protected virtual void OnSpinValueChanged (object sender, System.EventArgs e) | |
99 { | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
100 SetOkayButtonState(); |
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 |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
103 protected virtual void OnSystemComboChanged (object sender, System.EventArgs e) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
104 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
105 GameSystem system = ComboBoxUtils.GetSelectedItem<GameSystem>(systemCombo); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
106 SetRaces(system); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
107 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
|
108 SetOkayButtonState(); |
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 private void SetRaces(GameSystem system) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
112 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
113 ListStore store = new ListStore(typeof(Race)); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
114 |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
115 if (system != null) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
116 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
117 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
|
118 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
119 store.AppendValues(race); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
120 } |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
121 } |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
122 |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
123 lstRaces.Model = store; |
0 | 124 } |
125 | |
126 public Race SelectedRace | |
127 { | |
128 get { return race; } | |
129 } | |
130 | |
131 public string ArmyName | |
132 { | |
133 get { return armyName; } | |
134 } | |
135 | |
136 public int ArmySize | |
137 { | |
138 get { return pointsValue; } | |
139 } | |
140 } | |
141 } |