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.1 by root, Fri May 26 18:56:14 2006 UTC vs.
Revision 1.10 by elmex, Mon May 29 20:22:33 2006 UTC

1package CFClient::Protocol; 1package CFClient::Protocol;
2 2
3use utf8; 3use utf8;
4use strict; 4use strict;
5
6use Crossfire::Protocol::Constants;
5 7
6use CFClient::UI; 8use CFClient::UI;
7 9
8use base 'Crossfire::Protocol::Base'; 10use base 'Crossfire::Protocol::Base';
9 11
23 25
24 my $cmd = $1; 26 my $cmd = $1;
25 my @args = split /\|/, $2; 27 my @args = split /\|/, $2;
26 @args = (".*") unless @args; 28 @args = (".*") unless @args;
27 29
30 $_ = $_ eq ".*" ? "" : " $_"
31 for @args;
32
28 my $text = CFClient::pod_to_pango $head2->content; 33 my $text = CFClient::pod_to_pango $head2->content;
29 34
30 for my $arg (@args) {
31 $arg = $arg eq ".*" ? "" : " $arg";
32
33 $self->{map_widget}->add_command ("$cmd$arg", $text); 35 $self->{map_widget}->add_command ("$cmd$_", $text)
34 } 36 for sort { (length $a) <=> (length $b) }
37 @args;
35 } 38 }
36 39
37 $self->{noface} = new_from_file CFClient::Texture 40 $self->{noface} = new_from_file CFClient::Texture
38 CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; 41 CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1;
39 42
50} 53}
51 54
52sub stats_update { 55sub stats_update {
53 my ($self, $stats) = @_; 56 my ($self, $stats) = @_;
54 57
55 if (my $exp = $stats->{Crossfire::Protocol::Base::CS_STAT_EXP64}) { 58 if (my $exp = $stats->{+CS_STAT_EXP64}) {
56 my $diff = $exp - $self->{prev_exp}; 59 my $diff = $exp - $self->{prev_exp};
57 $self->{statusbox}->add ("$diff experience gained", group => "experience $diff", fg => [0.5, 1, 0.5, 0.8], timeout => 5) 60 $self->{statusbox}->add ("$diff experience gained", group => "experience $diff", fg => [0.5, 1, 0.5, 0.8], timeout => 5)
58 if exists $self->{prev_exp} && $diff; 61 if exists $self->{prev_exp} && $diff;
59 $self->{prev_exp} = $exp; 62 $self->{prev_exp} = $exp;
60 } 63 }
63} 66}
64 67
65sub user_send { 68sub user_send {
66 my ($self, $command) = @_; 69 my ($self, $command) = @_;
67 70
71 if ($self->{record}) {
72 push @{$self->{record}}, $command;
73 }
74
68 $self->send_command ($command); 75 $self->send_command ($command);
69 status $command; 76 ::status $command;
77}
78
79sub start_record {
80 my ($self) = @_;
81
82 $self->{record} = [];
83}
84
85sub stop_record {
86 my ($self) = @_;
87 return delete $self->{record};
70} 88}
71 89
72sub map_scroll { 90sub map_scroll {
73 my ($self, $dx, $dy) = @_; 91 my ($self, $dx, $dy) = @_;
74 92
322 $prompt = $LAST_QUERY unless length $prompt; 340 $prompt = $LAST_QUERY unless length $prompt;
323 $LAST_QUERY = $prompt; 341 $LAST_QUERY = $prompt;
324 342
325 my $dialog = new CFClient::UI::FancyFrame 343 my $dialog = new CFClient::UI::FancyFrame
326 title => "Query", 344 title => "Query",
327 child => my $vbox = new CFClient::UI::VBox; 345 child => my $vbox = new CFClient::UI::VBox,
346 on_visibility_change => sub {
347 my ($self, $visible) = @_;
348 $self->center if $visible;
349 },
350 ;
328 351
329 $vbox->add (new CFClient::UI::Label 352 $vbox->add (new CFClient::UI::Label
330 max_w => $::WIDTH * 0.4, 353 max_w => $::WIDTH * 0.4,
331 ellipsise => 0, 354 ellipsise => 0,
332 text => $prompt); 355 text => $prompt);
333 356
334 if ($flags & Crossfire::Protocol::Base::CS_QUERY_YESNO) { 357 if ($flags & CS_QUERY_YESNO) {
335 $vbox->add (my $hbox = new CFClient::UI::HBox); 358 $vbox->add (my $hbox = new CFClient::UI::HBox);
336 $hbox->add (new CFClient::UI::Button 359 $hbox->add (new CFClient::UI::Button
337 text => "No", 360 text => "No",
338 connect_activate => sub { 361 on_activate => sub {
339 $self->send ("reply n"); 362 $self->send ("reply n");
340 $dialog->destroy; 363 $dialog->destroy;
341 $self->{map_widget}->focus_in; 364 $self->{map_widget}->focus_in;
342 } 365 }
343 ); 366 );
344 $hbox->add (new CFClient::UI::Button 367 $hbox->add (new CFClient::UI::Button
345 text => "Yes", 368 text => "Yes",
346 connect_activate => sub { 369 on_activate => sub {
347 $self->send ("reply y"); 370 $self->send ("reply y");
348 $dialog->destroy; 371 $dialog->destroy;
349 }, 372 },
350 ); 373 );
351 374
352 $dialog->focus_in; 375 $dialog->focus_in;
353 376
354 } elsif ($flags & Crossfire::Protocol::Base::CS_QUERY_SINGLECHAR) { 377 } elsif ($flags & CS_QUERY_SINGLECHAR) {
355 $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)"; 378 $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)";
356 $vbox->add (my $entry = new CFClient::UI::Entry 379 $vbox->add (my $entry = new CFClient::UI::Entry
357 connect_changed => sub { 380 on_changed => sub {
358 $self->send ("reply $_[1]"); 381 $self->send ("reply $_[1]");
359 $dialog->destroy; 382 $dialog->destroy;
360 }, 383 },
361 ); 384 );
362 385
364 387
365 } else { 388 } else {
366 $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)"; 389 $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)";
367 390
368 $vbox->add (my $entry = new CFClient::UI::Entry 391 $vbox->add (my $entry = new CFClient::UI::Entry
369 $flags & Crossfire::Protocol::Base::CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), 392 $flags & CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (),
370 connect_activate => sub { 393 on_activate => sub {
371 $self->send ("reply $_[1]"); 394 $self->send ("reply $_[1]");
372 $dialog->destroy; 395 $dialog->destroy;
373 }, 396 },
374 ); 397 );
375 398
376 $entry->focus_in; 399 $entry->focus_in;
377 } 400 }
378 401
379 $dialog->show_centered; 402 $dialog->show;
380} 403}
381 404
382sub drawinfo { 405sub drawinfo {
383 my ($self, $color, $text) = @_; 406 my ($self, $color, $text) = @_;
384 407
529} 552}
530 553
531sub set_opencont { 554sub set_opencont {
532 my ($conn, $tag, $name) = @_; 555 my ($conn, $tag, $name) = @_;
533 $conn->{open_container} = $tag; 556 $conn->{open_container} = $tag;
534 $::INVR_LBL->set_text ($name); 557
558 $::INV_RIGHT_HB->clear ();
559 $::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name);
560
561 if ($tag != 0) { # Floor isn't closable, is it?
562 $::INV_RIGHT_HB->add (new CFClient::UI::Button
563 text => "Close container",
564 tooltip => "Close the currently open container (if one is open)",
565 on_activate => sub {
566 $::CONN->send ("apply $tag") # $::CONN->{open_container}")
567 if $tag != 0;
568 #if $CONN->{open_container} != 0;
569 },
570 );
571 }
572
535 $::INVR->set_items ($conn->{container}{$tag}); 573 $::INVR->set_items ($conn->{container}{$tag});
536} 574}
537 575
538sub update_container { 576sub update_container {
539 my ($tag) = @_; 577 my ($tag) = @_;
602 return; 640 return;
603 } 641 }
604 642
605 CFClient::Item::update_widgets $item; 643 CFClient::Item::update_widgets $item;
606 644
607 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & Crossfire::Protocol::Base::F_OPEN)) { 645 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) {
608 set_opencont ($::CONN, 0, "Floor"); 646 set_opencont ($::CONN, 0, "Floor");
609 647
610 } elsif ($item->{flags} & Crossfire::Protocol::Base::F_OPEN) { 648 } elsif ($item->{flags} & F_OPEN) {
611 set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item); 649 set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item);
612 } else { 650 } else {
613 if ($item->{container} == 0) { 651 if ($item->{container} == 0) {
614 update_floorbox; 652 update_floorbox;
615 update_container (0); 653 update_container (0);
617 $::INV->set_items ($self->{container}{$item->{container}}) 655 $::INV->set_items ($self->{container}{$item->{container}})
618 } 656 }
619 } 657 }
620} 658}
621 659
660sub player_update {
661 my ($self, $player) = @_;
662 $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000);
663}
664
6221; 6651;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines