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.9 by elmex, Mon May 29 19:30:28 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;
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
405sub drawinfo { 355sub drawinfo {
406 my ($self, $color, $text) = @_; 356 my ($self, $color, $text) = @_;
407 357
431 join "\n", map "$time $_", split /\n/, $text); 381 join "\n", map "$time $_", split /\n/, $text);
432 382
433 $self->{statusbox}->add ($text, 383 $self->{statusbox}->add ($text,
434 group => $text, 384 group => $text,
435 fg => $color[$color], 385 fg => $color[$color],
436 timeout => 10, 386 timeout => $color >= 2 ? 60 : 10,
437 tooltip_font => $::FONT_FIXED, 387 tooltip_font => $::FONT_FIXED,
438 ); 388 );
439} 389}
440 390
441sub drawextinfo { 391sub drawextinfo {
447sub spell_add { 397sub spell_add {
448 my ($self, $spell) = @_; 398 my ($self, $spell) = @_;
449 399
450 # TODO 400 # TODO
451 # create a widget dynamically, using spell face (CF::Protocol downloads them) 401 # create a widget dynamically, using spell face (CF::Protocol downloads them)
402 $::SETUP_SPELLS->add_spell ($spell);
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) = @_;
410 $::SETUP_SPELLS->remove_spell ($spell);
458} 411}
459 412
460sub addme_success { 413sub addme_success {
461 my ($self) = @_; 414 my ($self) = @_;
462 415
463 $self->send ("command output-sync $::CFG->{output_sync}"); 416 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}"); 417 my ($pom) = @_;
465 418
466 my $parser = new Pod::POM;
467 my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod");
468
469 my %skill_tooltip; 419 my %skill_help;
470 420
471 for my $head2 ($pod->head1->[-2]->head2) { 421 for my $head2 ($pom->head1->[3]->head2) {
472 $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
473 } 426 };
474 427
475 for my $skill (values %{$self->{skill_info}}) { 428 for my $skill (values %{$self->{skill_info}}) {
476 $self->{map_widget}->add_command ("ready_skill $skill", 429 $self->{map_widget}->add_command ("ready_skill $skill",
477 (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") 430 (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n")
478 . $skill_tooltip{$skill}); 431 . $skill_help->{$skill});
479 $self->{map_widget}->add_command ("use_skill $skill", 432 $self->{map_widget}->add_command ("use_skill $skill",
480 (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") 433 (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n")
481 . $skill_tooltip{$skill}); 434 . $skill_help->{$skill});
482 } 435 }
483} 436}
484 437
485sub eof { 438sub eof {
486 my ($self) = @_; 439 my ($self) = @_;
511 my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); 464 my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, ();
512 465
513 $self->send ("requestinfo image_sums $face $face"); 466 $self->send ("requestinfo image_sums $face $face");
514 467
515 $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", 468 $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo",
516 group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); 469 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
517 } elsif (!exists $self->{num_faces}) { 470 } elsif (!exists $self->{num_faces}) {
518 $self->send ("requestinfo image_info"); 471 $self->send ("requestinfo image_info");
519 472
520 $self->{num_faces} = 0; 473 $self->{num_faces} = 0;
521 474
522 $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", 475 $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch",
523 group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); 476 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
524 } 477 }
525} 478}
526 479
527sub update_floorbox { 480sub update_floorbox {
528 $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { 481 $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub {
552} 505}
553 506
554sub set_opencont { 507sub set_opencont {
555 my ($conn, $tag, $name) = @_; 508 my ($conn, $tag, $name) = @_;
556 $conn->{open_container} = $tag; 509 $conn->{open_container} = $tag;
557 $::INVR_LBL->set_text ($name); 510
511 $::INV_RIGHT_HB->clear ();
512 $::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name);
513
514 if ($tag != 0) { # Floor isn't closable, is it?
515 $::INV_RIGHT_HB->add (new CFClient::UI::Button
516 text => "Close container",
517 tooltip => "Close the currently open container (if one is open)",
518 on_activate => sub {
519 $::CONN->send ("apply $tag") # $::CONN->{open_container}")
520 if $tag != 0;
521 #if $CONN->{open_container} != 0;
522 },
523 );
524 }
525
558 $::INVR->set_items ($conn->{container}{$tag}); 526 $::INVR->set_items ($conn->{container}{$tag});
559} 527}
560 528
561sub update_container { 529sub update_container {
562 my ($tag) = @_; 530 my ($tag) = @_;
591 if ($tag == 0) { 559 if ($tag == 0) {
592 update_floorbox; 560 update_floorbox;
593 update_container (0); 561 update_container (0);
594 } elsif ($tag == $self->{player}{tag}) { 562 } elsif ($tag == $self->{player}{tag}) {
595 $::INV->set_items ($self->{container}{$tag}) 563 $::INV->set_items ($self->{container}{$tag})
564 } else {
565 update_container ($tag);
596 } 566 }
597 567
598# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 568# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
599} 569}
600 570
608 update_floorbox; 578 update_floorbox;
609 update_container ($_->{tag}); 579 update_container ($_->{tag});
610 } elsif ($_->{container} == $self->{player}{tag}) { 580 } elsif ($_->{container} == $self->{player}{tag}) {
611 $::INV->set_items ($self->{container}{$self->{player}{tag}}) 581 $::INV->set_items ($self->{container}{$self->{player}{tag}})
612 } else { 582 } else {
613 update_container ($_->{tag}); 583 update_container ($_->{container});
614 } 584 }
615 } 585 }
616} 586}
617 587
618sub item_update { 588sub item_update {
643} 613}
644 614
645sub player_update { 615sub player_update {
646 my ($self, $player) = @_; 616 my ($self, $player) = @_;
647 $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); 617 $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000);
618
619 # do it here because it is ignored earlier, and there is no "login" event
620 $self->send_command ("output-sync $::CFG->{output_sync}");
621 $self->send_command ("output-count $::CFG->{output_count}");
648} 622}
649 623
6501; 6241;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines