Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
annotate FrmNewUnit.cs @ 89:31d54f67d50d
Re #308: Make GTK# UI translatable
* Start to make use of TranslatableButtons now that we've finally got them working and usable
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 30 Dec 2010 21:00:00 +0000 |
parents | b0089e875754 |
children | b4416ca69153 |
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; | |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
12 using IBBoard.Lang; |
0 | 13 |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
14 namespace IBBoard.WarFoundry.GUI.GTK |
0 | 15 { |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
16 public partial class FrmNewUnit : TranslatableDialog |
13 | 17 { |
0 | 18 private ILog logger = LogManager.GetLogger(typeof(FrmNewUnit)); |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
19 private UnitType unitType; |
0 | 20 private Army unitArmy; |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
21 private Category cat; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
22 |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
23 public FrmNewUnit(Race race, Category category, Army army) |
0 | 24 { |
25 this.Build(); | |
26 unitArmy = army; | |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
27 cat = category; |
0 | 28 |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
29 TreeViewColumn unitTypeColumn = new TreeViewColumn(); |
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
30 CellRendererText unitTypeCell = new CellRendererText(); |
0 | 31 unitTypeColumn.PackStart(unitTypeCell, true); |
32 lstUnitTypes.AppendColumn(unitTypeColumn); | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
33 unitTypeColumn.SetCellDataFunc(unitTypeCell, new TreeCellDataFunc(RenderUnitTypeName)); |
0 | 34 ListStore store = new ListStore(typeof(UnitType)); |
35 UnitType[] types = race.GetUnitTypes(cat); | |
36 logger.DebugFormat("Listing {0} unit types in {1}", types.Length, cat.Name); | |
37 | |
38 foreach (UnitType type in types) | |
39 { | |
40 logger.DebugFormat("Adding unit type {0}", type.Name); | |
41 store.AppendValues(type); | |
42 } | |
43 | |
44 lstUnitTypes.Model = store; | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
45 lstUnitTypes.Selection.Changed += new EventHandler(OnSelectionChanged); |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
46 Translate(); |
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
47 } |
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
48 |
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
49 protected override void Translate() |
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
50 { |
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
51 base.Translate(); |
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
52 lstUnitTypes.Columns[0].Title = Translation.GetTranslation("frmNewUnitNewUnitColumn", "unit type"); |
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
53 Title = Translation.GetTranslation(Name, "Create new unit", cat.Name); |
0 | 54 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
55 |
0 | 56 private void RenderUnitTypeName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
57 { | |
58 UnitType type = (UnitType)model.GetValue(iter, 0); | |
59 (cell as CellRendererText).Text = type.Name; | |
60 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
61 |
0 | 62 protected virtual void OnSelectionChanged(object o, EventArgs e) |
63 { | |
64 SetSelectUnitEnabledVal(); | |
65 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
66 |
13 | 67 public UnitType SelectedUnit |
0 | 68 { |
69 get { return unitType; } | |
70 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
71 |
0 | 72 private UnitType GetSelectedUnitType() |
73 { | |
74 TreeModel model; | |
75 TreeIter iter; | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
76 lstUnitTypes.Selection.GetSelected(out model, out iter); |
0 | 77 UnitType toReturn = null; |
78 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
79 if (model != null) |
0 | 80 { |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
81 toReturn = (UnitType)model.GetValue(iter, 0); |
0 | 82 } |
83 | |
84 return toReturn; | |
85 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
86 |
13 | 87 private void SetSelectUnitEnabledVal() |
0 | 88 { |
89 UnitType type = GetSelectedUnitType(); | |
13 | 90 |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
91 if (type != null) |
13 | 92 { |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
93 bttnCreate.Sensitive = true; |
13 | 94 List<FailedUnitRequirement> fails = unitArmy.CanAddUnitType(type); |
95 lblNewUnitWarning.Visible = (fails != null); | |
96 | |
97 if (fails.Count > 0) | |
0 | 98 { |
13 | 99 //FIXME: currently only show the first error |
100 lblNewUnitWarning.Text = fails[0].Description; | |
101 } | |
102 } | |
103 else | |
104 { | |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
105 bttnCreate.Sensitive = false; |
13 | 106 lblNewUnitWarning.Visible = false; |
107 } | |
0 | 108 } |
109 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
110 protected virtual void OnButtonCancelActivated(object sender, System.EventArgs e) |
0 | 111 { |
112 Respond(ResponseType.Cancel); | |
113 } | |
114 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
115 protected virtual void OnRowActivated(object o, Gtk.RowActivatedArgs args) |
0 | 116 { |
117 unitType = GetSelectedUnitType(); | |
118 Respond(ResponseType.Ok); | |
119 } | |
120 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
121 protected virtual void OnButtonOkClicked(object sender, System.EventArgs e) |
0 | 122 { |
123 unitType = GetSelectedUnitType(); | |
124 Respond(ResponseType.Ok); | |
125 } | |
126 } | |
127 } |