view FrmNewArmy.cs @ 60:04c0f6a7625c

Re #60: Add UI to add/remove/edit weapons in GTK * Implement Remove button * Hack "code-behind" file again to make things work, until MD bug is fixed
author IBBoard <dev@ibboard.co.uk>
date Fri, 27 Aug 2010 14:44:48 +0000
parents d68992a831df
children 2ceae5d685d8
line source
1 // This file (FrmNewArmy.cs) is a part of the IBBoard.WarFoundry.GTK project and is copyright 2008, 2009 IBBoard.
2 //
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.
5 using System;
6 using Gtk;
7 using IBBoard.Lang;
8 using IBBoard.WarFoundry.API;
9 using IBBoard.WarFoundry.API.Objects;
10 using IBBoard.GtkSharp;
11 using log4net;
12 using IBBoard.WarFoundry.GUI.GTK.Util;
14 namespace IBBoard.WarFoundry.GTK
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;
23 public FrmNewArmy(GameSystem gameSystem)
24 {
25 this.Build();
27 GameSystem[] gameSystems = WarFoundryLoader.GetDefault().GetGameSystems();
28 ComboBoxUtils.FillCombo(systemCombo, gameSystems, delegate(GameSystem sys){return sys.Name;});
30 if (gameSystem != null)
31 {
32 ComboBoxUtils.SelectItem(systemCombo, gameSystem);
33 }
34 else if (gameSystems.Length == 1)
35 {
36 ComboBoxUtils.SelectIndex(systemCombo, 0);
37 }
39 lstRaces.Selection.Changed+= new EventHandler(OnSelectionChanged);
41 TreeViewColumn raceColumn = new TreeViewColumn ();
42 raceColumn.Title = "Race";
43 CellRendererText raceCell = new CellRendererText ();
44 raceColumn.PackStart (raceCell, true);
45 lstRaces.AppendColumn(raceColumn);
46 raceColumn.SetCellDataFunc(raceCell, GtkWarFoundryUtil.RenderWarFoundryObjectName);
49 if (gameSystem!=null)
50 {
51 SetRaces(gameSystem);
52 }
53 }
55 public string Text
56 {
57 get { return Title; }
58 set { Title = value; }
59 }
61 protected virtual void OnSelectionChanged(object o, EventArgs e)
62 {
63 logger.Debug("Race selection changed");
64 SetOkayButtonState();
65 }
67 private void SetOkayButtonState()
68 {
69 bttnCreate.Sensitive = (lstRaces.Selection.CountSelectedRows() == 1 && txtArmyName.Text!="" && sbPointsValue.Value > 0);
70 }
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 }
83 protected virtual void OnCancelClicked (object sender, System.EventArgs e)
84 {
85 Respond(ResponseType.Cancel);
86 }
88 protected virtual void OnTextChanged (object sender, System.EventArgs e)
89 {
90 SetOkayButtonState();
91 }
93 protected virtual void OnSpinChangeValue (object o, Gtk.ChangeValueArgs args)
94 {
95 SetOkayButtonState();
96 }
98 protected virtual void OnSpinValueChanged (object sender, System.EventArgs e)
99 {
100 SetOkayButtonState();
101 }
103 protected virtual void OnSystemComboChanged (object sender, System.EventArgs e)
104 {
105 GameSystem system = ComboBoxUtils.GetSelectedItem<GameSystem>(systemCombo);
106 SetRaces(system);
107 logger.Debug("System selection changed: " + (system == null ? "null" : system.Name));
108 SetOkayButtonState();
109 }
111 private void SetRaces(GameSystem system)
112 {
113 ListStore store = new ListStore(typeof(Race));
115 if (system != null)
116 {
117 foreach (Race race in WarFoundryLoader.GetDefault().GetRaces(system))
118 {
119 store.AppendValues(race);
120 }
121 }
123 lstRaces.Model = store;
124 }
126 public Race SelectedRace
127 {
128 get { return race; }
129 }
131 public string ArmyName
132 {
133 get { return armyName; }
134 }
136 public int ArmySize
137 {
138 get { return pointsValue; }
139 }
140 }
141 }