Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
annotate FrmNewUnit.cs @ 129:ac4231d6c3f0
* Add extra icon sizes for scaling
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 01 Oct 2011 20:30:45 +0100 |
parents | 76b73f15d07e |
children | f23e5b40ca9d |
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); |
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
111 lblNewUnitWarning.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 { |
110
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
115 StringBuilder sb = new StringBuilder(); |
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
116 |
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
117 foreach (string msg in failureMessages) |
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
118 { |
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
119 sb.AppendLine(msg); |
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
120 } |
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
121 |
76b73f15d07e
Re #344: Show unit requirement failures
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
122 lblNewUnitWarning.Text = sb.ToString(); |
13 | 123 } |
124 } | |
125 else | |
126 { | |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
127 bttnCreate.Sensitive = false; |
13 | 128 lblNewUnitWarning.Visible = false; |
129 } | |
0 | 130 } |
131 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
132 protected virtual void OnButtonCancelActivated(object sender, System.EventArgs e) |
0 | 133 { |
134 Respond(ResponseType.Cancel); | |
135 } | |
136 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
137 protected virtual void OnRowActivated(object o, Gtk.RowActivatedArgs args) |
0 | 138 { |
139 unitType = GetSelectedUnitType(); | |
140 Respond(ResponseType.Ok); | |
141 } | |
142 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
143 protected virtual void OnButtonOkClicked(object sender, System.EventArgs e) |
0 | 144 { |
145 unitType = GetSelectedUnitType(); | |
146 Respond(ResponseType.Ok); | |
147 } | |
148 } | |
149 } |