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.34 by elmex, Tue Jun 13 14:35:17 2006 UTC vs.
Revision 1.42 by root, Fri Jun 23 23:54:30 2006 UTC

83 83
84 print $fh "$ts ", @a, "\n"; 84 print $fh "$ts ", @a, "\n";
85 $fh->flush; 85 $fh->flush;
86} 86}
87 87
88
89
90sub stats_update { 88sub stats_update {
91 my ($self, $stats) = @_; 89 my ($self, $stats) = @_;
92 90
93 if (my $exp = $stats->{+CS_STAT_EXP64}) { 91 if (my $exp = $stats->{+CS_STAT_EXP64}) {
94 my $diff = $exp - $self->{prev_exp}; 92 my $diff = $exp - $self->{prev_exp};
134 132
135 $self->{map}->map1a_update ($data); 133 $self->{map}->map1a_update ($data);
136 $self->{map_widget}->update; 134 $self->{map_widget}->update;
137} 135}
138 136
137sub magicmap {
138 my ($self, $w, $h, $x, $y, $data) = @_;
139
140 $self->{map_widget}->set_magicmap ($w, $h, $x, $y, $data);
141}
142
139sub flush_map { 143sub flush_map {
140 my ($self) = @_; 144 my ($self) = @_;
141 145
142 my $map_info = delete $self->{map_info} 146 my $map_info = delete $self->{map_info}
143 or return; 147 or return;
154 158
155 $self->flush_map; 159 $self->flush_map;
156 delete $self->{neigh_map}; 160 delete $self->{neigh_map};
157 161
158 $self->{map}->clear; 162 $self->{map}->clear;
163 delete $self->{map_widget}{magicmap};
159} 164}
160 165
161 166
162sub load_map($$$) { 167sub load_map($$$) {
163 my ($self, $hash, $x, $y) = @_; 168 my ($self, $hash, $x, $y) = @_;
306 # I love transactions 311 # I love transactions
307 for (1..100) { 312 for (1..100) {
308 my $txn = $CFClient::DB_ENV->txn_begin; 313 my $txn = $CFClient::DB_ENV->txn_begin;
309 my $status = $self->{facemap}->db_get (id => $id); 314 my $status = $self->{facemap}->db_get (id => $id);
310 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { 315 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) {
311 $id = ($id || 16) + 1; 316 $id = ($id || 64) + 1;
312 if ($self->{facemap}->put (id => $id) == 0 317 if ($self->{facemap}->put (id => $id) == 0
313 && $self->{facemap}->put ($hash => $id) == 0) { 318 && $self->{facemap}->put ($hash => $id) == 0) {
314 $txn->txn_commit; 319 $txn->txn_commit;
315 320
316 goto gotid; 321 goto gotid;
407 412
408 $text = CFClient::UI::Label::escape $text; 413 $text = CFClient::UI::Label::escape $text;
409 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 414 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
410 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 415 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
411 416
412 $self->{logview}->add_paragraph ($color[$color], 417 $self->{logview}->add_paragraph ($color[$color], $_)
413 join "\n", map "$time $_", split /\n/, $text); 418 for map "$time $_", split /\n/, $text;
419 $self->{logview}->scroll_to_bottom;
414 420
415 $self->{statusbox}->add ($text, 421 $self->{statusbox}->add ($text,
416 group => $text, 422 group => $text,
417 fg => $color[$color], 423 fg => $color[$color],
418 timeout => $color >= 2 ? 60 : 10, 424 timeout => $color >= 2 ? 60 : 10,
530 536
531 $row++; 537 $row++;
532 } else { 538 } else {
533 $::FLOORBOX->add (1, $row, new CFClient::UI::Button 539 $::FLOORBOX->add (1, $row, new CFClient::UI::Button
534 text => "More...", 540 text => "More...",
535 on_activate => sub { $::INV_WINDOW->toggle_visibility }, 541 on_activate => sub { $::INV_WINDOW->toggle_visibility; 0 },
536 ); 542 );
537 last; 543 last;
538 } 544 }
539 } 545 }
540 }); 546 });
555 tooltip => "Close the currently open container (if one is open)", 561 tooltip => "Close the currently open container (if one is open)",
556 on_activate => sub { 562 on_activate => sub {
557 $::CONN->send ("apply $tag") # $::CONN->{open_container}") 563 $::CONN->send ("apply $tag") # $::CONN->{open_container}")
558 if $tag != 0; 564 if $tag != 0;
559 #if $CONN->{open_container} != 0; 565 #if $CONN->{open_container} != 0;
566 0
560 }, 567 },
561 ); 568 );
562 } 569 }
563 570
564 $::INVR->set_items ($conn->{container}{$tag}); 571 $::INVR->set_items ($conn->{container}{$tag});
756 763
757 return unless $text =~ /\S/; 764 return unless $text =~ /\S/;
758 765
759 $entry->set_text (""); 766 $entry->set_text ("");
760 $this->send ($text); 767 $this->send ($text);
768
769 0
761 }, 770 },
762 ); 771 );
763 772
764 $vbox->add ($self->{options} = new CFClient::UI::VBox); 773 $vbox->add ($self->{options} = new CFClient::UI::VBox);
765 774
766 $self->{close_button} = new CFClient::UI::Button 775 $self->{bye_button} = new CFClient::UI::Button
767 text => "Bye (close)", 776 text => "Bye (close)",
768 tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", 777 tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.",
769 on_activate => sub { $this->destroy }, 778 on_activate => sub { $this->destroy; 0 },
770 ; 779 ;
771 780
772 $self->update_options; 781 $self->update_options;
773 782
774 $self->{token} = $self->{conn}->ext_token; 783 $self->{token} = $self->{conn}->ext_token;
775 $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) }); 784 $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) });
776 $self->{conn}->send ("ext npc_dialog_begin $self->{token} $self->{dx} $self->{dy}"); 785 $self->{conn}->send ("ext npc_dialog_begin $self->{token} $self->{dx} $self->{dy}");
777 786
778 $self->{entry}->focus_in; 787 $self->{entry}->grab_focus;
779 788
780 $self->{textview}->add_paragraph ([1, 1, 0, 1], "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n"); 789 $self->{textview}->add_paragraph ([1, 1, 0, 1], "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n");
781 790
782 $self->show; 791 $self->show;
783 $self 792 $self
787 my ($self) = @_; 796 my ($self) = @_;
788 797
789 Scalar::Util::weaken $self; 798 Scalar::Util::weaken $self;
790 799
791 $self->{options}->clear; 800 $self->{options}->clear;
792 $self->{options}->add ($self->{close_button}); 801 $self->{options}->add ($self->{bye_button});
793 802
794 for my $kw (sort keys %{ $self->{kw} }) { 803 for my $kw (sort keys %{ $self->{kw} }) {
795 $self->{options}->add (new CFClient::UI::Button 804 $self->{options}->add (new CFClient::UI::Button
796 text => $kw, 805 text => $kw,
797 on_activate => sub { 806 on_activate => sub {
798 $self->send ($kw); 807 $self->send ($kw);
808 0
799 }, 809 },
800 ); 810 );
801 } 811 }
802} 812}
803 813
804sub feed { 814sub feed {
805 my ($self, $data) = @_; 815 my ($self, $data) = @_;
816
817 Scalar::Util::weaken $self;
806 818
807 my ($type, $msg) = split / /, $data, 2; 819 my ($type, $msg) = split / /, $data, 2;
808 820
809 if ($type eq "msg") { 821 if ($type eq "msg") {
810 my ($msg, @kw) = split /\x00/, $msg; 822 my ($msg, @kw) = split /\x00/, $msg;
811 $self->{kw}{$_} = 1 for @kw; 823 $self->{kw}{$_} = 1 for @kw;
812 824
813 $msg = CFClient::UI::Label::escape $msg; 825 $msg = "\n" . CFClient::UI::Label::escape $msg;
814 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; 826 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} };
815 $msg =~ s/($match)/<span foreground='#c0c0ff' underline='none'>$1<\/span>/gi; # underline when http-ready, huh. 827 my @link;
828 $msg =~ s{
829 ($match)
830 }{
831 my $kw = $1;
832
833 push @link, new CFClient::UI::Label
834 markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>",
835 can_hover => 1,
836 can_events => 1,
837 on_button_up => sub {
838 $self->send ($kw);
839 };
840
841 chr 0xfffc
842 }giex;
816 843
817 $self->{textview}->add_paragraph ([1, 1, 1, 1], "\n$msg"); 844 $self->{textview}->add_paragraph ([1, 1, 1, 1], [$msg, @link]);
845 $self->{textview}->scroll_to_bottom;
818 $self->update_options; 846 $self->update_options;
819 } else { 847 } else {
820 $self->destroy; 848 $self->destroy;
821 } 849 }
822 850
826sub send { 854sub send {
827 my ($self, $msg) = @_; 855 my ($self, $msg) = @_;
828 856
829 $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); 857 $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg");
830 $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg); 858 $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg);
859 $self->{textview}->scroll_to_bottom;
831} 860}
832 861
833sub destroy { 862sub destroy {
834 my ($self) = @_; 863 my ($self) = @_;
835 864
836 #Carp::cluck "debug\n";#d# #todo# enable: destroyx gets called twice because scalar keys {} is 1 865 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1
837 866
838 delete $self->{conn}{npc_dialog}; 867 delete $self->{conn}{npc_dialog};
839 $self->{conn}->disconnect_ext ($self->{token}); 868 $self->{conn}->disconnect_ext ($self->{token});
840 869
841 $self->SUPER::destroy; 870 $self->SUPER::destroy;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines