Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate FrmNewUnit.cs @ 105:0ddef7087602
* Remove in-code references to Rollcall plugin
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 28 Feb 2011 20:23:22 +0000 |
parents | b4416ca69153 |
children | 76b73f15d07e |
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 IBBoard.WarFoundry.API.Requirements; | |
11 using log4net; | |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
12 using IBBoard.Lang; |
0 | 13 |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
14 namespace IBBoard.WarFoundry.GUI.GTK |
0 | 15 { |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
16 public partial class FrmNewUnit : TranslatableDialog |
13 | 17 { |
0 | 18 private ILog logger = LogManager.GetLogger(typeof(FrmNewUnit)); |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
19 private UnitType unitType; |
0 | 20 private Army unitArmy; |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
21 private Category cat; |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
22 |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
23 public FrmNewUnit(Race race, Category category, Army army) |
0 | 24 { |
25 this.Build(); | |
26 unitArmy = army; | |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
27 cat = category; |
0 | 28 |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
29 TreeViewColumn unitTypeColumn = new TreeViewColumn(); |
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
30 CellRendererText unitTypeCell = new CellRendererText(); |
0 | 31 unitTypeColumn.PackStart(unitTypeCell, true); |
32 lstUnitTypes.AppendColumn(unitTypeColumn); | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
33 unitTypeColumn.SetCellDataFunc(unitTypeCell, new TreeCellDataFunc(RenderUnitTypeName)); |
0 | 34 ListStore store = new ListStore(typeof(UnitType)); |
35 UnitType[] types = race.GetUnitTypes(cat); | |
36 logger.DebugFormat("Listing {0} unit types in {1}", types.Length, cat.Name); | |
37 | |
38 foreach (UnitType type in types) | |
39 { | |
40 logger.DebugFormat("Adding unit type {0}", type.Name); | |
41 store.AppendValues(type); | |
42 } | |
43 | |
44 lstUnitTypes.Model = store; | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
45 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
|
46 |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
47 Translation.TranslationChanged += Retranslate; |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
48 Translate(); |
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
49 } |
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
50 |
96
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
51 private void Retranslate() |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
52 { |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
53 Translate(); |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
54 } |
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 public override void Dispose() |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
57 { |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
58 Translation.TranslationChanged -= Retranslate; |
b4416ca69153
Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
59 base.Dispose(); |
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 |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
62 protected override void 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 base.Translate(); |
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
65 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
|
66 Title = Translation.GetTranslation(Name, "Create new unit", cat.Name); |
0 | 67 } |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
68 |
0 | 69 private void RenderUnitTypeName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
70 { | |
71 UnitType type = (UnitType)model.GetValue(iter, 0); | |
72 (cell as CellRendererText).Text = type.Name; | |
73 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
74 |
0 | 75 protected virtual void OnSelectionChanged(object o, EventArgs e) |
76 { | |
77 SetSelectUnitEnabledVal(); | |
78 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
79 |
13 | 80 public UnitType SelectedUnit |
0 | 81 { |
82 get { return unitType; } | |
83 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
84 |
0 | 85 private UnitType GetSelectedUnitType() |
86 { | |
87 TreeModel model; | |
88 TreeIter iter; | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
89 lstUnitTypes.Selection.GetSelected(out model, out iter); |
0 | 90 UnitType toReturn = null; |
91 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
92 if (model != null) |
0 | 93 { |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
94 toReturn = (UnitType)model.GetValue(iter, 0); |
0 | 95 } |
96 | |
97 return toReturn; | |
98 } | |
77
68804784bf6f
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
76
diff
changeset
|
99 |
13 | 100 private void SetSelectUnitEnabledVal() |
0 | 101 { |
102 UnitType type = GetSelectedUnitType(); | |
13 | 103 |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
104 if (type != null) |
13 | 105 { |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
106 bttnCreate.Sensitive = true; |
13 | 107 List<FailedUnitRequirement> fails = unitArmy.CanAddUnitType(type); |
108 lblNewUnitWarning.Visible = (fails != null); | |
109 | |
110 if (fails.Count > 0) | |
0 | 111 { |
13 | 112 //FIXME: currently only show the first error |
113 lblNewUnitWarning.Text = fails[0].Description; | |
114 } | |
115 } | |
116 else | |
117 { | |
88
b0089e875754
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
118 bttnCreate.Sensitive = false; |
13 | 119 lblNewUnitWarning.Visible = false; |
120 } | |
0 | 121 } |
122 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
123 protected virtual void OnButtonCancelActivated(object sender, System.EventArgs e) |
0 | 124 { |
125 Respond(ResponseType.Cancel); | |
126 } | |
127 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
128 protected virtual void OnRowActivated(object o, Gtk.RowActivatedArgs args) |
0 | 129 { |
130 unitType = GetSelectedUnitType(); | |
131 Respond(ResponseType.Ok); | |
132 } | |
133 | |
76
7055b24cfc79
Re #308: Make GTK# UI translatable
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
134 protected virtual void OnButtonOkClicked(object sender, System.EventArgs e) |
0 | 135 { |
136 unitType = GetSelectedUnitType(); | |
137 Respond(ResponseType.Ok); | |
138 } | |
139 } | |
140 } |