… | |
… | |
15 | |
15 | |
16 | my $self = $class->SUPER::new (@_); |
16 | my $self = $class->SUPER::new (@_); |
17 | |
17 | |
18 | $self->{map_widget}->clr_commands; |
18 | $self->{map_widget}->clr_commands; |
19 | |
19 | |
20 | my $pod = CFClient::load_pod CFClient::find_rcfile "pod/command_help.pod"; |
20 | my $cmd_help = CFClient::load_pod CFClient::find_rcfile "pod/command_help.pod", command_help => 1, sub { |
|
|
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; |
… | |
… | |
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 | x => "center", |
|
|
345 | y => "center", |
|
|
346 | title => "Query", |
|
|
347 | child => my $vbox = new CFClient::UI::VBox, |
|
|
348 | ; |
|
|
349 | |
|
|
350 | $vbox->add (new CFClient::UI::Label |
|
|
351 | max_w => $::WIDTH * 0.4, |
|
|
352 | ellipsise => 0, |
|
|
353 | text => $prompt); |
|
|
354 | |
|
|
355 | if ($flags & CS_QUERY_YESNO) { |
|
|
356 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
|
|
357 | $hbox->add (new CFClient::UI::Button |
|
|
358 | text => "No", |
|
|
359 | on_activate => sub { |
|
|
360 | $self->send ("reply n"); |
|
|
361 | $dialog->destroy; |
|
|
362 | $self->{map_widget}->focus_in; |
|
|
363 | } |
|
|
364 | ); |
|
|
365 | $hbox->add (new CFClient::UI::Button |
|
|
366 | text => "Yes", |
|
|
367 | on_activate => sub { |
|
|
368 | $self->send ("reply y"); |
|
|
369 | $dialog->destroy; |
|
|
370 | }, |
|
|
371 | ); |
|
|
372 | |
|
|
373 | $dialog->focus_in; |
|
|
374 | |
|
|
375 | } elsif ($flags & CS_QUERY_SINGLECHAR) { |
|
|
376 | $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)"; |
|
|
377 | $vbox->add (my $entry = new CFClient::UI::Entry |
|
|
378 | on_changed => sub { |
|
|
379 | $self->send ("reply $_[1]"); |
|
|
380 | $dialog->destroy; |
|
|
381 | }, |
|
|
382 | ); |
|
|
383 | |
|
|
384 | $entry->focus_in; |
|
|
385 | |
|
|
386 | } else { |
|
|
387 | $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)"; |
|
|
388 | |
|
|
389 | $vbox->add (my $entry = new CFClient::UI::Entry |
|
|
390 | $flags & CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), |
|
|
391 | on_activate => sub { |
|
|
392 | $self->send ("reply $_[1]"); |
|
|
393 | $dialog->destroy; |
|
|
394 | }, |
|
|
395 | ); |
|
|
396 | |
|
|
397 | $entry->focus_in; |
|
|
398 | } |
|
|
399 | |
|
|
400 | $dialog->show; |
|
|
401 | } |
353 | } |
402 | |
354 | |
403 | sub drawinfo { |
355 | sub drawinfo { |
404 | my ($self, $color, $text) = @_; |
356 | my ($self, $color, $text) = @_; |
405 | |
357 | |
… | |
… | |
419 | [0.74, 0.65, 0.41], |
371 | [0.74, 0.65, 0.41], |
420 | ); |
372 | ); |
421 | |
373 | |
422 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
374 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
423 | |
375 | |
|
|
376 | # try to create single paragraphs of multiple lines sent by the server |
|
|
377 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
378 | |
424 | $text = CFClient::UI::Label::escape $text; |
379 | $text = CFClient::UI::Label::escape $text; |
425 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
380 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
426 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
381 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
427 | |
382 | |
428 | $self->{logview}->add_paragraph ($color[$color], |
383 | $self->{logview}->add_paragraph ($color[$color], |
… | |
… | |
443 | } |
398 | } |
444 | |
399 | |
445 | sub spell_add { |
400 | sub spell_add { |
446 | my ($self, $spell) = @_; |
401 | my ($self, $spell) = @_; |
447 | |
402 | |
448 | # TODO |
403 | # try to create single paragraphs of multiple lines sent by the server |
449 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
404 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
405 | $spell->{message} =~ s/\n+$//; |
|
|
406 | $spell->{message} ||= "Server did not provide a description for this spell."; |
|
|
407 | |
450 | $::SETUP_SPELLS->add_spell ($spell); |
408 | $::SETUP_SPELLS->add_spell ($spell); |
451 | |
409 | |
452 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
410 | $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}); |
411 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
454 | } |
412 | } |
… | |
… | |
459 | } |
417 | } |
460 | |
418 | |
461 | sub addme_success { |
419 | sub addme_success { |
462 | my ($self) = @_; |
420 | my ($self) = @_; |
463 | |
421 | |
464 | my $pod = CFClient::load_pod CFClient::find_rcfile "pod/skill_help.pod"; |
422 | my $skill_help = CFClient::load_pod CFClient::find_rcfile "pod/skill_help.pod", skill_help => 1, sub { |
|
|
423 | my ($pom) = @_; |
465 | |
424 | |
466 | my %skill_tooltip; |
425 | my %skill_help; |
467 | |
426 | |
468 | for my $head2 ($pod->head1->[-2]->head2) { |
427 | for my $head2 ($pom->head1->[3]->head2) { |
469 | $skill_tooltip{$head2->title} = CFClient::pod_to_pango $head2->content; |
428 | $skill_help{$head2->title} = CFClient::pod_to_pango $head2->content; |
|
|
429 | } |
|
|
430 | |
|
|
431 | \%skill_help |
470 | } |
432 | }; |
471 | |
433 | |
472 | for my $skill (values %{$self->{skill_info}}) { |
434 | for my $skill (values %{$self->{skill_info}}) { |
473 | $self->{map_widget}->add_command ("ready_skill $skill", |
435 | $self->{map_widget}->add_command ("ready_skill $skill", |
474 | (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
436 | (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
475 | . $skill_tooltip{$skill}); |
437 | . $skill_help->{$skill}); |
476 | $self->{map_widget}->add_command ("use_skill $skill", |
438 | $self->{map_widget}->add_command ("use_skill $skill", |
477 | (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
439 | (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
478 | . $skill_tooltip{$skill}); |
440 | . $skill_help->{$skill}); |
479 | } |
441 | } |
480 | } |
442 | } |
481 | |
443 | |
482 | sub eof { |
444 | sub eof { |
483 | my ($self) = @_; |
445 | my ($self) = @_; |
… | |
… | |
527 | |
489 | |
528 | $::FLOORBOX->clear; |
490 | $::FLOORBOX->clear; |
529 | |
491 | |
530 | my $row; |
492 | my $row; |
531 | for (@{ $::CONN->{container}{0} }) { |
493 | for (@{ $::CONN->{container}{0} }) { |
532 | if ($row < 7) { |
494 | if ($row < 6) { |
533 | local $_->{face_widget}; # hack to force recreation of widget |
495 | local $_->{face_widget}; # hack to force recreation of widget |
534 | local $_->{desc_widget}; # hack to force recreation of widget |
496 | local $_->{desc_widget}; # hack to force recreation of widget |
535 | CFClient::Item::update_widgets $_; |
497 | CFClient::Item::update_widgets $_; |
536 | |
498 | |
537 | $::FLOORBOX->add (0, $row, $_->{face_widget}); |
499 | $::FLOORBOX->add (0, $row, $_->{face_widget}); |
538 | $::FLOORBOX->add (1, $row, $_->{desc_widget}); |
500 | $::FLOORBOX->add (1, $row, $_->{desc_widget}); |
539 | |
501 | |
540 | $row++; |
502 | $row++; |
541 | } else { |
503 | } else { |
542 | $::FLOORBOX->add (1, $row, new CFClient::UI::Label text => "More..."); |
504 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
|
|
505 | text => "More...", |
|
|
506 | on_activate => sub { $::INV_WINDOW->toggle_visibility }, |
|
|
507 | ); |
543 | last; |
508 | last; |
544 | } |
509 | } |
545 | } |
510 | } |
546 | }); |
511 | }); |
547 | |
512 | |
… | |
… | |
656 | } |
621 | } |
657 | } |
622 | } |
658 | |
623 | |
659 | sub player_update { |
624 | sub player_update { |
660 | my ($self, $player) = @_; |
625 | my ($self, $player) = @_; |
|
|
626 | |
661 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
627 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
|
|
628 | } |
662 | |
629 | |
663 | # do it here because it is ignored earlier, and there is no "login" event |
630 | sub logged_in { |
|
|
631 | my ($self) = @_; |
|
|
632 | |
|
|
633 | $self->send_ext_req (cfplus => "version", "1", sub { |
|
|
634 | $self->{cfplus_ext} = $_[0]; |
|
|
635 | }); |
|
|
636 | |
664 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
637 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
665 | $self->send_command ("output-count $::CFG->{output_count}"); |
638 | $self->send_command ("output-count $::CFG->{output_count}"); |
|
|
639 | $self->send_command ("pickup $::CFG->{pickup}"); |
|
|
640 | |
|
|
641 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
|
|
642 | |
|
|
643 | $::SERVER_INFO->set_markup ( |
|
|
644 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
|
|
645 | . "protocol version <tt>$self->{version}</tt>\n" |
|
|
646 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
647 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
648 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]\n" |
|
|
649 | . "map size $self->{mapw}×$self->{maph}\n" |
|
|
650 | ); |
666 | } |
651 | } |
667 | |
652 | |
668 | 1; |
653 | 1; |