annotate Widgets/UnitDisplayWidget.cs @ 53:28b242612ad7

Re #60: Add UI to add/remove/edit weapons in GTK * Use proper method for making dialog appear Re #306: Combine equipment lists in GTK# * Populate unit equipment lists on unit display widget
author IBBoard <dev@ibboard.co.uk>
date Wed, 25 Aug 2010 15:21:56 +0000
parents 4bad8cb3f889
children 7bba99c368c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using Gtk;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using IBBoard.Commands;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using IBBoard.Lang;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
16 namespace IBBoard.WarFoundry.GTK.Widgets
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
18 [System.ComponentModel.Category("WarFoundry GTK# GUI")]
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
19 [System.ComponentModel.ToolboxItem(true)]
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 public partial class UnitDisplayWidget : Gtk.Bin
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 {
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
22 private WFObjects.Unit unit;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 private CommandStack stack;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
25 public UnitDisplayWidget(WFObjects.Unit sourceUnit, CommandStack commandStack)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 this.Build();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 stack = commandStack;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 unit = sourceUnit;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 unitName.Text = unit.Name;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 unitSize.Value = unit.Size;
48
23238d998535 Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
32 notesView.Buffer.Text = unit.UnitType.Notes;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 double max = unit.UnitType.MaxSize;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 if (max == -1)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 max = double.MaxValue;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 unitSize.SetRange(unit.UnitType.MinSize, max);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 unit.NameChanged+= new StringValChangedDelegate(UnitNameChanged);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 unit.UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChanged);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 SetStats();
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
44 SetWeapons();
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
45 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
46
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
47 private void SetStats()
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
48 {
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 CellRendererText renderer = new CellRendererText();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 unitStats.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, new TreeCellDataFunc(RenderUnitName));
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51
11
4e5e382fbd2e Re #10 (Code readability) and Re #86 (Complete GTK# GUI):
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
52 TreeCellDataFunc statFunc = new TreeCellDataFunc(RenderUnitStat);
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
53 Stat[] stats = unit.UnitStatsArray;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
54
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
55 int length = stats.Length;
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
56
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
57 for (int i = 0; i < length; i++)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 {
34
a35c8be46006 Re #198: Add unit equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
59 unitStats.AppendColumn(stats[i].ParentSlotName, renderer, statFunc);
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
60 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
62 TreeStore model = new TreeStore(typeof(WFObjects.Unit));
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
63 model.AppendValues(unit);
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
64 unitStats.Model = model;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 private void RenderUnitName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 object o = model.GetValue(iter, 0);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
71 if (o is WFObjects.Unit)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 {
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
73 WFObjects.Unit u = (WFObjects.Unit)o;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 (cell as CellRendererText).Text = u.UnitType.Name;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 private void RenderUnitStat(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 object o = model.GetValue(iter, 0);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
82 if (o is WFObjects.Unit)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 {
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
84 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
85 (cell as CellRendererText).Text = u.GetStatValue(column.Title);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 }
15
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
88
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
89 private void SetWeapons()
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
90 {
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
91 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
92 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
93
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
94
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
95 TreeStore model = new TreeStore(typeof(UnitEquipmentItem));
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
96 model.AppendValues(unit.GetEquipment());
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
97 equipmentList.Model = model;
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
98 }
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
99
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
100 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
101 {
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
102 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
103
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
104 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
105 {
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
106 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
107 (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
108 }
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
109
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
110 }
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
111
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
112 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
113 {
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
114 string translation = "";
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
115
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
116 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
117 {
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
118 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
119 }
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
120 else
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 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
123 }
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
124
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
125 return translation;
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
126 }
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 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
129 {
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
130 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
131 string amountString = "";
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 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
134 {
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
135 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
136
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
137 if (amount == 100)
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
138 {
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
139 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
140 }
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 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
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
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
148 else
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 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
151 }
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
152
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
153 return 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
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
156 public WFObjects.Unit Unit
15
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
157 {
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
158 get { return unit; }
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
159 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
160
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
161 private void UnitNameChanged(WarFoundryObject obj, string oldValue, string newValue)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
162 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
163 unitName.Text = newValue;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
164 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
165
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 private void UnitSizeChanged(WarFoundryObject obj, int oldValue, int newValue)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
167 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
168 unitSize.Value = newValue;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
169 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 protected virtual void OnUnitSizeFocusOut (object o, Gtk.FocusOutEventArgs args)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
172 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
173 SetNewUnitSize();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
174 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
176 [GLib.ConnectBefore ()]
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
177 protected virtual void OnUnitSizeKeyPress (object o, Gtk.KeyPressEventArgs args)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
178 {
51
dafbd432ca23 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
179 if (args.Event.Key == Gdk.Key.Return || args.Event.Key == Gdk.Key.KP_Enter)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
180 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
181 SetNewUnitSize();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
182 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
183 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
184
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
185 private void SetNewUnitSize()
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
186 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
187 if (unitSize.Value!=unit.Size)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
188 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
189 SetUnitSizeCommand cmd = new SetUnitSizeCommand(unit, (int)Math.Round(unitSize.Value));
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
190 stack.Execute(cmd);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
191 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
192 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
193
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
194 protected virtual void OnUnitNameFocusOut (object o, Gtk.FocusOutEventArgs args)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
195 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
196 SetNewUnitName();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
197 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
198
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
199 [GLib.ConnectBefore ()]
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
200 protected virtual void OnUnitNameKeyPress (object o, Gtk.KeyPressEventArgs args)
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
201 {
49
d29ad8445461 Re #86: Complete GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 48
diff changeset
202 if (args.Event.Key == Gdk.Key.Return || args.Event.Key == Gdk.Key.KP_Enter)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
203 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
204 SetNewUnitName();
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
205 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
206 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
207
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
208 private void SetNewUnitName()
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
209 {
51
dafbd432ca23 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
210 if (unitName.Text != unit.Name)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
211 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
212 SetNameCommand cmd = new SetNameCommand(unit, unitName.Text);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
213 stack.Execute(cmd);
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
214 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
215 }
51
dafbd432ca23 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
216
52
4bad8cb3f889 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 51
diff changeset
217 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
218 {
dafbd432ca23 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
219 AddEquipment();
dafbd432ca23 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
220 }
dafbd432ca23 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
221
dafbd432ca23 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
222 private void AddEquipment()
dafbd432ca23 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
223 {
dafbd432ca23 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
224 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
225 addEquipment.Show();
dafbd432ca23 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
226 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
227 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
228 }