… | |
… | |
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 | |
… | |
… | |
429 | join "\n", map "$time $_", split /\n/, $text); |
438 | join "\n", map "$time $_", split /\n/, $text); |
430 | |
439 | |
431 | $self->{statusbox}->add ($text, |
440 | $self->{statusbox}->add ($text, |
432 | group => $text, |
441 | group => $text, |
433 | fg => $color[$color], |
442 | fg => $color[$color], |
434 | timeout => 10, |
443 | timeout => $color >= 2 ? 60 : 10, |
435 | tooltip_font => $::FONT_FIXED, |
444 | tooltip_font => $::FONT_FIXED, |
436 | ); |
445 | ); |
437 | } |
446 | } |
438 | |
447 | |
439 | sub drawextinfo { |
448 | sub drawextinfo { |
… | |
… | |
445 | sub spell_add { |
454 | sub spell_add { |
446 | my ($self, $spell) = @_; |
455 | my ($self, $spell) = @_; |
447 | |
456 | |
448 | # TODO |
457 | # TODO |
449 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
458 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
|
|
459 | $::SETUP_SPELLS->add_spell ($spell); |
|
|
460 | |
450 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
461 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
451 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
462 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
452 | } |
463 | } |
453 | |
464 | |
454 | sub spell_delete { |
465 | sub spell_delete { |
455 | my ($self, $spell) = @_; |
466 | my ($self, $spell) = @_; |
|
|
467 | $::SETUP_SPELLS->remove_spell ($spell); |
456 | } |
468 | } |
457 | |
469 | |
458 | sub addme_success { |
470 | sub addme_success { |
459 | my ($self) = @_; |
471 | my ($self) = @_; |
460 | |
472 | |
461 | $self->send ("command output-sync $::CFG->{output_sync}"); |
473 | my $skill_help = CFClient::load_pod CFClient::find_rcfile "pod/skill_help.pod", skill_help => 1, sub { |
462 | $self->send ("command output-count $::CFG->{output_count}"); |
474 | my ($pom) = @_; |
463 | |
475 | |
464 | my $parser = new Pod::POM; |
|
|
465 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod"); |
|
|
466 | |
|
|
467 | my %skill_tooltip; |
476 | my %skill_help; |
468 | |
477 | |
469 | for my $head2 ($pod->head1->[-2]->head2) { |
478 | for my $head2 ($pom->head1->[3]->head2) { |
470 | $skill_tooltip{$head2->title} = CFClient::pod_to_pango $head2->content; |
479 | $skill_help{$head2->title} = CFClient::pod_to_pango $head2->content; |
|
|
480 | } |
|
|
481 | |
|
|
482 | \%skill_help |
471 | } |
483 | }; |
472 | |
484 | |
473 | for my $skill (values %{$self->{skill_info}}) { |
485 | for my $skill (values %{$self->{skill_info}}) { |
474 | $self->{map_widget}->add_command ("ready_skill $skill", |
486 | $self->{map_widget}->add_command ("ready_skill $skill", |
475 | (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
487 | (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
476 | . $skill_tooltip{$skill}); |
488 | . $skill_help->{$skill}); |
477 | $self->{map_widget}->add_command ("use_skill $skill", |
489 | $self->{map_widget}->add_command ("use_skill $skill", |
478 | (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
490 | (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
479 | . $skill_tooltip{$skill}); |
491 | . $skill_help->{$skill}); |
480 | } |
492 | } |
481 | } |
493 | } |
482 | |
494 | |
483 | sub eof { |
495 | sub eof { |
484 | my ($self) = @_; |
496 | my ($self) = @_; |
… | |
… | |
509 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
521 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
510 | |
522 | |
511 | $self->send ("requestinfo image_sums $face $face"); |
523 | $self->send ("requestinfo image_sums $face $face"); |
512 | |
524 | |
513 | $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
525 | $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
514 | group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); |
526 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
515 | } elsif (!exists $self->{num_faces}) { |
527 | } elsif (!exists $self->{num_faces}) { |
516 | $self->send ("requestinfo image_info"); |
528 | $self->send ("requestinfo image_info"); |
517 | |
529 | |
518 | $self->{num_faces} = 0; |
530 | $self->{num_faces} = 0; |
519 | |
531 | |
520 | $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
532 | $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
521 | group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); |
533 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
522 | } |
534 | } |
523 | } |
535 | } |
524 | |
536 | |
525 | sub update_floorbox { |
537 | sub update_floorbox { |
526 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
538 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
… | |
… | |
658 | } |
670 | } |
659 | |
671 | |
660 | sub player_update { |
672 | sub player_update { |
661 | my ($self, $player) = @_; |
673 | my ($self, $player) = @_; |
662 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
674 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
|
|
675 | |
|
|
676 | # do it here because it is ignored earlier, and there is no "login" event |
|
|
677 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
|
|
678 | $self->send_command ("output-count $::CFG->{output_count}"); |
663 | } |
679 | } |
664 | |
680 | |
665 | 1; |
681 | 1; |