Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate Widgets/UnitDisplayWidget.cs @ 28:9440eef124b0
Closes #69: Add "export" UI
* Add base menu for exports (will be populated automatically once exports are plugins)
* Add menu item for "Basic HTML"
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 01 Sep 2009 19:10:13 +0000 |
parents | a191d0655f55 |
children | a35c8be46006 |
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; | |
29 double max = unit.UnitType.MaxSize; | |
30 | |
31 if (max == -1) | |
32 { | |
33 max = double.MaxValue; | |
34 } | |
35 | |
36 unitSize.SetRange(unit.UnitType.MinSize, max); | |
37 unit.NameChanged+= new StringValChangedDelegate(UnitNameChanged); | |
38 unit.UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChanged); | |
39 SetStats(); | |
13 | 40 } |
41 | |
42 private void SetStats() | |
43 { | |
44 //GameSystem system = unit.Army.GameSystem; | |
0 | 45 //SystemStats stats = system.StandardSystemStats; |
46 CellRendererText renderer = new CellRendererText(); | |
47 unitStats.AppendColumn(Translation.GetTranslation("UnitNameColumn", "Unit Type", null), renderer, new TreeCellDataFunc(RenderUnitName)); | |
48 | |
11
4e5e382fbd2e
Re #10 (Code readability) and Re #86 (Complete GTK# GUI):
IBBoard <dev@ibboard.co.uk>
parents:
5
diff
changeset
|
49 TreeCellDataFunc statFunc = new TreeCellDataFunc(RenderUnitStat); |
13 | 50 Stat[] stats = unit.UnitStatsArray; |
51 | |
52 int length = stats.Length; | |
53 | |
54 for (int i = 0; i < length; i++) | |
0 | 55 { |
13 | 56 unitStats.AppendColumn(stats[i].ParentSlot.Name, renderer, statFunc); |
57 } | |
0 | 58 |
59 TreeStore model = new TreeStore(typeof(IBBoard.WarFoundry.API.Objects.Unit)); | |
13 | 60 model.AppendValues(unit); |
61 unitStats.Model = model; | |
0 | 62 } |
63 | |
64 private void RenderUnitName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | |
65 { | |
66 object o = model.GetValue(iter, 0); | |
67 | |
68 if (o is IBBoard.WarFoundry.API.Objects.Unit) | |
69 { | |
70 IBBoard.WarFoundry.API.Objects.Unit u = (IBBoard.WarFoundry.API.Objects.Unit)o; | |
71 (cell as CellRendererText).Text = u.UnitType.Name; | |
72 } | |
73 } | |
74 | |
75 private void RenderUnitStat(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) | |
76 { | |
77 object o = model.GetValue(iter, 0); | |
78 | |
79 if (o is IBBoard.WarFoundry.API.Objects.Unit) | |
80 { | |
81 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
|
82 (cell as CellRendererText).Text = u.GetStatValue(column.Title); |
0 | 83 } |
84 } | |
15
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
85 |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
86 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
|
87 { |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
88 get { return unit; } |
85db2c9a1546
Fixes #95: Can't re-open GTK# tabs
IBBoard <dev@ibboard.co.uk>
parents:
13
diff
changeset
|
89 } |
0 | 90 |
91 private void UnitNameChanged(WarFoundryObject obj, string oldValue, string newValue) | |
92 { | |
93 unitName.Text = newValue; | |
94 } | |
95 | |
96 private void UnitSizeChanged(WarFoundryObject obj, int oldValue, int newValue) | |
97 { | |
98 unitSize.Value = newValue; | |
99 } | |
100 | |
101 protected virtual void OnUnitSizeFocusOut (object o, Gtk.FocusOutEventArgs args) | |
102 { | |
103 SetNewUnitSize(); | |
104 } | |
105 | |
106 [GLib.ConnectBefore ()] | |
107 protected virtual void OnUnitSizeKeyPress (object o, Gtk.KeyPressEventArgs args) | |
108 { | |
109 if (args.Event.Key == Gdk.Key.Return) | |
110 { | |
111 SetNewUnitSize(); | |
112 } | |
113 } | |
114 | |
115 private void SetNewUnitSize() | |
116 { | |
117 if (unitSize.Value!=unit.Size) | |
118 { | |
119 SetUnitSizeCommand cmd = new SetUnitSizeCommand(unit, (int)Math.Round(unitSize.Value)); | |
120 stack.Execute(cmd); | |
121 } | |
122 } | |
123 | |
124 protected virtual void OnUnitNameFocusOut (object o, Gtk.FocusOutEventArgs args) | |
125 { | |
126 SetNewUnitName(); | |
127 } | |
128 | |
129 [GLib.ConnectBefore ()] | |
130 protected virtual void OnUnitNameKeyPress (object o, Gtk.KeyPressEventArgs args) | |
131 { | |
132 if (args.Event.Key == Gdk.Key.Return) | |
133 { | |
134 SetNewUnitName(); | |
135 } | |
136 } | |
137 | |
138 private void SetNewUnitName() | |
139 { | |
140 if (unitName.Text!=unit.Name) | |
141 { | |
142 SetNameCommand cmd = new SetNameCommand(unit, unitName.Text); | |
143 stack.Execute(cmd); | |
144 } | |
145 } | |
146 } | |
147 } |