… | |
… | |
3 | use utf8; |
3 | use utf8; |
4 | use strict; |
4 | use strict; |
5 | |
5 | |
6 | use Crossfire::Protocol::Constants; |
6 | use Crossfire::Protocol::Constants; |
7 | |
7 | |
|
|
8 | use CFClient; |
8 | use CFClient::UI; |
9 | use CFClient::UI; |
9 | |
10 | |
10 | use base 'Crossfire::Protocol::Base'; |
11 | use base 'Crossfire::Protocol::Base'; |
11 | |
12 | |
12 | sub new { |
13 | sub new { |
… | |
… | |
14 | |
15 | |
15 | my $self = $class->SUPER::new (@_); |
16 | my $self = $class->SUPER::new (@_); |
16 | |
17 | |
17 | $self->{map_widget}->clr_commands; |
18 | $self->{map_widget}->clr_commands; |
18 | |
19 | |
19 | my $parser = new Pod::POM; |
20 | my $cmd_help = CFClient::load_pod CFClient::find_rcfile "pod/command_help.pod", command_help => 1, sub { |
20 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/command_help.pod"); |
21 | my ($pom) = @_; |
21 | |
22 | |
|
|
23 | my @cmd_help; |
|
|
24 | |
22 | for my $head2 ($pod->head1->[-2]->head2) { |
25 | for my $head2 ($pom->head1->[-2]->head2) { |
23 | $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
26 | $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
24 | or next; |
27 | or next; |
25 | |
28 | |
26 | my $cmd = $1; |
29 | my $cmd = $1; |
27 | my @args = split /\|/, $2; |
30 | my @args = split /\|/, $2; |
28 | @args = (".*") unless @args; |
31 | @args = (".*") unless @args; |
29 | |
32 | |
30 | $_ = $_ eq ".*" ? "" : " $_" |
33 | $_ = $_ eq ".*" ? "" : " $_" |
31 | for @args; |
34 | for @args; |
32 | |
35 | |
33 | my $text = CFClient::pod_to_pango $head2->content; |
36 | my $text = CFClient::pod_to_pango $head2->content; |
34 | |
37 | |
35 | $self->{map_widget}->add_command ("$cmd$_", $text) |
38 | push @cmd_help, ["$cmd$_", $text] |
36 | for sort { (length $a) <=> (length $b) } |
39 | for sort { (length $a) <=> (length $b) } |
37 | @args; |
40 | @args; |
|
|
41 | } |
|
|
42 | |
|
|
43 | \@cmd_help |
38 | } |
44 | }; |
|
|
45 | |
|
|
46 | $self->{map_widget}->add_command (@$_) |
|
|
47 | for @$cmd_help; |
39 | |
48 | |
40 | $self->{noface} = new_from_file CFClient::Texture |
49 | $self->{noface} = new_from_file CFClient::Texture |
41 | CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; |
50 | CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; |
42 | |
51 | |
43 | $self->{open_container} = 0; |
52 | $self->{open_container} = 0; |
… | |
… | |
268 | unless ($id) { |
277 | unless ($id) { |
269 | # create new id for face |
278 | # create new id for face |
270 | # I love transactions |
279 | # I love transactions |
271 | for (1..100) { |
280 | for (1..100) { |
272 | my $txn = $CFClient::DB_ENV->txn_begin; |
281 | my $txn = $CFClient::DB_ENV->txn_begin; |
273 | my $status = $self->{facemap}->db_get (id => $id, BerkeleyDB::DB_RMW); |
282 | my $status = $self->{facemap}->db_get (id => $id); |
274 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
283 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
275 | $id = ($id || 16) + 1; |
284 | $id = ($id || 16) + 1; |
276 | if ($self->{facemap}->put (id => $id) == 0 |
285 | if ($self->{facemap}->put (id => $id) == 0 |
277 | && $self->{facemap}->put ($hash => $id) == 0) { |
286 | && $self->{facemap}->put ($hash => $id) == 0) { |
278 | $txn->txn_commit; |
287 | $txn->txn_commit; |
279 | |
288 | |
280 | goto gotid; |
289 | goto gotid; |
281 | } |
290 | } |
282 | } |
291 | } |
283 | $txn->abort; |
292 | $txn->txn_abort; |
284 | } |
293 | } |
285 | |
294 | |
286 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
295 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
287 | } |
296 | } |
288 | |
297 | |
… | |
… | |
338 | my ($self, $flags, $prompt) = @_; |
347 | my ($self, $flags, $prompt) = @_; |
339 | |
348 | |
340 | $prompt = $LAST_QUERY unless length $prompt; |
349 | $prompt = $LAST_QUERY unless length $prompt; |
341 | $LAST_QUERY = $prompt; |
350 | $LAST_QUERY = $prompt; |
342 | |
351 | |
343 | my $dialog = new CFClient::UI::FancyFrame |
352 | $self->{query}-> ($self, $flags, $prompt); |
344 | title => "Query", |
|
|
345 | child => my $vbox = new CFClient::UI::VBox, |
|
|
346 | on_visibility_change => sub { |
|
|
347 | my ($self, $visible) = @_; |
|
|
348 | $self->center if $visible; |
|
|
349 | }, |
|
|
350 | ; |
|
|
351 | |
|
|
352 | $vbox->add (new CFClient::UI::Label |
|
|
353 | max_w => $::WIDTH * 0.4, |
|
|
354 | ellipsise => 0, |
|
|
355 | text => $prompt); |
|
|
356 | |
|
|
357 | if ($flags & CS_QUERY_YESNO) { |
|
|
358 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
|
|
359 | $hbox->add (new CFClient::UI::Button |
|
|
360 | text => "No", |
|
|
361 | on_activate => sub { |
|
|
362 | $self->send ("reply n"); |
|
|
363 | $dialog->destroy; |
|
|
364 | $self->{map_widget}->focus_in; |
|
|
365 | } |
|
|
366 | ); |
|
|
367 | $hbox->add (new CFClient::UI::Button |
|
|
368 | text => "Yes", |
|
|
369 | on_activate => sub { |
|
|
370 | $self->send ("reply y"); |
|
|
371 | $dialog->destroy; |
|
|
372 | }, |
|
|
373 | ); |
|
|
374 | |
|
|
375 | $dialog->focus_in; |
|
|
376 | |
|
|
377 | } elsif ($flags & CS_QUERY_SINGLECHAR) { |
|
|
378 | $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)"; |
|
|
379 | $vbox->add (my $entry = new CFClient::UI::Entry |
|
|
380 | on_changed => sub { |
|
|
381 | $self->send ("reply $_[1]"); |
|
|
382 | $dialog->destroy; |
|
|
383 | }, |
|
|
384 | ); |
|
|
385 | |
|
|
386 | $entry->focus_in; |
|
|
387 | |
|
|
388 | } else { |
|
|
389 | $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)"; |
|
|
390 | |
|
|
391 | $vbox->add (my $entry = new CFClient::UI::Entry |
|
|
392 | $flags & CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), |
|
|
393 | on_activate => sub { |
|
|
394 | $self->send ("reply $_[1]"); |
|
|
395 | $dialog->destroy; |
|
|
396 | }, |
|
|
397 | ); |
|
|
398 | |
|
|
399 | $entry->focus_in; |
|
|
400 | } |
|
|
401 | |
|
|
402 | $dialog->show; |
|
|
403 | } |
353 | } |
404 | |
354 | |
405 | sub drawinfo { |
355 | sub drawinfo { |
406 | my ($self, $color, $text) = @_; |
356 | my ($self, $color, $text) = @_; |
407 | |
357 | |
… | |
… | |
421 | [0.74, 0.65, 0.41], |
371 | [0.74, 0.65, 0.41], |
422 | ); |
372 | ); |
423 | |
373 | |
424 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
374 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
425 | |
375 | |
|
|
376 | # try to create single paragraphs of multiple lines sent by the server |
|
|
377 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
378 | |
426 | $text = CFClient::UI::Label::escape $text; |
379 | $text = CFClient::UI::Label::escape $text; |
427 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
380 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
428 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
381 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
429 | |
382 | |
430 | $self->{logview}->add_paragraph ($color[$color], |
383 | $self->{logview}->add_paragraph ($color[$color], |
431 | join "\n", map "$time $_", split /\n/, $text); |
384 | join "\n", map "$time $_", split /\n/, $text); |
432 | |
385 | |
433 | $self->{statusbox}->add ($text, |
386 | $self->{statusbox}->add ($text, |
434 | group => $text, |
387 | group => $text, |
435 | fg => $color[$color], |
388 | fg => $color[$color], |
436 | timeout => 10, |
389 | timeout => $color >= 2 ? 60 : 10, |
437 | tooltip_font => $::FONT_FIXED, |
390 | tooltip_font => $::FONT_FIXED, |
438 | ); |
391 | ); |
439 | } |
392 | } |
440 | |
393 | |
441 | sub drawextinfo { |
394 | sub drawextinfo { |
… | |
… | |
447 | sub spell_add { |
400 | sub spell_add { |
448 | my ($self, $spell) = @_; |
401 | my ($self, $spell) = @_; |
449 | |
402 | |
450 | # TODO |
403 | # TODO |
451 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
404 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
|
|
405 | $::SETUP_SPELLS->add_spell ($spell); |
|
|
406 | |
452 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
407 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
453 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
408 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
454 | } |
409 | } |
455 | |
410 | |
456 | sub spell_delete { |
411 | sub spell_delete { |
457 | my ($self, $spell) = @_; |
412 | my ($self, $spell) = @_; |
|
|
413 | $::SETUP_SPELLS->remove_spell ($spell); |
458 | } |
414 | } |
459 | |
415 | |
460 | sub addme_success { |
416 | sub addme_success { |
461 | my ($self) = @_; |
417 | my ($self) = @_; |
462 | |
418 | |
463 | $self->send ("command output-sync $::CFG->{output_sync}"); |
419 | my $skill_help = CFClient::load_pod CFClient::find_rcfile "pod/skill_help.pod", skill_help => 1, sub { |
464 | $self->send ("command output-count $::CFG->{output_count}"); |
420 | my ($pom) = @_; |
465 | |
421 | |
466 | my $parser = new Pod::POM; |
|
|
467 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod"); |
|
|
468 | |
|
|
469 | my %skill_tooltip; |
422 | my %skill_help; |
470 | |
423 | |
471 | for my $head2 ($pod->head1->[-2]->head2) { |
424 | for my $head2 ($pom->head1->[3]->head2) { |
472 | $skill_tooltip{$head2->title} = CFClient::pod_to_pango $head2->content; |
425 | $skill_help{$head2->title} = CFClient::pod_to_pango $head2->content; |
|
|
426 | } |
|
|
427 | |
|
|
428 | \%skill_help |
473 | } |
429 | }; |
474 | |
430 | |
475 | for my $skill (values %{$self->{skill_info}}) { |
431 | for my $skill (values %{$self->{skill_info}}) { |
476 | $self->{map_widget}->add_command ("ready_skill $skill", |
432 | $self->{map_widget}->add_command ("ready_skill $skill", |
477 | (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
433 | (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
478 | . $skill_tooltip{$skill}); |
434 | . $skill_help->{$skill}); |
479 | $self->{map_widget}->add_command ("use_skill $skill", |
435 | $self->{map_widget}->add_command ("use_skill $skill", |
480 | (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
436 | (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
481 | . $skill_tooltip{$skill}); |
437 | . $skill_help->{$skill}); |
482 | } |
438 | } |
483 | } |
439 | } |
484 | |
440 | |
485 | sub eof { |
441 | sub eof { |
486 | my ($self) = @_; |
442 | my ($self) = @_; |
… | |
… | |
511 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
467 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
512 | |
468 | |
513 | $self->send ("requestinfo image_sums $face $face"); |
469 | $self->send ("requestinfo image_sums $face $face"); |
514 | |
470 | |
515 | $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
471 | $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
516 | group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); |
472 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
517 | } elsif (!exists $self->{num_faces}) { |
473 | } elsif (!exists $self->{num_faces}) { |
518 | $self->send ("requestinfo image_info"); |
474 | $self->send ("requestinfo image_info"); |
519 | |
475 | |
520 | $self->{num_faces} = 0; |
476 | $self->{num_faces} = 0; |
521 | |
477 | |
522 | $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
478 | $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
523 | group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); |
479 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
524 | } |
480 | } |
525 | } |
481 | } |
526 | |
482 | |
527 | sub update_floorbox { |
483 | sub update_floorbox { |
528 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
484 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
… | |
… | |
530 | |
486 | |
531 | $::FLOORBOX->clear; |
487 | $::FLOORBOX->clear; |
532 | |
488 | |
533 | my $row; |
489 | my $row; |
534 | for (@{ $::CONN->{container}{0} }) { |
490 | for (@{ $::CONN->{container}{0} }) { |
535 | if ($row < 7) { |
491 | if ($row < 6) { |
536 | local $_->{face_widget}; # hack to force recreation of widget |
492 | local $_->{face_widget}; # hack to force recreation of widget |
537 | local $_->{desc_widget}; # hack to force recreation of widget |
493 | local $_->{desc_widget}; # hack to force recreation of widget |
538 | CFClient::Item::update_widgets $_; |
494 | CFClient::Item::update_widgets $_; |
539 | |
495 | |
540 | $::FLOORBOX->add (0, $row, $_->{face_widget}); |
496 | $::FLOORBOX->add (0, $row, $_->{face_widget}); |
541 | $::FLOORBOX->add (1, $row, $_->{desc_widget}); |
497 | $::FLOORBOX->add (1, $row, $_->{desc_widget}); |
542 | |
498 | |
543 | $row++; |
499 | $row++; |
544 | } else { |
500 | } else { |
545 | $::FLOORBOX->add (1, $row, new CFClient::UI::Label text => "More..."); |
501 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
|
|
502 | text => "More...", |
|
|
503 | on_activate => sub { $::INV_WINDOW->toggle_visibility }, |
|
|
504 | ); |
546 | last; |
505 | last; |
547 | } |
506 | } |
548 | } |
507 | } |
549 | }); |
508 | }); |
550 | |
509 | |
… | |
… | |
552 | } |
511 | } |
553 | |
512 | |
554 | sub set_opencont { |
513 | sub set_opencont { |
555 | my ($conn, $tag, $name) = @_; |
514 | my ($conn, $tag, $name) = @_; |
556 | $conn->{open_container} = $tag; |
515 | $conn->{open_container} = $tag; |
557 | $::INVR_LBL->set_text ($name); |
516 | |
|
|
517 | $::INV_RIGHT_HB->clear (); |
|
|
518 | $::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name); |
|
|
519 | |
|
|
520 | if ($tag != 0) { # Floor isn't closable, is it? |
|
|
521 | $::INV_RIGHT_HB->add (new CFClient::UI::Button |
|
|
522 | text => "Close container", |
|
|
523 | tooltip => "Close the currently open container (if one is open)", |
|
|
524 | on_activate => sub { |
|
|
525 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
|
|
526 | if $tag != 0; |
|
|
527 | #if $CONN->{open_container} != 0; |
|
|
528 | }, |
|
|
529 | ); |
|
|
530 | } |
|
|
531 | |
558 | $::INVR->set_items ($conn->{container}{$tag}); |
532 | $::INVR->set_items ($conn->{container}{$tag}); |
559 | } |
533 | } |
560 | |
534 | |
561 | sub update_container { |
535 | sub update_container { |
562 | my ($tag) = @_; |
536 | my ($tag) = @_; |
… | |
… | |
591 | if ($tag == 0) { |
565 | if ($tag == 0) { |
592 | update_floorbox; |
566 | update_floorbox; |
593 | update_container (0); |
567 | update_container (0); |
594 | } elsif ($tag == $self->{player}{tag}) { |
568 | } elsif ($tag == $self->{player}{tag}) { |
595 | $::INV->set_items ($self->{container}{$tag}) |
569 | $::INV->set_items ($self->{container}{$tag}) |
|
|
570 | } else { |
|
|
571 | update_container ($tag); |
596 | } |
572 | } |
597 | |
573 | |
598 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
574 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
599 | } |
575 | } |
600 | |
576 | |
… | |
… | |
608 | update_floorbox; |
584 | update_floorbox; |
609 | update_container ($_->{tag}); |
585 | update_container ($_->{tag}); |
610 | } elsif ($_->{container} == $self->{player}{tag}) { |
586 | } elsif ($_->{container} == $self->{player}{tag}) { |
611 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
587 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
612 | } else { |
588 | } else { |
613 | update_container ($_->{tag}); |
589 | update_container ($_->{container}); |
614 | } |
590 | } |
615 | } |
591 | } |
616 | } |
592 | } |
617 | |
593 | |
618 | sub item_update { |
594 | sub item_update { |
… | |
… | |
643 | } |
619 | } |
644 | |
620 | |
645 | sub player_update { |
621 | sub player_update { |
646 | my ($self, $player) = @_; |
622 | my ($self, $player) = @_; |
647 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
623 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
|
|
624 | |
|
|
625 | # do it here because it is ignored earlier, and there is no "login" event |
|
|
626 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
|
|
627 | $self->send_command ("output-count $::CFG->{output_count}"); |
648 | } |
628 | } |
649 | |
629 | |
650 | 1; |
630 | 1; |