annotate FrmNewArmy.cs @ 48:23238d998535

Re #86: Complete initial GTK# UI * Add "notes" section to unit tab
author IBBoard <dev@ibboard.co.uk>
date Sun, 15 Aug 2010 14:34:06 +0000
parents d68992a831df
children 4bad8cb3f889 4a33b3012100
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
a191d0655f55 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
1 // This file (FrmNewArmy.cs) is a part of the IBBoard.WarFoundry.GTK project and is copyright 2008, 2009 IBBoard.
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
19
a191d0655f55 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
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
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using Gtk;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using IBBoard.Lang;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using IBBoard.WarFoundry.API;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 using log4net;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
13 namespace IBBoard.WarFoundry.GTK
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 public partial class FrmNewArmy : Dialog, ITranslatable
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 private ILog logger = LogManager.GetLogger(typeof(FrmNewArmy));
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 private Race race;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 private string armyName;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 private int pointsValue;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 public FrmNewArmy(GameSystem gameSystem)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 this.Build();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 TreeViewColumn raceColumn = new TreeViewColumn ();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 raceColumn.Title = "Race";
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 CellRendererText raceCell = new CellRendererText ();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 raceColumn.PackStart (raceCell, true);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 lstRaces.AppendColumn(raceColumn);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 {
36
d68992a831df Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
50 SetRaces(gameSystem);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 public string Text
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 get { return Title; }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 set { Title = value; }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 private void RenderRaceName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 Race r = (Race)model.GetValue(iter, 0);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 (cell as CellRendererText).Text = r.Name;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 protected virtual void OnSelectionChanged(object o, EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 protected virtual void OnCreateClicked (object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 TreeModel model;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 TreeIter iter;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 lstRaces.Selection.GetSelected (out model, out iter);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 race = (Race) model.GetValue(iter, 0);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 armyName = txtArmyName.Text;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 pointsValue = (int)sbPointsValue.Value;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 Respond(ResponseType.Ok);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 protected virtual void OnCancelClicked (object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 Respond(ResponseType.Cancel);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 protected virtual void OnTextChanged (object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 {
36
d68992a831df Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
95 SetOkayButtonState();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 protected virtual void OnSpinChangeValue (object o, Gtk.ChangeValueArgs args)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 {
36
d68992a831df Fixes #182: Make GTK# more like WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
100 SetOkayButtonState();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 protected virtual void OnSpinValueChanged (object sender, System.EventArgs e)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
130
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131 public Race SelectedRace
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
133 get { return race; }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
134 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
135
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
136 public string ArmyName
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
138 get { return armyName; }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
139 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
140
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
141 public int ArmySize
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
142 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
143 get { return pointsValue; }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
144 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
145 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
146 }