Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
annotate FrmNewUnit.cs @ 147:18c7b0b4bc30
* Try to fix Unicode build issues on Jenkins server by changing "invisible character" (which is only used on passwords anyway)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 26 Nov 2011 11:56:35 +0000 |
parents | f23e5b40ca9d |
children | 354c1d2ad086 |
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 log4net; | |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
11 using IBBoard.Lang; |
110
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
12 using IBBoard.WarFoundry.API.Objects.Requirement; |
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
13 using System.Text; |
0 | 14 |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
15 namespace IBBoard.WarFoundry.GUI.GTK |
0 | 16 { |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
17 public partial class FrmNewUnit : TranslatableDialog |
13 | 18 { |
0 | 19 private ILog logger = LogManager.GetLogger(typeof(FrmNewUnit)); |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
20 private UnitType unitType; |
0 | 21 private Army unitArmy; |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
22 private Category cat; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
23 |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
24 public FrmNewUnit(Race race, Category category, Army army) |
0 | 25 { |
26 this.Build(); | |
27 unitArmy = army; | |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
28 cat = category; |
0 | 29 |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
30 TreeViewColumn unitTypeColumn = new TreeViewColumn(); |
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
31 CellRendererText unitTypeCell = new CellRendererText(); |
0 | 32 unitTypeColumn.PackStart(unitTypeCell, true); |
33 lstUnitTypes.AppendColumn(unitTypeColumn); | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
34 unitTypeColumn.SetCellDataFunc(unitTypeCell, new TreeCellDataFunc(RenderUnitTypeName)); |
0 | 35 ListStore store = new ListStore(typeof(UnitType)); |
36 UnitType[] types = race.GetUnitTypes(cat); | |
37 logger.DebugFormat("Listing {0} unit types in {1}", types.Length, cat.Name); | |
38 | |
39 foreach (UnitType type in types) | |
40 { | |
41 logger.DebugFormat("Adding unit type {0}", type.Name); | |
42 store.AppendValues(type); | |
43 } | |
44 | |
45 lstUnitTypes.Model = store; | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
46 lstUnitTypes.Selection.Changed += new EventHandler(OnSelectionChanged); |
96
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
47 |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
48 Translation.TranslationChanged += Retranslate; |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
49 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 |
96
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
52 private void Retranslate() |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
53 { |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
54 Translate(); |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
55 } |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
56 |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
57 public override void Dispose() |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
58 { |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
59 Translation.TranslationChanged -= Retranslate; |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
60 base.Dispose(); |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
61 } |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
62 |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
63 protected override void Translate() |
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
64 { |
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
65 base.Translate(); |
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
66 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
|
67 Title = Translation.GetTranslation(Name, "Create new unit", cat.Name); |
0 | 68 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
69 |
0 | 70 private void RenderUnitTypeName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
71 { | |
72 UnitType type = (UnitType)model.GetValue(iter, 0); | |
73 (cell as CellRendererText).Text = type.Name; | |
74 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
75 |
0 | 76 protected virtual void OnSelectionChanged(object o, EventArgs e) |
77 { | |
78 SetSelectUnitEnabledVal(); | |
79 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
80 |
13 | 81 public UnitType SelectedUnit |
0 | 82 { |
83 get { return unitType; } | |
84 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
85 |
0 | 86 private UnitType GetSelectedUnitType() |
87 { | |
88 TreeModel model; | |
89 TreeIter iter; | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
90 lstUnitTypes.Selection.GetSelected(out model, out iter); |
0 | 91 UnitType toReturn = null; |
92 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
93 if (model != null) |
0 | 94 { |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
95 toReturn = (UnitType)model.GetValue(iter, 0); |
0 | 96 } |
97 | |
98 return toReturn; | |
99 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
100 |
13 | 101 private void SetSelectUnitEnabledVal() |
0 | 102 { |
103 UnitType type = GetSelectedUnitType(); | |
13 | 104 |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
105 if (type != null) |
13 | 106 { |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
107 bttnCreate.Sensitive = true; |
110
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
108 ICollection<string> failureMessages; |
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
109 Validation result = RequirementHandler.AllowsAdding(type, unitArmy, out failureMessages); |
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
110 bool validationFailed = !Validates.AsOkay(result); |
142
f23e5b40ca9d
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
110
diff
changeset
|
111 validationWidget.Visible = validationFailed; |
13 | 112 |
110
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
113 if (validationFailed) |
0 | 114 { |
142
f23e5b40ca9d
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
110
diff
changeset
|
115 validationWidget.SetMessages(failureMessages); |
13 | 116 } |
117 } | |
118 else | |
119 { | |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
120 bttnCreate.Sensitive = false; |
142
f23e5b40ca9d
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
110
diff
changeset
|
121 validationWidget.Visible = false; |
13 | 122 } |
0 | 123 } |
124 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
125 protected virtual void OnButtonCancelActivated(object sender, System.EventArgs e) |
0 | 126 { |
127 Respond(ResponseType.Cancel); | |
128 } | |
129 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
130 protected virtual void OnRowActivated(object o, Gtk.RowActivatedArgs args) |
0 | 131 { |
132 unitType = GetSelectedUnitType(); | |
133 Respond(ResponseType.Ok); | |
134 } | |
135 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
136 protected virtual void OnButtonOkClicked(object sender, System.EventArgs e) |
0 | 137 { |
138 unitType = GetSelectedUnitType(); | |
139 Respond(ResponseType.Ok); | |
140 } | |
141 } | |
142 } |