Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate Widgets/UnitDisplayWidget.cs @ 49:d29ad8445461
Re #86: Complete GTK# UI
* Make keypad "enter" work for confirming unit name
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 15 Aug 2010 15:57:25 +0000 |
parents | 23238d998535 |
children | dafbd432ca23 |
rev | line source |
---|---|
19
a191d0655f55
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
1 // This file (UnitDisplayWidget.cs) is a part of the IBBoard.WarFoundry.GTK project and is copyright 2008, 2009 IBBoard. |
0 | 2 // |
19
a191d0655f55
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
0 | 4 |
5 using System; | |
6 using Gtk; | |
7 using IBBoard.Commands; | |
8 using IBBoard.Lang; | |
9 using IBBoard.WarFoundry.API; | |
10 using IBBoard.WarFoundry.API.Objects; | |
11 using IBBoard.WarFoundry.API.Commands; | |
12 | |
5 | 13 namespace IBBoard.WarFoundry.GTK.Widgets |
0 | 14 { |
5 | 15 [System.ComponentModel.Category("WarFoundry GTK# GUI")] |
16 [System.ComponentModel.ToolboxItem(true)] | |
0 | 17 public partial class UnitDisplayWidget : Gtk.Bin |
18 { | |
19 private IBBoard.WarFoundry.API.Objects.Unit unit; | |
20 private CommandStack stack; | |
21 | |
22 public UnitDisplayWidget(IBBoard.WarFoundry.API.Objects.Unit sourceUnit, CommandStack commandStack) | |
23 { | |
24 this.Build(); | |
25 stack = commandStack; | |
26 unit = sourceUnit; | |
27 unitName.Text = unit.Name; | |
28 unitSize.Value = unit.Size; | |
48
23238d998535
Re #86: Complete initial GTK# UI
IBBoard <dev@ibboard.co.uk>
parents:
34
diff
changeset
|
29 notesView.Buffer.Text = unit.UnitType.Notes; |
0 | 30 double max = unit.UnitType.MaxSize; |
31 | |
32 if (max == -1) | |
33 { | |
34 max = double.MaxValue; | |
35 } | |
36 | |
37 unitSize.SetRange(unit.UnitType.MinSize, max); | |
38 unit.NameChanged+= new StringValChangedDelegate(UnitNameChanged); | |
39 unit.UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChanged); | |
40 SetStats(); | |
13 | 41 } |
42 | |
43 private void SetStats() | |
44 { | |
45 //GameSystem system = unit.Army.GameSystem; | |
0 | 46 //SystemStats stats = system.StandardSystemStats; |
47 CellRendererText renderer = new CellRendererText(); | |
48 unitStats.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, new TreeCellDataFunc(RenderUnitName)); | |
49 | |
11
4e5e382fbd2e
Re #10 (Code readability) and Re #86 (Complete GTK# GUI):
IBBoard <dev@ibboard.co.uk>
parents:
5
diff
changeset
|
50 TreeCellDataFunc statFunc = new TreeCellDataFunc(RenderUnitStat); |
13 | 51 Stat[] stats = unit.UnitStatsArray; |
52 | |
53 int length = stats.Length; | |
54 | |
55 for (int i = 0; i < length; i++) | |
0 | 56 { |
34
a35c8be46006
Re #198: Add unit equipment slots
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
57 unitStats.AppendColumn(stats[i].ParentSlotName, renderer, statFunc); |
13 | 58 } |
0 | 59 |
60 TreeStore model = new TreeStore(typeof(IBBoard.WarFoundry.API.Objects.Unit)); | |
13 | 61 model.AppendValues(unit); |
62 unitStats.Model = model; | |
0 | 63 } |
64 | |
65 private void RenderUnitName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | |
66 { | |
67 object o = model.GetValue(iter, 0); | |
68 | |
69 if (o is IBBoard.WarFoundry.API.Objects.Unit) | |
70 { | |
71 IBBoard.WarFoundry.API.Objects.Unit u = (IBBoard.WarFoundry.API.Objects.Unit)o; | |
72 (cell as CellRendererText).Text = u.UnitType.Name; | |
73 } | |
74 } | |
75 | |
76 private void RenderUnitStat(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | |
77 { | |
78 object o = model.GetValue(iter, 0); | |
79 | |
80 if (o is IBBoard.WarFoundry.API.Objects.Unit) | |
81 { | |
82 IBBoard.WarFoundry.API.Objects.Unit u = (IBBoard.WarFoundry.API.Objects.Unit)o; | |
11
4e5e382fbd2e
Re #10 (Code readability) and Re #86 (Complete GTK# GUI):
IBBoard <dev@ibboard.co.uk>
parents:
5
diff
changeset
|
83 (cell as CellRendererText).Text = u.GetStatValue(column.Title); |
0 | 84 } |
85 } | |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
86 |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
87 public IBBoard.WarFoundry.API.Objects.Unit Unit |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
88 { |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
89 get { return unit; } |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
90 } |
0 | 91 |
92 private void UnitNameChanged(WarFoundryObject obj, string oldValue, string newValue) | |
93 { | |
94 unitName.Text = newValue; | |
95 } | |
96 | |
97 private void UnitSizeChanged(WarFoundryObject obj, int oldValue, int newValue) | |
98 { | |
99 unitSize.Value = newValue; | |
100 } | |
101 | |
102 protected virtual void OnUnitSizeFocusOut (object o, Gtk.FocusOutEventArgs args) | |
103 { | |
104 SetNewUnitSize(); | |
105 } | |
106 | |
107 [GLib.ConnectBefore ()] | |
108 protected virtual void OnUnitSizeKeyPress (object o, Gtk.KeyPressEventArgs args) | |
109 { | |
110 if (args.Event.Key == Gdk.Key.Return) | |
111 { | |
112 SetNewUnitSize(); | |
113 } | |
114 } | |
115 | |
116 private void SetNewUnitSize() | |
117 { | |
118 if (unitSize.Value!=unit.Size) | |
119 { | |
120 SetUnitSizeCommand cmd = new SetUnitSizeCommand(unit, (int)Math.Round(unitSize.Value)); | |
121 stack.Execute(cmd); | |
122 } | |
123 } | |
124 | |
125 protected virtual void OnUnitNameFocusOut (object o, Gtk.FocusOutEventArgs args) | |
126 { | |
127 SetNewUnitName(); | |
128 } | |
129 | |
130 [GLib.ConnectBefore ()] | |
131 protected virtual void OnUnitNameKeyPress (object o, Gtk.KeyPressEventArgs args) | |
132 { | |
49 | 133 if (args.Event.Key == Gdk.Key.Return || args.Event.Key == Gdk.Key.KP_Enter) |
0 | 134 { |
135 SetNewUnitName(); | |
136 } | |
137 } | |
138 | |
139 private void SetNewUnitName() | |
140 { | |
141 if (unitName.Text!=unit.Name) | |
142 { | |
143 SetNameCommand cmd = new SetNameCommand(unit, unitName.Text); | |
144 stack.Execute(cmd); | |
145 } | |
146 } | |
147 } | |
148 } |