annotate Widgets/UnitDisplayWidget.cs @ 91:986fc923c0fa

Fixes #331: Equipment buttons should be disabled when options aren't available * Edit was already handled via UnitEquipmentUtil call * Added enabling/disabling for Add via extracted methods on AddEquipmentUIControl
author IBBoard <dev@ibboard.co.uk>
date Fri, 31 Dec 2010 11:36:06 +0000
parents 68804784bf6f
children 58779fcd0166
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 ();
91
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
48 SetAddButtonEnabledState();
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
49 }
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
50
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
51 private void HandleEquipmentListSelectionChanged (object sender, EventArgs e)
60
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
52 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
53 SetButtonsEnabledState ();
60
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
54 }
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
55
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
56 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
57 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
58 UnitEquipmentItem equipItem = GetSelectedEquipmentItem ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
59 bttnReplaceEquipment.Sensitive = (equipItem != null && equipItem.HasAlternatives ());
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
60 bttnEditEquipment.Sensitive = (UnitEquipmentUtil.CanEditEquipmentAmount (unit, equipItem));
60
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
61 bttnRemoveEquipment.Sensitive = (equipItem != null && !equipItem.IsRequired);
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
62 }
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
63
91
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
64 private void SetAddButtonEnabledState()
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
65 {
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
66 bttnAddEquipment.Sensitive = AddEquipmentUIControl.HasEquipmentToAdd(unit);
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
67 }
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
68
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
69 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
70 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
71 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
72 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
73
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
74 private void SetAbilities ()
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
75 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
76 CellRendererText renderer = new CellRendererText ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
77 abilitiesList.AppendColumn ("", renderer, new TreeCellDataFunc (RenderAbility));
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
78
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
79 ListStore model = new ListStore (typeof (Ability));
71
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 foreach (Ability ability in unit.UnitType.GetRequiredAbilities ()) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
82 model.AppendValues (ability);
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
83 }
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
84
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
85 abilitiesList.Model = model;
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
86 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
87
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
88 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
89 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
90 object o = model.GetValue (iter, 0);
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
91
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
92 if (o is Ability) {
71
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
93 Ability ability = (Ability)o;
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
94 (cell as CellRendererText).Text = ability.Name;
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
95 }
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
96
91354245218a Fixes #305: Add abilities to GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 68
diff changeset
97 }
60
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
diff changeset
98
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
99 private void SetStats ()
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
100 {
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
101 Stat[][] stats = unit.UnitStatsArraysWithName;
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
102 string[] statsIDs = unit.UnitStatsArrayIDs;
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
103 int statsCount = stats.Length;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
104 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
105
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
106 for (int i = 0; i < statsCount; i++) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
107 NodeView statsGrid = GetStatsView (statsIDs [i]);
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
108 TreeStore model = (TreeStore)statsGrid.Model;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
109 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
110 log.DebugFormat ("TreeStore supports {0} columns", model.NColumns);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
111 model.AppendValues ((object)stats [i]);
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
112 }
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
113 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
114
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
115 private NodeView GetStatsView (string statsID)
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
116 {
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
117 NodeView statsView;
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
118
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
119 if (statsViews.ContainsKey (statsID)) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
120 statsView = DictionaryUtils.GetValue (statsViews, statsID);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
121 } else {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
122 statsView = CreateStatsView (statsID);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
123 statsViews [statsID] = statsView;
13
6b2c8e55564a * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
124 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
126 return statsView;
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
127 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
128
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
129 private NodeView CreateStatsView (string statsID)
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
130 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
131 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
132 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
133 StatSlot[] sysStatSlots = sysStats.StatSlots;
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
134 int statsCount = sysStatSlots.Length;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
135 NodeView statsGrid = CreateNodeView ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
136 CellRendererText renderer = new CellRendererText ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
137 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
138
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
139 for (int i = 0; i < statsCount; i++) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
140 StatSlot stat = sysStatSlots [i];
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
141 string slotName = stat.Name;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
142 statsGrid.AppendColumn (slotName, renderer, RenderUnitStat);
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
143 }
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 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
146 return statsGrid;
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
147 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
148
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
149 private NodeView CreateNodeView ()
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
150 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
151 NodeView nodeView = new NodeView ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
152 statsRepeatBox.Add (nodeView);
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
153 return nodeView;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
154 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
155
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
156 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
157 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
158 object o = model.GetValue (iter, 0);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
159
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
160 if (o is Stat[]) {
73
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
161 Stat[] stats = (Stat[])o;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
162 (cell as CellRendererText).Text = stats [GetStatColumnIndex (column)].SlotValueString;
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
163 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
164 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
165
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
166 private int GetStatColumnIndex (TreeViewColumn column)
73
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
167 {
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
168 int idx = -1;
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
169 TreeViewColumn[] cols = ((TreeView)column.TreeView).Columns;
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
170 int colCount = cols.Length;
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
171
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
172 for (int i = 0; i < colCount; i++) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
173 if (cols [i] == column) {
73
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
174 idx = i;
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
175 break;
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
176 }
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
177 }
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
178
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
179 return idx;
19e7123aafd5 Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 72
diff changeset
180 }
15
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
181
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
182 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
183 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
184 CellRendererText renderer = new CellRendererText ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
185 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
186
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
187 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
188
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
189 foreach (UnitEquipmentItem item in unit.GetEquipment ()) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
190 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
191 }
7bba99c368c8 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 53
diff changeset
192
53
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
193 equipmentList.Model = model;
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
194 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
195
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
196 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
197 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
198 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
199
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
200 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
201 UnitEquipmentItem item = (UnitEquipmentItem)o;
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
202 (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
203 }
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
204
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
205 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
206
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
207 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
208 {
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
209 string translation = "";
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
210
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
211 if (item.Cost == 0) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
212 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
213 } else {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
214 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
215 }
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
216
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
217 return translation;
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
218 }
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
219
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
220 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
221 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
222 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
223 string amountString = "";
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
224
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
225 if (UnitEquipmentUtil.GetEquipmentAmountIsRatio (unit, item)) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
226 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
227
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
228 if (amount == 100) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
229 amountString = Translation.GetTranslation ("equipmentChoiceAmountAll", "all ({1})", amount, number);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
230 } else {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
231 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
232 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
233 } else {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
234 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
235 }
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
236
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
237 return amountString;
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
238 }
28b242612ad7 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 52
diff changeset
239
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
240 public WFObjects.Unit Unit {
15
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
241 get { return unit; }
85db2c9a1546 Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents: 13
diff changeset
242 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
243
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
244 private void UnitNameChanged (WarFoundryObject obj, string oldValue, string newValue)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
245 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
246 unitName.Text = newValue;
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
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
249 private void UnitSizeChanged (WarFoundryObject obj, int oldValue, int newValue)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
250 {
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
251 unitSize.Value = newValue;
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
252 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
253
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
254 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
255 {
91
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
256 if (oldValue == 0)
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
257 {
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
258 ((ListStore)equipmentList.Model).AppendValues(obj);
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
259 }
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
260 else
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
261 {
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
262 if (newValue == 0)
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
263 {
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
264 TreeIter treeIter = TreeUtils.GetItemIter(equipmentList, obj);
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
265 ((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
266 }
91
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
267 }
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
268
91
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
269 SetAddButtonEnabledState();
986fc923c0fa Fixes #331: Equipment buttons should be disabled when options aren't available
IBBoard <dev@ibboard.co.uk>
parents: 77
diff changeset
270 equipmentList.QueueDraw();
59
c3415c6df551 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
271 }
c3415c6df551 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 58
diff changeset
272
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
273 protected virtual void OnUnitSizeFocusOut (object o, Gtk.FocusOutEventArgs args)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
274 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
275 SetNewUnitSize ();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
276 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
277
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
278 [GLib.ConnectBefore ()]
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
279
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
280 protected virtual void OnUnitSizeKeyPress (object o, Gtk.KeyPressEventArgs args)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
281 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
282 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
283 SetNewUnitSize ();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
284 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
285 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
286
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
287 private void SetNewUnitSize ()
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
288 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
289 if (unitSize.Value != unit.Size) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
290 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
291 stack.Execute (cmd);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
292 }
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
293 }
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
294
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
295 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
296 {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
297 SetNewUnitName ();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
298 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
299
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
300 [GLib.ConnectBefore ()]
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
301
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
302 protected virtual void OnUnitNameKeyPress (object o, Gtk.KeyPressEventArgs args)
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
303 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
304 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
305 SetNewUnitName ();
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
306 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
307 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
308
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
309 private void SetNewUnitName ()
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
310 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
311 if (unitName.Text != unit.Name) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
312 SetNameCommand cmd = new SetNameCommand (unit, unitName.Text);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
313 stack.Execute (cmd);
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
314 }
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
315 }
77
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 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
318 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
319 AddEquipment ();
51
dafbd432ca23 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
320 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
321
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
322 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
323 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
324 AddEquipmentUIControl addEquipment = new AddEquipmentUIControl (unit, stack);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
325 addEquipment.Show ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
326 }
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 HandleRemoveButtonActivated (object sender, System.EventArgs e)
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
329 {
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 ("Remove " + item);
60
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
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 SetUnitEquipmentNumericAmountCommand cmd = new SetUnitEquipmentNumericAmountCommand (unit, item, 0);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
335 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
336 }
04c0f6a7625c Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 59
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 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
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 ("Edit " + item);
64
e3fe48c4d794 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 60
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 EditEquipmentUIControl editEquipment = new EditEquipmentUIControl (unit, item, stack);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
346 editEquipment.Show ();
64
e3fe48c4d794 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
347 }
e3fe48c4d794 Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 60
diff changeset
348 }
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
349
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
350 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
351 {
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
352 UnitEquipmentItem item = GetSelectedEquipmentItem ();
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
353 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
354
77
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
355 if (item != null) {
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
356 ReplaceEquipmentUIControl addEquipment = new ReplaceEquipmentUIControl (unit, item, stack);
68804784bf6f Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents: 73
diff changeset
357 addEquipment.Show ();
68
7028e24b67ec Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents: 65
diff changeset
358 }
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
359 }
0
1bb28f84d567 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
360 }
72
f0cc295e883c Re #307: Add support for multiple stat lines
IBBoard <dev@ibboard.co.uk>
parents: 71
diff changeset
361 }