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.8 by root, Sun May 28 19:25:55 2006 UTC vs.
Revision 1.25 by root, Tue Jun 6 03:13:00 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;
66} 75}
67 76
68sub user_send { 77sub user_send {
69 my ($self, $command) = @_; 78 my ($self, $command) = @_;
70 79
80 if ($self->{record}) {
81 push @{$self->{record}}, $command;
82 }
83
71 $self->send_command ($command); 84 $self->send_command ($command);
72 ::status $command; 85 ::status $command;
86}
87
88sub start_record {
89 my ($self) = @_;
90
91 $self->{record} = [];
92}
93
94sub stop_record {
95 my ($self) = @_;
96 return delete $self->{record};
73} 97}
74 98
75sub map_scroll { 99sub map_scroll {
76 my ($self, $dx, $dy) = @_; 100 my ($self, $dx, $dy) = @_;
77 101
253 unless ($id) { 277 unless ($id) {
254 # create new id for face 278 # create new id for face
255 # I love transactions 279 # I love transactions
256 for (1..100) { 280 for (1..100) {
257 my $txn = $CFClient::DB_ENV->txn_begin; 281 my $txn = $CFClient::DB_ENV->txn_begin;
258 my $status = $self->{facemap}->db_get (id => $id, BerkeleyDB::DB_RMW); 282 my $status = $self->{facemap}->db_get (id => $id);
259 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { 283 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) {
260 $id = ($id || 16) + 1; 284 $id = ($id || 16) + 1;
261 if ($self->{facemap}->put (id => $id) == 0 285 if ($self->{facemap}->put (id => $id) == 0
262 && $self->{facemap}->put ($hash => $id) == 0) { 286 && $self->{facemap}->put ($hash => $id) == 0) {
263 $txn->txn_commit; 287 $txn->txn_commit;
264 288
265 goto gotid; 289 goto gotid;
266 } 290 }
267 } 291 }
268 $txn->abort; 292 $txn->txn_abort;
269 } 293 }
270 294
271 CFClient::fatal "maximum number of transaction retries reached - database problems?"; 295 CFClient::fatal "maximum number of transaction retries reached - database problems?";
272 } 296 }
273 297
323 my ($self, $flags, $prompt) = @_; 347 my ($self, $flags, $prompt) = @_;
324 348
325 $prompt = $LAST_QUERY unless length $prompt; 349 $prompt = $LAST_QUERY unless length $prompt;
326 $LAST_QUERY = $prompt; 350 $LAST_QUERY = $prompt;
327 351
328 my $dialog = new CFClient::UI::FancyFrame 352 $self->{query}-> ($self, $flags, $prompt);
329 title => "Query",
330 child => my $vbox = new CFClient::UI::VBox,
331 on_visibility_change => sub {
332 my ($self, $visible) = @_;
333 $self->center if $visible;
334 },
335 ;
336
337 $vbox->add (new CFClient::UI::Label
338 max_w => $::WIDTH * 0.4,
339 ellipsise => 0,
340 text => $prompt);
341
342 if ($flags & CS_QUERY_YESNO) {
343 $vbox->add (my $hbox = new CFClient::UI::HBox);
344 $hbox->add (new CFClient::UI::Button
345 text => "No",
346 on_activate => sub {
347 $self->send ("reply n");
348 $dialog->destroy;
349 $self->{map_widget}->focus_in;
350 }
351 );
352 $hbox->add (new CFClient::UI::Button
353 text => "Yes",
354 on_activate => sub {
355 $self->send ("reply y");
356 $dialog->destroy;
357 },
358 );
359
360 $dialog->focus_in;
361
362 } elsif ($flags & CS_QUERY_SINGLECHAR) {
363 $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)";
364 $vbox->add (my $entry = new CFClient::UI::Entry
365 on_changed => sub {
366 $self->send ("reply $_[1]");
367 $dialog->destroy;
368 },
369 );
370
371 $entry->focus_in;
372
373 } else {
374 $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)";
375
376 $vbox->add (my $entry = new CFClient::UI::Entry
377 $flags & CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (),
378 on_activate => sub {
379 $self->send ("reply $_[1]");
380 $dialog->destroy;
381 },
382 );
383
384 $entry->focus_in;
385 }
386
387 $dialog->show;
388} 353}
389 354
390sub drawinfo { 355sub drawinfo {
391 my ($self, $color, $text) = @_; 356 my ($self, $color, $text) = @_;
392 357
406 [0.74, 0.65, 0.41], 371 [0.74, 0.65, 0.41],
407 ); 372 );
408 373
409 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; 374 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
410 375
376 # try to create single paragraphs of multiple lines sent by the server
377 $text =~ s/(?<=\S)\n(?=\w)/ /g;
378
411 $text = CFClient::UI::Label::escape $text; 379 $text = CFClient::UI::Label::escape $text;
412 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 380 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
413 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 381 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
414 382
415 $self->{logview}->add_paragraph ($color[$color], 383 $self->{logview}->add_paragraph ($color[$color],
416 join "\n", map "$time $_", split /\n/, $text); 384 join "\n", map "$time $_", split /\n/, $text);
417 385
418 $self->{statusbox}->add ($text, 386 $self->{statusbox}->add ($text,
419 group => $text, 387 group => $text,
420 fg => $color[$color], 388 fg => $color[$color],
421 timeout => 10, 389 timeout => $color >= 2 ? 60 : 10,
422 tooltip_font => $::FONT_FIXED, 390 tooltip_font => $::FONT_FIXED,
423 ); 391 );
424} 392}
425 393
426sub drawextinfo { 394sub drawextinfo {
432sub spell_add { 400sub spell_add {
433 my ($self, $spell) = @_; 401 my ($self, $spell) = @_;
434 402
435 # TODO 403 # TODO
436 # 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
437 $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});
438 $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});
439} 409}
440 410
441sub spell_delete { 411sub spell_delete {
442 my ($self, $spell) = @_; 412 my ($self, $spell) = @_;
413 $::SETUP_SPELLS->remove_spell ($spell);
443} 414}
444 415
445sub addme_success { 416sub addme_success {
446 my ($self) = @_; 417 my ($self) = @_;
447 418
448 $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 {
449 $self->send ("command output-count $::CFG->{output_count}"); 420 my ($pom) = @_;
450 421
451 my $parser = new Pod::POM;
452 my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod");
453
454 my %skill_tooltip; 422 my %skill_help;
455 423
456 for my $head2 ($pod->head1->[-2]->head2) { 424 for my $head2 ($pom->head1->[3]->head2) {
457 $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
458 } 429 };
459 430
460 for my $skill (values %{$self->{skill_info}}) { 431 for my $skill (values %{$self->{skill_info}}) {
461 $self->{map_widget}->add_command ("ready_skill $skill", 432 $self->{map_widget}->add_command ("ready_skill $skill",
462 (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") 433 (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n")
463 . $skill_tooltip{$skill}); 434 . $skill_help->{$skill});
464 $self->{map_widget}->add_command ("use_skill $skill", 435 $self->{map_widget}->add_command ("use_skill $skill",
465 (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") 436 (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n")
466 . $skill_tooltip{$skill}); 437 . $skill_help->{$skill});
467 } 438 }
468} 439}
469 440
470sub eof { 441sub eof {
471 my ($self) = @_; 442 my ($self) = @_;
496 my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); 467 my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, ();
497 468
498 $self->send ("requestinfo image_sums $face $face"); 469 $self->send ("requestinfo image_sums $face $face");
499 470
500 $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", 471 $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo",
501 group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); 472 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
502 } elsif (!exists $self->{num_faces}) { 473 } elsif (!exists $self->{num_faces}) {
503 $self->send ("requestinfo image_info"); 474 $self->send ("requestinfo image_info");
504 475
505 $self->{num_faces} = 0; 476 $self->{num_faces} = 0;
506 477
507 $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", 478 $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch",
508 group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); 479 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
509 } 480 }
510} 481}
511 482
512sub update_floorbox { 483sub update_floorbox {
513 $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { 484 $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub {
515 486
516 $::FLOORBOX->clear; 487 $::FLOORBOX->clear;
517 488
518 my $row; 489 my $row;
519 for (@{ $::CONN->{container}{0} }) { 490 for (@{ $::CONN->{container}{0} }) {
520 if ($row < 7) { 491 if ($row < 6) {
521 local $_->{face_widget}; # hack to force recreation of widget 492 local $_->{face_widget}; # hack to force recreation of widget
522 local $_->{desc_widget}; # hack to force recreation of widget 493 local $_->{desc_widget}; # hack to force recreation of widget
523 CFClient::Item::update_widgets $_; 494 CFClient::Item::update_widgets $_;
524 495
525 $::FLOORBOX->add (0, $row, $_->{face_widget}); 496 $::FLOORBOX->add (0, $row, $_->{face_widget});
526 $::FLOORBOX->add (1, $row, $_->{desc_widget}); 497 $::FLOORBOX->add (1, $row, $_->{desc_widget});
527 498
528 $row++; 499 $row++;
529 } else { 500 } else {
530 $::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 );
531 last; 505 last;
532 } 506 }
533 } 507 }
534 }); 508 });
535 509
537} 511}
538 512
539sub set_opencont { 513sub set_opencont {
540 my ($conn, $tag, $name) = @_; 514 my ($conn, $tag, $name) = @_;
541 $conn->{open_container} = $tag; 515 $conn->{open_container} = $tag;
542 $::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
543 $::INVR->set_items ($conn->{container}{$tag}); 532 $::INVR->set_items ($conn->{container}{$tag});
544} 533}
545 534
546sub update_container { 535sub update_container {
547 my ($tag) = @_; 536 my ($tag) = @_;
576 if ($tag == 0) { 565 if ($tag == 0) {
577 update_floorbox; 566 update_floorbox;
578 update_container (0); 567 update_container (0);
579 } elsif ($tag == $self->{player}{tag}) { 568 } elsif ($tag == $self->{player}{tag}) {
580 $::INV->set_items ($self->{container}{$tag}) 569 $::INV->set_items ($self->{container}{$tag})
570 } else {
571 update_container ($tag);
581 } 572 }
582 573
583# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 574# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
584} 575}
585 576
593 update_floorbox; 584 update_floorbox;
594 update_container ($_->{tag}); 585 update_container ($_->{tag});
595 } elsif ($_->{container} == $self->{player}{tag}) { 586 } elsif ($_->{container} == $self->{player}{tag}) {
596 $::INV->set_items ($self->{container}{$self->{player}{tag}}) 587 $::INV->set_items ($self->{container}{$self->{player}{tag}})
597 } else { 588 } else {
598 update_container ($_->{tag}); 589 update_container ($_->{container});
599 } 590 }
600 } 591 }
601} 592}
602 593
603sub item_update { 594sub item_update {
628} 619}
629 620
630sub player_update { 621sub player_update {
631 my ($self, $player) = @_; 622 my ($self, $player) = @_;
632 $::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}");
633} 628}
634 629
6351; 6301;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines