5
|
1 // This file (FrmNewArmy.cs) is a part of the IBBoard.WarFoundry.GTK project and is copyright 2009 IBBoard.
|
0
|
2 //
|
5
|
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL 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;
|
|
10 using log4net;
|
|
11
|
5
|
12 namespace IBBoard.WarFoundry.GTK
|
0
|
13 {
|
|
14 public partial class FrmNewArmy : Dialog, ITranslatable
|
|
15 {
|
|
16 private ILog logger = LogManager.GetLogger(typeof(FrmNewArmy));
|
|
17 private GameSystem system;
|
|
18 private Race race;
|
|
19 private string armyName;
|
|
20 private int pointsValue;
|
|
21
|
|
22 public FrmNewArmy(GameSystem gameSystem)
|
|
23 {
|
|
24 this.Build();
|
|
25
|
|
26 system = gameSystem;
|
|
27 lstRaces.Selection.Changed+= new EventHandler(OnSelectionChanged);
|
|
28 TreeViewColumn raceColumn = new TreeViewColumn ();
|
|
29 raceColumn.Title = "Race";
|
|
30 CellRendererText raceCell = new CellRendererText ();
|
|
31 raceColumn.PackStart (raceCell, true);
|
|
32 lstRaces.AppendColumn(raceColumn);
|
|
33 raceColumn.SetCellDataFunc(raceCell, new TreeCellDataFunc(RenderRaceName));
|
|
34 ListStore store = new ListStore(typeof(Race));
|
|
35
|
|
36 foreach (Race r in WarFoundryLoader.GetDefault().GetRaces(system))
|
|
37 {
|
|
38 store.AppendValues(r);
|
|
39 }
|
|
40
|
|
41 lstRaces.Model = store;
|
|
42 }
|
|
43
|
|
44 public string Text
|
|
45 {
|
|
46 get { return Title; }
|
|
47 set { Title = value; }
|
|
48 }
|
|
49
|
|
50 private void RenderRaceName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
|
|
51 {
|
|
52 Race r = (Race)model.GetValue(iter, 0);
|
|
53 (cell as CellRendererText).Text = r.Name;
|
|
54 }
|
|
55
|
|
56 protected virtual void OnSelectionChanged(object o, EventArgs e)
|
|
57 {
|
|
58 logger.Debug("Selection changed");
|
|
59 setOkayButtonState();
|
|
60 }
|
|
61
|
|
62 private void setOkayButtonState()
|
|
63 {
|
|
64 bttnCreate.Sensitive = (lstRaces.Selection.CountSelectedRows() > 0 && txtArmyName.Text!="" && sbPointsValue.Value > 0);
|
|
65 }
|
|
66
|
|
67 protected virtual void OnCreateClicked (object sender, System.EventArgs e)
|
|
68 {
|
|
69 TreeModel model;
|
|
70 TreeIter iter;
|
|
71 lstRaces.Selection.GetSelected (out model, out iter);
|
|
72 race = (Race) model.GetValue(iter, 0);
|
|
73 armyName = txtArmyName.Text;
|
|
74 pointsValue = (int)sbPointsValue.Value;
|
|
75 Respond(ResponseType.Ok);
|
|
76 }
|
|
77
|
|
78 protected virtual void OnCancelClicked (object sender, System.EventArgs e)
|
|
79 {
|
|
80 Respond(ResponseType.Cancel);
|
|
81 }
|
|
82
|
|
83 protected virtual void OnTextChanged (object sender, System.EventArgs e)
|
|
84 {
|
|
85 setOkayButtonState();
|
|
86 }
|
|
87
|
|
88 protected virtual void OnSpinChangeValue (object o, Gtk.ChangeValueArgs args)
|
|
89 {
|
|
90 setOkayButtonState();
|
|
91 }
|
|
92
|
|
93 protected virtual void OnSpinValueChanged (object sender, System.EventArgs e)
|
|
94 {
|
|
95 setOkayButtonState();
|
|
96 }
|
|
97
|
|
98 public Race SelectedRace
|
|
99 {
|
|
100 get { return race; }
|
|
101 }
|
|
102
|
|
103 public string ArmyName
|
|
104 {
|
|
105 get { return armyName; }
|
|
106 }
|
|
107
|
|
108 public int ArmySize
|
|
109 {
|
|
110 get { return pointsValue; }
|
|
111 }
|
|
112 }
|
|
113 }
|