Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate Widgets/UnitDisplayWidget.cs @ 72:f0cc295e883c
Re #307: Add support for multiple stat lines
* Implement starts of multiple stat lines, based on WinForms method
* Replace existing NodeView with a VBox for repeat widgets
* Create NodeViews for each stat line type and append stats
Currently fails to show stats.
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 09 Nov 2010 20:29:50 +0000 |
parents | 91354245218a |
children | 19e7123aafd5 |
rev | line source |
---|---|
19
a191d0655f55
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
1 // This file (UnitDisplayWidget.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:
15
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 Gtk; | |
7 using IBBoard.Commands; | |
71
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
8 using IBBoard.GtkSharp; |
0 | 9 using IBBoard.Lang; |
10 using IBBoard.WarFoundry.API; | |
11 using IBBoard.WarFoundry.API.Commands; | |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
12 using IBBoard.WarFoundry.API.Objects; |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
13 using IBBoard.WarFoundry.API.Util; |
71
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
14 using IBBoard.WarFoundry.GUI.GTK.UIControl; |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
15 using log4net; |
71
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
16 using WFObjects = IBBoard.WarFoundry.API.Objects; |
72
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
17 using System.Collections.Generic; |
0 | 18 |
5 | 19 namespace IBBoard.WarFoundry.GTK.Widgets |
0 | 20 { |
5 | 21 [System.ComponentModel.Category("WarFoundry GTK# GUI")] |
22 [System.ComponentModel.ToolboxItem(true)] | |
0 | 23 public partial class UnitDisplayWidget : Gtk.Bin |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
24 { |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
25 private static ILog log = LogManager.GetLogger(typeof(UnitDisplayWidget)); |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
26 private WFObjects.Unit unit; |
0 | 27 private CommandStack stack; |
72
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
28 private Dictionary<string, NodeView> statsViews = new Dictionary<string, NodeView>(); |
0 | 29 |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
30 public UnitDisplayWidget(WFObjects.Unit sourceUnit, CommandStack commandStack) |
0 | 31 { |
32 this.Build(); | |
33 stack = commandStack; | |
34 unit = sourceUnit; | |
35 unitName.Text = unit.Name; | |
36 unitSize.Value = unit.Size; | |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
37 int maxSize = (unit.UnitType.MaxSize == WarFoundryCore.INFINITY ? int.MaxValue : unit.UnitType.MaxSize); |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
38 int minSize = unit.UnitType.MinSize; |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
39 unitSize.SetRange(minSize, maxSize); |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
40 unitSize.Sensitive = (maxSize != minSize); |
48
23238d998535
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
41 notesView.Buffer.Text = unit.UnitType.Notes; |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
42 unit.NameChanged += UnitNameChanged; |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
43 unit.UnitSizeChanged += UnitSizeChanged; |
59
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
44 unit.UnitEquipmentAmountChanged += HandleUnitUnitEquipmentAmountChanged; |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
45 equipmentList.Selection.Changed += HandleEquipmentListSelectionChanged; |
71
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
46 SetAbilities(); |
0 | 47 SetStats(); |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
48 SetWeapons(); |
13 | 49 } |
50 | |
68
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
51 private void HandleEquipmentListSelectionChanged(object sender, EventArgs e) |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
52 { |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
53 SetButtonsEnabledState(); |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
54 } |
68
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
55 |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
56 private void SetButtonsEnabledState() |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
57 { |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
58 UnitEquipmentItem equipItem = GetSelectedEquipmentItem(); |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
59 bttnReplaceEquipment.Sensitive = (equipItem != null && equipItem.HasAlternatives()); |
65
77448375d2f9
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
64
diff
changeset
|
60 bttnEditEquipment.Sensitive = (UnitEquipmentUtil.CanEditEquipmentAmount(unit, equipItem)); |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
61 bttnRemoveEquipment.Sensitive = (equipItem != null && !equipItem.IsRequired); |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
62 } |
68
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
63 |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
64 private UnitEquipmentItem GetSelectedEquipmentItem() |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
65 { |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
66 return (UnitEquipmentItem)TreeUtils.GetSelectedItem(equipmentList); |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
67 } |
71
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
68 |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
69 private void SetAbilities() |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
70 { |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
71 CellRendererText renderer = new CellRendererText(); |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
72 abilitiesList.AppendColumn("", renderer, new TreeCellDataFunc(RenderAbility)); |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
73 |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
74 ListStore model = new ListStore(typeof(Ability)); |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
75 |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
76 foreach (Ability ability in unit.UnitType.GetRequiredAbilities()) |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
77 { |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
78 model.AppendValues(ability); |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
79 } |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
80 |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
81 abilitiesList.Model = model; |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
82 } |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
83 |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
84 public void RenderAbility(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
85 { |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
86 object o = model.GetValue(iter, 0); |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
87 |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
88 if (o is Ability) |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
89 { |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
90 Ability ability = (Ability)o; |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
91 (cell as CellRendererText).Text = ability.Name; |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
92 } |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
93 |
91354245218a
Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
68
diff
changeset
|
94 } |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
95 |
13 | 96 private void SetStats() |
97 { | |
72
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
98 Stat[][] stats = unit.UnitStatsArraysWithName; |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
99 string[] statsIDs = unit.UnitStatsArrayIDs; |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
100 int statsCount = stats.Length; |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
101 log.DebugFormat("Unit {0} has {1} stats arrays", unit.UnitType.Name, statsCount); |
13 | 102 |
72
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
103 for (int i = 0; i < statsCount; i++) |
0 | 104 { |
72
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
105 NodeView statsGrid = GetStatsView(statsIDs[i]); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
106 TreeStore model = (TreeStore)statsGrid.Model; |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
107 log.DebugFormat("Adding row to data table for {0}", statsIDs[i]); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
108 log.DebugFormat("TreeStore supports {0} columns", model.NColumns); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
109 model.AppendValues(stats[i]); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
110 } |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
111 } |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
112 |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
113 private NodeView GetStatsView(string statsID) |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
114 { |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
115 NodeView statsView; |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
116 |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
117 if (statsViews.ContainsKey(statsID)) |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
118 { |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
119 statsView = DictionaryUtils.GetValue(statsViews, statsID); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
120 } |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
121 else |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
122 { |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
123 statsView = CreateStatsView(statsID); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
124 statsViews[statsID] = statsView; |
13 | 125 } |
0 | 126 |
72
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
127 return statsView; |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
128 } |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
129 |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
130 private NodeView CreateStatsView(string statsID) |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
131 { |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
132 log.DebugFormat("Create NodeView for stats ID {0}", statsID); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
133 SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID(statsID); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
134 StatSlot[] sysStatSlots = sysStats.StatSlots; |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
135 int statsCount = sysStatSlots.Length; |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
136 NodeView statsGrid = CreateNodeView(); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
137 CellRendererText renderer = new CellRendererText(); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
138 statsGrid.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, RenderUnitName); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
139 |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
140 for (int i = 0; i < statsCount; i++) |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
141 { |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
142 StatSlot stat = sysStatSlots[i]; |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
143 string slotName = stat.Name; |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
144 statsGrid.AppendColumn(slotName, renderer, RenderUnitStat); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
145 } |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
146 |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
147 statsGrid.Model = new TreeStore(typeof(Stat[])); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
148 return statsGrid; |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
149 } |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
150 |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
151 private NodeView CreateNodeView() |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
152 { |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
153 NodeView nodeView = new NodeView(); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
154 statsRepeatBox.Add(nodeView); |
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
155 return nodeView; |
0 | 156 } |
157 | |
158 private void RenderUnitName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | |
159 { | |
160 object o = model.GetValue(iter, 0); | |
161 | |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
162 if (o is WFObjects.Unit) |
0 | 163 { |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
164 WFObjects.Unit u = (WFObjects.Unit)o; |
0 | 165 (cell as CellRendererText).Text = u.UnitType.Name; |
166 } | |
167 } | |
168 | |
169 private void RenderUnitStat(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | |
170 { | |
171 object o = model.GetValue(iter, 0); | |
172 | |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
173 if (o is WFObjects.Unit) |
0 | 174 { |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
175 WFObjects.Unit u = (WFObjects.Unit)o; |
11
4e5e382fbd2e
Re #10 (Code readability) and Re #86 (Complete GTK# GUI):
IBBoard <dev@ibboard.co.uk>
parents:
5
diff
changeset
|
176 (cell as CellRendererText).Text = u.GetStatValue(column.Title); |
0 | 177 } |
178 } | |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
179 |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
180 private void SetWeapons() |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
181 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
182 CellRendererText renderer = new CellRendererText(); |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
183 equipmentList.AppendColumn("", renderer, new TreeCellDataFunc(RenderEquipmentLine)); |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
184 |
59
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
185 ListStore model = new ListStore(typeof(UnitEquipmentItem)); |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
186 |
58
7bba99c368c8
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
187 foreach (UnitEquipmentItem item in unit.GetEquipment()) |
7bba99c368c8
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
188 { |
7bba99c368c8
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
189 model.AppendValues(item); |
7bba99c368c8
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
190 } |
7bba99c368c8
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
191 |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
192 equipmentList.Model = model; |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
193 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
194 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
195 public void RenderEquipmentLine(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
196 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
197 object o = model.GetValue(iter, 0); |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
198 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
199 if (o is UnitEquipmentItem) |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
200 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
201 UnitEquipmentItem item = (UnitEquipmentItem)o; |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
202 (cell as CellRendererText).Text = GetUnitEquipmentText(item); |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
203 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
204 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
205 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
206 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
207 private string GetUnitEquipmentText(UnitEquipmentItem item) |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
208 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
209 string translation = ""; |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
210 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
211 if (item.Cost == 0) |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
212 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
213 translation = Translation.GetTranslation("equipmentAmountWithZeroCost", "{0} ({1} - free)", item.Name, GetAmountString(item)); |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
214 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
215 else |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
216 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
217 translation = Translation.GetTranslation("equipmentAmountWithCost", "{0} ({1} at {2}pts each)", item.Name, GetAmountString(item), item.Cost); |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
218 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
219 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
220 return translation; |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
221 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
222 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
223 private string GetAmountString(UnitEquipmentItem item) |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
224 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
225 double amount = UnitEquipmentUtil.GetEquipmentAmount(unit, item); |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
226 string amountString = ""; |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
227 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
228 if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, item)) |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
229 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
230 int number = UnitEquipmentUtil.GetEquipmentAmountTaken(unit, item); |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
231 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
232 if (amount == 100) |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
233 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
234 amountString = Translation.GetTranslation("equipmentChoiceAmountAll", "all ({1})", amount, number); |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
235 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
236 else |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
237 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
238 amountString = Translation.GetTranslation("equipmentChoiceAmountPercentage", "{0}% ({1})", amount, number); |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
239 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
240 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
241 else |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
242 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
243 amountString = Translation.GetTranslation("equipmentChoiceAmountNumber", "{0}", amount); |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
244 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
245 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
246 return amountString; |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
247 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
248 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
249 public WFObjects.Unit Unit |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
250 { |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
251 get { return unit; } |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
252 } |
0 | 253 |
254 private void UnitNameChanged(WarFoundryObject obj, string oldValue, string newValue) | |
255 { | |
256 unitName.Text = newValue; | |
257 } | |
258 | |
259 private void UnitSizeChanged(WarFoundryObject obj, int oldValue, int newValue) | |
260 { | |
261 unitSize.Value = newValue; | |
262 } | |
263 | |
59
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
264 private void HandleUnitUnitEquipmentAmountChanged(WarFoundryObject obj, double oldValue, double newValue) |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
265 { |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
266 if (oldValue == 0) |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
267 { |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
268 ((ListStore)equipmentList.Model).AppendValues(obj); |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
269 } |
68
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
270 else |
59
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
271 { |
68
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
272 if (newValue == 0) |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
273 { |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
274 TreeIter treeIter = TreeUtils.GetItemIter(equipmentList, obj); |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
275 ((ListStore)equipmentList.Model).Remove(ref treeIter); |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
276 } |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
277 |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
278 } |
59
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
279 equipmentList.QueueDraw(); |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
280 } |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
281 |
68
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
282 protected virtual void OnUnitSizeFocusOut(object o, Gtk.FocusOutEventArgs args) |
0 | 283 { |
284 SetNewUnitSize(); | |
285 } | |
286 | |
287 [GLib.ConnectBefore ()] | |
68
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
288 |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
289 protected virtual void OnUnitSizeKeyPress(object o, Gtk.KeyPressEventArgs args) |
0 | 290 { |
51
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
291 if (args.Event.Key == Gdk.Key.Return || args.Event.Key == Gdk.Key.KP_Enter) |
0 | 292 { |
293 SetNewUnitSize(); | |
294 } | |
295 } | |
296 | |
297 private void SetNewUnitSize() | |
298 { | |
68
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
299 if (unitSize.Value != unit.Size) |
0 | 300 { |
301 SetUnitSizeCommand cmd = new SetUnitSizeCommand(unit, (int)Math.Round(unitSize.Value)); | |
302 stack.Execute(cmd); | |
303 } | |
304 } | |
305 | |
68
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
306 protected virtual void OnUnitNameFocusOut(object o, Gtk.FocusOutEventArgs args) |
0 | 307 { |
308 SetNewUnitName(); | |
309 } | |
310 | |
311 [GLib.ConnectBefore ()] | |
68
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
312 |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
313 protected virtual void OnUnitNameKeyPress(object o, Gtk.KeyPressEventArgs args) |
0 | 314 { |
49 | 315 if (args.Event.Key == Gdk.Key.Return || args.Event.Key == Gdk.Key.KP_Enter) |
0 | 316 { |
317 SetNewUnitName(); | |
318 } | |
319 } | |
320 | |
321 private void SetNewUnitName() | |
322 { | |
51
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
323 if (unitName.Text != unit.Name) |
0 | 324 { |
325 SetNameCommand cmd = new SetNameCommand(unit, unitName.Text); | |
326 stack.Execute(cmd); | |
327 } | |
328 } | |
51
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
329 |
52
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
51
diff
changeset
|
330 private void OnBttnAddEquipmentClicked(object sender, System.EventArgs e) |
51
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
331 { |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
332 AddEquipment(); |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
333 } |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
334 |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
335 private void AddEquipment() |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
336 { |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
337 AddEquipmentUIControl addEquipment = new AddEquipmentUIControl(unit, stack); |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
338 addEquipment.Show(); |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
339 } |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
340 |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
341 protected virtual void HandleRemoveButtonActivated(object sender, System.EventArgs e) |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
342 { |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
343 UnitEquipmentItem item = GetSelectedEquipmentItem(); |
68
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
344 log.Debug("Remove " + item); |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
345 |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
346 if (item != null) |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
347 { |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
348 SetUnitEquipmentNumericAmountCommand cmd = new SetUnitEquipmentNumericAmountCommand(unit, item, 0); |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
349 stack.Execute(cmd); |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
350 } |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
351 } |
64
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
352 |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
353 protected virtual void HandleEditButtonClicked(object sender, System.EventArgs e) |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
354 { |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
355 UnitEquipmentItem item = GetSelectedEquipmentItem(); |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
356 log.Debug("Edit " + item); |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
357 |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
358 if (item != null) |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
359 { |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
360 EditEquipmentUIControl editEquipment = new EditEquipmentUIControl(unit, item, stack); |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
361 editEquipment.Show(); |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
362 } |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
363 } |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
364 |
68
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
365 protected virtual void HandleReplaceButtonClicked(object sender, System.EventArgs e) |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
366 { |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
367 UnitEquipmentItem item = GetSelectedEquipmentItem(); |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
368 log.Debug("Replace " + item); |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
369 |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
370 if (item != null) |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
371 { |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
372 ReplaceEquipmentUIControl addEquipment = new ReplaceEquipmentUIControl(unit, item, stack); |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
373 addEquipment.Show(); |
7028e24b67ec
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
65
diff
changeset
|
374 } |
72
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
375 } |
0 | 376 } |
72
f0cc295e883c
Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
377 } |