Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
comparison FrmNewUnit.cs @ 76:7055b24cfc79
Re #308: Make GTK# UI translatable
* Extend new TranslatableDialog
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 23 Nov 2010 21:03:46 +0000 |
parents | a191d0655f55 |
children | 68804784bf6f |
comparison
equal
deleted
inserted
replaced
75:2ceae5d685d8 | 76:7055b24cfc79 |
---|---|
2 // | 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. | 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. |
4 | 4 |
5 using System; | 5 using System; |
6 using System.Collections.Generic; | 6 using System.Collections.Generic; |
7 using Gtk; | |
8 using IBBoard.GtkSharp.Translatable; | |
7 using IBBoard.WarFoundry.API.Objects; | 9 using IBBoard.WarFoundry.API.Objects; |
8 using IBBoard.WarFoundry.API.Requirements; | 10 using IBBoard.WarFoundry.API.Requirements; |
9 using Gtk; | |
10 using log4net; | 11 using log4net; |
11 | 12 |
12 namespace IBBoard.WarFoundry.GTK | 13 namespace IBBoard.WarFoundry.GTK |
13 { | 14 { |
14 public partial class FrmNewUnit : Gtk.Dialog | 15 public partial class FrmNewUnit : TranslatableDialog |
15 { | 16 { |
16 private ILog logger = LogManager.GetLogger(typeof(FrmNewUnit)); | 17 private ILog logger = LogManager.GetLogger(typeof(FrmNewUnit)); |
17 | 18 private UnitType unitType; |
18 private UnitType unitType; | |
19 private Army unitArmy; | 19 private Army unitArmy; |
20 | 20 |
21 public FrmNewUnit(Race race, Category cat, Army army) | 21 public FrmNewUnit(Race race, Category cat, Army army) |
22 { | 22 { |
23 this.Build(); | 23 this.Build(); |
24 unitArmy = army; | 24 unitArmy = army; |
25 | 25 |
26 TreeViewColumn unitTypeColumn = new TreeViewColumn (); | 26 TreeViewColumn unitTypeColumn = new TreeViewColumn(); |
27 unitTypeColumn.Title = "Unit Type"; | 27 unitTypeColumn.Title = "Unit Type"; |
28 CellRendererText unitTypeCell = new CellRendererText (); | 28 CellRendererText unitTypeCell = new CellRendererText(); |
29 unitTypeColumn.PackStart(unitTypeCell, true); | 29 unitTypeColumn.PackStart(unitTypeCell, true); |
30 lstUnitTypes.AppendColumn(unitTypeColumn); | 30 lstUnitTypes.AppendColumn(unitTypeColumn); |
31 unitTypeColumn.SetCellDataFunc (unitTypeCell, new TreeCellDataFunc(RenderUnitTypeName)); | 31 unitTypeColumn.SetCellDataFunc(unitTypeCell, new TreeCellDataFunc(RenderUnitTypeName)); |
32 ListStore store = new ListStore(typeof(UnitType)); | 32 ListStore store = new ListStore(typeof(UnitType)); |
33 UnitType[] types = race.GetUnitTypes(cat); | 33 UnitType[] types = race.GetUnitTypes(cat); |
34 logger.DebugFormat("Listing {0} unit types in {1}", types.Length, cat.Name); | 34 logger.DebugFormat("Listing {0} unit types in {1}", types.Length, cat.Name); |
35 | 35 |
36 foreach (UnitType type in types) | 36 foreach (UnitType type in types) |
38 logger.DebugFormat("Adding unit type {0}", type.Name); | 38 logger.DebugFormat("Adding unit type {0}", type.Name); |
39 store.AppendValues(type); | 39 store.AppendValues(type); |
40 } | 40 } |
41 | 41 |
42 lstUnitTypes.Model = store; | 42 lstUnitTypes.Model = store; |
43 lstUnitTypes.Selection.Changed+= new EventHandler(OnSelectionChanged); | 43 lstUnitTypes.Selection.Changed += new EventHandler(OnSelectionChanged); |
44 } | 44 } |
45 | 45 |
46 private void RenderUnitTypeName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | 46 private void RenderUnitTypeName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
47 { | 47 { |
48 UnitType type = (UnitType)model.GetValue(iter, 0); | 48 UnitType type = (UnitType)model.GetValue(iter, 0); |
61 | 61 |
62 private UnitType GetSelectedUnitType() | 62 private UnitType GetSelectedUnitType() |
63 { | 63 { |
64 TreeModel model; | 64 TreeModel model; |
65 TreeIter iter; | 65 TreeIter iter; |
66 lstUnitTypes.Selection.GetSelected (out model, out iter); | 66 lstUnitTypes.Selection.GetSelected(out model, out iter); |
67 UnitType toReturn = null; | 67 UnitType toReturn = null; |
68 | 68 |
69 if (model!=null) | 69 if (model != null) |
70 { | 70 { |
71 toReturn = (UnitType) model.GetValue(iter, 0); | 71 toReturn = (UnitType)model.GetValue(iter, 0); |
72 } | 72 } |
73 | 73 |
74 return toReturn; | 74 return toReturn; |
75 } | 75 } |
76 | 76 |
77 private void SetSelectUnitEnabledVal() | 77 private void SetSelectUnitEnabledVal() |
78 { | 78 { |
79 UnitType type = GetSelectedUnitType(); | 79 UnitType type = GetSelectedUnitType(); |
80 | 80 |
81 if (type!=null) | 81 if (type != null) |
82 { | 82 { |
83 buttonOk.Sensitive = true; | 83 buttonOk.Sensitive = true; |
84 List<FailedUnitRequirement> fails = unitArmy.CanAddUnitType(type); | 84 List<FailedUnitRequirement> fails = unitArmy.CanAddUnitType(type); |
85 lblNewUnitWarning.Visible = (fails != null); | 85 lblNewUnitWarning.Visible = (fails != null); |
86 | 86 |
95 buttonOk.Sensitive = false; | 95 buttonOk.Sensitive = false; |
96 lblNewUnitWarning.Visible = false; | 96 lblNewUnitWarning.Visible = false; |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 protected virtual void OnButtonCancelActivated (object sender, System.EventArgs e) | 100 protected virtual void OnButtonCancelActivated(object sender, System.EventArgs e) |
101 { | 101 { |
102 Respond(ResponseType.Cancel); | 102 Respond(ResponseType.Cancel); |
103 } | 103 } |
104 | 104 |
105 protected virtual void OnRowActivated (object o, Gtk.RowActivatedArgs args) | 105 protected virtual void OnRowActivated(object o, Gtk.RowActivatedArgs args) |
106 { | 106 { |
107 unitType = GetSelectedUnitType(); | 107 unitType = GetSelectedUnitType(); |
108 Respond(ResponseType.Ok); | 108 Respond(ResponseType.Ok); |
109 } | 109 } |
110 | 110 |
111 protected virtual void OnButtonOkClicked (object sender, System.EventArgs e) | 111 protected virtual void OnButtonOkClicked(object sender, System.EventArgs e) |
112 { | 112 { |
113 unitType = GetSelectedUnitType(); | 113 unitType = GetSelectedUnitType(); |
114 Respond(ResponseType.Ok); | 114 Respond(ResponseType.Ok); |
115 } | 115 } |
116 } | 116 } |