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