comparison FrmNewArmy.cs @ 0:1bb28f84d567

Initial commit of WarFoundry code
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 15:57:51 +0000
parents
children 65279b85446f
comparison
equal deleted inserted replaced
-1:000000000000 0:1bb28f84d567
1 // FrmNewArmy.cs
2 //
3 // Copyright (C) 2007 IBBoard
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License version 2.1 of the License as published by the Free
8 // Software Foundation.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 //
19 //
20
21 using System;
22 using Gtk;
23 using IBBoard.Lang;
24 using IBBoard.WarFoundry.API;
25 using IBBoard.WarFoundry.API.Objects;
26 using log4net;
27
28 namespace IBBoard.WarFoundry
29 {
30 public partial class FrmNewArmy : Dialog, ITranslatable
31 {
32 private ILog logger = LogManager.GetLogger(typeof(FrmNewArmy));
33 private GameSystem system;
34 private Race race;
35 private string armyName;
36 private int pointsValue;
37
38 public FrmNewArmy(GameSystem gameSystem)
39 {
40 this.Build();
41
42 system = gameSystem;
43 lstRaces.Selection.Changed+= new EventHandler(OnSelectionChanged);
44 TreeViewColumn raceColumn = new TreeViewColumn ();
45 raceColumn.Title = "Race";
46 CellRendererText raceCell = new CellRendererText ();
47 raceColumn.PackStart (raceCell, true);
48 lstRaces.AppendColumn(raceColumn);
49 raceColumn.SetCellDataFunc(raceCell, new TreeCellDataFunc(RenderRaceName));
50 ListStore store = new ListStore(typeof(Race));
51
52 foreach (Race r in WarFoundryLoader.GetDefault().GetRaces(system))
53 {
54 store.AppendValues(r);
55 }
56
57 lstRaces.Model = store;
58 }
59
60 public string Text
61 {
62 get { return Title; }
63 set { Title = value; }
64 }
65
66 private void RenderRaceName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
67 {
68 Race r = (Race)model.GetValue(iter, 0);
69 (cell as CellRendererText).Text = r.Name;
70 }
71
72 protected virtual void OnSelectionChanged(object o, EventArgs e)
73 {
74 logger.Debug("Selection changed");
75 setOkayButtonState();
76 }
77
78 private void setOkayButtonState()
79 {
80 bttnCreate.Sensitive = (lstRaces.Selection.CountSelectedRows() > 0 && txtArmyName.Text!="" && sbPointsValue.Value > 0);
81 }
82
83 protected virtual void OnCreateClicked (object sender, System.EventArgs e)
84 {
85 TreeModel model;
86 TreeIter iter;
87 lstRaces.Selection.GetSelected (out model, out iter);
88 race = (Race) model.GetValue(iter, 0);
89 armyName = txtArmyName.Text;
90 pointsValue = (int)sbPointsValue.Value;
91 Respond(ResponseType.Ok);
92 }
93
94 protected virtual void OnCancelClicked (object sender, System.EventArgs e)
95 {
96 Respond(ResponseType.Cancel);
97 }
98
99 protected virtual void OnTextChanged (object sender, System.EventArgs e)
100 {
101 setOkayButtonState();
102 }
103
104 protected virtual void OnSpinChangeValue (object o, Gtk.ChangeValueArgs args)
105 {
106 setOkayButtonState();
107 }
108
109 protected virtual void OnSpinValueChanged (object sender, System.EventArgs e)
110 {
111 setOkayButtonState();
112 }
113
114 public Race SelectedRace
115 {
116 get { return race; }
117 }
118
119 public string ArmyName
120 {
121 get { return armyName; }
122 }
123
124 public int ArmySize
125 {
126 get { return pointsValue; }
127 }
128 }
129 }