1 |
elmex |
1.1 |
package GCE::AttrEdit; |
2 |
|
|
|
3 |
|
|
=head1 NAME |
4 |
|
|
|
5 |
|
|
GCE::AttrEdit - an edit wiget for attributes |
6 |
|
|
|
7 |
|
|
=cut |
8 |
|
|
|
9 |
|
|
use Gtk2; |
10 |
|
|
use Gtk2::Gdk::Keysyms; |
11 |
|
|
use Gtk2::SimpleList; |
12 |
|
|
|
13 |
elmex |
1.19 |
use GCE::Util; |
14 |
elmex |
1.15 |
use GCE::InventoryEditor; |
15 |
elmex |
1.37 |
use GCE::AttachEditor; |
16 |
elmex |
1.15 |
|
17 |
elmex |
1.37 |
use Glib::Object::Subclass |
18 |
|
|
Gtk2::HPaned; |
19 |
elmex |
1.3 |
|
20 |
|
|
use Crossfire; |
21 |
elmex |
1.34 |
use strict; |
22 |
elmex |
1.1 |
|
23 |
elmex |
1.30 |
sub save_layout { |
24 |
|
|
my ($self) = @_; |
25 |
|
|
|
26 |
|
|
$::CFG->{attr_view_hpane_pos} = $self->get_position; |
27 |
elmex |
1.35 |
$::CFG->{attr_view_show_use} = $self->{use_btn}->get_active * 1; |
28 |
elmex |
1.37 |
|
29 |
|
|
$self->{attach_editor}->save_layout |
30 |
|
|
if $self->{attach_editor}; |
31 |
elmex |
1.30 |
} |
32 |
|
|
|
33 |
|
|
sub load_layout { |
34 |
|
|
my ($self) = @_; |
35 |
|
|
|
36 |
elmex |
1.33 |
$self->set_position ($::CFG->{attr_view_hpane_pos} || 350); |
37 |
elmex |
1.35 |
$self->{use_btn}->set_active ($::CFG->{attr_view_show_use} * 1); |
38 |
|
|
|
39 |
|
|
$self->{use_al}->remove ($_) for $self->{use_al}->get_children; |
40 |
|
|
if ($self->{use_btn}->get_active) { |
41 |
|
|
$self->{use_al}->add ($self->{use_lbl}); |
42 |
|
|
$self->{use_lbl}->show; |
43 |
|
|
} |
44 |
elmex |
1.30 |
} |
45 |
|
|
|
46 |
elmex |
1.1 |
sub INIT_INSTANCE { |
47 |
|
|
my ($self) = @_; |
48 |
|
|
|
49 |
elmex |
1.23 |
my $pb = $self->{arch_pb} = new_arch_pb; |
50 |
|
|
|
51 |
elmex |
1.30 |
$self->add (my $topvb = Gtk2::VBox->new); |
52 |
|
|
$topvb->pack_start (my $hb2 = Gtk2::HBox->new, 0, 1, 0); |
53 |
|
|
$hb2->pack_start (my $img = $self->{arch_img} = (new_from_pixbuf Gtk2::Image $pb), 0, 0, 0); |
54 |
|
|
$img->set_alignment (0, 0.5); |
55 |
|
|
|
56 |
|
|
$hb2->pack_start (my $lbl = $self->{arch_name_lbl} = Gtk2::Label->new, 0, 0, 0); |
57 |
|
|
$lbl->set_alignment (0, 0.5); |
58 |
|
|
|
59 |
|
|
$hb2->pack_start (my $defbtn = Gtk2::Button->new ('reset to defaults'), 0, 0, 0); |
60 |
|
|
$defbtn->signal_connect (clicked => sub { |
61 |
elmex |
1.32 |
my $ar = $self->{archref}; |
62 |
|
|
$ar->reset_to_defaults; |
63 |
|
|
#XXXAR $self->set_arch ($arch, $self->{change_cb}); |
64 |
elmex |
1.30 |
}); |
65 |
|
|
|
66 |
elmex |
1.39 |
$hb2->pack_start (my $attbtn = Gtk2::Button->new ('attach (CF+)'), 0, 0, 0); |
67 |
elmex |
1.37 |
$attbtn->signal_connect (clicked => sub { |
68 |
|
|
my $ar = $self->{archref}; |
69 |
|
|
return unless $ar; |
70 |
|
|
unless ($self->{attach_editor}) { |
71 |
|
|
my $w = GCE::AttachEditor->new; |
72 |
|
|
$w->set_attachment ( |
73 |
|
|
$ar->get ('attach'), |
74 |
|
|
sub { |
75 |
|
|
if (@{$_[0]}) { |
76 |
elmex |
1.38 |
$ar->set_silent (attach => $_[0]) |
77 |
elmex |
1.37 |
} else { |
78 |
elmex |
1.38 |
$ar->set_silent (attach => undef) |
79 |
elmex |
1.37 |
} |
80 |
|
|
} |
81 |
|
|
); |
82 |
|
|
$self->{attach_editor} = $w; |
83 |
|
|
$w->signal_connect (destroy => sub { delete $self->{attach_editor} }); |
84 |
|
|
$w->show_all; |
85 |
|
|
} |
86 |
|
|
}); |
87 |
|
|
|
88 |
|
|
|
89 |
elmex |
1.30 |
$topvb->pack_start (my $docal = Gtk2::Alignment->new (0, 0.5, 0, 1), 0, 1, 0); |
90 |
elmex |
1.35 |
$topvb->pack_start (my $usebtn = $self->{use_btn} = Gtk2::ToggleButton->new ('show use'), 0, 1, 0); |
91 |
|
|
$topvb->pack_start (my $useal = $self->{use_al} = Gtk2::Alignment->new (0, 0.5, 0, 1), 0, 1, 0); |
92 |
elmex |
1.30 |
$topvb->pack_start (my $ntbook = $self->{ntbook} = Gtk2::Notebook->new, 1, 1, 0); |
93 |
|
|
$ntbook->set_scrollable (1); |
94 |
|
|
$docal->add ($self->{doc_lbl} = Gtk2::Label->new); |
95 |
|
|
|
96 |
|
|
$usebtn->set_active (0); |
97 |
|
|
$self->{use_lbl} = Gtk2::Label->new; |
98 |
|
|
$usebtn->signal_connect (toggled => sub { |
99 |
|
|
my ($usebtn) = @_; |
100 |
|
|
|
101 |
|
|
$useal->remove ($_) for $useal->get_children; |
102 |
|
|
if ($usebtn->get_active) { |
103 |
|
|
$useal->add ($self->{use_lbl}); |
104 |
|
|
$self->{use_lbl}->show; |
105 |
elmex |
1.24 |
} |
106 |
|
|
}); |
107 |
elmex |
1.30 |
$self->{doc_lbl}->set_line_wrap (1); |
108 |
|
|
$self->{use_lbl}->set_line_wrap (1); |
109 |
elmex |
1.23 |
|
110 |
elmex |
1.30 |
$self->add2 (my $sw = Gtk2::ScrolledWindow->new); |
111 |
|
|
$sw->set_policy ('automatic', 'automatic'); |
112 |
|
|
$sw->add_with_viewport (my $inv = $self->{inv_edit} = GCE::InventoryEditor->new); |
113 |
elmex |
1.3 |
} |
114 |
|
|
|
115 |
elmex |
1.29 |
#sub spawn_editor { |
116 |
|
|
# my ($arch, $cb) = @_; |
117 |
|
|
# |
118 |
|
|
# my $w = Gtk2::Window->new; |
119 |
|
|
# $w->set_title ("gce - edit attrs"); |
120 |
|
|
# $w->add (my $ae = GCE::AttrEdit->new); |
121 |
|
|
# |
122 |
|
|
# main::set_pos_and_size ($w, $main::CFG->{attr_view}, 200, 200); |
123 |
|
|
# |
124 |
|
|
# $ae->set_arch ($arch, $cb); |
125 |
|
|
# $w->set_title ("gce - edit $arch->{_name}"); |
126 |
|
|
# |
127 |
|
|
# $w->show_all; |
128 |
|
|
#} |
129 |
elmex |
1.23 |
|
130 |
elmex |
1.3 |
sub update_arch { |
131 |
elmex |
1.32 |
my ($self, $ar, $key, $value) = @_; |
132 |
|
|
$ar->set ($key, $value); |
133 |
elmex |
1.1 |
} |
134 |
|
|
|
135 |
elmex |
1.5 |
sub set_attr { |
136 |
|
|
my ($self, $key, $value) = @_; |
137 |
|
|
|
138 |
elmex |
1.32 |
my $attr = $self->{archref}->get ($key); |
139 |
elmex |
1.5 |
|
140 |
|
|
unless (ref $attr) { |
141 |
|
|
|
142 |
elmex |
1.32 |
$self->{archref}->set ($key, $value); |
143 |
elmex |
1.5 |
} |
144 |
|
|
} |
145 |
|
|
|
146 |
elmex |
1.29 |
sub get_arch { |
147 |
|
|
my ($self) = @_; |
148 |
|
|
|
149 |
elmex |
1.32 |
$self->{archref} |
150 |
elmex |
1.29 |
} |
151 |
|
|
|
152 |
elmex |
1.32 |
#sub update { |
153 |
|
|
# my ($self, $narch) = @_; |
154 |
|
|
# |
155 |
|
|
# if (ref ($narch) ne 'GCE::ArchRef') { require Carp; Carp::confess ("NO ARCH REF!") } |
156 |
|
|
# |
157 |
|
|
# if ($narch) { |
158 |
|
|
# $self->set_arch ($narch); |
159 |
|
|
# } else { |
160 |
|
|
# $self->set_arch ($self->{archref}); |
161 |
|
|
# } |
162 |
|
|
#} |
163 |
elmex |
1.30 |
|
164 |
elmex |
1.2 |
sub set_arch { |
165 |
elmex |
1.32 |
my ($self, $ar, $clear_inv) = @_; |
166 |
elmex |
1.7 |
|
167 |
elmex |
1.32 |
if ((defined $self->{archref}) && ($self->{archref} != $ar)) { |
168 |
|
|
$self->{archref}->remove_on_change ('attredit') |
169 |
|
|
if defined $self->{archref}; |
170 |
|
|
$ar->add_on_change (attredit => sub { $self->set_arch ($_[0]) }); |
171 |
elmex |
1.38 |
$self->{attach_editor}->destroy if $self->{attach_editor}; |
172 |
elmex |
1.26 |
|
173 |
elmex |
1.32 |
} elsif (not defined $self->{archref}) { |
174 |
|
|
$ar->add_on_change (attredit => sub { $self->set_arch ($_[0]) }); |
175 |
|
|
} |
176 |
elmex |
1.3 |
|
177 |
elmex |
1.32 |
$self->{inv_edit}->clear_inv_hist if $clear_inv; |
178 |
|
|
$self->{inv_edit}->set_arch ($ar); |
179 |
elmex |
1.30 |
|
180 |
elmex |
1.32 |
$self->{archref} = $ar; |
181 |
elmex |
1.21 |
|
182 |
elmex |
1.32 |
$self->{arch_name_lbl}->set_text ($ar->longname); |
183 |
elmex |
1.8 |
|
184 |
elmex |
1.32 |
fill_pb_from_arch ($self->{arch_pb}, $ar->getarch); |
185 |
elmex |
1.23 |
$self->{arch_img}->set_from_pixbuf ($self->{arch_pb}); |
186 |
|
|
|
187 |
elmex |
1.32 |
# get current page (to remember it for later) |
188 |
|
|
my $pgnum = $self->{ntbook}->get_current_page; |
189 |
|
|
my $curwid = $self->{ntbook}->get_nth_page ($pgnum); |
190 |
|
|
my $curpage_text = defined $curwid ? $self->{ntbook}->get_tab_label_text ($curwid) : undef; |
191 |
|
|
|
192 |
|
|
my $al_arch = $ar->archetype; |
193 |
|
|
|
194 |
elmex |
1.18 |
$self->hide; |
195 |
|
|
$self->{ntbook}->remove ($_) |
196 |
|
|
for $self->{ntbook}->get_children; |
197 |
elmex |
1.8 |
|
198 |
elmex |
1.18 |
$self->{ttip} = Gtk2::Tooltips->new; |
199 |
elmex |
1.8 |
|
200 |
elmex |
1.32 |
my $type = $ar->type; |
201 |
|
|
|
202 |
|
|
for my $sec (@{$type->{section}}) { |
203 |
elmex |
1.18 |
my $secname = shift @$sec; |
204 |
elmex |
1.32 |
$self->add_section_edit_widgets ($self->{ntbook}, $secname, $ar, $sec); |
205 |
elmex |
1.18 |
} |
206 |
elmex |
1.8 |
|
207 |
elmex |
1.18 |
for my $key (qw/lore msg/) { |
208 |
|
|
$self->{ntbook}->append_page (my $v = Gtk2::VBox->new, $key); |
209 |
|
|
$v->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0); |
210 |
|
|
$sw->set_policy ('automatic', 'automatic'); |
211 |
|
|
$sw->add (my $tb = $self->{"${key}_txt"} = Gtk2::TextView->new); |
212 |
|
|
my $buf = $tb->get_buffer; |
213 |
elmex |
1.32 |
$buf->set_text ($ar->get ($key)); |
214 |
elmex |
1.20 |
$buf->signal_connect (changed => sub { |
215 |
|
|
my ($buf) = @_; |
216 |
elmex |
1.36 |
my $txt = $buf->get_text ($buf->get_start_iter, $buf->get_end_iter, 0); |
217 |
|
|
if ($txt ne $ar->get ($key)) { |
218 |
|
|
$ar->set_silent ($key, $txt); |
219 |
|
|
} |
220 |
|
|
1 |
221 |
elmex |
1.20 |
}); |
222 |
elmex |
1.18 |
} |
223 |
elmex |
1.15 |
|
224 |
elmex |
1.34 |
my $desc = pseudohtml2txt $type->{desc}; |
225 |
|
|
my $use = pseudohtml2txt $type->{use}; |
226 |
elmex |
1.28 |
$self->{doc_lbl}->set_text ($desc); |
227 |
|
|
$self->{use_lbl}->set_text ($use); |
228 |
elmex |
1.25 |
|
229 |
elmex |
1.18 |
$self->{ttip}->enable; |
230 |
elmex |
1.3 |
|
231 |
elmex |
1.18 |
$self->show_all; |
232 |
elmex |
1.26 |
|
233 |
|
|
# reset the current page if found |
234 |
|
|
# XXX: it's braindamaged: it has to be done AFTER show all for some reason |
235 |
|
|
if (defined $curpage_text) { |
236 |
|
|
|
237 |
|
|
for (my $i = 0; $i <= $self->{ntbook}->get_n_pages; $i++) { |
238 |
|
|
my $w = $self->{ntbook}->get_nth_page ($i); |
239 |
|
|
|
240 |
|
|
if ($w && $self->{ntbook}->get_tab_label_text ($w) eq $curpage_text) { |
241 |
|
|
$self->{ntbook}->set_current_page ($i); |
242 |
|
|
last; |
243 |
|
|
} |
244 |
|
|
} |
245 |
|
|
} |
246 |
elmex |
1.8 |
} |
247 |
|
|
|
248 |
|
|
sub add_section_edit_widgets { |
249 |
elmex |
1.32 |
my ($self, $ntbook, $name, $ar, $section) = @_; |
250 |
elmex |
1.8 |
|
251 |
elmex |
1.13 |
$self->{ntbook}->append_page (my $sw = Gtk2::ScrolledWindow->new, $name); |
252 |
elmex |
1.27 |
$sw->set_policy ('automatic', 'automatic'); |
253 |
elmex |
1.13 |
$sw->add_with_viewport (my $vb = Gtk2::VBox->new); |
254 |
elmex |
1.34 |
$vb->pack_start (my $table = new Gtk2::Table (2, (scalar @$section) + 1), 0, 1, 0); |
255 |
elmex |
1.8 |
|
256 |
|
|
my $i = 0; |
257 |
elmex |
1.11 |
for my $sec (@$section) { |
258 |
elmex |
1.32 |
my ($key, $sec) = ($sec->[0], $sec->[1]); |
259 |
|
|
|
260 |
elmex |
1.28 |
next if grep { $key eq $_ } qw/msg lore/; |
261 |
elmex |
1.32 |
|
262 |
elmex |
1.11 |
my $bwid = Gtk2::EventBox->new; |
263 |
elmex |
1.32 |
$bwid->add (my $al = Gtk2::Alignment->new (0.0, 0.5, 0, 1)); |
264 |
|
|
$al->add (Gtk2::Label->new (def ($sec->{name}, $key))); |
265 |
|
|
|
266 |
elmex |
1.11 |
if ($sec->{desc} !~ m/^\s*$/s) { |
267 |
|
|
$self->{ttip}->set_tip ($bwid, $sec->{desc}); |
268 |
elmex |
1.9 |
} |
269 |
elmex |
1.32 |
|
270 |
elmex |
1.12 |
$table->attach ($bwid, 0, 1, $i, $i + 1, ['shrink','fill'], 'fill', 5, 0); |
271 |
elmex |
1.11 |
|
272 |
|
|
$al = Gtk2::Alignment->new (0.0, 0.5, 1, 0); |
273 |
elmex |
1.32 |
$table->attach ($al, 1, 2, $i, $i + 1, ['expand', 'fill'], 'expand', 0, 0); |
274 |
|
|
$al->add ($self->get_edit_widget ($key, $sec, $ar, $bwid)); |
275 |
|
|
|
276 |
elmex |
1.8 |
$i++; |
277 |
elmex |
1.3 |
} |
278 |
elmex |
1.8 |
} |
279 |
elmex |
1.3 |
|
280 |
elmex |
1.41 |
sub label_set_color { |
281 |
|
|
my ($self, $lbl, $dark) = @_; |
282 |
|
|
if ($dark) { |
283 |
elmex |
1.12 |
for (qw/normal active prelight selected insensitive/) { |
284 |
|
|
$lbl->modify_bg ($_, $lbl->get_default_style->bg ('active')); |
285 |
|
|
$lbl->modify_fg ($_, $lbl->get_default_style->fg ('active')); |
286 |
|
|
} |
287 |
elmex |
1.32 |
|
288 |
elmex |
1.12 |
} else { |
289 |
|
|
for (qw/normal active prelight selected insensitive/) { |
290 |
|
|
$lbl->modify_bg ($_, $lbl->get_default_style->bg ($_)); |
291 |
|
|
} |
292 |
|
|
} |
293 |
elmex |
1.41 |
|
294 |
|
|
} |
295 |
|
|
|
296 |
|
|
sub label_set_color_default { |
297 |
|
|
my ($self, $lbl, $ar, $key, $val) = @_; |
298 |
|
|
require Carp; $ar or Carp::confess ("UNDEF"); |
299 |
|
|
my $al_arch = $ar->archetype; |
300 |
|
|
$self->label_set_color ($lbl, $ar->field_value_is_default ($key, $val)); |
301 |
|
|
|
302 |
elmex |
1.9 |
} |
303 |
|
|
|
304 |
elmex |
1.17 |
# XXX: Warning: Ugly code ahead: |
305 |
elmex |
1.8 |
sub get_edit_widget { |
306 |
elmex |
1.32 |
my ($self, $key, $edspec, $ar, $lbl) = @_; |
307 |
elmex |
1.4 |
|
308 |
elmex |
1.32 |
my $type = $edspec->{type}; |
309 |
|
|
my $al_arch = $ar->archetype; |
310 |
elmex |
1.3 |
|
311 |
elmex |
1.8 |
if ($type eq 'bool') { |
312 |
elmex |
1.19 |
my $boolval = def ($edspec->{value}, [0, 1]); |
313 |
elmex |
1.15 |
|
314 |
elmex |
1.32 |
|
315 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
316 |
|
|
|
317 |
elmex |
1.19 |
my $chk = new Gtk2::CheckButton (def ($edspec->{name}, $key)); |
318 |
elmex |
1.32 |
$chk->set_active ($ar->get_or_default ($key) == $boolval->[1]); |
319 |
|
|
$chk->signal_connect (clicked => sub { |
320 |
|
|
my ($chk) = @_; |
321 |
|
|
|
322 |
|
|
$ar->set_silent ($key, $boolval->[$chk->get_active * 1]); |
323 |
|
|
|
324 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $boolval->[$chk->get_active * 1]); |
325 |
|
|
}); |
326 |
elmex |
1.15 |
|
327 |
elmex |
1.12 |
$self->{ttip}->set_tip ($chk, $al_arch->{$key} * 1); |
328 |
elmex |
1.15 |
|
329 |
elmex |
1.8 |
return $chk |
330 |
|
|
|
331 |
|
|
} elsif (grep { $type eq $_ } qw/string int treasurelist float/) { |
332 |
elmex |
1.32 |
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
333 |
|
|
|
334 |
elmex |
1.8 |
my $entry = new Gtk2::Entry; |
335 |
elmex |
1.32 |
$entry->set_text ($ar->get_or_default ($key)); |
336 |
|
|
$entry->signal_connect (changed => sub { |
337 |
|
|
my ($entry) = @_; |
338 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $entry->get_text); |
339 |
|
|
$ar->set_silent ($key, $entry->get_text); |
340 |
|
|
1 |
341 |
|
|
}); |
342 |
|
|
|
343 |
|
|
$self->{ttip}->set_tip ($entry, $ar->archetype->{$key}); |
344 |
|
|
|
345 |
elmex |
1.8 |
return $entry |
346 |
|
|
|
347 |
|
|
} elsif ($type eq 'spell' or $type eq 'nz_spell') { # XXX: nz_spell bug in datafiles? |
348 |
|
|
my $comb = Gtk2::ComboBox->new_text; |
349 |
|
|
my $spells_idx = {}; |
350 |
elmex |
1.34 |
my $spells_cmd_idx = {}; |
351 |
elmex |
1.8 |
my $sp = \%Crossfire::Data::SPELL; |
352 |
|
|
|
353 |
|
|
$comb->append_text ("<none>"); |
354 |
|
|
|
355 |
|
|
my $idx = 1; # XXX: replace this idx with a more save/correct method? |
356 |
|
|
for (sort { $sp->{$a} cmp $sp->{$b} } keys %$sp) { |
357 |
elmex |
1.34 |
$spells_cmd_idx->{$idx} = $_; |
358 |
|
|
$spells_idx->{$_} = $idx++; |
359 |
elmex |
1.8 |
|
360 |
|
|
$comb->append_text ($sp->{$_}); |
361 |
|
|
} |
362 |
elmex |
1.12 |
#XXX: FIXME: $self->{ttip}->set_tip ($comb, $sp->{$al_arch->{$key}}); |
363 |
elmex |
1.32 |
|
364 |
elmex |
1.34 |
$comb->set_active ($spells_idx->{$ar->get_or_default ($key)}); |
365 |
elmex |
1.32 |
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
366 |
elmex |
1.8 |
|
367 |
|
|
$comb->signal_connect (changed => sub { |
368 |
|
|
my ($comb) = @_; |
369 |
elmex |
1.34 |
$self->label_set_color_default ($lbl, $ar, $key, $spells_cmd_idx->{$comb->get_active}); |
370 |
|
|
$ar->set_silent ($key, $spells_cmd_idx->{$comb->get_active}); |
371 |
elmex |
1.8 |
}); |
372 |
|
|
return $comb |
373 |
elmex |
1.3 |
|
374 |
elmex |
1.14 |
} elsif ($type eq 'bitmask') { |
375 |
elmex |
1.32 |
my $chval = $ar->get_or_default ($key); |
376 |
elmex |
1.14 |
my $btn = Gtk2::Button->new; |
377 |
elmex |
1.32 |
$btn->add (my $lblb = Gtk2::Label->new ("bitmask: " . ($chval * 1))); |
378 |
elmex |
1.14 |
$self->{ttip}->set_tip ($btn, $al_arch->{$key}); |
379 |
|
|
|
380 |
elmex |
1.32 |
my $menu = $self->create_bitmask_menu ($edspec->{value}, $lbl, $lblb, $ar, $key, \$chval); |
381 |
|
|
|
382 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $chval); |
383 |
elmex |
1.14 |
|
384 |
|
|
$btn->signal_connect (button_press_event => sub { |
385 |
|
|
my ($btn, $ev) = @_; |
386 |
|
|
$menu->popup (undef, undef, undef, undef, $ev->button, 0); |
387 |
|
|
}); |
388 |
elmex |
1.32 |
|
389 |
elmex |
1.14 |
return $btn; |
390 |
|
|
|
391 |
|
|
} elsif ($type eq 'list') { |
392 |
elmex |
1.32 |
my $lblb = Gtk2::Label->new ($edspec->{value}->{$ar->get_or_default ($key) * 1}); |
393 |
elmex |
1.14 |
my $btn = Gtk2::Button->new; |
394 |
|
|
$self->{ttip}->set_tip ($btn, $edspec->{value}->{$al_arch->{$key}}); |
395 |
|
|
$btn->add ($lblb); |
396 |
elmex |
1.32 |
my $menu = $self->create_list_menu ($edspec->{value}, $lbl, $lblb, $ar, $key); |
397 |
elmex |
1.14 |
|
398 |
elmex |
1.32 |
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
399 |
elmex |
1.14 |
|
400 |
|
|
$btn->signal_connect (button_press_event => sub { |
401 |
|
|
my ($btn, $ev) = @_; |
402 |
|
|
$menu->popup (undef, undef, undef, undef, $ev->button, 0); |
403 |
|
|
}); |
404 |
|
|
return $btn; |
405 |
|
|
|
406 |
elmex |
1.8 |
} elsif ($type eq 'fixed') { |
407 |
|
|
return Gtk2::Label->new ("$edspec->{name} = $edspec->{value}"); |
408 |
elmex |
1.3 |
|
409 |
elmex |
1.9 |
} elsif ($type eq 'text') { |
410 |
elmex |
1.20 |
return Gtk2::Label->new ("<see $key tab>"); |
411 |
elmex |
1.9 |
|
412 |
elmex |
1.41 |
} elsif ($type eq 'movement_type') { # ok... this is quite a big one... awww |
413 |
|
|
my $v = Gtk2::VBox->new; |
414 |
|
|
my $btns1 = Gtk2::HButtonBox->new; |
415 |
|
|
my $btns2 = Gtk2::HButtonBox->new; |
416 |
|
|
$btns1->set_layout ('start'); |
417 |
|
|
$btns2->set_layout ('start'); |
418 |
|
|
|
419 |
|
|
$v->pack_start ($btns1, 0, 1, 0); |
420 |
|
|
$v->pack_start ($btns2, 0, 1, 0); |
421 |
|
|
|
422 |
|
|
my @lblbtns; |
423 |
|
|
my $calc_lbl = sub { # update callback for the buttons |
424 |
|
|
for (@lblbtns) { |
425 |
|
|
my $btn = $_->[0]; |
426 |
|
|
my $lbl = $_->[1]; |
427 |
|
|
|
428 |
|
|
if (defined $ar->get ($key)) { |
429 |
|
|
my $res = $ar->get ($key) >= $lbl; |
430 |
|
|
|
431 |
|
|
if (defined $res) { |
432 |
|
|
$self->label_set_color ($btn, 0); |
433 |
|
|
$lbl = ($res ? "+" : "-") . $lbl; |
434 |
|
|
|
435 |
|
|
} else { |
436 |
|
|
$self->label_set_color ($btn, 1); |
437 |
|
|
$lbl = "$lbl?"; |
438 |
|
|
} |
439 |
|
|
} else { |
440 |
|
|
$self->label_set_color ($btn, 1); |
441 |
|
|
$lbl = "$lbl?"; |
442 |
|
|
} |
443 |
|
|
|
444 |
|
|
$btn->set_label ($lbl); |
445 |
|
|
} |
446 |
|
|
}; |
447 |
|
|
|
448 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
449 |
|
|
|
450 |
|
|
my $mid = (scalar @Crossfire::MOVE_TYPE) / 2; |
451 |
|
|
my $cnt = 0; |
452 |
|
|
my $box = $btns1; |
453 |
|
|
|
454 |
elmex |
1.40 |
for my $mty (@Crossfire::MOVE_TYPE) { |
455 |
elmex |
1.41 |
$box->pack_start (my $btn = Gtk2::Button->new ($calc_lbl->()), 0, 1, 0); |
456 |
|
|
push @lblbtns, [$btn, $mty]; |
457 |
|
|
|
458 |
|
|
$self->{ttip}->set_tip ($btn, $ar->archetype->{$key}); |
459 |
|
|
$btn->signal_connect (clicked => sub { |
460 |
|
|
my $v = $ar->get ($key) || Crossfire::MoveType->new; |
461 |
|
|
|
462 |
|
|
$v x= $mty; |
463 |
|
|
$v = $v eq '' ? undef : $v; |
464 |
|
|
$ar->set_silent ($key, $v); |
465 |
|
|
|
466 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $v); |
467 |
|
|
$calc_lbl->(); |
468 |
|
|
}); |
469 |
|
|
|
470 |
|
|
if (++$cnt >= $mid) { $box = $btns2 } # for wrapping into the second button box |
471 |
elmex |
1.40 |
} |
472 |
elmex |
1.41 |
$calc_lbl->(); |
473 |
|
|
|
474 |
|
|
return $v; |
475 |
elmex |
1.40 |
|
476 |
elmex |
1.3 |
} else { |
477 |
elmex |
1.8 |
return Gtk2::Label->new ("$key => $edspec->{name} ($type)"); |
478 |
elmex |
1.2 |
|
479 |
elmex |
1.3 |
} |
480 |
elmex |
1.2 |
} |
481 |
|
|
|
482 |
elmex |
1.14 |
sub bitmask_to_list { |
483 |
|
|
my ($self, $bitlist, $bits) = @_; |
484 |
|
|
|
485 |
|
|
my @l; |
486 |
|
|
for (%$bitlist) { |
487 |
|
|
if ($bits & (1 << $_)) { |
488 |
|
|
push @l, $bitlist->{$_}; |
489 |
|
|
} |
490 |
|
|
} |
491 |
|
|
return @l; |
492 |
|
|
} |
493 |
|
|
|
494 |
|
|
sub create_list_menu { |
495 |
elmex |
1.32 |
my ($self, $list, $clbl, $lbl, $ar, $key) = @_; |
496 |
elmex |
1.14 |
|
497 |
|
|
my $menu = Gtk2::Menu->new; |
498 |
|
|
|
499 |
|
|
for my $item (sort keys %$list) { |
500 |
|
|
my $lbltxt = $list->{$item}; |
501 |
|
|
my $menuitem = Gtk2::MenuItem->new_with_label ($lbltxt); |
502 |
|
|
$menuitem->signal_connect (activate => sub { |
503 |
|
|
my ($menuitem) = @_; |
504 |
|
|
$lbl->set_text ($list->{$item}); |
505 |
elmex |
1.32 |
$self->label_set_color_default ($clbl, $ar, $key, $item); |
506 |
|
|
$ar->set_silent ($key, $item); |
507 |
elmex |
1.14 |
}); |
508 |
|
|
$menu->append ($menuitem); |
509 |
|
|
$menuitem->show; |
510 |
|
|
} |
511 |
|
|
|
512 |
|
|
return $menu; |
513 |
|
|
} |
514 |
|
|
|
515 |
|
|
sub create_bitmask_menu { |
516 |
elmex |
1.32 |
my ($self, $bits, $clbl, $lbl, $ar, $key, $rval) = @_; |
517 |
elmex |
1.14 |
|
518 |
|
|
my $menu = Gtk2::Menu->new; |
519 |
|
|
|
520 |
elmex |
1.29 |
for my $bit (sort { $a <=> $b } keys %$bits) { |
521 |
elmex |
1.14 |
my $lbltxt = $bits->{$bit}; |
522 |
|
|
my $menuitem = Gtk2::CheckMenuItem->new_with_label ($lbltxt); |
523 |
elmex |
1.15 |
if ($$rval & (1 << $bit)) { |
524 |
elmex |
1.14 |
$menuitem->set_active (1);#$arch->{$key} & (1 << $bit)); |
525 |
|
|
} |
526 |
|
|
$menuitem->signal_connect (toggled => sub { |
527 |
|
|
my ($menuitem) = @_; |
528 |
elmex |
1.32 |
my $newval = $ar->get ($key); |
529 |
elmex |
1.15 |
$$rval &= ~(1 << $bit); |
530 |
|
|
$$rval |= (1 << $bit) if $menuitem->get_active; |
531 |
|
|
$lbl->set_text ("bitmask: " . ($$rval * 1)); |
532 |
elmex |
1.32 |
$self->label_set_color_default ($clbl, $ar, $key, $$rval); |
533 |
|
|
$ar->set_silent ($key, $$rval); |
534 |
elmex |
1.14 |
}); |
535 |
|
|
$menu->append ($menuitem); |
536 |
|
|
$menuitem->show; |
537 |
|
|
} |
538 |
|
|
|
539 |
|
|
return $menu; |
540 |
|
|
} |
541 |
|
|
|
542 |
elmex |
1.1 |
|
543 |
|
|
=head1 AUTHOR |
544 |
|
|
|
545 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
546 |
|
|
http://home.schmorp.de/ |
547 |
|
|
|
548 |
|
|
Robin Redeker <elmex@ta-sa.org> |
549 |
|
|
http://www.ta-sa.org/ |
550 |
|
|
|
551 |
|
|
=cut |
552 |
|
|
1; |