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.174 by root, Sun Sep 2 08:44:28 2007 UTC vs.
Revision 1.207 by root, Sat Dec 20 19:45:50 2008 UTC

1package CFPlus::Protocol; 1package DC::Protocol;
2 2
3use utf8; 3use utf8;
4use strict; 4use strict;
5 5
6use Crossfire::Protocol::Constants; 6use Deliantra::Protocol::Constants;
7 7
8use CFPlus; 8use DC;
9use CFPlus::DB; 9use DC::DB;
10use CFPlus::UI; 10use DC::UI;
11use CFPlus::Pod; 11use DC::Pod;
12use CFPlus::Macro; 12use DC::Macro;
13use CFPlus::Item; 13use DC::Item;
14 14
15use base 'Crossfire::Protocol::Base'; 15use base 'Deliantra::Protocol::Base';
16
17our $TEX_DIALOGUE = new_from_resource DC::Texture
18 "dialogue.png", minify => 1, mipmap => 1;
19
20our $TEX_NOFACE = new_from_resource DC::Texture
21 "noface.png", minify => 1, mipmap => 1;
22
23our $TEX_HIDDEN = new_from_resource DC::Texture
24 "hidden.png", minify => 1, mipmap => 1;
25
26sub MIN_TEXTURE_UNUSED() { 1 }#d#
16 27
17sub new { 28sub new {
18 my ($class, %arg) = @_; 29 my ($class, %arg) = @_;
19 30
20 my $self = $class->SUPER::new (%arg, 31 my $self = $class->SUPER::new (%arg,
21 setup_req => { 32 setup_req => {
22 extmap => 1, 33 extmap => 1,
23 excmd => 1, 34 excmd => 1,
24 #xwidget2 => 1,#d# 35 widget => 2,
25 %{$arg{setup_req} || {}}, 36 %{$arg{setup_req} || {}},
26 msg => 0,
27 }, 37 },
28 ); 38 );
29 39
30 $self->{map_widget}->clr_commands; 40 $self->{map_widget}->clr_commands;
31 41
32 my @cmd_help = map { 42 my @cmd_help = map {
33 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 43 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
34 or die "unparseable command help: $_->{kw}[0]"; 44 or die "unparseable command help: $_->[DC::Pod::N_KW][0]";
35 45
36 my $cmd = $1; 46 my $cmd = $1;
37 my @args = split /\|/, $2; 47 my @args = split /\|/, $2;
38 @args = (".*") unless @args; 48 @args = (".*") unless @args;
39 49
40 my (undef, @par) = CFPlus::Pod::section_of $_; 50 my (undef, @par) = DC::Pod::section_of $_;
41 my $text = CFPlus::Pod::as_label @par; 51 my $text = DC::Pod::as_label @par;
42 52
43 $_ = $_ eq ".*" ? "" : " $_" 53 $_ = $_ eq ".*" ? "" : " $_"
44 for @args; 54 for @args;
45 55
46 map ["$cmd$_", $text], 56 map ["$cmd$_", $text],
47 sort { (length $a) <=> (length $b) } 57 sort { (length $a) <=> (length $b) }
48 @args 58 @args
49 } sort { $a->{par} <=> $b->{par} } 59 } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] }
50 CFPlus::Pod::find command => "*"; 60 DC::Pod::find command => "*";
51 61
52 $self->{json_coder} 62 $self->{json_coder}
53 ->convert_blessed 63 ->convert_blessed
54 ->filter_json_single_key_object ("\fw" => sub { 64 ->filter_json_single_key_object ("\fw" => sub {
55 $self->{widget}{$_[0]} 65 $self->{widget}{$_[0]}
65 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { 75 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
66 for my $ws (values %{delete $self->{widgetset} || {}}) { 76 for my $ws (values %{delete $self->{widgetset} || {}}) {
67 $_->destroy 77 $_->destroy
68 for values %{delete $ws->{w} || {}}; 78 for values %{delete $ws->{w} || {}};
69 } 79 }
80
81 delete $self->{items};
82 $::INV->clear;
83 $::INVR->clear;
84 $::INVR_HB->clear;
85 $::FLOORBOX->clear;
70 }); 86 });
71 87
72 $self->{map_widget}->add_command (@$_) 88 $self->{map_widget}->add_command (@$_)
73 for @cmd_help; 89 for @cmd_help;
74 90
75 { 91 {
76 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture 92 $self->{dialogue} = my $tex = $TEX_DIALOGUE;
77 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
78 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 93 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
79 } 94 }
80 95
81 { 96 {
82 $self->{noface} = my $tex = new_from_file CFPlus::Texture 97 $self->{noface} = my $tex = $TEX_NOFACE;
83 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
84 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 98 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
85 } 99 }
100
101 {
102 $self->{hidden} = my $tex = $TEX_HIDDEN;
103 $self->{map}->set_texture (3, @$tex{qw(name w h s t)}, @{$tex->{minified}});
104 }
105
106# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
107# $self->{expire_w} = EV::timer 1, 1, sub {
108# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
109#
110# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
111# warn DC::SvREFCNT $self->{texture}[$_];
112# $self->{texture}[$_]->unload;
113# warn "expire texture $_\n";#d#
114# }
115#
116# ($self->{expire_count} += $count) < @{ $self->{texture} }
117# or $self->{expire_count} = DC::DB::FIRST_TILE_ID;
118# warn "count is $count\n";#d#
119# };
86 120
87 $self->{open_container} = 0; 121 $self->{open_container} = 0;
88 122
89 # per server 123 # per server
90 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 124 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
103} 137}
104 138
105sub ext_capabilities { 139sub ext_capabilities {
106 my ($self, %cap) = @_; 140 my ($self, %cap) = @_;
107 141
108 #$self->send ("setup sound 0"); # we use a different protocol
109 $self->update_fx_want; 142 $self->update_fx_want;
110 143
111 $self->send_exti_req (resource => "exp_table", sub { 144 $self->send_exti_req (resource => "exp_table", sub {
112 my ($exp_table) = @_; 145 my ($exp_table) = @_;
113 146
143############################################################################# 176#############################################################################
144 177
145sub widget_associate { 178sub widget_associate {
146 my ($self, $ws, $id, $widget) = @_; 179 my ($self, $ws, $id, $widget) = @_;
147 180
148 $widget ||= new CFPlus::UI::Bin; 181 $widget ||= new DC::UI::Bin;
149 182
150 $widget->{s_id} = $id; 183 $widget->{s_id} = $id;
151 $self->{widget}{$id} = $widget; 184 $self->{widget}{$id} = $widget;
152 185
153 if ($ws) { 186 if ($ws) {
189 my ($self, $ws, $id, $class, $args) = @_; 222 my ($self, $ws, $id, $class, $args) = @_;
190 223
191 $self->widget_associate ( 224 $self->widget_associate (
192 $ws, $id => scalar eval { 225 $ws, $id => scalar eval {
193 local $SIG{__DIE__}; 226 local $SIG{__DIE__};
194 "CFPlus::UI::$class"->new (%$args) 227 "DC::UI::$class"->new (%$args)
195 } 228 }
196 ); 229 );
230}
231
232# widgetset create template
233sub ext_ws_ct {
234 my ($self, $ws, $type, $template, $done_cb, $cfg) = @_;
235
236 $done_cb ||= sub { };
237
238 my $parse_list; $parse_list = sub {
239 my ($list) = @_;
240 my @w;
241
242 while (@$list) {
243 my ($class, $args) = splice @$list, 0, 2;
244 my $name = delete $args->{s_id};
245 my $cl = delete $args->{s_cl};
246 my $cfg = delete $cfg->{$name};
247 my $id = delete $cfg->{id};
248 my $w = eval { "DC::UI::$class"->new (%$args, %{ $cfg || {} }) }
249 or next;
250
251 $self->widget_associate ($ws, $id, $w)
252 if $id;
253
254 $w->add ($parse_list->($cl))
255 if $cl;
256
257 push @w, $w;
258 }
259
260 @w
261 };
262
263 # either array reference, or face #
264 if ($type eq "inline") {
265 $done_cb->();
266 $parse_list->($template);
267 } elsif ($type eq "face") {
268 my $handler; $handler = $self->register_face_handler ($template, sub {
269 my ($face) = @_;
270
271 undef $handler;
272 $done_cb->();
273 $parse_list->($self->{json_coder}->decode ($face->{data}));
274 });
275 } else {
276 $done_cb->(0);
277 }
197} 278}
198 279
199# widgetset associate 280# widgetset associate
200sub ext_ws_a { 281sub ext_ws_a {
201 my ($self, %ass) = @_; 282 my ($self, %ass) = @_;
202 283
203 # everything that has a name, wether conceivably useful or not 284 # everything that has a name, wether conceivably useful or not
204 my %wkw = ( 285 my %wkw = (
205 root => $CFPlus::UI::ROOT, 286 root => $DC::UI::ROOT,
206 tooltip => $CFPlus::UI::TOOLTIP, 287 tooltip => $DC::UI::TOOLTIP,
207 288
208 mapwidget => $::MAPWIDGET, 289 mapwidget => $::MAPWIDGET,
209 buttonbar => $::BUTTONBAR, 290 buttonbar => $::BUTTONBAR,
210 metaserver => $::METASERVER, 291 metaserver => $::METASERVER,
211 buttonbar => $::BUTTONBAR, 292 buttonbar => $::BUTTONBAR,
229 spell_list => $::SPELL_LIST, 310 spell_list => $::SPELL_LIST,
230 311
231 floorbox => $::FLOORBOX, 312 floorbox => $::FLOORBOX,
232 help_window => $::HELP_WINDOW, 313 help_window => $::HELP_WINDOW,
233 message_window => $::MESSAGE_WINDOW, 314 message_window => $::MESSAGE_WINDOW,
315 message_dist => $::MESSAGE_DIST,
234 statusbox => $::SDTATUSBOX, 316 statusbox => $::SDTATUSBOX,
235 317
236 inv => $::INV, 318 inv => $::INV,
237 invr => $::INVR, 319 invr => $::INVR,
238 invr_hb => $::INVR_HB, 320 invr_hb => $::INVR_HB,
287 369
288# message window 370# message window
289sub ext_channel_info { 371sub ext_channel_info {
290 my ($self, $info) = @_; 372 my ($self, $info) = @_;
291 $self->{channels}->{$info->{id}} = $info; 373 $self->{channels}->{$info->{id}} = $info;
292 $::MESSAGE_WINDOW->add_channel ($info); 374 $::MESSAGE_DIST->add_channel ($info);
293} 375}
294 376
295############################################################################# 377#############################################################################
296 378
297sub logprint { 379sub logprint {
298 my ($self, @a) = @_; 380 my ($self, @a) = @_;
299 381
300 CFPlus::DB::logprint "$Crossfire::VARDIR/log.$self->{host}" => (join "", @a), sub { }; 382 DC::DB::logprint "$Deliantra::VARDIR/log.$self->{host}" => (join "", @a), sub { };
301} 383}
302 384
303sub _stat_numdiff { 385sub _stat_numdiff {
304 my ($self, $name, $old, $new) = @_; 386 my ($self, $name, $old, $new) = @_;
305 387
477 $self->{stat_order} = join ",", map $_->[0], @order; 559 $self->{stat_order} = join ",", map $_->[0], @order;
478 560
479 $sktbl->clear; 561 $sktbl->clear;
480 562
481 my $sw = $self->{skillwid}{""} ||= [ 563 my $sw = $self->{skillwid}{""} ||= [
482 0, 0, (new CFPlus::UI::Label text => "Experience", align => 1), 564 0, 0, (new DC::UI::Label text => "Experience", align => 1),
483 1, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), 565 1, 0, (new DC::UI::Label text => "Lvl.", align => 1),
484 2, 0, (new CFPlus::UI::Label text => "Progress", align => 0), 566 2, 0, (new DC::UI::Label text => "Progress"),
485 3, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), 567 3, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
486 4, 0, (new CFPlus::UI::Label text => "Experience", align => 1), 568 4, 0, (new DC::UI::Label text => "Experience", align => 1),
487 5, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), 569 5, 0, (new DC::UI::Label text => "Lvl.", align => 1),
488 6, 0, (new CFPlus::UI::Label text => "Progress", align => 0), 570 6, 0, (new DC::UI::Label text => "Progress"),
489 7, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), 571 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
490 ]; 572 ];
491 573
492 my @add = @$sw; 574 my @add = @$sw;
493 575
494 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 576 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>";
495 577
496 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 578 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
497 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 579 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
498 580
499 my ($x, $y) = (0, 1); 581 my ($x, $y) = (0, 1);
506 if ($ev->{button} == 1) { 588 if ($ev->{button} == 1) {
507 $::CONN->user_send ("ready_skill $name"); 589 $::CONN->user_send ("ready_skill $name");
508 } elsif ($ev->{button} == 2) { 590 } elsif ($ev->{button} == 2) {
509 $::CONN->user_send ("use_skill $name"); 591 $::CONN->user_send ("use_skill $name");
510 } elsif ($ev->{button} == 3) { 592 } elsif ($ev->{button} == 3) {
511 my $shortname = CFPlus::shorten $name, 14; 593 my $shortname = DC::shorten $name, 14;
512 (new CFPlus::UI::Menu 594 (new DC::UI::Menu
513 items => [ 595 items => [
514 ["bind <i>ready_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["ready_skill $name"] }], 596 ["bind <i>ready_skill $shortname</i> to a key" => sub { DC::Macro::quick_macro ["ready_skill $name"] }],
515 ["bind <i>use_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["use_skill $name"] }], 597 ["bind <i>use_skill $shortname</i> to a key" => sub { DC::Macro::quick_macro ["use_skill $name"] }],
516 ], 598 ],
517 )->popup ($ev); 599 )->popup ($ev);
518 } else { 600 } else {
519 return 0; 601 return 0;
520 } 602 }
522 1 604 1
523 }; 605 };
524 606
525 my $sw = $self->{skillwid}{$idx} ||= [ 607 my $sw = $self->{skillwid}{$idx} ||= [
526 # exp 608 # exp
527 (new CFPlus::UI::Label 609 (new DC::UI::Label
528 align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP), 610 align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP),
529 611
530 # level 612 # level
531 (new CFPlus::UI::Label 613 (new DC::UI::Label
532 text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL), 614 text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL),
533 615
534 # progress 616 # progress
535 (new CFPlus::UI::ExperienceProgress), 617 (new DC::UI::ExperienceProgress),
536 618
537 # label 619 # label
538 (new CFPlus::UI::Label text => $name, on_button_down => $spell_cb, 620 (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0,
539 can_events => 1, can_hover => 1, tooltip => (CFPlus::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), 621 can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL),
540 ]; 622 ];
541 623
542 push @add, 624 push @add,
543 $x * 4 + 0, $y, $sw->[0], 625 $x * 4 + 0, $y, $sw->[0],
544 $x * 4 + 1, $y, $sw->[1], 626 $x * 4 + 1, $y, $sw->[1],
585} 667}
586 668
587sub map_scroll { 669sub map_scroll {
588 my ($self, $dx, $dy) = @_; 670 my ($self, $dx, $dy) = @_;
589 671
590 $self->{map}->scroll ($dx, $dy); 672 $self->{map_widget}->scroll ($dx, $dy);
591} 673}
592 674
593sub feed_map1a { 675sub feed_map1a {
594 my ($self, $data) = @_; 676 my ($self, $data) = @_;
595 677
599 for my $tile (@$missing) { 681 for my $tile (@$missing) {
600 next if $self->{delay}{$tile}; 682 next if $self->{delay}{$tile};
601 683
602 $delay = 1; 684 $delay = 1;
603 685
604 if (my $tex = $::CONN->{texture}[$tile]) { 686 if (my $tex = $self->{texture}[$tile]) {
605 $tex->upload; 687 $tex->upload;
606 } else { 688 } else {
607 $self->{delay}{$tile} = 1; 689 $self->{delay}{$tile} = 1;
608 690
609 # we assume the face is in-flight and will eventually come 691 # we assume the face is in-flight and will eventually arrive
610 push @{$self->{tile_cb}{$tile}}, sub { 692 push @{$self->{tile_cb}{$tile}}, sub {
611 delete $self->{delay}{$tile}; 693 delete $self->{delay}{$tile};
612 $_[0]->upload; 694 $_[0]->upload;
613 }; 695 };
614 } 696 }
615 } 697 }
616 698
617 if ($delay) { 699 if ($delay) {
618 # delay the map drawing a tiny bit in the hope of getting the missing fetched 700 # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched
619 Event->timer (after => 0.03, cb => sub { 701 EV::once undef, 0, 0.03, sub {
620 $_[0]->w->cancel;
621 $self->{map_widget}->update 702 $self->{map_widget}->update
622 if $self->{map_widget}; 703 if $self->{map_widget};
623 }); 704 };
624 } else { 705 } else {
625 $self->{map_widget}->update; 706 $self->{map_widget}->update;
626 } 707 }
627} 708}
628 709
633} 714}
634 715
635sub flush_map { 716sub flush_map {
636 my ($self) = @_; 717 my ($self) = @_;
637 718
638 my $map_info = delete $self->{map_info} 719 return unless $self->{map_info};
639 or return;
640 720
721 for my $map_info (values %{ $self->{map_cache} || {} }) {
641 my ($hash, $x, $y, $w, $h) = @$map_info; 722 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
642 723
643 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 724 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
644 $self->{map_cache_new}{$hash} = \$data; 725
726 if ($data ne $$rdata) {
727 $map_info->[1] = \$data;
728 my $cdata = Compress::LZF::compress $data;
645 CFPlus::DB::put $self->{mapcache} => $hash => $data, sub { }; 729 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
730 }
731 }
646} 732}
647 733
648sub map_clear { 734sub map_clear {
649 my ($self) = @_; 735 my ($self) = @_;
650 736
651 $self->flush_map; 737 $self->flush_map;
738 delete $self->{map_info};
652 delete $self->{neigh_map}; 739 delete $self->{neigh_map};
653 740
654 $self->{map}->clear; 741 $self->{map}->clear;
655 delete $self->{map_widget}{magicmap}; 742 delete $self->{map_widget}{magicmap};
656} 743}
663 do { 750 do {
664 $tile = pop @{$self->{bg_fetch}} 751 $tile = pop @{$self->{bg_fetch}}
665 or return; 752 or return;
666 } while $self->{texture}[$tile]; 753 } while $self->{texture}[$tile];
667 754
668 CFPlus::DB::get tilecache => $tile, sub { 755 DC::DB::get tilecache => $tile, sub {
669 my ($data) = @_; 756 my ($data) = @_;
670 757
671 return unless $self->{map}; # stop when destroyed 758 return unless $self->{map}; # stop when destroyed
672 759
673 if (defined $data) { 760 if (defined $data) {
677 764
678 $self->bg_fetch; 765 $self->bg_fetch;
679 }; 766 };
680} 767}
681 768
682sub load_map($$$) { 769sub load_map($$$$$$) {
683 my ($self, $hash, $x, $y) = @_; 770 my ($self, $hash, $x, $y, $w, $h) = @_;
684 771
685 my $gen = $self->{map_change_gen}; 772 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
686 773
687 my $cb = sub { 774 my $cb = sub {
688 return unless $gen == $self->{map_change_gen}; 775 $map_info->[1] = \$_[0];
689 776
690 my ($data) = @_;
691
692 if (defined $data) {
693 $self->{map_cache_new}{$hash} = \$data;
694
695 my $data = Compress::LZF::decompress $data;
696
697 my $inprogress = @{ $self->{bg_fetch} || [] }; 777 my $inprogress = @{ $self->{bg_fetch} || [] };
698 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 778 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
699 $self->bg_fetch unless $inprogress; 779 $self->bg_fetch unless $inprogress;
700 }
701 }; 780 };
702 781
703 if (my $rdata = $self->{map_cache_old}{$hash}) { 782 if (my $map_info = $self->{map_cache_old}{$hash}) {
704 $cb->($$rdata); 783 $cb->(${ $map_info->[1] });
705 } else { 784 } else {
785 my $gen = $self->{map_change_gen};
786
706 CFPlus::DB::get $self->{mapcache} => $hash, $cb; 787 DC::DB::get $self->{mapcache} => $hash, sub {
788 return unless $gen == $self->{map_change_gen};
789 return unless defined $_[0];
790 $cb->(Compress::LZF::decompress $_[0]);
791 };
707 } 792 }
708} 793}
709 794
710# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 795# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
711# (server resource,s latency, bandwidth), so this hack is warranted. 796# (server resources, latency, bandwidth), so this hack is warranted.
712# the right fix is to make real tiled maps with an overview file 797# the right fix is to make real tiled maps with an overview file
713sub send_mapinfo { 798sub send_mapinfo {
714 my ($self, $data, $cb) = @_; 799 my ($self, $data, $cb) = @_;
715 800
716 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { 801 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) {
741} 826}
742 827
743# this method does a "flood fill" into every tile direction 828# this method does a "flood fill" into every tile direction
744# it assumes that tiles are arranged in a rectangular grid, 829# it assumes that tiles are arranged in a rectangular grid,
745# i.e. a map is the same as the left of the right map etc. 830# i.e. a map is the same as the left of the right map etc.
746# failure to comply are harmless and result in display errors 831# failure to comply is harmless and results in display errors
747# at worst. 832# at worst.
748sub flood_fill { 833sub flood_fill {
749 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 834 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
750 835
751 # the server does not allow map paths > 6 836 # the server does not allow map paths > 6
787 return if $mode ne "spatial"; 872 return if $mode ne "spatial";
788 873
789 $x += $self->{map}->ox; 874 $x += $self->{map}->ox;
790 $y += $self->{map}->oy; 875 $y += $self->{map}->oy;
791 876
792 $self->load_map ($hash, $x, $y) 877 $self->load_map ($hash, $x, $y, $w, $h)
793 unless $self->{neigh_map}{$hash}[5]++;#d# 878 unless $self->{neigh_map}{$hash}[5]++;#d#
794 879
795 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 880 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
796 881
797 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 882 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
805 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 890 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
806 891
807 $self->flush_map; 892 $self->flush_map;
808 893
809 ++$self->{map_change_gen}; 894 ++$self->{map_change_gen};
810 $self->{map_cache_old} = delete $self->{map_cache_new}; 895 $self->{map_cache_old} = delete $self->{map_cache};
811 896
812 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 897 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
813 898
814 my $mapmapw = $self->{mapmap}->{w}; 899 my $mapmapw = $self->{mapmap}->{w};
815 my $mapmaph = $self->{mapmap}->{h}; 900 my $mapmaph = $self->{mapmap}->{h};
827 $self->{map_info} = [$hash, $x, $y, $w, $h]; 912 $self->{map_info} = [$hash, $x, $y, $w, $h];
828 913
829 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 914 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
830 $::STATWIDS->{map}->set_text ("Map: " . $map); 915 $::STATWIDS->{map}->set_text ("Map: " . $map);
831 916
832 $self->load_map ($hash, $x, $y); 917 $self->load_map ($hash, $x, $y, $w, $h);
833 $self->flood_fill (0, 0, 0, "", $hash, $flags); 918 $self->flood_fill (0, 0, 0, "", $hash, $flags);
834} 919}
835 920
836sub face_find { 921sub face_find {
837 my ($self, $facenum, $face, $cb) = @_; 922 my ($self, $facenum, $face, $cb) = @_;
838 923
839 if ($face->{type} == 0) { # FT_FACE 924 if ($face->{type} == 0) { # FT_FACE
840 my $id = CFPlus::DB::get_tile_id_sync $face->{name}; 925 my $id = DC::DB::get_tile_id_sync $face->{name};
841 926
842 $face->{id} = $id; 927 $face->{id} = $id;
843 $self->{map}->set_tileid ($facenum => $id); 928 $self->{map}->set_tileid ($facenum => $id);
844 929
845 CFPlus::DB::get tilecache => $id, $cb; 930 DC::DB::get tilecache => $id, $cb;
846 931
847 } elsif ($face->{type} & 1) { # with metadata 932 } elsif ($face->{type} & 1) { # with metadata
848 CFPlus::DB::get res_meta => $face->{name}, $cb; 933 DC::DB::get res_meta => $face->{name}, $cb;
849 934
850 } else { # no metadata 935 } else { # no metadata
851 CFPlus::DB::get res_data => $face->{name}, $cb; 936 DC::DB::get res_data => $face->{name}, $cb;
852 } 937 }
853} 938}
854 939
855sub face_update { 940sub face_update {
856 my ($self, $facenum, $face, $changed) = @_; 941 my ($self, $facenum, $face, $changed) = @_;
857 942
858 if ($face->{type} == 0) { 943 if ($face->{type} == 0) {
859 # image, FT_FACE 944 # image, FT_FACE
860 CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } 945 DC::DB::put tilecache => $face->{id} => $face->{data}, sub { }
861 if $changed; 946 if $changed;
862 947
863 $self->have_tile ($face->{id}, delete $face->{data}); 948 $self->have_tile ($face->{id}, delete $face->{data});
864 949
865 } elsif ($face->{type} & 1) { 950 } elsif ($face->{type} & 1) {
867 if ($changed) { # new data 952 if ($changed) { # new data
868 my ($meta, $data) = unpack "(w/a*)*", $face->{data}; 953 my ($meta, $data) = unpack "(w/a*)*", $face->{data};
869 $face->{data} = $meta; 954 $face->{data} = $meta;
870 955
871 # rely on strict ordering here and also on later fetch 956 # rely on strict ordering here and also on later fetch
872 CFPlus::DB::put res_data => $face->{name} => $data, sub { }; 957 DC::DB::put res_data => $face->{name} => $data, sub { };
873 CFPlus::DB::put res_meta => $face->{name} => $meta, sub { }; 958 DC::DB::put res_meta => $face->{name} => $meta, sub { };
874 } 959 }
875 960
876 $face->{data} = $self->{json_coder}->decode ($face->{data}); 961 $face->{data} = $self->{json_coder}->decode ($face->{data});
877 ::add_license ($face); 962 ::add_license ($face);
878 ::message ({ markup => CFPlus::asxml "downloaded resource '$face->{data}{name}', type $face->{type}." }) 963 ::message ({ markup => DC::asxml "downloaded resource '$face->{data}{name}', type $face->{type}." })
879 if $changed; 964 if $changed;
880 965
881 if ($face->{type} == 3) { # FT_MUSIC 966 if ($face->{type} == 3) { # FT_MUSIC
882 &::audio_music_push ($facenum); 967 &::audio_music_push ($facenum);
883 } elsif ($face->{type} == 5) { # FT_SOUND 968 } elsif ($face->{type} == 5) { # FT_SOUND
884 &::audio_sound_push ($facenum); 969 &::audio_sound_push ($facenum);
885 } 970 }
886 971
887 } else { 972 } else {
888 # flat resource case, FT_RSRC 973 # flat resource case, FT_RSRC
889 CFPlus::DB::put res_data => $face->{name} => $face->{data}, sub { } 974 DC::DB::put res_data => $face->{name} => $face->{data}, sub { }
890 if $changed; 975 if $changed;
891 } 976 }
892 977
893 if (my $cbs = $self->{face_cb}{$facenum}) { 978 if (my $cbs = $self->{face_cb}{$facenum}) {
894 $_->($face, $changed) for @$cbs; 979 $_->($face, $changed) for @$cbs;
905 my ($self, $tile, $data) = @_; 990 my ($self, $tile, $data) = @_;
906 991
907 return unless $self->{map}; 992 return unless $self->{map};
908 993
909 my $tex = $self->{texture}[$tile] ||= 994 my $tex = $self->{texture}[$tile] ||=
910 new CFPlus::Texture 995 new DC::Texture
911 tile => $tile, 996 tile => $tile,
912 image => $data, delete_image => 1, 997 image => $data, delete_image => 1,
913 minify => 1, mipmap => 1; 998 minify => 1, mipmap => 1;
914 999
915 if (my $cbs = delete $self->{tile_cb}{$tile}) { 1000 if (my $cbs = delete $self->{tile_cb}{$tile}) {
923 my ($self, $num, $cb) = @_; 1008 my ($self, $num, $cb) = @_;
924 1009
925 push @{$self->{face_cb}{$num}}, $cb; 1010 push @{$self->{face_cb}{$num}}, $cb;
926 1011
927 defined wantarray 1012 defined wantarray
928 ? CFPlus::guard { 1013 ? DC::guard {
929 @{$self->{face_cb}{$num}} 1014 @{$self->{face_cb}{$num}}
930 = grep $_ != $cb, 1015 = grep $_ != $cb,
931 @{$self->{face_cb}{$num}}; 1016 @{$self->{face_cb}{$num}};
932 } 1017 }
933 : () 1018 : ()
979 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g; 1064 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
980 1065
981 # handle some elements 1066 # handle some elements
982 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; 1067 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
983 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; 1068 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
1069
1070 s/\s+$//;
984 1071
985 $_ 1072 $_
986} 1073}
987 1074
988our %NAME_TO_COLOR = ( 1075our %NAME_TO_COLOR = (
1035 1122
1036 ## try to create single paragraphs of multiple lines sent by the server 1123 ## try to create single paragraphs of multiple lines sent by the server
1037 # no longer neecssary with TRT servers 1124 # no longer neecssary with TRT servers
1038 #$text =~ s/(?<=\S)\n(?=\w)/ /g; 1125 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1039 1126
1040 for (split /\n/, $text) {
1041 ::message ({ 1127 ::message ({
1042 fg => $fg, 1128 fg => $fg,
1043 markup => $_, 1129 markup => $text,
1044 type => $type, 1130 type => $type,
1045 extra => [@extra], 1131 extra => [@extra],
1046 color_flags => $color, #d# ugly, kill 1132 color_flags => $color, #d# ugly, kill
1047 }); 1133 });
1048 1134
1049 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1135# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1050 # actually, this is an ugly design. _we_ should control the channels, 1136# # actually, this is an ugly design. _we_ should control the channels,
1051 # not some random other widget, as the channels are clearly protocol-specific. 1137# # not some random other widget, as the channels are clearly protocol-specific.
1052 # then we could also react to flags such as CLEAR without resorting to 1138# # then we could also react to flags such as CLEAR without resorting to
1053 # hacks such as color_flags, above. 1139# # hacks such as color_flags, above.
1054 }
1055 1140
1056 $self->{statusbox}->add ($text, 1141 $self->{statusbox}->add ($text,
1057 group => $text, 1142 group => $text,
1058 fg => $fg, 1143 fg => $fg,
1059 timeout => $color >= 2 ? 180 : 10, 1144 timeout => $color >= 2 ? 180 : 10,
1070 $spell->{message} =~ s/\n+$//; 1155 $spell->{message} =~ s/\n+$//;
1071 $spell->{message} ||= "Server did not provide a description for this spell."; 1156 $spell->{message} ||= "Server did not provide a description for this spell.";
1072 1157
1073 $::SPELL_LIST->add_spell ($spell); 1158 $::SPELL_LIST->add_spell ($spell);
1074 1159
1075 $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); 1160 $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message});
1076 $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message}); 1161 $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message});
1077} 1162}
1078 1163
1079sub spell_delete { 1164sub spell_delete {
1080 my ($self, $spell) = @_; 1165 my ($self, $spell) = @_;
1081 1166
1092sub addme_success { 1177sub addme_success {
1093 my ($self) = @_; 1178 my ($self) = @_;
1094 1179
1095 my %skill_help; 1180 my %skill_help;
1096 1181
1097 for my $node (CFPlus::Pod::find skill_description => "*") { 1182 for my $node (DC::Pod::find skill_description => "*") {
1098 my (undef, @par) = CFPlus::Pod::section_of $node; 1183 my (undef, @par) = DC::Pod::section_of $node;
1099 $skill_help{$node->{kw}[0]} = CFPlus::Pod::as_label @par; 1184 $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par;
1100 }; 1185 };
1101 1186
1102 for my $skill (values %{$self->{skill_info}}) { 1187 for my $skill (values %{$self->{skill_info}}) {
1103 $self->{map_widget}->add_command ("ready_skill $skill", 1188 $self->{map_widget}->add_command ("ready_skill $skill",
1104 (CFPlus::asxml "Ready the skill '$skill'\n\n") 1189 (DC::asxml "Ready the skill '$skill'\n\n")
1105 . $skill_help{$skill}); 1190 . $skill_help{$skill});
1106 $self->{map_widget}->add_command ("use_skill $skill", 1191 $self->{map_widget}->add_command ("use_skill $skill",
1107 (CFPlus::asxml "Immediately use the skill '$skill'\n\n") 1192 (DC::asxml "Immediately use the skill '$skill'\n\n")
1108 . $skill_help{$skill}); 1193 . $skill_help{$skill});
1109 } 1194 }
1110} 1195}
1111 1196
1112sub eof { 1197sub eof {
1116 1201
1117 ::stop_game (); 1202 ::stop_game ();
1118} 1203}
1119 1204
1120sub update_floorbox { 1205sub update_floorbox {
1121 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { 1206 $DC::UI::ROOT->on_refresh ($::FLOORBOX => sub {
1122 return unless $::CONN; 1207 return unless $::CONN;
1123 1208
1124 $::FLOORBOX->clear; 1209 $::FLOORBOX->clear;
1125 1210
1126 my @add; 1211 my @add;
1127 1212
1128 my $row; 1213 my $row;
1129 for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { 1214 for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) {
1215 next if $_->{tag} & 0x80000000;
1130 if ($row < 6) { 1216 if ($row < 6) {
1131 local $_->{face_widget}; # hack to force recreation of widget 1217 local $_->{face_widget}; # hack to force recreation of widget
1132 local $_->{desc_widget}; # hack to force recreation of widget 1218 local $_->{desc_widget}; # hack to force recreation of widget
1133 CFPlus::Item::update_widgets $_; 1219 DC::Item::update_widgets $_;
1134 1220
1135 push @add, 1221 push @add,
1136 0, $row, $_->{face_widget}, 1222 0, $row, $_->{face_widget},
1137 1, $row, $_->{desc_widget}; 1223 1, $row, $_->{desc_widget};
1138 1224
1139 $row++; 1225 $row++;
1140 } else { 1226 } else {
1141 push @add, 1, $row, new CFPlus::UI::Button 1227 push @add, 1, $row, new DC::UI::Button
1142 text => "More...", 1228 text => "More...",
1143 on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, 1229 on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 },
1144 ; 1230 ;
1145 last; 1231 last;
1146 } 1232 }
1147 } 1233 }
1148 if ($::CONN->{open_container}) { 1234 if ($::CONN->{open_container}) {
1149 push @add, 1, $row++, new CFPlus::UI::Button 1235 push @add, 1, $row++, new DC::UI::Button
1150 text => "Close container", 1236 text => "Close container",
1151 on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } 1237 on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") }
1152 ; 1238 ;
1153 } 1239 }
1154 1240
1155 $::FLOORBOX->add_at (@add); 1241 $::FLOORBOX->add_at (@add);
1156 }); 1242 });
1157 1243
1158 $::WANT_REFRESH->start; 1244 $::WANT_REFRESH = 1;
1159} 1245}
1160 1246
1161sub set_opencont { 1247sub set_opencont {
1162 my ($conn, $tag, $name) = @_; 1248 my ($conn, $tag, $name) = @_;
1163 $conn->{open_container} = $tag; 1249 $conn->{open_container} = $tag;
1164 update_floorbox; 1250 update_floorbox;
1165 1251
1166 $::INVR_HB->clear (); 1252 $::INVR_HB->clear;
1167 $::INVR_HB->add (new CFPlus::UI::Label align => 0, expand => 1, text => $name); 1253 $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name);
1168 1254
1169 if ($tag != 0) { # Floor isn't closable, is it? 1255 if ($tag != 0) { # Floor isn't closable, is it?
1170 $::INVR_HB->add (new CFPlus::UI::Button 1256 $::INVR_HB->add (new DC::UI::Button
1171 text => "Close container", 1257 text => "Close container",
1172 tooltip => "Close the currently open container (if one is open)", 1258 tooltip => "Close the currently open container (if one is open)",
1173 on_activate => sub { 1259 on_activate => sub {
1174 $::CONN->send ("apply $tag") # $::CONN->{open_container}") 1260 $::CONN->send ("apply $tag") # $::CONN->{open_container}")
1175 if $tag != 0; 1261 if $tag != 0;
1182} 1268}
1183 1269
1184sub update_containers { 1270sub update_containers {
1185 my ($self) = @_; 1271 my ($self) = @_;
1186 1272
1187 $CFPlus::UI::ROOT->on_refresh ("update_containers_$self" => sub { 1273 $DC::UI::ROOT->on_refresh ("update_containers_$self" => sub {
1188 my $todo = delete $self->{update_container} 1274 my $todo = delete $self->{update_container}
1189 or return; 1275 or return;
1190 1276
1191 for my $tag (keys %$todo) { 1277 for my $tag (keys %$todo) {
1192 update_floorbox if $tag == 0 or $tag == $self->{open_container}; 1278 update_floorbox if $tag == 0 or $tag == $self->{open_container};
1227} 1313}
1228 1314
1229sub item_update { 1315sub item_update {
1230 my ($self, $item) = @_; 1316 my ($self, $item) = @_;
1231 1317
1232 #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; 1318 #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n";
1233 1319
1234 CFPlus::Item::update_widgets $item; 1320 DC::Item::update_widgets $item;
1235 1321
1236 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { 1322 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) {
1237 set_opencont ($::CONN, 0, "Floor"); 1323 set_opencont ($::CONN, 0, "Floor");
1238 1324
1239 } elsif ($item->{flags} & F_OPEN) { 1325 } elsif ($item->{flags} & F_OPEN) {
1240 set_opencont ($::CONN, $item->{tag}, CFPlus::Item::desc_string $item); 1326 set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item);
1241 1327
1242 } else { 1328 } else {
1243 $self->{update_container}{$item->{container}}++; 1329 $self->{update_container}{$item->{container}}++;
1244 $self->update_containers; 1330 $self->update_containers;
1245 } 1331 }
1256 1342
1257 my $weight = .001 * $self->{player}{weight}; 1343 my $weight = .001 * $self->{player}{weight};
1258 my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; 1344 my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM};
1259 1345
1260 $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); 1346 $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight);
1261 $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); 1347 $::STATWIDS->{m_weight}->set_text (sprintf "Max Weight: %.1fkg", $limit);
1262 $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); 1348 $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit);
1263} 1349}
1264 1350
1265sub update_server_info { 1351sub update_server_info {
1266 my ($self) = @_; 1352 my ($self) = @_;
1274 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 1360 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1275 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" 1361 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1276 . "editing support $yesno[!!$self->{editor_support}]\n" 1362 . "editing support $yesno[!!$self->{editor_support}]\n"
1277 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 1363 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1278 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" 1364 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1279 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 1365 . "client support $yesno[$self->{cfplus_ext} > 0]"
1280 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1366 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1281 . "map size $self->{mapw}×$self->{maph}\n" 1367 . "map size $self->{mapw}×$self->{maph}\n"
1282 ); 1368 );
1283 1369
1284} 1370}
1304 0 1390 0
1305 }); 1391 });
1306 1392
1307 $self->update_server_info; 1393 $self->update_server_info;
1308 1394
1309 $self->send_command ("output-sync $::CFG->{output_sync}");
1310 $self->send_command ("output-count $::CFG->{output_count}");
1311 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1395 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1312 $self->send_command ("pickup $::CFG->{pickup}"); 1396 $self->send_command ("pickup $::CFG->{pickup}");
1397
1398 $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]",
1399 DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d#
1313} 1400}
1314 1401
1315sub lookat { 1402sub lookat {
1316 my ($self, $x, $y) = @_; 1403 my ($self, $x, $y) = @_;
1317 1404
1319 $self->send_ext_req (lookat => $x, $y, sub { 1406 $self->send_ext_req (lookat => $x, $y, sub {
1320 my (%msg) = @_; 1407 my (%msg) = @_;
1321 1408
1322 if (exists $msg{npc_dialog}) { 1409 if (exists $msg{npc_dialog}) {
1323 # start npc chat dialog 1410 # start npc chat dialog
1324 $self->{npc_dialog} = new CFPlus::NPCDialog:: 1411 $self->{npc_dialog} = new DC::NPCDialog::
1325 token => $msg{npc_dialog}, 1412 token => $msg{npc_dialog},
1326 title => "$msg{npc_dialog}[0] (NPC)", 1413 title => "$msg{npc_dialog}[0] (NPC)",
1327 conn => $self, 1414 conn => $self,
1328 ; 1415 ;
1329 } 1416 }
1342 $self->SUPER::destroy; 1429 $self->SUPER::destroy;
1343 1430
1344 %$self = (); 1431 %$self = ();
1345} 1432}
1346 1433
1347package CFPlus::NPCDialog; 1434package DC::NPCDialog;
1348 1435
1349our @ISA = 'CFPlus::UI::Toplevel'; 1436our @ISA = 'DC::UI::Toplevel';
1350 1437
1351sub new { 1438sub new {
1352 my $class = shift; 1439 my $class = shift;
1353 1440
1354 my $self = $class->SUPER::new ( 1441 my $self = $class->SUPER::new (
1361 kw => { hi => 0, yes => 0, no => 0 }, 1448 kw => { hi => 0, yes => 0, no => 0 },
1362 has_close_button => 1, 1449 has_close_button => 1,
1363 @_, 1450 @_,
1364 ); 1451 );
1365 1452
1366 CFPlus::weaken (my $this = $self); 1453 DC::weaken (my $this = $self);
1367 1454
1368 $self->connect (delete => sub { $this->destroy; 1 }); 1455 $self->connect (delete => sub { $this->destroy; 1 });
1369 1456
1370 # better use a pane... 1457 # better use a pane...
1371 $self->add (my $hbox = new CFPlus::UI::HBox); 1458 $self->add (my $hbox = new DC::UI::HBox);
1372 $hbox->add ($self->{textview} = new CFPlus::UI::TextScroller expand => 1); 1459 $hbox->add ($self->{textview} = new DC::UI::TextScroller expand => 1);
1373 1460
1374 $hbox->add (my $vbox = new CFPlus::UI::VBox); 1461 $hbox->add (my $vbox = new DC::UI::VBox);
1375 1462
1376 $vbox->add (new CFPlus::UI::Label text => "Message Entry:"); 1463 $vbox->add (new DC::UI::Label text => "Message Entry:");
1377 $vbox->add ($self->{entry} = new CFPlus::UI::Entry 1464 $vbox->add ($self->{entry} = new DC::UI::Entry
1378 tooltip => "#npc_message_entry", 1465 tooltip => "#npc_message_entry",
1379 on_activate => sub { 1466 on_activate => sub {
1380 my ($entry, $text) = @_; 1467 my ($entry, $text) = @_;
1381 1468
1382 return unless $text =~ /\S/; 1469 return unless $text =~ /\S/;
1386 1473
1387 0 1474 0
1388 }, 1475 },
1389 ); 1476 );
1390 1477
1391 $vbox->add ($self->{options} = new CFPlus::UI::VBox); 1478 $vbox->add ($self->{options} = new DC::UI::VBox);
1392 1479
1393 $self->{bye_button} = new CFPlus::UI::Button 1480 $self->{bye_button} = new DC::UI::Button
1394 text => "Bye (close)", 1481 text => "Bye (close)",
1395 tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", 1482 tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.",
1396 on_activate => sub { $this->destroy; 1 }, 1483 on_activate => sub { $this->destroy; 1 },
1397 ; 1484 ;
1398 1485
1417}; 1504};
1418 1505
1419sub update_options { 1506sub update_options {
1420 my ($self) = @_; 1507 my ($self) = @_;
1421 1508
1422 CFPlus::weaken $self; 1509 DC::weaken $self;
1423 1510
1424 $self->{options}->clear; 1511 $self->{options}->clear;
1425 $self->{options}->add ($self->{bye_button}); 1512 $self->{options}->add ($self->{bye_button});
1426 1513
1427 for my $kw (sort keys %{ $self->{kw} }) { 1514 for my $kw (sort keys %{ $self->{kw} }) {
1428 $self->{options}->add (new CFPlus::UI::Button 1515 $self->{options}->add (new DC::UI::Button
1429 text => $kw, 1516 text => $kw,
1430 on_activate => sub { 1517 on_activate => sub {
1431 $self->send ($kw); 1518 $self->send ($kw);
1432 0 1519 0
1433 }, 1520 },
1436} 1523}
1437 1524
1438sub feed { 1525sub feed {
1439 my ($self, $type, @arg) = @_; 1526 my ($self, $type, @arg) = @_;
1440 1527
1441 CFPlus::weaken $self; 1528 DC::weaken $self;
1442 1529
1443 if ($type eq "update") { 1530 if ($type eq "update") {
1444 my (%info) = @arg; 1531 my (%info) = @arg;
1445 1532
1446 $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; 1533 $self->{kw}{$_} = 1 for @{$info{add_topics} || []};
1447 $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; 1534 $self->{kw}{$_} = 0 for @{$info{del_topics} || []};
1448 1535
1449 if (exists $info{msg}) { 1536 if (exists $info{msg}) {
1450 my $text = "\n" . CFPlus::Protocol::sanitise_xml $info{msg}; 1537 my $text = "\n" . DC::Protocol::sanitise_xml $info{msg};
1451 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; 1538 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} };
1452 my @link; 1539 my @link;
1453 $text =~ s{ 1540 $text =~ s{
1454 ($match) 1541 ($match)
1455 }{ 1542 }{
1456 my $kw = $1; 1543 my $kw = $1;
1457 1544
1458 push @link, new CFPlus::UI::Label 1545 push @link, new DC::UI::Label
1459 markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>", 1546 markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>",
1460 can_hover => 1, 1547 can_hover => 1,
1461 can_events => 1, 1548 can_events => 1,
1462 padding_x => 0, 1549 padding_x => 0,
1463 padding_y => 0, 1550 padding_y => 0,
1481} 1568}
1482 1569
1483sub send { 1570sub send {
1484 my ($self, $msg) = @_; 1571 my ($self, $msg) = @_;
1485 1572
1486 $self->{textview}->add_paragraph ({ markup => "\n" . CFPlus::asxml $msg }); 1573 $self->{textview}->add_paragraph ({
1574 markup =>
1575 "\n<span foreground='#ffff00'><b>"
1576 . (DC::asxml $msg)
1577 . "</b></span>"
1578 });
1487 $self->{textview}->scroll_to_bottom; 1579 $self->{textview}->scroll_to_bottom;
1488 1580
1489 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1581 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1490} 1582}
1491 1583

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines