ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.15 by root, Thu Jun 1 18:56:05 2006 UTC vs.
Revision 1.22 by root, Tue Jun 6 02:55:50 2006 UTC

3use utf8; 3use utf8;
4use strict; 4use strict;
5 5
6use Crossfire::Protocol::Constants; 6use Crossfire::Protocol::Constants;
7 7
8use CFClient;
8use CFClient::UI; 9use CFClient::UI;
9 10
10use base 'Crossfire::Protocol::Base'; 11use base 'Crossfire::Protocol::Base';
11 12
12sub new { 13sub 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;
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
403sub drawinfo { 355sub drawinfo {
404 my ($self, $color, $text) = @_; 356 my ($self, $color, $text) = @_;
405 357
429 join "\n", map "$time $_", split /\n/, $text); 381 join "\n", map "$time $_", split /\n/, $text);
430 382
431 $self->{statusbox}->add ($text, 383 $self->{statusbox}->add ($text,
432 group => $text, 384 group => $text,
433 fg => $color[$color], 385 fg => $color[$color],
434 timeout => 10, 386 timeout => $color >= 2 ? 60 : 10,
435 tooltip_font => $::FONT_FIXED, 387 tooltip_font => $::FONT_FIXED,
436 ); 388 );
437} 389}
438 390
439sub drawextinfo { 391sub drawextinfo {
445sub spell_add { 397sub spell_add {
446 my ($self, $spell) = @_; 398 my ($self, $spell) = @_;
447 399
448 # TODO 400 # TODO
449 # create a widget dynamically, using spell face (CF::Protocol downloads them) 401 # create a widget dynamically, using spell face (CF::Protocol downloads them)
450 $::SPELL_LIST->add_spell ($spell); 402 $::SETUP_SPELLS->add_spell ($spell);
451 403
452 $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); 404 $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}); 405 $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message});
454} 406}
455 407
456sub spell_delete { 408sub spell_delete {
457 my ($self, $spell) = @_; 409 my ($self, $spell) = @_;
458 $::SPELL_LIST->remove_spell ($spell); 410 $::SETUP_SPELLS->remove_spell ($spell);
459} 411}
460 412
461sub addme_success { 413sub addme_success {
462 my ($self) = @_; 414 my ($self) = @_;
463 415
464 my $parser = new Pod::POM; 416 my $skill_help = CFClient::load_pod CFClient::find_rcfile "pod/skill_help.pod", skill_help => 1, sub {
465 my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod"); 417 my ($pom) = @_;
466 418
467 my %skill_tooltip; 419 my %skill_help;
468 420
469 for my $head2 ($pod->head1->[-2]->head2) { 421 for my $head2 ($pom->head1->[3]->head2) {
470 $skill_tooltip{$head2->title} = CFClient::pod_to_pango $head2->content; 422 $skill_help{$head2->title} = CFClient::pod_to_pango $head2->content;
423 }
424
425 \%skill_help
471 } 426 };
472 427
473 for my $skill (values %{$self->{skill_info}}) { 428 for my $skill (values %{$self->{skill_info}}) {
474 $self->{map_widget}->add_command ("ready_skill $skill", 429 $self->{map_widget}->add_command ("ready_skill $skill",
475 (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") 430 (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n")
476 . $skill_tooltip{$skill}); 431 . $skill_help->{$skill});
477 $self->{map_widget}->add_command ("use_skill $skill", 432 $self->{map_widget}->add_command ("use_skill $skill",
478 (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") 433 (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n")
479 . $skill_tooltip{$skill}); 434 . $skill_help->{$skill});
480 } 435 }
481} 436}
482 437
483sub eof { 438sub eof {
484 my ($self) = @_; 439 my ($self) = @_;
509 my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); 464 my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, ();
510 465
511 $self->send ("requestinfo image_sums $face $face"); 466 $self->send ("requestinfo image_sums $face $face");
512 467
513 $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", 468 $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo",
514 group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); 469 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
515 } elsif (!exists $self->{num_faces}) { 470 } elsif (!exists $self->{num_faces}) {
516 $self->send ("requestinfo image_info"); 471 $self->send ("requestinfo image_info");
517 472
518 $self->{num_faces} = 0; 473 $self->{num_faces} = 0;
519 474
520 $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", 475 $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch",
521 group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); 476 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
522 } 477 }
523} 478}
524 479
525sub update_floorbox { 480sub update_floorbox {
526 $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { 481 $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines