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.171 by root, Sat Sep 1 08:08:52 2007 UTC vs.
Revision 1.215 by root, Sat Apr 3 02:58:25 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines