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 |
elmex |
1.50 |
use AnyEvent::EditText; |
21 |
|
|
|
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 |
|
|
$ar->get ('attach'), |
72 |
|
|
sub { |
73 |
|
|
if (@{$_[0]}) { |
74 |
|
|
$ar->set_silent (attach => $_[0]) |
75 |
|
|
} else { |
76 |
|
|
$ar->set_silent (attach => undef) |
77 |
|
|
} |
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.3 |
} |
123 |
|
|
|
124 |
elmex |
1.29 |
#sub spawn_editor { |
125 |
|
|
# my ($arch, $cb) = @_; |
126 |
|
|
# |
127 |
|
|
# my $w = Gtk2::Window->new; |
128 |
|
|
# $w->set_title ("gce - edit attrs"); |
129 |
|
|
# $w->add (my $ae = GCE::AttrEdit->new); |
130 |
|
|
# |
131 |
|
|
# main::set_pos_and_size ($w, $main::CFG->{attr_view}, 200, 200); |
132 |
|
|
# |
133 |
|
|
# $ae->set_arch ($arch, $cb); |
134 |
|
|
# $w->set_title ("gce - edit $arch->{_name}"); |
135 |
|
|
# |
136 |
|
|
# $w->show_all; |
137 |
|
|
#} |
138 |
elmex |
1.23 |
|
139 |
elmex |
1.3 |
sub update_arch { |
140 |
elmex |
1.32 |
my ($self, $ar, $key, $value) = @_; |
141 |
|
|
$ar->set ($key, $value); |
142 |
elmex |
1.1 |
} |
143 |
|
|
|
144 |
elmex |
1.5 |
sub set_attr { |
145 |
|
|
my ($self, $key, $value) = @_; |
146 |
|
|
|
147 |
elmex |
1.32 |
my $attr = $self->{archref}->get ($key); |
148 |
elmex |
1.5 |
|
149 |
|
|
unless (ref $attr) { |
150 |
|
|
|
151 |
elmex |
1.32 |
$self->{archref}->set ($key, $value); |
152 |
elmex |
1.5 |
} |
153 |
|
|
} |
154 |
|
|
|
155 |
elmex |
1.29 |
sub get_arch { |
156 |
|
|
my ($self) = @_; |
157 |
|
|
|
158 |
elmex |
1.32 |
$self->{archref} |
159 |
elmex |
1.29 |
} |
160 |
|
|
|
161 |
elmex |
1.32 |
#sub update { |
162 |
|
|
# my ($self, $narch) = @_; |
163 |
|
|
# |
164 |
|
|
# if (ref ($narch) ne 'GCE::ArchRef') { require Carp; Carp::confess ("NO ARCH REF!") } |
165 |
|
|
# |
166 |
|
|
# if ($narch) { |
167 |
|
|
# $self->set_arch ($narch); |
168 |
|
|
# } else { |
169 |
|
|
# $self->set_arch ($self->{archref}); |
170 |
|
|
# } |
171 |
|
|
#} |
172 |
elmex |
1.30 |
|
173 |
elmex |
1.2 |
sub set_arch { |
174 |
elmex |
1.32 |
my ($self, $ar, $clear_inv) = @_; |
175 |
elmex |
1.7 |
|
176 |
elmex |
1.32 |
if ((defined $self->{archref}) && ($self->{archref} != $ar)) { |
177 |
|
|
$self->{archref}->remove_on_change ('attredit') |
178 |
|
|
if defined $self->{archref}; |
179 |
|
|
$ar->add_on_change (attredit => sub { $self->set_arch ($_[0]) }); |
180 |
elmex |
1.38 |
$self->{attach_editor}->destroy if $self->{attach_editor}; |
181 |
elmex |
1.26 |
|
182 |
elmex |
1.32 |
} elsif (not defined $self->{archref}) { |
183 |
|
|
$ar->add_on_change (attredit => sub { $self->set_arch ($_[0]) }); |
184 |
|
|
} |
185 |
elmex |
1.3 |
|
186 |
elmex |
1.32 |
$self->{inv_edit}->clear_inv_hist if $clear_inv; |
187 |
|
|
$self->{inv_edit}->set_arch ($ar); |
188 |
elmex |
1.30 |
|
189 |
elmex |
1.32 |
$self->{archref} = $ar; |
190 |
elmex |
1.21 |
|
191 |
elmex |
1.32 |
$self->{arch_name_lbl}->set_text ($ar->longname); |
192 |
elmex |
1.8 |
|
193 |
elmex |
1.32 |
fill_pb_from_arch ($self->{arch_pb}, $ar->getarch); |
194 |
elmex |
1.23 |
$self->{arch_img}->set_from_pixbuf ($self->{arch_pb}); |
195 |
elmex |
1.43 |
$self->label_set_color ($self->{arch_name_lbl}, 0); |
196 |
|
|
|
197 |
|
|
$self->{arch_stat_btn}->set_label ($ar->{source}); |
198 |
elmex |
1.23 |
|
199 |
elmex |
1.32 |
# get current page (to remember it for later) |
200 |
|
|
my $pgnum = $self->{ntbook}->get_current_page; |
201 |
|
|
my $curwid = $self->{ntbook}->get_nth_page ($pgnum); |
202 |
elmex |
1.44 |
my $curpage_text = |
203 |
|
|
defined $curwid |
204 |
|
|
? $self->{ntbook}->get_tab_label_text ($curwid) |
205 |
|
|
: undef; |
206 |
elmex |
1.32 |
|
207 |
|
|
my $al_arch = $ar->archetype; |
208 |
|
|
|
209 |
elmex |
1.18 |
$self->hide; |
210 |
|
|
$self->{ntbook}->remove ($_) |
211 |
|
|
for $self->{ntbook}->get_children; |
212 |
elmex |
1.8 |
|
213 |
elmex |
1.18 |
$self->{ttip} = Gtk2::Tooltips->new; |
214 |
elmex |
1.8 |
|
215 |
elmex |
1.32 |
my $type = $ar->type; |
216 |
|
|
|
217 |
|
|
for my $sec (@{$type->{section}}) { |
218 |
elmex |
1.18 |
my $secname = shift @$sec; |
219 |
elmex |
1.32 |
$self->add_section_edit_widgets ($self->{ntbook}, $secname, $ar, $sec); |
220 |
elmex |
1.18 |
} |
221 |
elmex |
1.8 |
|
222 |
elmex |
1.18 |
for my $key (qw/lore msg/) { |
223 |
elmex |
1.50 |
|
224 |
elmex |
1.18 |
$self->{ntbook}->append_page (my $v = Gtk2::VBox->new, $key); |
225 |
elmex |
1.50 |
$v->pack_start (my $ed = Gtk2::Button->new ("Open Editor"), 0, 1, 0); |
226 |
elmex |
1.18 |
$v->pack_start (my $sw = Gtk2::ScrolledWindow->new, 1, 1, 0); |
227 |
|
|
$sw->set_policy ('automatic', 'automatic'); |
228 |
|
|
$sw->add (my $tb = $self->{"${key}_txt"} = Gtk2::TextView->new); |
229 |
elmex |
1.50 |
|
230 |
|
|
my $change_field = sub { |
231 |
|
|
my ($txt) = @_; |
232 |
|
|
|
233 |
|
|
my $buf = $tb->get_buffer; |
234 |
|
|
|
235 |
|
|
my $old_txt = $buf->get_text ($buf->get_start_iter, $buf->get_end_iter, 0); |
236 |
|
|
$txt = $old_txt unless defined $txt; |
237 |
|
|
|
238 |
|
|
$ar->set_silent ($key, $txt) |
239 |
|
|
if $txt ne $ar->get ($key); |
240 |
|
|
$buf->set_text ($txt) |
241 |
|
|
if $txt ne $old_txt; |
242 |
|
|
}; |
243 |
|
|
|
244 |
elmex |
1.18 |
my $buf = $tb->get_buffer; |
245 |
elmex |
1.50 |
$change_field->($ar->get ($key)); |
246 |
elmex |
1.20 |
$buf->signal_connect (changed => sub { |
247 |
elmex |
1.50 |
$change_field->(); |
248 |
elmex |
1.36 |
1 |
249 |
elmex |
1.20 |
}); |
250 |
elmex |
1.50 |
|
251 |
|
|
$ed->signal_connect (clicked => sub { |
252 |
|
|
AnyEvent::EditText::edit ($ar->get ($key), sub { |
253 |
|
|
my ($new, $change) = @_; |
254 |
|
|
|
255 |
|
|
$change_field->($new) |
256 |
|
|
if $change; |
257 |
|
|
}); |
258 |
|
|
}); |
259 |
elmex |
1.18 |
} |
260 |
elmex |
1.15 |
|
261 |
elmex |
1.34 |
my $desc = pseudohtml2txt $type->{desc}; |
262 |
|
|
my $use = pseudohtml2txt $type->{use}; |
263 |
elmex |
1.28 |
$self->{doc_lbl}->set_text ($desc); |
264 |
|
|
$self->{use_lbl}->set_text ($use); |
265 |
elmex |
1.25 |
|
266 |
elmex |
1.18 |
$self->{ttip}->enable; |
267 |
elmex |
1.3 |
|
268 |
elmex |
1.18 |
$self->show_all; |
269 |
elmex |
1.26 |
|
270 |
|
|
# reset the current page if found |
271 |
|
|
# XXX: it's braindamaged: it has to be done AFTER show all for some reason |
272 |
|
|
if (defined $curpage_text) { |
273 |
|
|
|
274 |
|
|
for (my $i = 0; $i <= $self->{ntbook}->get_n_pages; $i++) { |
275 |
|
|
my $w = $self->{ntbook}->get_nth_page ($i); |
276 |
|
|
|
277 |
|
|
if ($w && $self->{ntbook}->get_tab_label_text ($w) eq $curpage_text) { |
278 |
|
|
$self->{ntbook}->set_current_page ($i); |
279 |
|
|
last; |
280 |
|
|
} |
281 |
|
|
} |
282 |
|
|
} |
283 |
elmex |
1.8 |
} |
284 |
|
|
|
285 |
|
|
sub add_section_edit_widgets { |
286 |
elmex |
1.32 |
my ($self, $ntbook, $name, $ar, $section) = @_; |
287 |
elmex |
1.8 |
|
288 |
elmex |
1.13 |
$self->{ntbook}->append_page (my $sw = Gtk2::ScrolledWindow->new, $name); |
289 |
elmex |
1.27 |
$sw->set_policy ('automatic', 'automatic'); |
290 |
elmex |
1.13 |
$sw->add_with_viewport (my $vb = Gtk2::VBox->new); |
291 |
elmex |
1.34 |
$vb->pack_start (my $table = new Gtk2::Table (2, (scalar @$section) + 1), 0, 1, 0); |
292 |
elmex |
1.8 |
|
293 |
|
|
my $i = 0; |
294 |
elmex |
1.11 |
for my $sec (@$section) { |
295 |
elmex |
1.32 |
my ($key, $sec) = ($sec->[0], $sec->[1]); |
296 |
|
|
|
297 |
elmex |
1.28 |
next if grep { $key eq $_ } qw/msg lore/; |
298 |
elmex |
1.32 |
|
299 |
elmex |
1.11 |
my $bwid = Gtk2::EventBox->new; |
300 |
elmex |
1.32 |
$bwid->add (my $al = Gtk2::Alignment->new (0.0, 0.5, 0, 1)); |
301 |
|
|
$al->add (Gtk2::Label->new (def ($sec->{name}, $key))); |
302 |
|
|
|
303 |
elmex |
1.11 |
if ($sec->{desc} !~ m/^\s*$/s) { |
304 |
|
|
$self->{ttip}->set_tip ($bwid, $sec->{desc}); |
305 |
elmex |
1.9 |
} |
306 |
elmex |
1.32 |
|
307 |
elmex |
1.12 |
$table->attach ($bwid, 0, 1, $i, $i + 1, ['shrink','fill'], 'fill', 5, 0); |
308 |
elmex |
1.11 |
|
309 |
|
|
$al = Gtk2::Alignment->new (0.0, 0.5, 1, 0); |
310 |
elmex |
1.32 |
$table->attach ($al, 1, 2, $i, $i + 1, ['expand', 'fill'], 'expand', 0, 0); |
311 |
|
|
$al->add ($self->get_edit_widget ($key, $sec, $ar, $bwid)); |
312 |
|
|
|
313 |
elmex |
1.8 |
$i++; |
314 |
elmex |
1.3 |
} |
315 |
elmex |
1.8 |
} |
316 |
elmex |
1.3 |
|
317 |
elmex |
1.41 |
sub label_set_color { |
318 |
|
|
my ($self, $lbl, $dark) = @_; |
319 |
|
|
if ($dark) { |
320 |
elmex |
1.12 |
for (qw/normal active prelight selected insensitive/) { |
321 |
|
|
$lbl->modify_bg ($_, $lbl->get_default_style->bg ('active')); |
322 |
|
|
$lbl->modify_fg ($_, $lbl->get_default_style->fg ('active')); |
323 |
|
|
} |
324 |
elmex |
1.32 |
|
325 |
elmex |
1.12 |
} else { |
326 |
|
|
for (qw/normal active prelight selected insensitive/) { |
327 |
|
|
$lbl->modify_bg ($_, $lbl->get_default_style->bg ($_)); |
328 |
|
|
} |
329 |
|
|
} |
330 |
elmex |
1.41 |
|
331 |
|
|
} |
332 |
|
|
|
333 |
|
|
sub label_set_color_default { |
334 |
|
|
my ($self, $lbl, $ar, $key, $val) = @_; |
335 |
|
|
require Carp; $ar or Carp::confess ("UNDEF"); |
336 |
|
|
my $al_arch = $ar->archetype; |
337 |
|
|
$self->label_set_color ($lbl, $ar->field_value_is_default ($key, $val)); |
338 |
|
|
|
339 |
elmex |
1.9 |
} |
340 |
|
|
|
341 |
elmex |
1.17 |
# XXX: Warning: Ugly code ahead: |
342 |
elmex |
1.8 |
sub get_edit_widget { |
343 |
elmex |
1.32 |
my ($self, $key, $edspec, $ar, $lbl) = @_; |
344 |
elmex |
1.4 |
|
345 |
elmex |
1.32 |
my $type = $edspec->{type}; |
346 |
|
|
my $al_arch = $ar->archetype; |
347 |
elmex |
1.3 |
|
348 |
elmex |
1.8 |
if ($type eq 'bool') { |
349 |
elmex |
1.19 |
my $boolval = def ($edspec->{value}, [0, 1]); |
350 |
elmex |
1.15 |
|
351 |
elmex |
1.32 |
|
352 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
353 |
|
|
|
354 |
elmex |
1.19 |
my $chk = new Gtk2::CheckButton (def ($edspec->{name}, $key)); |
355 |
elmex |
1.32 |
$chk->set_active ($ar->get_or_default ($key) == $boolval->[1]); |
356 |
|
|
$chk->signal_connect (clicked => sub { |
357 |
|
|
my ($chk) = @_; |
358 |
|
|
|
359 |
elmex |
1.46 |
$ar->set_silent ($key, $boolval->[$chk->get_active * 1], $type); |
360 |
elmex |
1.32 |
|
361 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $boolval->[$chk->get_active * 1]); |
362 |
|
|
}); |
363 |
elmex |
1.15 |
|
364 |
elmex |
1.12 |
$self->{ttip}->set_tip ($chk, $al_arch->{$key} * 1); |
365 |
elmex |
1.15 |
|
366 |
elmex |
1.8 |
return $chk |
367 |
|
|
|
368 |
|
|
} elsif (grep { $type eq $_ } qw/string int treasurelist float/) { |
369 |
elmex |
1.32 |
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
370 |
|
|
|
371 |
elmex |
1.8 |
my $entry = new Gtk2::Entry; |
372 |
elmex |
1.32 |
$entry->set_text ($ar->get_or_default ($key)); |
373 |
|
|
$entry->signal_connect (changed => sub { |
374 |
|
|
my ($entry) = @_; |
375 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $entry->get_text); |
376 |
|
|
$ar->set_silent ($key, $entry->get_text); |
377 |
|
|
1 |
378 |
|
|
}); |
379 |
|
|
|
380 |
|
|
$self->{ttip}->set_tip ($entry, $ar->archetype->{$key}); |
381 |
|
|
|
382 |
elmex |
1.8 |
return $entry |
383 |
|
|
|
384 |
|
|
} elsif ($type eq 'spell' or $type eq 'nz_spell') { # XXX: nz_spell bug in datafiles? |
385 |
|
|
my $comb = Gtk2::ComboBox->new_text; |
386 |
|
|
my $spells_idx = {}; |
387 |
elmex |
1.34 |
my $spells_cmd_idx = {}; |
388 |
root |
1.45 |
my $sp = \%Deliantra::Data::SPELL; |
389 |
elmex |
1.8 |
|
390 |
|
|
$comb->append_text ("<none>"); |
391 |
|
|
|
392 |
|
|
my $idx = 1; # XXX: replace this idx with a more save/correct method? |
393 |
|
|
for (sort { $sp->{$a} cmp $sp->{$b} } keys %$sp) { |
394 |
elmex |
1.34 |
$spells_cmd_idx->{$idx} = $_; |
395 |
|
|
$spells_idx->{$_} = $idx++; |
396 |
elmex |
1.8 |
|
397 |
|
|
$comb->append_text ($sp->{$_}); |
398 |
|
|
} |
399 |
elmex |
1.12 |
#XXX: FIXME: $self->{ttip}->set_tip ($comb, $sp->{$al_arch->{$key}}); |
400 |
elmex |
1.32 |
|
401 |
elmex |
1.34 |
$comb->set_active ($spells_idx->{$ar->get_or_default ($key)}); |
402 |
elmex |
1.32 |
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
403 |
elmex |
1.8 |
|
404 |
|
|
$comb->signal_connect (changed => sub { |
405 |
|
|
my ($comb) = @_; |
406 |
elmex |
1.34 |
$self->label_set_color_default ($lbl, $ar, $key, $spells_cmd_idx->{$comb->get_active}); |
407 |
|
|
$ar->set_silent ($key, $spells_cmd_idx->{$comb->get_active}); |
408 |
elmex |
1.8 |
}); |
409 |
|
|
return $comb |
410 |
elmex |
1.3 |
|
411 |
elmex |
1.14 |
} elsif ($type eq 'bitmask') { |
412 |
elmex |
1.32 |
my $chval = $ar->get_or_default ($key); |
413 |
elmex |
1.14 |
my $btn = Gtk2::Button->new; |
414 |
elmex |
1.32 |
$btn->add (my $lblb = Gtk2::Label->new ("bitmask: " . ($chval * 1))); |
415 |
elmex |
1.14 |
$self->{ttip}->set_tip ($btn, $al_arch->{$key}); |
416 |
|
|
|
417 |
elmex |
1.32 |
my $menu = $self->create_bitmask_menu ($edspec->{value}, $lbl, $lblb, $ar, $key, \$chval); |
418 |
|
|
|
419 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $chval); |
420 |
elmex |
1.14 |
|
421 |
|
|
$btn->signal_connect (button_press_event => sub { |
422 |
|
|
my ($btn, $ev) = @_; |
423 |
|
|
$menu->popup (undef, undef, undef, undef, $ev->button, 0); |
424 |
|
|
}); |
425 |
elmex |
1.32 |
|
426 |
elmex |
1.14 |
return $btn; |
427 |
|
|
|
428 |
|
|
} elsif ($type eq 'list') { |
429 |
elmex |
1.32 |
my $lblb = Gtk2::Label->new ($edspec->{value}->{$ar->get_or_default ($key) * 1}); |
430 |
elmex |
1.14 |
my $btn = Gtk2::Button->new; |
431 |
|
|
$self->{ttip}->set_tip ($btn, $edspec->{value}->{$al_arch->{$key}}); |
432 |
|
|
$btn->add ($lblb); |
433 |
elmex |
1.32 |
my $menu = $self->create_list_menu ($edspec->{value}, $lbl, $lblb, $ar, $key); |
434 |
elmex |
1.14 |
|
435 |
elmex |
1.32 |
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
436 |
elmex |
1.14 |
|
437 |
|
|
$btn->signal_connect (button_press_event => sub { |
438 |
|
|
my ($btn, $ev) = @_; |
439 |
|
|
$menu->popup (undef, undef, undef, undef, $ev->button, 0); |
440 |
|
|
}); |
441 |
|
|
return $btn; |
442 |
|
|
|
443 |
elmex |
1.8 |
} elsif ($type eq 'fixed') { |
444 |
|
|
return Gtk2::Label->new ("$edspec->{name} = $edspec->{value}"); |
445 |
elmex |
1.3 |
|
446 |
elmex |
1.9 |
} elsif ($type eq 'text') { |
447 |
elmex |
1.20 |
return Gtk2::Label->new ("<see $key tab>"); |
448 |
elmex |
1.9 |
|
449 |
elmex |
1.41 |
} elsif ($type eq 'movement_type') { # ok... this is quite a big one... awww |
450 |
elmex |
1.42 |
my $a = Gtk2::Alignment->new (0, 0, 0, 0); |
451 |
|
|
$a->add (my $v = Gtk2::VBox->new (0, 0)); |
452 |
|
|
$a->set_padding (4, 4, 0, 0); |
453 |
elmex |
1.41 |
my $btns1 = Gtk2::HButtonBox->new; |
454 |
|
|
my $btns2 = Gtk2::HButtonBox->new; |
455 |
|
|
$btns1->set_layout ('start'); |
456 |
|
|
$btns2->set_layout ('start'); |
457 |
|
|
|
458 |
|
|
$v->pack_start ($btns1, 0, 1, 0); |
459 |
|
|
$v->pack_start ($btns2, 0, 1, 0); |
460 |
|
|
|
461 |
|
|
my @lblbtns; |
462 |
|
|
my $calc_lbl = sub { # update callback for the buttons |
463 |
|
|
for (@lblbtns) { |
464 |
|
|
my $btn = $_->[0]; |
465 |
|
|
my $lbl = $_->[1]; |
466 |
|
|
|
467 |
elmex |
1.49 |
if (defined $ar->get_or_default ($key)) { |
468 |
|
|
my $res = |
469 |
|
|
Deliantra::MoveType->new ($ar->get_or_default ($key)) |
470 |
|
|
>= $lbl; |
471 |
elmex |
1.41 |
|
472 |
|
|
if (defined $res) { |
473 |
|
|
$self->label_set_color ($btn, 0); |
474 |
|
|
$lbl = ($res ? "+" : "-") . $lbl; |
475 |
|
|
|
476 |
|
|
} else { |
477 |
|
|
$self->label_set_color ($btn, 1); |
478 |
|
|
$lbl = "$lbl?"; |
479 |
|
|
} |
480 |
|
|
} else { |
481 |
|
|
$self->label_set_color ($btn, 1); |
482 |
|
|
$lbl = "$lbl?"; |
483 |
|
|
} |
484 |
|
|
|
485 |
|
|
$btn->set_label ($lbl); |
486 |
|
|
} |
487 |
|
|
}; |
488 |
|
|
|
489 |
|
|
$self->label_set_color_default ($lbl, $ar, $key, $ar->get_or_default ($key)); |
490 |
|
|
|
491 |
root |
1.45 |
my $mid = (scalar @Deliantra::MOVE_TYPE) / 2; |
492 |
elmex |
1.41 |
my $cnt = 0; |
493 |
|
|
my $box = $btns1; |
494 |
|
|
|
495 |
root |
1.45 |
for my $mty (@Deliantra::MOVE_TYPE) { |
496 |
elmex |
1.41 |
$box->pack_start (my $btn = Gtk2::Button->new ($calc_lbl->()), 0, 1, 0); |
497 |
|
|
push @lblbtns, [$btn, $mty]; |
498 |
|
|
|
499 |
|
|
$self->{ttip}->set_tip ($btn, $ar->archetype->{$key}); |
500 |
|
|
$btn->signal_connect (clicked => sub { |
501 |
root |
1.45 |
my $v = $ar->get ($key) || Deliantra::MoveType->new; |
502 |
elmex |
1.41 |
|
503 |
|
|
$v x= $mty; |
504 |
|
|
$v = $v eq '' ? undef : $v; |
505 |
|
|
$ar->set_silent ($key, $v); |
506 |
|
|
|
507 |
elmex |
1.49 |
$self->label_set_color_default ( |
508 |
|
|
$lbl, $ar, $key, $ar->get_or_default ($key)); |
509 |
elmex |
1.41 |
$calc_lbl->(); |
510 |
|
|
}); |
511 |
|
|
|
512 |
|
|
if (++$cnt >= $mid) { $box = $btns2 } # for wrapping into the second button box |
513 |
elmex |
1.40 |
} |
514 |
elmex |
1.41 |
$calc_lbl->(); |
515 |
|
|
|
516 |
elmex |
1.42 |
return $a; |
517 |
elmex |
1.40 |
|
518 |
elmex |
1.3 |
} else { |
519 |
elmex |
1.8 |
return Gtk2::Label->new ("$key => $edspec->{name} ($type)"); |
520 |
elmex |
1.2 |
|
521 |
elmex |
1.3 |
} |
522 |
elmex |
1.2 |
} |
523 |
|
|
|
524 |
elmex |
1.14 |
sub bitmask_to_list { |
525 |
|
|
my ($self, $bitlist, $bits) = @_; |
526 |
|
|
|
527 |
|
|
my @l; |
528 |
|
|
for (%$bitlist) { |
529 |
|
|
if ($bits & (1 << $_)) { |
530 |
|
|
push @l, $bitlist->{$_}; |
531 |
|
|
} |
532 |
|
|
} |
533 |
|
|
return @l; |
534 |
|
|
} |
535 |
|
|
|
536 |
|
|
sub create_list_menu { |
537 |
elmex |
1.32 |
my ($self, $list, $clbl, $lbl, $ar, $key) = @_; |
538 |
elmex |
1.14 |
|
539 |
|
|
my $menu = Gtk2::Menu->new; |
540 |
|
|
|
541 |
|
|
for my $item (sort keys %$list) { |
542 |
|
|
my $lbltxt = $list->{$item}; |
543 |
|
|
my $menuitem = Gtk2::MenuItem->new_with_label ($lbltxt); |
544 |
|
|
$menuitem->signal_connect (activate => sub { |
545 |
|
|
my ($menuitem) = @_; |
546 |
|
|
$lbl->set_text ($list->{$item}); |
547 |
elmex |
1.32 |
$self->label_set_color_default ($clbl, $ar, $key, $item); |
548 |
|
|
$ar->set_silent ($key, $item); |
549 |
elmex |
1.14 |
}); |
550 |
|
|
$menu->append ($menuitem); |
551 |
|
|
$menuitem->show; |
552 |
|
|
} |
553 |
|
|
|
554 |
|
|
return $menu; |
555 |
|
|
} |
556 |
|
|
|
557 |
|
|
sub create_bitmask_menu { |
558 |
elmex |
1.32 |
my ($self, $bits, $clbl, $lbl, $ar, $key, $rval) = @_; |
559 |
elmex |
1.14 |
|
560 |
|
|
my $menu = Gtk2::Menu->new; |
561 |
|
|
|
562 |
elmex |
1.29 |
for my $bit (sort { $a <=> $b } keys %$bits) { |
563 |
elmex |
1.14 |
my $lbltxt = $bits->{$bit}; |
564 |
|
|
my $menuitem = Gtk2::CheckMenuItem->new_with_label ($lbltxt); |
565 |
elmex |
1.15 |
if ($$rval & (1 << $bit)) { |
566 |
elmex |
1.14 |
$menuitem->set_active (1);#$arch->{$key} & (1 << $bit)); |
567 |
|
|
} |
568 |
|
|
$menuitem->signal_connect (toggled => sub { |
569 |
|
|
my ($menuitem) = @_; |
570 |
elmex |
1.32 |
my $newval = $ar->get ($key); |
571 |
elmex |
1.15 |
$$rval &= ~(1 << $bit); |
572 |
|
|
$$rval |= (1 << $bit) if $menuitem->get_active; |
573 |
|
|
$lbl->set_text ("bitmask: " . ($$rval * 1)); |
574 |
elmex |
1.32 |
$self->label_set_color_default ($clbl, $ar, $key, $$rval); |
575 |
|
|
$ar->set_silent ($key, $$rval); |
576 |
elmex |
1.14 |
}); |
577 |
|
|
$menu->append ($menuitem); |
578 |
|
|
$menuitem->show; |
579 |
|
|
} |
580 |
|
|
|
581 |
|
|
return $menu; |
582 |
|
|
} |
583 |
|
|
|
584 |
elmex |
1.1 |
|
585 |
|
|
=head1 AUTHOR |
586 |
|
|
|
587 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
588 |
|
|
http://home.schmorp.de/ |
589 |
|
|
|
590 |
|
|
Robin Redeker <elmex@ta-sa.org> |
591 |
|
|
http://www.ta-sa.org/ |
592 |
|
|
|
593 |
|
|
=cut |
594 |
|
|
1; |