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