Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate FrmNewUnit.cs @ 24:105c68bb759c
Re #86: Complete initial GTK# UI
* Enable "open" buttons now that saving is starting to work
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 22 Aug 2009 19:10:45 +0000 |
parents | a191d0655f55 |
children | 7055b24cfc79 4a33b3012100 |
rev | line source |
---|---|
19
a191d0655f55
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
1 // This file (FrmNewUnit.cs) is a part of the IBBoard.WarFoundry.GTK project and is copyright 2008, 2009 IBBoard. |
0 | 2 // |
19
a191d0655f55
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
13
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 | 4 |
5 using System; | |
6 using System.Collections.Generic; | |
7 using IBBoard.WarFoundry.API.Objects; | |
8 using IBBoard.WarFoundry.API.Requirements; | |
9 using Gtk; | |
10 using log4net; | |
11 | |
5 | 12 namespace IBBoard.WarFoundry.GTK |
0 | 13 { |
14 public partial class FrmNewUnit : Gtk.Dialog | |
13 | 15 { |
0 | 16 private ILog logger = LogManager.GetLogger(typeof(FrmNewUnit)); |
17 | |
18 private UnitType unitType; | |
19 private Army unitArmy; | |
20 | |
21 public FrmNewUnit(Race race, Category cat, Army army) | |
22 { | |
23 this.Build(); | |
24 unitArmy = army; | |
25 | |
26 TreeViewColumn unitTypeColumn = new TreeViewColumn (); | |
27 unitTypeColumn.Title = "Unit Type"; | |
28 CellRendererText unitTypeCell = new CellRendererText (); | |
29 unitTypeColumn.PackStart(unitTypeCell, true); | |
30 lstUnitTypes.AppendColumn(unitTypeColumn); | |
31 unitTypeColumn.SetCellDataFunc (unitTypeCell, new TreeCellDataFunc(RenderUnitTypeName)); | |
32 ListStore store = new ListStore(typeof(UnitType)); | |
33 UnitType[] types = race.GetUnitTypes(cat); | |
34 logger.DebugFormat("Listing {0} unit types in {1}", types.Length, cat.Name); | |
35 | |
36 foreach (UnitType type in types) | |
37 { | |
38 logger.DebugFormat("Adding unit type {0}", type.Name); | |
39 store.AppendValues(type); | |
40 } | |
41 | |
42 lstUnitTypes.Model = store; | |
43 lstUnitTypes.Selection.Changed+= new EventHandler(OnSelectionChanged); | |
44 } | |
45 | |
46 private void RenderUnitTypeName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | |
47 { | |
48 UnitType type = (UnitType)model.GetValue(iter, 0); | |
49 (cell as CellRendererText).Text = type.Name; | |
50 } | |
51 | |
52 protected virtual void OnSelectionChanged(object o, EventArgs e) | |
53 { | |
54 SetSelectUnitEnabledVal(); | |
55 } | |
56 | |
13 | 57 public UnitType SelectedUnit |
0 | 58 { |
59 get { return unitType; } | |
60 } | |
61 | |
62 private UnitType GetSelectedUnitType() | |
63 { | |
64 TreeModel model; | |
65 TreeIter iter; | |
66 lstUnitTypes.Selection.GetSelected (out model, out iter); | |
67 UnitType toReturn = null; | |
68 | |
69 if (model!=null) | |
70 { | |
71 toReturn = (UnitType) model.GetValue(iter, 0); | |
72 } | |
73 | |
74 return toReturn; | |
75 } | |
76 | |
13 | 77 private void SetSelectUnitEnabledVal() |
0 | 78 { |
79 UnitType type = GetSelectedUnitType(); | |
13 | 80 |
81 if (type!=null) | |
82 { | |
0 | 83 buttonOk.Sensitive = true; |
13 | 84 List<FailedUnitRequirement> fails = unitArmy.CanAddUnitType(type); |
85 lblNewUnitWarning.Visible = (fails != null); | |
86 | |
87 if (fails.Count > 0) | |
0 | 88 { |
13 | 89 //FIXME: currently only show the first error |
90 lblNewUnitWarning.Text = fails[0].Description; | |
91 } | |
92 } | |
93 else | |
94 { | |
0 | 95 buttonOk.Sensitive = false; |
13 | 96 lblNewUnitWarning.Visible = false; |
97 } | |
0 | 98 } |
99 | |
100 protected virtual void OnButtonCancelActivated (object sender, System.EventArgs e) | |
101 { | |
102 Respond(ResponseType.Cancel); | |
103 } | |
104 | |
105 protected virtual void OnRowActivated (object o, Gtk.RowActivatedArgs args) | |
106 { | |
107 unitType = GetSelectedUnitType(); | |
108 Respond(ResponseType.Ok); | |
109 } | |
110 | |
111 protected virtual void OnButtonOkClicked (object sender, System.EventArgs e) | |
112 { | |
113 unitType = GetSelectedUnitType(); | |
114 Respond(ResponseType.Ok); | |
115 } | |
116 } | |
117 } |