annotate Widgets/UnitDisplayWidget.cs @ 88:b0089e875754

Re #308: Make GTK# UI translatable * Make FrmNewUnit translatable
author IBBoard <dev@ibboard.co.uk>
date Wed, 29 Dec 2010 20:56:03 +0000
parents 68804784bf6f
children 986fc923c0fa
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 using System;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using Gtk;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.Commands;
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
7 using IBBoard.GtkSharp;
0
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;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 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
11 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
12 using IBBoard.WarFoundry.API.Util;
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
13 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
14 using log4net;
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
15 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
16 using System.Collections.Generic;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
18 namespace IBBoard.WarFoundry.GUI.GTK.Widgets
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 {
5
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
20 [System.ComponentModel.Category("WarFoundry GTK# GUI")]
65279b85446f Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
21 [System.ComponentModel.ToolboxItem(true)]
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
24 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
25 private WFObjects.Unit unit;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 private CommandStack stack;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
27 private Dictionary<string, NodeView> statsViews = new Dictionary<string, NodeView> ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
28
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
29 public UnitDisplayWidget (WFObjects.Unit sourceUnit, CommandStack commandStack)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
31 this.Build ();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 stack = commandStack;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 unit = sourceUnit;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 unitName.Text = unit.Name;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
38 unitSize.SetRange (minSize, maxSize);
60
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;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
45 SetAbilities ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
46 SetStats ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
47 SetWeapons ();
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
48 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
49
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
50 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
51 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
52 SetButtonsEnabledState ();
60
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
53 }
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
54
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
55 private void SetButtonsEnabledState ()
60
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
56 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
57 UnitEquipmentItem equipItem = GetSelectedEquipmentItem ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
58 bttnReplaceEquipment.Sensitive = (equipItem != null && equipItem.HasAlternatives ());
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
59 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
60 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
61 }
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
62
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
63 private UnitEquipmentItem GetSelectedEquipmentItem ()
60
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
64 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
65 return (UnitEquipmentItem)TreeUtils.GetSelectedItem (equipmentList);
60
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
66 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
67
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
68 private void SetAbilities ()
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
69 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
70 CellRendererText renderer = new CellRendererText ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
71 abilitiesList.AppendColumn ("", renderer, new TreeCellDataFunc (RenderAbility));
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
72
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
73 ListStore model = new ListStore (typeof (Ability));
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
74
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
75 foreach (Ability ability in unit.UnitType.GetRequiredAbilities ()) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
76 model.AppendValues (ability);
71
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
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
79 abilitiesList.Model = model;
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
80 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
81
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
82 public void RenderAbility (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
83 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
84 object o = model.GetValue (iter, 0);
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
85
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
86 if (o is Ability) {
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
87 Ability ability = (Ability)o;
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
88 (cell as CellRendererText).Text = ability.Name;
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
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
91 }
60
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
92
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
93 private void SetStats ()
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
94 {
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
95 Stat[][] stats = unit.UnitStatsArraysWithName;
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
96 string[] statsIDs = unit.UnitStatsArrayIDs;
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
97 int statsCount = stats.Length;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
98 log.DebugFormat ("Unit {0} has {1} stats arrays", unit.UnitType.Name, statsCount);
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
99
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
100 for (int i = 0; i < statsCount; i++) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
101 NodeView statsGrid = GetStatsView (statsIDs [i]);
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
102 TreeStore model = (TreeStore)statsGrid.Model;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
103 log.DebugFormat ("Adding row to data table for {0}", statsIDs [i]);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
104 log.DebugFormat ("TreeStore supports {0} columns", model.NColumns);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
105 model.AppendValues ((object)stats [i]);
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
106 }
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
107 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
108
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
109 private NodeView GetStatsView (string statsID)
72
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 NodeView statsView;
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
112
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
113 if (statsViews.ContainsKey (statsID)) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
114 statsView = DictionaryUtils.GetValue (statsViews, statsID);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
115 } else {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
116 statsView = CreateStatsView (statsID);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
117 statsViews [statsID] = statsView;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
118 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
120 return statsView;
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
121 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
122
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
123 private NodeView CreateStatsView (string statsID)
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
124 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
125 log.DebugFormat ("Create NodeView for stats ID {0}", statsID);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
126 SystemStats sysStats = unit.Race.GameSystem.GetSystemStatsForID (statsID);
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
127 StatSlot[] sysStatSlots = sysStats.StatSlots;
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
128 int statsCount = sysStatSlots.Length;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
129 NodeView statsGrid = CreateNodeView ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
130 CellRendererText renderer = new CellRendererText ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
131 statsGrid.AppendColumn (Translation.GetTranslation ("UnitNameColumn", "Unit Type", null), renderer, RenderUnitStat);
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
132
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
133 for (int i = 0; i < statsCount; i++) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
134 StatSlot stat = sysStatSlots [i];
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
135 string slotName = stat.Name;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
136 statsGrid.AppendColumn (slotName, renderer, RenderUnitStat);
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
137 }
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
138
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
139 statsGrid.Model = new TreeStore (typeof (Stat[]));
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
140 return statsGrid;
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
141 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
142
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
143 private NodeView CreateNodeView ()
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
144 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
145 NodeView nodeView = new NodeView ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
146 statsRepeatBox.Add (nodeView);
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
147 return nodeView;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
148 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
149
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
150 private void RenderUnitStat (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
151 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
152 object o = model.GetValue (iter, 0);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
153
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
154 if (o is Stat[]) {
73
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
155 Stat[] stats = (Stat[])o;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
156 (cell as CellRendererText).Text = stats [GetStatColumnIndex (column)].SlotValueString;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
157 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
158 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
159
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
160 private int GetStatColumnIndex (TreeViewColumn column)
73
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
161 {
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
162 int idx = -1;
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
163 TreeViewColumn[] cols = ((TreeView)column.TreeView).Columns;
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
164 int colCount = cols.Length;
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
165
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
166 for (int i = 0; i < colCount; i++) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
167 if (cols [i] == column) {
73
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
168 idx = i;
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
169 break;
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
170 }
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
171 }
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
172
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
173 return idx;
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
174 }
15
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
175
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
176 private void SetWeapons ()
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
177 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
178 CellRendererText renderer = new CellRendererText ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
179 equipmentList.AppendColumn ("", renderer, new TreeCellDataFunc (RenderEquipmentLine));
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
180
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
181 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
182
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
183 foreach (UnitEquipmentItem item in unit.GetEquipment ()) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
184 model.AppendValues (item);
58
7bba99c368c8 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 53
diff changeset
185 }
7bba99c368c8 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 53
diff changeset
186
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
187 equipmentList.Model = model;
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
188 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
189
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
190 public void RenderEquipmentLine (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
191 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
192 object o = model.GetValue (iter, 0);
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
193
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
194 if (o is UnitEquipmentItem) {
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
195 UnitEquipmentItem item = (UnitEquipmentItem)o;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
196 (cell as CellRendererText).Text = GetUnitEquipmentText (item);
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
197 }
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 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
200
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
201 private string GetUnitEquipmentText (UnitEquipmentItem item)
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
202 {
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
203 string translation = "";
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
204
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
205 if (item.Cost == 0) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
206 translation = Translation.GetTranslation ("equipmentAmountWithZeroCost", "{0} ({1} - free)", item.Name, GetAmountString (item));
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
207 } else {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
208 translation = Translation.GetTranslation ("equipmentAmountWithCost", "{0} ({1} at {2}pts each)", item.Name, GetAmountString (item), item.Cost);
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
209 }
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 return translation;
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
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
214 private string GetAmountString (UnitEquipmentItem item)
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
215 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
216 double amount = UnitEquipmentUtil.GetEquipmentAmount (unit, item);
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
217 string amountString = "";
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
218
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
219 if (UnitEquipmentUtil.GetEquipmentAmountIsRatio (unit, item)) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
220 int number = UnitEquipmentUtil.GetEquipmentAmountTaken (unit, item);
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
221
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
222 if (amount == 100) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
223 amountString = Translation.GetTranslation ("equipmentChoiceAmountAll", "all ({1})", amount, number);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
224 } else {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
225 amountString = Translation.GetTranslation ("equipmentChoiceAmountPercentage", "{0}% ({1})", amount, number);
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
226 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
227 } else {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
228 amountString = Translation.GetTranslation ("equipmentChoiceAmountNumber", "{0}", amount);
53
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
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
231 return amountString;
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
232 }
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
233
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
234 public WFObjects.Unit Unit {
15
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
235 get { return unit; }
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
236 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
237
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
238 private void UnitNameChanged (WarFoundryObject obj, string oldValue, string newValue)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
239 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
240 unitName.Text = newValue;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
241 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
242
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
243 private void UnitSizeChanged (WarFoundryObject obj, int oldValue, int newValue)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
244 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
245 unitSize.Value = newValue;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
246 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
247
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
248 private void HandleUnitUnitEquipmentAmountChanged (WarFoundryObject obj, double oldValue, double newValue)
59
c3415c6df551 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
249 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
250 if (oldValue == 0) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
251 ((ListStore)equipmentList.Model).AppendValues (obj);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
252 } else {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
253 if (newValue == 0) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
254 TreeIter treeIter = TreeUtils.GetItemIter (equipmentList, obj);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
255 ((ListStore)equipmentList.Model).Remove (ref treeIter);
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
256 }
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
257
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
258 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
259 equipmentList.QueueDraw ();
59
c3415c6df551 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
260 }
c3415c6df551 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
261
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
262 protected virtual void OnUnitSizeFocusOut (object o, Gtk.FocusOutEventArgs args)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
263 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
264 SetNewUnitSize ();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
265 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
266
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
267 [GLib.ConnectBefore ()]
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
268
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
269 protected virtual void OnUnitSizeKeyPress (object o, Gtk.KeyPressEventArgs args)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
270 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
271 if (args.Event.Key == Gdk.Key.Return || args.Event.Key == Gdk.Key.KP_Enter) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
272 SetNewUnitSize ();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
273 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
274 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
275
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
276 private void SetNewUnitSize ()
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
277 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
278 if (unitSize.Value != unit.Size) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
279 SetUnitSizeCommand cmd = new SetUnitSizeCommand (unit, (int)Math.Round (unitSize.Value));
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
280 stack.Execute (cmd);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
281 }
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
282 }
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
283
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
284 protected virtual void OnUnitNameFocusOut (object o, Gtk.FocusOutEventArgs args)
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
285 {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
286 SetNewUnitName ();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
287 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
288
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
289 [GLib.ConnectBefore ()]
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
290
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
291 protected virtual void OnUnitNameKeyPress (object o, Gtk.KeyPressEventArgs args)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
292 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
293 if (args.Event.Key == Gdk.Key.Return || args.Event.Key == Gdk.Key.KP_Enter) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
294 SetNewUnitName ();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
295 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
296 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
297
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
298 private void SetNewUnitName ()
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
299 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
300 if (unitName.Text != unit.Name) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
301 SetNameCommand cmd = new SetNameCommand (unit, unitName.Text);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
302 stack.Execute (cmd);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
303 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
304 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
305
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
306 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
307 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
308 AddEquipment ();
51
dafbd432ca23 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
309 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
310
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
311 private void AddEquipment ()
60
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
312 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
313 AddEquipmentUIControl addEquipment = new AddEquipmentUIControl (unit, stack);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
314 addEquipment.Show ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
315 }
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
316
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
317 protected virtual void HandleRemoveButtonActivated (object sender, System.EventArgs e)
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
318 {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
319 UnitEquipmentItem item = GetSelectedEquipmentItem ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
320 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
321
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
322 if (item != null) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
323 SetUnitEquipmentNumericAmountCommand cmd = new SetUnitEquipmentNumericAmountCommand (unit, item, 0);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
324 stack.Execute (cmd);
60
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
325 }
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
326 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
327
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
328 protected virtual void HandleEditButtonClicked (object sender, System.EventArgs e)
64
e3fe48c4d794 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
329 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
330 UnitEquipmentItem item = GetSelectedEquipmentItem ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
331 log.Debug ("Edit " + item);
64
e3fe48c4d794 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
332
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
333 if (item != null) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
334 EditEquipmentUIControl editEquipment = new EditEquipmentUIControl (unit, item, stack);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
335 editEquipment.Show ();
64
e3fe48c4d794 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
336 }
e3fe48c4d794 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
337 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
338
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
339 protected virtual void HandleReplaceButtonClicked (object sender, System.EventArgs e)
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
340 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
341 UnitEquipmentItem item = GetSelectedEquipmentItem ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
342 log.Debug ("Replace " + item);
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
343
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
344 if (item != null) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
345 ReplaceEquipmentUIControl addEquipment = new ReplaceEquipmentUIControl (unit, item, stack);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
346 addEquipment.Show ();
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
347 }
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
348 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
349 }
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
350 }