Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate FrmNewUnit.cs @ 78:e63209ab2cfa
Re #86: Complete initial GTK# UI
* Make sure that undo/redo are not sensitive on first opening app
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 18 Dec 2010 16:46:16 +0000 |
parents | 68804784bf6f |
children | b0089e875754 |
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; | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
7 using Gtk; |
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
8 using IBBoard.GtkSharp.Translatable; |
0 | 9 using IBBoard.WarFoundry.API.Objects; |
10 using IBBoard.WarFoundry.API.Requirements; | |
11 using log4net; | |
12 | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
13 namespace IBBoard.WarFoundry.GUI.GTK |
0 | 14 { |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
15 public partial class FrmNewUnit : TranslatableDialog |
13 | 16 { |
0 | 17 private ILog logger = LogManager.GetLogger(typeof(FrmNewUnit)); |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
18 private UnitType unitType; |
0 | 19 private Army unitArmy; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
20 |
0 | 21 public FrmNewUnit(Race race, Category cat, Army army) |
22 { | |
23 this.Build(); | |
24 unitArmy = army; | |
25 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
26 TreeViewColumn unitTypeColumn = new TreeViewColumn(); |
0 | 27 unitTypeColumn.Title = "Unit Type"; |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
28 CellRendererText unitTypeCell = new CellRendererText(); |
0 | 29 unitTypeColumn.PackStart(unitTypeCell, true); |
30 lstUnitTypes.AppendColumn(unitTypeColumn); | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
31 unitTypeColumn.SetCellDataFunc(unitTypeCell, new TreeCellDataFunc(RenderUnitTypeName)); |
0 | 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; | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
43 lstUnitTypes.Selection.Changed += new EventHandler(OnSelectionChanged); |
0 | 44 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
45 |
0 | 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 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
51 |
0 | 52 protected virtual void OnSelectionChanged(object o, EventArgs e) |
53 { | |
54 SetSelectUnitEnabledVal(); | |
55 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
56 |
13 | 57 public UnitType SelectedUnit |
0 | 58 { |
59 get { return unitType; } | |
60 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
61 |
0 | 62 private UnitType GetSelectedUnitType() |
63 { | |
64 TreeModel model; | |
65 TreeIter iter; | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
66 lstUnitTypes.Selection.GetSelected(out model, out iter); |
0 | 67 UnitType toReturn = null; |
68 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
69 if (model != null) |
0 | 70 { |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
71 toReturn = (UnitType)model.GetValue(iter, 0); |
0 | 72 } |
73 | |
74 return toReturn; | |
75 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
76 |
13 | 77 private void SetSelectUnitEnabledVal() |
0 | 78 { |
79 UnitType type = GetSelectedUnitType(); | |
13 | 80 |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
81 if (type != null) |
13 | 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 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
100 protected virtual void OnButtonCancelActivated(object sender, System.EventArgs e) |
0 | 101 { |
102 Respond(ResponseType.Cancel); | |
103 } | |
104 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
105 protected virtual void OnRowActivated(object o, Gtk.RowActivatedArgs args) |
0 | 106 { |
107 unitType = GetSelectedUnitType(); | |
108 Respond(ResponseType.Ok); | |
109 } | |
110 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
111 protected virtual void OnButtonOkClicked(object sender, System.EventArgs e) |
0 | 112 { |
113 unitType = GetSelectedUnitType(); | |
114 Respond(ResponseType.Ok); | |
115 } | |
116 } | |
117 } |