comparison FrmNewUnit.cs @ 113:4a33b3012100 WarFoundry_v0.1RC1

* Tag v0.1RC1 release no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Mon, 17 Jan 2011 19:43:47 +0000
parents a191d0655f55
children
comparison
equal deleted inserted replaced
39:146b7a893a01 113:4a33b3012100
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;
12 using IBBoard.Lang;
11 13
12 namespace IBBoard.WarFoundry.GTK 14 namespace IBBoard.WarFoundry.GUI.GTK
13 { 15 {
14 public partial class FrmNewUnit : Gtk.Dialog 16 public partial class FrmNewUnit : TranslatableDialog
15 { 17 {
16 private ILog logger = LogManager.GetLogger(typeof(FrmNewUnit)); 18 private ILog logger = LogManager.GetLogger(typeof(FrmNewUnit));
17
18 private UnitType unitType; 19 private UnitType unitType;
19 private Army unitArmy; 20 private Army unitArmy;
20 21 private Category cat;
21 public FrmNewUnit(Race race, Category cat, Army army) 22
23 public FrmNewUnit(Race race, Category category, Army army)
22 { 24 {
23 this.Build(); 25 this.Build();
24 unitArmy = army; 26 unitArmy = army;
27 cat = category;
25 28
26 TreeViewColumn unitTypeColumn = new TreeViewColumn (); 29 TreeViewColumn unitTypeColumn = new TreeViewColumn();
27 unitTypeColumn.Title = "Unit Type"; 30 CellRendererText unitTypeCell = new CellRendererText();
28 CellRendererText unitTypeCell = new CellRendererText ();
29 unitTypeColumn.PackStart(unitTypeCell, true); 31 unitTypeColumn.PackStart(unitTypeCell, true);
30 lstUnitTypes.AppendColumn(unitTypeColumn); 32 lstUnitTypes.AppendColumn(unitTypeColumn);
31 unitTypeColumn.SetCellDataFunc (unitTypeCell, new TreeCellDataFunc(RenderUnitTypeName)); 33 unitTypeColumn.SetCellDataFunc(unitTypeCell, new TreeCellDataFunc(RenderUnitTypeName));
32 ListStore store = new ListStore(typeof(UnitType)); 34 ListStore store = new ListStore(typeof(UnitType));
33 UnitType[] types = race.GetUnitTypes(cat); 35 UnitType[] types = race.GetUnitTypes(cat);
34 logger.DebugFormat("Listing {0} unit types in {1}", types.Length, cat.Name); 36 logger.DebugFormat("Listing {0} unit types in {1}", types.Length, cat.Name);
35 37
36 foreach (UnitType type in types) 38 foreach (UnitType type in types)
38 logger.DebugFormat("Adding unit type {0}", type.Name); 40 logger.DebugFormat("Adding unit type {0}", type.Name);
39 store.AppendValues(type); 41 store.AppendValues(type);
40 } 42 }
41 43
42 lstUnitTypes.Model = store; 44 lstUnitTypes.Model = store;
43 lstUnitTypes.Selection.Changed+= new EventHandler(OnSelectionChanged); 45 lstUnitTypes.Selection.Changed += new EventHandler(OnSelectionChanged);
46
47 Translation.TranslationChanged += Retranslate;
48 Translate();
44 } 49 }
45 50
51 private void Retranslate()
52 {
53 Translate();
54 }
55
56 public override void Dispose()
57 {
58 Translation.TranslationChanged -= Retranslate;
59 base.Dispose();
60 }
61
62 protected override void Translate()
63 {
64 base.Translate();
65 lstUnitTypes.Columns[0].Title = Translation.GetTranslation("frmNewUnitNewUnitColumn", "unit type");
66 Title = Translation.GetTranslation(Name, "Create new unit", cat.Name);
67 }
68
46 private void RenderUnitTypeName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) 69 private void RenderUnitTypeName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
47 { 70 {
48 UnitType type = (UnitType)model.GetValue(iter, 0); 71 UnitType type = (UnitType)model.GetValue(iter, 0);
49 (cell as CellRendererText).Text = type.Name; 72 (cell as CellRendererText).Text = type.Name;
50 } 73 }
51 74
52 protected virtual void OnSelectionChanged(object o, EventArgs e) 75 protected virtual void OnSelectionChanged(object o, EventArgs e)
53 { 76 {
54 SetSelectUnitEnabledVal(); 77 SetSelectUnitEnabledVal();
55 } 78 }
56 79
57 public UnitType SelectedUnit 80 public UnitType SelectedUnit
58 { 81 {
59 get { return unitType; } 82 get { return unitType; }
60 } 83 }
61 84
62 private UnitType GetSelectedUnitType() 85 private UnitType GetSelectedUnitType()
63 { 86 {
64 TreeModel model; 87 TreeModel model;
65 TreeIter iter; 88 TreeIter iter;
66 lstUnitTypes.Selection.GetSelected (out model, out iter); 89 lstUnitTypes.Selection.GetSelected(out model, out iter);
67 UnitType toReturn = null; 90 UnitType toReturn = null;
68 91
69 if (model!=null) 92 if (model != null)
70 { 93 {
71 toReturn = (UnitType) model.GetValue(iter, 0); 94 toReturn = (UnitType)model.GetValue(iter, 0);
72 } 95 }
73 96
74 return toReturn; 97 return toReturn;
75 } 98 }
76 99
77 private void SetSelectUnitEnabledVal() 100 private void SetSelectUnitEnabledVal()
78 { 101 {
79 UnitType type = GetSelectedUnitType(); 102 UnitType type = GetSelectedUnitType();
80 103
81 if (type!=null) 104 if (type != null)
82 { 105 {
83 buttonOk.Sensitive = true; 106 bttnCreate.Sensitive = true;
84 List<FailedUnitRequirement> fails = unitArmy.CanAddUnitType(type); 107 List<FailedUnitRequirement> fails = unitArmy.CanAddUnitType(type);
85 lblNewUnitWarning.Visible = (fails != null); 108 lblNewUnitWarning.Visible = (fails != null);
86 109
87 if (fails.Count > 0) 110 if (fails.Count > 0)
88 { 111 {
90 lblNewUnitWarning.Text = fails[0].Description; 113 lblNewUnitWarning.Text = fails[0].Description;
91 } 114 }
92 } 115 }
93 else 116 else
94 { 117 {
95 buttonOk.Sensitive = false; 118 bttnCreate.Sensitive = false;
96 lblNewUnitWarning.Visible = false; 119 lblNewUnitWarning.Visible = false;
97 } 120 }
98 } 121 }
99 122
100 protected virtual void OnButtonCancelActivated (object sender, System.EventArgs e) 123 protected virtual void OnButtonCancelActivated(object sender, System.EventArgs e)
101 { 124 {
102 Respond(ResponseType.Cancel); 125 Respond(ResponseType.Cancel);
103 } 126 }
104 127
105 protected virtual void OnRowActivated (object o, Gtk.RowActivatedArgs args) 128 protected virtual void OnRowActivated(object o, Gtk.RowActivatedArgs args)
106 { 129 {
107 unitType = GetSelectedUnitType(); 130 unitType = GetSelectedUnitType();
108 Respond(ResponseType.Ok); 131 Respond(ResponseType.Ok);
109 } 132 }
110 133
111 protected virtual void OnButtonOkClicked (object sender, System.EventArgs e) 134 protected virtual void OnButtonOkClicked(object sender, System.EventArgs e)
112 { 135 {
113 unitType = GetSelectedUnitType(); 136 unitType = GetSelectedUnitType();
114 Respond(ResponseType.Ok); 137 Respond(ResponseType.Ok);
115 } 138 }
116 } 139 }