Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate FrmNewArmy.cs @ 42:35ad26ac59c0
Fixes #143: GTK "Army has been modified" dialog has no buttons
* Use "AddButton" method to add a button that returns "Cancel" response
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 11 Aug 2010 19:11:00 +0000 |
parents | d68992a831df |
children | 4bad8cb3f889 4a33b3012100 |
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; |
12 | |
5 | 13 namespace IBBoard.WarFoundry.GTK |
0 | 14 { |
15 public partial class FrmNewArmy : Dialog, ITranslatable | |
16 { | |
17 private ILog logger = LogManager.GetLogger(typeof(FrmNewArmy)); | |
18 private Race race; | |
19 private string armyName; | |
20 private int pointsValue; | |
21 | |
22 public FrmNewArmy(GameSystem gameSystem) | |
23 { | |
24 this.Build(); | |
25 | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
26 GameSystem[] gameSystems = WarFoundryLoader.GetDefault().GetGameSystems(); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
27 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
|
28 |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
29 if (gameSystem != null) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
30 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
31 ComboBoxUtils.SelectItem(systemCombo, gameSystem); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
32 } |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
33 else if (gameSystems.Length == 1) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
34 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
35 ComboBoxUtils.SelectIndex(systemCombo, 0); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
36 } |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
37 |
0 | 38 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
|
39 |
0 | 40 TreeViewColumn raceColumn = new TreeViewColumn (); |
41 raceColumn.Title = "Race"; | |
42 CellRendererText raceCell = new CellRendererText (); | |
43 raceColumn.PackStart (raceCell, true); | |
44 lstRaces.AppendColumn(raceColumn); | |
45 raceColumn.SetCellDataFunc(raceCell, new TreeCellDataFunc(RenderRaceName)); | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
46 |
0 | 47 |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
48 if (gameSystem!=null) |
0 | 49 { |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
50 SetRaces(gameSystem); |
0 | 51 } |
52 } | |
53 | |
54 public string Text | |
55 { | |
56 get { return Title; } | |
57 set { Title = value; } | |
58 } | |
59 | |
60 private void RenderRaceName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | |
61 { | |
62 Race r = (Race)model.GetValue(iter, 0); | |
63 (cell as CellRendererText).Text = r.Name; | |
64 } | |
65 | |
66 protected virtual void OnSelectionChanged(object o, EventArgs e) | |
67 { | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
68 logger.Debug("Race selection changed"); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
69 SetOkayButtonState(); |
0 | 70 } |
71 | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
72 private void SetOkayButtonState() |
0 | 73 { |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
74 bttnCreate.Sensitive = (lstRaces.Selection.CountSelectedRows() == 1 && txtArmyName.Text!="" && sbPointsValue.Value > 0); |
0 | 75 } |
76 | |
77 protected virtual void OnCreateClicked (object sender, System.EventArgs e) | |
78 { | |
79 TreeModel model; | |
80 TreeIter iter; | |
81 lstRaces.Selection.GetSelected (out model, out iter); | |
82 race = (Race) model.GetValue(iter, 0); | |
83 armyName = txtArmyName.Text; | |
84 pointsValue = (int)sbPointsValue.Value; | |
85 Respond(ResponseType.Ok); | |
86 } | |
87 | |
88 protected virtual void OnCancelClicked (object sender, System.EventArgs e) | |
89 { | |
90 Respond(ResponseType.Cancel); | |
91 } | |
92 | |
93 protected virtual void OnTextChanged (object sender, System.EventArgs e) | |
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 OnSpinChangeValue (object o, Gtk.ChangeValueArgs args) | |
99 { | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
100 SetOkayButtonState(); |
0 | 101 } |
102 | |
103 protected virtual void OnSpinValueChanged (object sender, System.EventArgs e) | |
104 { | |
36
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
105 SetOkayButtonState(); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
106 } |
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 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
|
109 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
110 GameSystem system = ComboBoxUtils.GetSelectedItem<GameSystem>(systemCombo); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
111 SetRaces(system); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
112 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
|
113 SetOkayButtonState(); |
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 |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
116 private void SetRaces(GameSystem system) |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
117 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
118 ListStore store = new ListStore(typeof(Race)); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
119 |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
120 if (system != null) |
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 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
|
123 { |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
124 store.AppendValues(race); |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
125 } |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
126 } |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
127 |
d68992a831df
Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
128 lstRaces.Model = store; |
0 | 129 } |
130 | |
131 public Race SelectedRace | |
132 { | |
133 get { return race; } | |
134 } | |
135 | |
136 public string ArmyName | |
137 { | |
138 get { return armyName; } | |
139 } | |
140 | |
141 public int ArmySize | |
142 { | |
143 get { return pointsValue; } | |
144 } | |
145 } | |
146 } |