… | |
… | |
24 | use utf8; |
24 | use utf8; |
25 | |
25 | |
26 | use Carp (); |
26 | use Carp (); |
27 | use AnyEvent (); |
27 | use AnyEvent (); |
28 | use BerkeleyDB; |
28 | use BerkeleyDB; |
|
|
29 | use Pod::POM; |
29 | |
30 | |
30 | sub find_rcfile($) { |
31 | sub find_rcfile($) { |
31 | my $path; |
32 | my $path; |
32 | |
33 | |
33 | for (grep !ref, @INC) { |
34 | for (grep !ref, @INC) { |
… | |
… | |
68 | } |
69 | } |
69 | |
70 | |
70 | close CFG; |
71 | close CFG; |
71 | } |
72 | } |
72 | |
73 | |
|
|
74 | my %POD_CACHE; |
|
|
75 | |
|
|
76 | sub load_pod($) { |
|
|
77 | $POD_CACHE{$_[0]} ||= do { |
|
|
78 | my $pod = do { |
|
|
79 | local $/; |
|
|
80 | open my $pod, "<:utf8", $_[0] |
|
|
81 | or die "$_[0]: $!"; |
|
|
82 | <$pod> |
|
|
83 | }; |
|
|
84 | |
|
|
85 | Pod::POM->new->parse_text ($pod) |
|
|
86 | } |
|
|
87 | } |
|
|
88 | |
|
|
89 | our $DB_ENV; |
|
|
90 | |
|
|
91 | { |
|
|
92 | use strict; |
|
|
93 | |
73 | mkdir "$Crossfire::VARDIR/pclient", 0777; |
94 | mkdir "$Crossfire::VARDIR/cfplus", 0777; |
|
|
95 | my $recover = $BerkeleyDB::db_version >= 4.4 |
|
|
96 | ? eval "DB_REGISTER | DB_RECOVER" |
|
|
97 | : 0; |
74 | |
98 | |
75 | our $DB_ENV = new BerkeleyDB::Env |
99 | $DB_ENV = new BerkeleyDB::Env |
76 | -Home => "$Crossfire::VARDIR/pclient", |
100 | -Home => "$Crossfire::VARDIR/cfplus", |
77 | -Cachesize => 1_000_000, |
101 | -Cachesize => 1_000_000, |
78 | -ErrFile => "$Crossfire::VARDIR/pclient/errorlog.txt", |
102 | -ErrFile => "$Crossfire::VARDIR/cfplus/errorlog.txt", |
79 | # -ErrPrefix => "DATABASE", |
103 | # -ErrPrefix => "DATABASE", |
80 | -Verbose => 1, |
104 | -Verbose => 1, |
81 | -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN, |
105 | -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover, |
|
|
106 | -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE, |
82 | or die "unable to create/open database home $Crossfire::VARDIR/pclient: $BerkeleyDB::Error"; |
107 | or die "unable to create/open database home $Crossfire::VARDIR/cfplus: $BerkeleyDB::Error"; |
|
|
108 | } |
83 | |
109 | |
84 | sub db_table($) { |
110 | sub db_table($) { |
85 | my ($table) = @_; |
111 | my ($table) = @_; |
86 | |
112 | |
87 | $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; |
113 | $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; |
88 | |
114 | |
89 | new CFClient::Database |
115 | new CFClient::Database |
90 | -Env => $DB_ENV, |
116 | -Env => $DB_ENV, |
91 | -Filename => $table, |
117 | -Filename => $table, |
92 | # -Filename => "database", |
118 | # -Filename => "database", |
93 | # -Subname => $table, |
119 | # -Subname => $table, |
94 | -Property => DB_CHKSUM, |
120 | -Property => DB_CHKSUM, |
95 | -Flags => DB_CREATE | DB_UPGRADE, |
121 | -Flags => DB_CREATE | DB_UPGRADE, |
96 | or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"; |
122 | or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" |
97 | } |
123 | } |
98 | |
124 | |
99 | sub pod_to_pango($) { |
125 | sub pod_to_pango($) { |
100 | my ($pom) = @_; |
126 | my ($pom) = @_; |
101 | |
127 | |
… | |
… | |
192 | |
218 | |
193 | package CFClient::Item; |
219 | package CFClient::Item; |
194 | |
220 | |
195 | use strict; |
221 | use strict; |
196 | use Crossfire::Protocol::Constants; |
222 | use Crossfire::Protocol::Constants; |
|
|
223 | |
|
|
224 | my $last_enter_count = 1; |
197 | |
225 | |
198 | sub desc_string { |
226 | sub desc_string { |
199 | my ($self) = @_; |
227 | my ($self) = @_; |
200 | |
228 | |
201 | my $desc = |
229 | my $desc = |
… | |
… | |
227 | my $weight = ($self->{nrof} || 1) * $self->{weight}; |
255 | my $weight = ($self->{nrof} || 1) * $self->{weight}; |
228 | |
256 | |
229 | $weight < 0 ? "?" : $weight * 0.001 |
257 | $weight < 0 ? "?" : $weight * 0.001 |
230 | } |
258 | } |
231 | |
259 | |
|
|
260 | sub do_n_dialog { |
|
|
261 | my ($cb) = @_; |
|
|
262 | |
|
|
263 | my $w = new CFClient::UI::FancyFrame; |
|
|
264 | $w->add (my $vb = new CFClient::UI::VBox x => "center", y => "center"); |
|
|
265 | $vb->add (new CFClient::UI::Label text => "Enter item count:"); |
|
|
266 | $vb->add (my $entry = new CFClient::UI::Entry |
|
|
267 | text => $last_enter_count, |
|
|
268 | on_activate => sub { |
|
|
269 | my ($entry) = @_; |
|
|
270 | $last_enter_count = $entry->get_text; |
|
|
271 | $cb->($last_enter_count); |
|
|
272 | $w->hide; |
|
|
273 | $w = undef; |
|
|
274 | } |
|
|
275 | ); |
|
|
276 | $entry->focus_in; |
|
|
277 | $w->show; |
|
|
278 | |
|
|
279 | } |
|
|
280 | |
232 | sub update_widgets { |
281 | sub update_widgets { |
233 | my ($self) = @_; |
282 | my ($self) = @_; |
234 | |
283 | |
235 | my $button_cb = sub { |
284 | my $button_cb = sub { |
236 | my (undef, $ev, $x, $y) = @_; |
285 | my (undef, $ev, $x, $y) = @_; |
237 | |
286 | |
|
|
287 | my $targ = $::CONN->{player}{tag}; |
|
|
288 | |
|
|
289 | if ($self->{container} == $::CONN->{player}{tag}) { |
|
|
290 | $targ = $::CONN->{open_container}; |
|
|
291 | } |
|
|
292 | |
238 | if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { |
293 | if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { |
239 | my $targ = $::CONN->{player}{tag}; |
|
|
240 | |
|
|
241 | if ($self->{container} == $::CONN->{player}{tag}) { |
|
|
242 | $targ = $::CONN->{open_container}; |
|
|
243 | } |
|
|
244 | |
|
|
245 | $::CONN->send ("move $targ $self->{tag} 0"); |
294 | $::CONN->send ("move $targ $self->{tag} 0") |
|
|
295 | if $targ || !($self->{flags} & F_LOCKED); |
|
|
296 | } elsif (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 2) { |
|
|
297 | $self->{flags} & F_LOCKED |
|
|
298 | ? $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) |
|
|
299 | : $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) |
246 | } elsif ($ev->{button} == 1) { |
300 | } elsif ($ev->{button} == 1) { |
247 | $::CONN->send ("examine $self->{tag}"); |
301 | $::CONN->send ("examine $self->{tag}"); |
248 | } elsif ($ev->{button} == 2) { |
302 | } elsif ($ev->{button} == 2) { |
249 | $::CONN->send ("apply $self->{tag}"); |
303 | $::CONN->send ("apply $self->{tag}"); |
250 | } elsif ($ev->{button} == 3) { |
304 | } elsif ($ev->{button} == 3) { |
… | |
… | |
258 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }], |
312 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }], |
259 | ) |
313 | ) |
260 | : ( |
314 | : ( |
261 | ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }], |
315 | ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }], |
262 | ["drop", sub { $::CONN->send ("move $::CONN->{open_container} $self->{tag} 0") }], |
316 | ["drop", sub { $::CONN->send ("move $::CONN->{open_container} $self->{tag} 0") }], |
|
|
317 | ["move n", |
|
|
318 | sub { |
|
|
319 | do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") }) |
|
|
320 | } |
|
|
321 | ] |
263 | ) |
322 | ) |
264 | ), |
323 | ), |
265 | ); |
324 | ); |
266 | |
325 | |
267 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
326 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
… | |
… | |
272 | |
331 | |
273 | my $tooltip_std = "<small>" |
332 | my $tooltip_std = "<small>" |
274 | . "Left click - examine item\n" |
333 | . "Left click - examine item\n" |
275 | . "Shift-Left click - " . ($self->{container} ? "move or drop" : "take") . " item\n" |
334 | . "Shift-Left click - " . ($self->{container} ? "move or drop" : "take") . " item\n" |
276 | . "Middle click - apply\n" |
335 | . "Middle click - apply\n" |
|
|
336 | . "Shift-Middle click - lock/unlock\n" |
277 | . "Right click - further options" |
337 | . "Right click - further options" |
278 | . "</small>\n"; |
338 | . "</small>\n"; |
279 | |
339 | |
280 | $self->{face_widget} ||= new CFClient::UI::Face |
340 | $self->{face_widget} ||= new CFClient::UI::Face |
281 | can_events => 1, |
341 | can_events => 1, |
… | |
… | |
320 | . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") |
380 | . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") |
321 | . "\n\n$tooltip_std" |
381 | . "\n\n$tooltip_std" |
322 | ); |
382 | ); |
323 | } |
383 | } |
324 | |
384 | |
|
|
385 | package CFClient::Binder; |
|
|
386 | |
|
|
387 | my @ALLOWED_MODIFIER_KEYS = ( |
|
|
388 | CFClient::SDLK_LSHIFT, |
|
|
389 | CFClient::SDLK_LCTRL , |
|
|
390 | CFClient::SDLK_LALT , |
|
|
391 | CFClient::SDLK_LMETA , |
|
|
392 | |
|
|
393 | CFClient::SDLK_RSHIFT, |
|
|
394 | CFClient::SDLK_RCTRL , |
|
|
395 | CFClient::SDLK_RALT , |
|
|
396 | CFClient::SDLK_RMETA , |
|
|
397 | ); |
|
|
398 | |
|
|
399 | my %ALLOWED_MODIFIERS = ( |
|
|
400 | CFClient::KMOD_LSHIFT => "LSHIFT", |
|
|
401 | CFClient::KMOD_LCTRL => "LCTRL", |
|
|
402 | CFClient::KMOD_LALT => "LALT", |
|
|
403 | CFClient::KMOD_LMETA => "LMETA", |
|
|
404 | |
|
|
405 | CFClient::KMOD_RSHIFT => "RSHIFT", |
|
|
406 | CFClient::KMOD_RCTRL => "RCTRL", |
|
|
407 | CFClient::KMOD_RALT => "RALT", |
|
|
408 | CFClient::KMOD_RMETA => "RMETA", |
|
|
409 | ); |
|
|
410 | |
|
|
411 | my %DIRECT_BIND_CHARS = map { $_ => 1 } qw/0 1 2 3 4 5 6 7 8 9/; |
|
|
412 | my @DIRECT_BIND_KEYS = ( |
|
|
413 | CFClient::SDLK_F1, |
|
|
414 | CFClient::SDLK_F2, |
|
|
415 | CFClient::SDLK_F3, |
|
|
416 | CFClient::SDLK_F4, |
|
|
417 | CFClient::SDLK_F5, |
|
|
418 | CFClient::SDLK_F6, |
|
|
419 | CFClient::SDLK_F7, |
|
|
420 | CFClient::SDLK_F8, |
|
|
421 | CFClient::SDLK_F9, |
|
|
422 | CFClient::SDLK_F10, |
|
|
423 | CFClient::SDLK_F11, |
|
|
424 | CFClient::SDLK_F12, |
|
|
425 | CFClient::SDLK_F13, |
|
|
426 | CFClient::SDLK_F14, |
|
|
427 | CFClient::SDLK_F15, |
|
|
428 | ); |
|
|
429 | |
|
|
430 | # this binding dialog asks for a key-combo to be pressed |
|
|
431 | # and if successful it calls the $cb with $mod and $sym as args. |
|
|
432 | sub open_binding_dialog { |
|
|
433 | my ($cb) = @_; |
|
|
434 | |
|
|
435 | my $w = new CFClient::UI::FancyFrame |
|
|
436 | title => "Bind Action", |
|
|
437 | x => "center", |
|
|
438 | y => "center"; |
|
|
439 | |
|
|
440 | $w->add (my $vb = new CFClient::UI::VBox); |
|
|
441 | $vb->add (new CFClient::UI::Label |
|
|
442 | text => "Press a modifier (CTRL, ALT and/or SHIFT) and a key." |
|
|
443 | ."You can only bind 0-9 and F1-F15 without modifiers." |
|
|
444 | ); |
|
|
445 | $vb->add (my $entry = new CFClient::UI::Entry |
|
|
446 | text => "", |
|
|
447 | on_key_down => sub { |
|
|
448 | my ($entry, $ev) = @_; |
|
|
449 | |
|
|
450 | my $mod = $ev->{mod}; |
|
|
451 | my $sym = $ev->{sym}; |
|
|
452 | |
|
|
453 | # XXX: This seems a little bit hackisch to me, but i have to ignore them |
|
|
454 | if (grep { $_ == $sym } @ALLOWED_MODIFIER_KEYS) { |
|
|
455 | return; |
|
|
456 | } |
|
|
457 | |
|
|
458 | if ($mod == CFClient::KMOD_NONE |
|
|
459 | and not $DIRECT_BIND_CHARS{chr ($ev->{unicode})} |
|
|
460 | and not grep { $sym == $_ } @DIRECT_BIND_KEYS) |
|
|
461 | { |
|
|
462 | $::STATUSBOX->add ( |
|
|
463 | "Can't bind key ".CFClient::SDL_GetKeyName ($sym) |
|
|
464 | ." directly without modifier! It would damage the completer handling." |
|
|
465 | ); |
|
|
466 | return; |
|
|
467 | } |
|
|
468 | |
|
|
469 | $entry->focus_out; |
|
|
470 | |
|
|
471 | $cb->($mod, $sym); |
|
|
472 | |
|
|
473 | $w->destroy |
|
|
474 | }); |
|
|
475 | |
|
|
476 | $entry->focus_in; |
|
|
477 | $w->show; |
|
|
478 | } |
|
|
479 | |
|
|
480 | sub keycombo_to_name { |
|
|
481 | my ($mod, $sym) = @_; |
|
|
482 | |
|
|
483 | my $mods = join '+', |
|
|
484 | map { $ALLOWED_MODIFIERS{$_} } |
|
|
485 | grep { ($_ + 0) & ($mod + 0) } |
|
|
486 | keys %ALLOWED_MODIFIERS; |
|
|
487 | $mods .= "+" if $mods ne ''; |
|
|
488 | |
|
|
489 | return $mods . CFClient::SDL_GetKeyName ($sym); |
|
|
490 | } |
|
|
491 | |
|
|
492 | package CFClient::Pickup; |
|
|
493 | # some pickup constants |
|
|
494 | sub PU_NOTHING { 0x00000000 } |
|
|
495 | |
|
|
496 | sub PU_DEBUG { 0x10000000 } |
|
|
497 | sub PU_INHIBIT { 0x20000000 } |
|
|
498 | sub PU_STOP { 0x40000000 } |
|
|
499 | sub PU_NEWMODE { 0x80000000 } |
|
|
500 | |
|
|
501 | sub PU_RATIO { 0x0000000F } |
|
|
502 | |
|
|
503 | sub PU_FOOD { 0x00000010 } |
|
|
504 | sub PU_DRINK { 0x00000020 } |
|
|
505 | sub PU_VALUABLES { 0x00000040 } |
|
|
506 | sub PU_BOW { 0x00000080 } |
|
|
507 | |
|
|
508 | sub PU_ARROW { 0x00000100 } |
|
|
509 | sub PU_HELMET { 0x00000200 } |
|
|
510 | sub PU_SHIELD { 0x00000400 } |
|
|
511 | sub PU_ARMOUR { 0x00000800 } |
|
|
512 | |
|
|
513 | sub PU_BOOTS { 0x00001000 } |
|
|
514 | sub PU_GLOVES { 0x00002000 } |
|
|
515 | sub PU_CLOAK { 0x00004000 } |
|
|
516 | sub PU_KEY { 0x00008000 } |
|
|
517 | |
|
|
518 | sub PU_MISSILEWEAPON { 0x00010000 } |
|
|
519 | sub PU_ALLWEAPON { 0x00020000 } |
|
|
520 | sub PU_MAGICAL { 0x00040000 } |
|
|
521 | sub PU_POTION { 0x00080000 } |
|
|
522 | |
|
|
523 | sub PU_SPELLBOOK { 0x00100000 } |
|
|
524 | sub PU_SKILLSCROLL { 0x00200000 } |
|
|
525 | sub PU_READABLES { 0x00400000 } |
|
|
526 | sub PU_MAGIC_DEVICE { 0x00800000 } |
|
|
527 | |
|
|
528 | sub PU_NOT_CURSED { 0x01000000 } |
|
|
529 | |
|
|
530 | sub PU_JEWELS { 0x02000000 } |
|
|
531 | |
|
|
532 | |
325 | 1; |
533 | 1; |
326 | |
534 | |
327 | =back |
535 | =back |
328 | |
536 | |
329 | =head1 AUTHOR |
537 | =head1 AUTHOR |