Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate Widgets/UnitDisplayWidget.cs @ 67:a7306b5a229e
Re #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
* Add SharpZipLib to GTK# GUI solution
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 30 Oct 2010 14:30:29 +0000 |
parents | 77448375d2f9 |
children | 7028e24b67ec |
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; | |
8 using IBBoard.Lang; | |
9 using IBBoard.WarFoundry.API; | |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
10 using WFObjects = IBBoard.WarFoundry.API.Objects; |
0 | 11 using IBBoard.WarFoundry.API.Commands; |
51
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
12 using IBBoard.WarFoundry.GUI.GTK.UIControl; |
53
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.Objects; |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
14 using IBBoard.WarFoundry.API.Util; |
59
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
15 using IBBoard.GtkSharp; |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
16 using log4net; |
0 | 17 |
5 | 18 namespace IBBoard.WarFoundry.GTK.Widgets |
0 | 19 { |
5 | 20 [System.ComponentModel.Category("WarFoundry GTK# GUI")] |
21 [System.ComponentModel.ToolboxItem(true)] | |
0 | 22 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
|
23 { |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
24 private static ILog log = LogManager.GetLogger(typeof(UnitDisplayWidget)); |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
25 |
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; |
28 | |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
29 public UnitDisplayWidget(WFObjects.Unit sourceUnit, CommandStack commandStack) |
0 | 30 { |
31 this.Build(); | |
32 stack = commandStack; | |
33 unit = sourceUnit; | |
34 unitName.Text = unit.Name; | |
35 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
|
36 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
|
37 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
|
38 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
|
39 unitSize.Sensitive = (maxSize != minSize); |
48
23238d998535
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
40 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
|
41 unit.NameChanged += UnitNameChanged; |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
42 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
|
43 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
|
44 equipmentList.Selection.Changed += HandleEquipmentListSelectionChanged; |
0 | 45 SetStats(); |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
46 SetWeapons(); |
13 | 47 } |
48 | |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
49 private void HandleEquipmentListSelectionChanged (object sender, EventArgs e) |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
50 { |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
51 SetButtonsEnabledState(); |
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 private void SetButtonsEnabledState() |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
54 { |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
55 UnitEquipmentItem equipItem = GetSelectedEquipmentItem(); |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
56 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
|
57 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
|
58 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
|
59 } |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
60 private UnitEquipmentItem GetSelectedEquipmentItem() |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
61 { |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
62 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
|
63 } |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
64 |
13 | 65 private void SetStats() |
66 { | |
0 | 67 CellRendererText renderer = new CellRendererText(); |
68 unitStats.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, new TreeCellDataFunc(RenderUnitName)); | |
69 | |
11
4e5e382fbd2e
Re #10 (Code readability) and Re #86 (Complete GTK# GUI):
IBBoard <dev@ibboard.co.uk>
parents:
5
diff
changeset
|
70 TreeCellDataFunc statFunc = new TreeCellDataFunc(RenderUnitStat); |
13 | 71 Stat[] stats = unit.UnitStatsArray; |
72 | |
73 int length = stats.Length; | |
74 | |
75 for (int i = 0; i < length; i++) | |
0 | 76 { |
34
a35c8be46006
Re #198: Add unit equipment slots
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
77 unitStats.AppendColumn(stats[i].ParentSlotName, renderer, statFunc); |
13 | 78 } |
0 | 79 |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
80 TreeStore model = new TreeStore(typeof(WFObjects.Unit)); |
13 | 81 model.AppendValues(unit); |
82 unitStats.Model = model; | |
0 | 83 } |
84 | |
85 private void RenderUnitName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | |
86 { | |
87 object o = model.GetValue(iter, 0); | |
88 | |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
89 if (o is WFObjects.Unit) |
0 | 90 { |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
91 WFObjects.Unit u = (WFObjects.Unit)o; |
0 | 92 (cell as CellRendererText).Text = u.UnitType.Name; |
93 } | |
94 } | |
95 | |
96 private void RenderUnitStat(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | |
97 { | |
98 object o = model.GetValue(iter, 0); | |
99 | |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
100 if (o is WFObjects.Unit) |
0 | 101 { |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
102 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
|
103 (cell as CellRendererText).Text = u.GetStatValue(column.Title); |
0 | 104 } |
105 } | |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
106 |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
107 private void SetWeapons() |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
108 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
109 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
|
110 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
|
111 |
59
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
112 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
|
113 |
58
7bba99c368c8
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
114 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
|
115 { |
7bba99c368c8
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
116 model.AppendValues(item); |
7bba99c368c8
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
117 } |
7bba99c368c8
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
53
diff
changeset
|
118 |
53
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
119 equipmentList.Model = model; |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
120 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
121 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
122 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
|
123 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
124 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
|
125 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
126 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
|
127 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
128 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
|
129 (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
|
130 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
131 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
132 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
133 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
134 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
|
135 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
136 string translation = ""; |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
137 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
138 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
|
139 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
140 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
|
141 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
142 else |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
143 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
144 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
|
145 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
146 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
147 return translation; |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
148 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
149 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
150 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
|
151 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
152 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
|
153 string amountString = ""; |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
154 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
155 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
|
156 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
157 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
|
158 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
159 if (amount == 100) |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
160 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
161 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
|
162 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
163 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
164 else |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
165 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
166 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
|
167 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
168 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
169 else |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
170 { |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
171 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
|
172 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
173 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
174 return amountString; |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
175 } |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
176 |
28b242612ad7
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
52
diff
changeset
|
177 public WFObjects.Unit Unit |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
178 { |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
179 get { return unit; } |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
180 } |
0 | 181 |
182 private void UnitNameChanged(WarFoundryObject obj, string oldValue, string newValue) | |
183 { | |
184 unitName.Text = newValue; | |
185 } | |
186 | |
187 private void UnitSizeChanged(WarFoundryObject obj, int oldValue, int newValue) | |
188 { | |
189 unitSize.Value = newValue; | |
190 } | |
191 | |
59
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
192 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
|
193 { |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
194 if (oldValue == 0) |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
195 { |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
196 ((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
|
197 } |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
198 else if (newValue == 0) |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
199 { |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
200 TreeIter treeIter = TreeUtils.GetItemIter(equipmentList, obj); |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
201 ((ListStore)equipmentList.Model).Remove(ref treeIter); |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
202 } |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
203 |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
204 equipmentList.QueueDraw(); |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
205 } |
c3415c6df551
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
58
diff
changeset
|
206 |
0 | 207 protected virtual void OnUnitSizeFocusOut (object o, Gtk.FocusOutEventArgs args) |
208 { | |
209 SetNewUnitSize(); | |
210 } | |
211 | |
212 [GLib.ConnectBefore ()] | |
213 protected virtual void OnUnitSizeKeyPress (object o, Gtk.KeyPressEventArgs args) | |
214 { | |
51
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
215 if (args.Event.Key == Gdk.Key.Return || args.Event.Key == Gdk.Key.KP_Enter) |
0 | 216 { |
217 SetNewUnitSize(); | |
218 } | |
219 } | |
220 | |
221 private void SetNewUnitSize() | |
222 { | |
223 if (unitSize.Value!=unit.Size) | |
224 { | |
225 SetUnitSizeCommand cmd = new SetUnitSizeCommand(unit, (int)Math.Round(unitSize.Value)); | |
226 stack.Execute(cmd); | |
227 } | |
228 } | |
229 | |
230 protected virtual void OnUnitNameFocusOut (object o, Gtk.FocusOutEventArgs args) | |
231 { | |
232 SetNewUnitName(); | |
233 } | |
234 | |
235 [GLib.ConnectBefore ()] | |
236 protected virtual void OnUnitNameKeyPress (object o, Gtk.KeyPressEventArgs args) | |
237 { | |
49 | 238 if (args.Event.Key == Gdk.Key.Return || args.Event.Key == Gdk.Key.KP_Enter) |
0 | 239 { |
240 SetNewUnitName(); | |
241 } | |
242 } | |
243 | |
244 private void SetNewUnitName() | |
245 { | |
51
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
246 if (unitName.Text != unit.Name) |
0 | 247 { |
248 SetNameCommand cmd = new SetNameCommand(unit, unitName.Text); | |
249 stack.Execute(cmd); | |
250 } | |
251 } | |
51
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
252 |
52
4bad8cb3f889
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
51
diff
changeset
|
253 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
|
254 { |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
255 AddEquipment(); |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
256 } |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
257 |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
258 private void AddEquipment() |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
259 { |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
260 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
|
261 addEquipment.Show(); |
dafbd432ca23
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
262 } |
60
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
263 |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
264 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
|
265 { |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
266 UnitEquipmentItem item = GetSelectedEquipmentItem(); |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
267 log.Debug("Remove "+item); |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
268 |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
269 if (item != null) |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
270 { |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
271 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
|
272 stack.Execute(cmd); |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
273 } |
04c0f6a7625c
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
59
diff
changeset
|
274 } |
64
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
275 |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
276 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
|
277 { |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
278 UnitEquipmentItem item = GetSelectedEquipmentItem(); |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
279 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
|
280 |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
281 if (item != null) |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
282 { |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
283 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
|
284 editEquipment.Show(); |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
285 } |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
286 } |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
287 |
e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
60
diff
changeset
|
288 |
0 | 289 } |
290 } |