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.226 by root, Thu Nov 15 03:07:46 2012 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,
26 xwidget2 => 1,#d# 32 widget => 2,
27 %{$arg{setup_req} || {}}, 33 %{$arg{setup_req} || {}},
28 }, 34 },
29 ); 35 );
30 36
37 $self->update_fx_want;
38
39 my $exp_guard = $self->addme_guard;
40 my $skl_guard = $self->addme_guard;
41 my $spl_guard = $self->addme_guard;
42 my $cmd_guard = $self->addme_guard;
43 $self->send_exti_req (resource => qw(exp_table skill_info spell_paths command_list), sub {
44 my ($exp, $skl, $spl, $cmd) = @_;
45
46 $self->register_face_handler ($exp, sub {
47 my ($face) = @_;
48
49 undef $exp_guard;
50 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
51 $_->() for values %{ $self->{on_exp_update} };
52 });
53
54 $self->register_face_handler ($skl, sub {
55 my ($face) = @_;
56
57 undef $skl_guard;
58 my $info = $self->{json_coder}->decode (delete $face->{data});
59 $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info };
60 });
61
62 $self->register_face_handler ($spl, sub {
63 my ($face) = @_;
64
65 undef $spl_guard;
66 my $info = $self->{json_coder}->decode (delete $face->{data});
67 $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info };
68 });
69
70 $self->register_face_handler ($cmd, sub {
71 my ($face) = @_;
72
73 undef $cmd_guard;
74 my $info = $self->{json_coder}->decode (delete $face->{data});
75 $self->{command_list} = [ sort map @{ $_->[1] }, grep $_->[0] != 2, @$info ];
76
77 });
78
79 ()
80 });
81
31 $self->{map_widget}->clr_commands; 82 $self->{map_widget}->clr_commands;
32 83
33 my @cmd_help = map { 84 my @cmd_help = map {
34 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 85 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
35 or die "unparseable command help: $_->{kw}[0]"; 86 or die "unparseable command help: $_->[DC::Pod::N_KW][0]";
36 87
37 my $cmd = $1; 88 my $cmd = $1;
38 my @args = split /\|/, $2; 89 my @args = split /\|/, $2;
39 @args = (".*") unless @args; 90 @args = (".*") unless @args;
40 91
41 my (undef, @par) = CFPlus::Pod::section_of $_; 92 my (undef, @par) = DC::Pod::section_of $_;
42 my $text = CFPlus::Pod::as_label @par; 93 my $text = DC::Pod::as_label @par;
43 94
44 $_ = $_ eq ".*" ? "" : " $_" 95 $_ = $_ eq ".*" ? "" : " $_"
45 for @args; 96 for @args;
46 97
47 map ["$cmd$_", $text], 98 map ["$cmd$_", $text],
48 sort { (length $a) <=> (length $b) } 99 sort { (length $a) <=> (length $b) }
49 @args 100 @args
50 } sort { $a->{par} <=> $b->{par} } 101 } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] }
51 CFPlus::Pod::find command => "*"; 102 DC::Pod::find command => "*";
52 103
53 $self->{json_coder} 104 $self->{json_coder}
54 ->convert_blessed 105 ->convert_blessed
55 ->filter_json_single_key_object ("\fw" => sub { 106 ->filter_json_single_key_object ("\fw" => sub {
56 $self->{widget}{$_[0]} 107 $self->{widget}{$_[0]}
66 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { 117 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
67 for my $ws (values %{delete $self->{widgetset} || {}}) { 118 for my $ws (values %{delete $self->{widgetset} || {}}) {
68 $_->destroy 119 $_->destroy
69 for values %{delete $ws->{w} || {}}; 120 for values %{delete $ws->{w} || {}};
70 } 121 }
122
123 delete $self->{items};
124 $::INV->clear;
125 $::INVR->clear;
126 $::INVR_HB->clear;
127 $::FLOORBOX->clear;
71 }); 128 });
72 129
73 $self->{map_widget}->add_command (@$_) 130 $self->{map_widget}->add_command (@$_)
74 for @cmd_help; 131 for @cmd_help;
75 132
76 { 133 {
77 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture 134 $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}}); 135 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
80 } 136 }
81 137
82 { 138 {
83 $self->{noface} = my $tex = new_from_file CFPlus::Texture 139 $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}}); 140 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
86 } 141 }
142
143# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
144# $self->{expire_w} = AE::timer 1, 1, sub {
145# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
146#
147# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
148# warn DC::SvREFCNT $self->{texture}[$_];
149# $self->{texture}[$_]->unload;
150# warn "expire texture $_\n";#d#
151# }
152#
153# ($self->{expire_count} += $count) < @{ $self->{texture} }
154# or $self->{expire_count} = DC::DB::FIRST_TILE_ID;
155# warn "count is $count\n";#d#
156# };
87 157
88 $self->{open_container} = 0; 158 $self->{open_container} = 0;
89 159
90 # per server 160 # per server
91 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 161 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
92 162
93 $self 163 $self
94} 164}
165
166 #$self->send_exti_req (nickmon => 1, sub { use Data::Dump; ddx \@_ });#d#
167#sub ext_nicklist { shift; use Data::Dump; ddx \@_; } #d#
95 168
96sub update_fx_want { 169sub update_fx_want {
97 my ($self) = @_; 170 my ($self) = @_;
98 171
99 $self->send_exti_msg (fx_want => { 172 $self->send_exti_msg (fx_want => {
104} 177}
105 178
106sub ext_capabilities { 179sub ext_capabilities {
107 my ($self, %cap) = @_; 180 my ($self, %cap) = @_;
108 181
109 #$self->send ("setup sound 0"); # we use a different protocol
110 $self->update_fx_want;
111
112 $self->send_exti_req (resource => "exp_table", sub {
113 my ($exp_table) = @_;
114
115 $self->register_face_handler ($exp_table, sub {
116 my ($face) = @_;
117
118 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
119 $_->() for values %{ $self->{on_exp_update} || {} };
120 });
121
122 ()
123 });
124
125 if (my $ts = $cap{tileset}) { 182 if (my $ts = $cap{tileset}) {
126 if (my ($default) = grep $_->[2] & 1, @$ts) { 183 if (my ($default) = grep $_->[2] & 1, @$ts) {
127 $self->{tileset} = $default; 184 $self->{tileset} = $default;
128 $self->{tilesize} = $default->[3]; 185 $self->{tilesize} = $default->[3];
129 $self->setup_req (tileset => $default->[0]); 186 $self->setup_req (tileset => $default->[0]);
144############################################################################# 201#############################################################################
145 202
146sub widget_associate { 203sub widget_associate {
147 my ($self, $ws, $id, $widget) = @_; 204 my ($self, $ws, $id, $widget) = @_;
148 205
149 $widget ||= new CFPlus::UI::Bin; 206 $widget ||= new DC::UI::Bin;
150 207
151 $widget->{s_id} = $id; 208 $widget->{s_id} = $id;
152 $self->{widget}{$id} = $widget; 209 $self->{widget}{$id} = $widget;
153 210
154 if ($ws) { 211 if ($ws) {
190 my ($self, $ws, $id, $class, $args) = @_; 247 my ($self, $ws, $id, $class, $args) = @_;
191 248
192 $self->widget_associate ( 249 $self->widget_associate (
193 $ws, $id => scalar eval { 250 $ws, $id => scalar eval {
194 local $SIG{__DIE__}; 251 local $SIG{__DIE__};
195 "CFPlus::UI::$class"->new (%$args) 252 "DC::UI::$class"->new (%$args)
196 } 253 }
197 ); 254 );
255}
256
257# widgetset create template
258sub ext_ws_ct {
259 my ($self, $ws, $type, $template, $done_cb, $cfg) = @_;
260
261 $done_cb ||= sub { };
262
263 my $parse_list; $parse_list = sub {
264 my ($list) = @_;
265 my @w;
266
267 while (@$list) {
268 my ($class, $args) = splice @$list, 0, 2;
269 my $name = delete $args->{s_id};
270 my $cl = delete $args->{s_cl};
271 my $cfg = delete $cfg->{$name};
272 my $id = delete $cfg->{id};
273 my $w = eval { "DC::UI::$class"->new (%$args, %{ $cfg || {} }) }
274 or next;
275
276 $self->widget_associate ($ws, $id, $w)
277 if $id;
278
279 $w->add ($parse_list->($cl))
280 if $cl;
281
282 push @w, $w;
283 }
284
285 @w
286 };
287
288 # either array reference, or face #
289 if ($type eq "inline") {
290 $done_cb->();
291 $parse_list->($template);
292 } elsif ($type eq "face") {
293 my $handler; $handler = $self->register_face_handler ($template, sub {
294 my ($face) = @_;
295
296 undef $handler;
297 $done_cb->();
298 $parse_list->($self->{json_coder}->decode ($face->{data}));
299 });
300 } else {
301 $done_cb->(0);
302 }
198} 303}
199 304
200# widgetset associate 305# widgetset associate
201sub ext_ws_a { 306sub ext_ws_a {
202 my ($self, %ass) = @_; 307 my ($self, %ass) = @_;
203 308
204 # everything that has a name, wether conceivably useful or not 309 # everything that has a name, wether conceivably useful or not
205 my %wkw = ( 310 my %wkw = (
206 root => $CFPlus::UI::ROOT, 311 root => $DC::UI::ROOT,
207 tooltip => $CFPlus::UI::TOOLTIP, 312 tooltip => $DC::UI::TOOLTIP,
208 313
209 mapwidget => $::MAPWIDGET, 314 mapwidget => $::MAPWIDGET,
315 menubar => $::MENUBAR,
316 menupopup => $::MENUPOPUP,
317 pickup_enable => $::PICKUP_ENABLE,
210 buttonbar => $::BUTTONBAR, 318 buttonbar => $::BUTTONBAR,
211 metaserver => $::METASERVER, 319 metaserver => $::METASERVER,
212 buttonbar => $::BUTTONBAR, 320 buttonbar => $::BUTTONBAR,
213 login_button => $::LOGIN_BUTTON, 321 login_button => $::LOGIN_BUTTON,
214 quit_dialog => $::QUIT_DIALOG, 322 quit_dialog => $::QUIT_DIALOG,
230 spell_list => $::SPELL_LIST, 338 spell_list => $::SPELL_LIST,
231 339
232 floorbox => $::FLOORBOX, 340 floorbox => $::FLOORBOX,
233 help_window => $::HELP_WINDOW, 341 help_window => $::HELP_WINDOW,
234 message_window => $::MESSAGE_WINDOW, 342 message_window => $::MESSAGE_WINDOW,
343 message_dist => $::MESSAGE_DIST,
235 statusbox => $::SDTATUSBOX, 344 statusbox => $::STATUSBOX,
236 345
237 inv => $::INV, 346 inv => $::INV,
238 invr => $::INVR, 347 invr => $::INVR,
239 invr_hb => $::INVR_HB, 348 invr_hb => $::INVR_HB,
240 ); 349 );
288 397
289# message window 398# message window
290sub ext_channel_info { 399sub ext_channel_info {
291 my ($self, $info) = @_; 400 my ($self, $info) = @_;
292 $self->{channels}->{$info->{id}} = $info; 401 $self->{channels}->{$info->{id}} = $info;
293 $::MESSAGE_WINDOW->add_channel ($info); 402 $::MESSAGE_DIST->add_channel ($info);
294} 403}
295 404
296############################################################################# 405#############################################################################
297 406
298sub logprint { 407sub logprint {
299 my ($self, @a) = @_; 408 my ($self, @a) = @_;
300 409
301 CFPlus::DB::logprint "$Crossfire::VARDIR/log.$self->{host}" => (join "", @a), sub { }; 410 DC::DB::logprint "$Deliantra::VARDIR/log.$self->{host}" => (join "", @a), sub { };
302} 411}
303 412
304sub _stat_numdiff { 413sub _stat_numdiff {
305 my ($self, $name, $old, $new) = @_; 414 my ($self, $name, $old, $new) = @_;
306 415
324 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) 433 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_})
325 : () 434 : ()
326 } 435 }
327 sort { $a <=> $b } keys %{$self->{spell_paths}}; 436 sort { $a <=> $b } keys %{$self->{spell_paths}};
328 437
329 join "", @diff 438 "\u$name: " . (join ", ", @diff)
330} 439}
331 440
332# all stats that are chacked against changes 441# all stats that are chacked against changes
333my @statchange = ( 442my @statchange = (
334 [&CS_STAT_STR => \&_stat_numdiff, "Str"], 443 [&CS_STAT_STR => \&_stat_numdiff, "Str"],
377 486
378 if (my @diffs = 487 if (my @diffs =
379 ( 488 (
380 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), 489 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()),
381 map { 490 map {
382 $stats->{$_} && $prev->{$_} 491 $stats->{$_} && $prev->{$_}
383 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 492 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
384 } sort { $a <=> $b } keys %{$self->{skill_info}} 493 } sort { $a <=> $b } keys %{$self->{skill_info}}
385 ) 494 )
386 ) { 495 ) {
387 my $msg = join " ", @diffs; 496 my $msg = join " ", @diffs;
389 } 498 }
390 499
391 if ( 500 if (
392 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange 501 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
393 ) { 502 ) {
394 my $msg = "<b>stat change</b>: " . (join " ", @diffs); 503 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); 504 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20);
396 } 505 }
397 506
398 $self->update_stats_window ($stats, $prev); 507 $self->update_stats_window ($stats, $prev);
399 508
437 546
438 $::GAUGES->{hp} ->set_value ($hp, $hp_m); 547 $::GAUGES->{hp} ->set_value ($hp, $hp_m);
439 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 548 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
440 $::GAUGES->{food} ->set_value ($fo, $fo_m); 549 $::GAUGES->{food} ->set_value ($fo, $fo_m);
441 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 550 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
442 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 551 $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d#
443 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 552 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
444 $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); 553 $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64});
445 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); 554 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
446 my $title = $stats->{+CS_STAT_TITLE}; 555 my $title = $stats->{+CS_STAT_TITLE};
447 $title =~ s/^Player: //; 556 $title =~ s/^Player: //;
448 $::STATWIDS->{title} ->set_text ("Title: " . $title); 557 $::STATWIDS->{title} ->set_text ("Title: " . $title);
449 558
461 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 570 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
462 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); 571 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP});
463 572
464 $self->update_weight; 573 $self->update_weight;
465 574
466 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 575 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
467 for keys %RES_TBL; 576 for keys %RES_TBL;
468 577
469 my $sktbl = $::STATWIDS->{skill_tbl}; 578 my $sktbl = $::STATWIDS->{skill_tbl};
470 my @skills = keys %{ $self->{skill_info} }; 579 my @skills = keys %{ $self->{skill_info} };
471 580
478 $self->{stat_order} = join ",", map $_->[0], @order; 587 $self->{stat_order} = join ",", map $_->[0], @order;
479 588
480 $sktbl->clear; 589 $sktbl->clear;
481 590
482 my $sw = $self->{skillwid}{""} ||= [ 591 my $sw = $self->{skillwid}{""} ||= [
483 0, 0, (new CFPlus::UI::Label text => "Experience", align => 1), 592 0, 0, (new DC::UI::Label text => "Experience", align => 1),
484 1, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), 593 1, 0, (new DC::UI::Label text => "Lvl.", align => 1),
485 2, 0, (new CFPlus::UI::Label text => "Progress", align => 0), 594 2, 0, (new DC::UI::Label text => "Progress"),
486 3, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), 595 3, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
487 4, 0, (new CFPlus::UI::Label text => "Experience", align => 1), 596 4, 0, (new DC::UI::Label text => "Experience", align => 1),
488 5, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), 597 5, 0, (new DC::UI::Label text => "Lvl.", align => 1),
489 6, 0, (new CFPlus::UI::Label text => "Progress", align => 0), 598 6, 0, (new DC::UI::Label text => "Progress"),
490 7, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), 599 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
491 ]; 600 ];
492 601
493 my @add = @$sw; 602 my @add = @$sw;
494 603
495 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 604 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>";
496 605
497 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 606 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); 607 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
499 608
500 my ($x, $y) = (0, 1); 609 my ($x, $y) = (0, 1);
507 if ($ev->{button} == 1) { 616 if ($ev->{button} == 1) {
508 $::CONN->user_send ("ready_skill $name"); 617 $::CONN->user_send ("ready_skill $name");
509 } elsif ($ev->{button} == 2) { 618 } elsif ($ev->{button} == 2) {
510 $::CONN->user_send ("use_skill $name"); 619 $::CONN->user_send ("use_skill $name");
511 } elsif ($ev->{button} == 3) { 620 } elsif ($ev->{button} == 3) {
512 my $shortname = CFPlus::shorten $name, 14; 621 my $shortname = DC::shorten $name, 14;
513 (new CFPlus::UI::Menu 622 (new DC::UI::Menu
514 items => [ 623 items => [
515 ["bind <i>ready_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["ready_skill $name"] }], 624 ["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"] }], 625 ["bind <i>use_skill $shortname</i> to a key" => sub { DC::Macro::quick_macro ["use_skill $name"] }],
517 ], 626 ],
518 )->popup ($ev); 627 )->popup ($ev);
519 } else { 628 } else {
520 return 0; 629 return 0;
521 } 630 }
523 1 632 1
524 }; 633 };
525 634
526 my $sw = $self->{skillwid}{$idx} ||= [ 635 my $sw = $self->{skillwid}{$idx} ||= [
527 # exp 636 # exp
528 (new CFPlus::UI::Label 637 (new DC::UI::Label
529 align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP), 638 align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP),
530 639
531 # level 640 # level
532 (new CFPlus::UI::Label 641 (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), 642 text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL),
534 643
535 # progress 644 # progress
536 (new CFPlus::UI::ExperienceProgress), 645 (new DC::UI::ExperienceProgress),
537 646
538 # label 647 # label
539 (new CFPlus::UI::Label text => $name, on_button_down => $spell_cb, 648 (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), 649 can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL),
541 ]; 650 ];
542 651
543 push @add, 652 push @add,
544 $x * 4 + 0, $y, $sw->[0], 653 $x * 4 + 0, $y, $sw->[0],
545 $x * 4 + 1, $y, $sw->[1], 654 $x * 4 + 1, $y, $sw->[1],
562 my $sw = $self->{skillwid}{$idx}; 671 my $sw = $self->{skillwid}{$idx};
563 $sw->[0]->set_text (::formsep ($val->[1])); 672 $sw->[0]->set_text (::formsep ($val->[1]));
564 $sw->[1]->set_text ($val->[0] * 1); 673 $sw->[1]->set_text ($val->[0] * 1);
565 $sw->[2]->set_value (@$val); 674 $sw->[2]->set_value (@$val);
566 675
567 $::GAUGES->{sklprg}->set_label ("$name %d%%"); 676 $::GAUGES->{skillexp}->set_label ("$name %d%%");
568 $::GAUGES->{sklprg}->set_value (@$val); 677 $::GAUGES->{skillexp}->set_value (@$val);
569 } 678 }
570} 679}
571 680
572sub user_send { 681sub user_send {
573 my ($self, $command) = @_; 682 my ($self, $command) = @_;
586} 695}
587 696
588sub map_scroll { 697sub map_scroll {
589 my ($self, $dx, $dy) = @_; 698 my ($self, $dx, $dy) = @_;
590 699
591 $self->{map}->scroll ($dx, $dy); 700 $self->{map_widget}->scroll ($dx, $dy);
592} 701}
593 702
594sub feed_map1a { 703sub feed_map1a {
595 my ($self, $data) = @_; 704 my ($self, $data) = @_;
596 705
597 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 706 my $missing = $self->{map}->map1a_update ($data);
598 my $delay; 707 my $delay;
599 708
600 for my $tile (@$missing) { 709 for my $tile (@$missing) {
601 next if $self->{delay}{$tile}; 710 next if $self->{delay}{$tile};
602 711
603 $delay = 1; 712 $delay = 1;
604 713
605 if (my $tex = $::CONN->{texture}[$tile]) { 714 if (my $tex = $self->{texture}[$tile]) {
606 $tex->upload; 715 $tex->upload;
607 } else { 716 } else {
608 $self->{delay}{$tile} = 1; 717 $self->{delay}{$tile} = 1;
609 718
610 # we assume the face is in-flight and will eventually come 719 # we assume the face is in-flight and will eventually arrive
611 push @{$self->{tile_cb}{$tile}}, sub { 720 push @{$self->{tile_cb}{$tile}}, sub {
612 delete $self->{delay}{$tile}; 721 delete $self->{delay}{$tile};
613 $_[0]->upload; 722 $_[0]->upload;
614 }; 723 };
615 } 724 }
616 } 725 }
617 726
618 if ($delay) { 727 if ($delay) {
619 # delay the map drawing a tiny bit in the hope of getting the missing fetched 728 # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched
620 Event->timer (after => 0.03, cb => sub { 729 EV::once undef, 0, 0.03, sub {
621 $_[0]->w->cancel;
622 $self->{map_widget}->update 730 $self->{map_widget}->update
623 if $self->{map_widget}; 731 if $self->{map_widget};
624 }); 732 };
625 } else { 733 } else {
626 $self->{map_widget}->update; 734 $self->{map_widget}->update;
627 } 735 }
628} 736}
629 737
634} 742}
635 743
636sub flush_map { 744sub flush_map {
637 my ($self) = @_; 745 my ($self) = @_;
638 746
639 my $map_info = delete $self->{map_info} 747 return unless $self->{map_info};
640 or return;
641 748
749 for my $map_info (values %{ $self->{map_cache} || {} }) {
642 my ($hash, $x, $y, $w, $h) = @$map_info; 750 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
643 751
644 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 752 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
645 $self->{map_cache_new}{$hash} = \$data; 753
754 if ($data ne $$rdata) {
755 $map_info->[1] = \$data;
756 my $cdata = Compress::LZF::compress $data;
646 CFPlus::DB::put $self->{mapcache} => $hash => $data, sub { }; 757 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
758 }
759 }
647} 760}
648 761
649sub map_clear { 762sub map_clear {
650 my ($self) = @_; 763 my ($self) = @_;
651 764
652 $self->flush_map; 765 $self->flush_map;
766 delete $self->{map_info};
653 delete $self->{neigh_map}; 767 delete $self->{neigh_map};
654 768
655 $self->{map}->clear; 769 $self->{map}->clear;
656 delete $self->{map_widget}{magicmap}; 770 delete $self->{map_widget}{magicmap};
657} 771}
664 do { 778 do {
665 $tile = pop @{$self->{bg_fetch}} 779 $tile = pop @{$self->{bg_fetch}}
666 or return; 780 or return;
667 } while $self->{texture}[$tile]; 781 } while $self->{texture}[$tile];
668 782
669 CFPlus::DB::get tilecache => $tile, sub { 783 DC::DB::get tilecache => $tile, sub {
670 my ($data) = @_; 784 my ($data) = @_;
671 785
672 return unless $self->{map}; # stop when destroyed 786 return unless $self->{map}; # stop when destroyed
673 787
674 if (defined $data) { 788 if (defined $data) {
678 792
679 $self->bg_fetch; 793 $self->bg_fetch;
680 }; 794 };
681} 795}
682 796
683sub load_map($$$) { 797sub load_map($$$$$$) {
684 my ($self, $hash, $x, $y) = @_; 798 my ($self, $hash, $x, $y, $w, $h) = @_;
685 799
686 my $gen = $self->{map_change_gen}; 800 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
687 801
688 my $cb = sub { 802 my $cb = sub {
689 return unless $gen == $self->{map_change_gen}; 803 $map_info->[1] = \$_[0];
690 804
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} || [] }; 805 my $inprogress = @{ $self->{bg_fetch} || [] };
699 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 806 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
700 $self->bg_fetch unless $inprogress; 807 $self->bg_fetch unless $inprogress;
701 }
702 }; 808 };
703 809
704 if (my $rdata = $self->{map_cache_old}{$hash}) { 810 if (my $map_info = $self->{map_cache_old}{$hash}) {
705 $cb->($$rdata); 811 $cb->(${ $map_info->[1] });
706 } else { 812 } else {
813 my $gen = $self->{map_change_gen};
814
707 CFPlus::DB::get $self->{mapcache} => $hash, $cb; 815 DC::DB::get $self->{mapcache} => $hash, sub {
816 return unless $gen == $self->{map_change_gen};
817 return unless defined $_[0];
818 $cb->(Compress::LZF::decompress $_[0]);
819 };
708 } 820 }
709} 821}
710 822
711# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 823# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
712# (server resource,s latency, bandwidth), so this hack is warranted. 824# (server resources, latency, bandwidth), so this hack is warranted.
713# the right fix is to make real tiled maps with an overview file 825# the right fix is to make real tiled maps with an overview file
714sub send_mapinfo { 826sub send_mapinfo {
715 my ($self, $data, $cb) = @_; 827 my ($self, $data, $cb) = @_;
716 828
717 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { 829 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) {
742} 854}
743 855
744# this method does a "flood fill" into every tile direction 856# this method does a "flood fill" into every tile direction
745# it assumes that tiles are arranged in a rectangular grid, 857# 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. 858# 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 859# failure to comply is harmless and results in display errors
748# at worst. 860# at worst.
749sub flood_fill { 861sub flood_fill {
750 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 862 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
751 863
752 # the server does not allow map paths > 6 864 # the server does not allow map paths > 6
788 return if $mode ne "spatial"; 900 return if $mode ne "spatial";
789 901
790 $x += $self->{map}->ox; 902 $x += $self->{map}->ox;
791 $y += $self->{map}->oy; 903 $y += $self->{map}->oy;
792 904
793 $self->load_map ($hash, $x, $y) 905 $self->load_map ($hash, $x, $y, $w, $h)
794 unless $self->{neigh_map}{$hash}[5]++;#d# 906 unless $self->{neigh_map}{$hash}[5]++;#d#
795 907
796 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 908 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
797 909
798 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 910 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
806 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 918 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
807 919
808 $self->flush_map; 920 $self->flush_map;
809 921
810 ++$self->{map_change_gen}; 922 ++$self->{map_change_gen};
811 $self->{map_cache_old} = delete $self->{map_cache_new}; 923 $self->{map_cache_old} = delete $self->{map_cache};
812 924
813 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 925 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
814 926
815 my $mapmapw = $self->{mapmap}->{w}; 927 my $mapmapw = $self->{mapmap}->{w};
816 my $mapmaph = $self->{mapmap}->{h}; 928 my $mapmaph = $self->{mapmap}->{h};
828 $self->{map_info} = [$hash, $x, $y, $w, $h]; 940 $self->{map_info} = [$hash, $x, $y, $w, $h];
829 941
830 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 942 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
831 $::STATWIDS->{map}->set_text ("Map: " . $map); 943 $::STATWIDS->{map}->set_text ("Map: " . $map);
832 944
833 $self->load_map ($hash, $x, $y); 945 $self->load_map ($hash, $x, $y, $w, $h);
834 $self->flood_fill (0, 0, 0, "", $hash, $flags); 946 $self->flood_fill (0, 0, 0, "", $hash, $flags);
835} 947}
836 948
837sub face_find { 949sub face_find {
838 my ($self, $facenum, $face, $cb) = @_; 950 my ($self, $facenum, $face, $cb) = @_;
839 951
840 if ($face->{type} == 0) { # FT_FACE 952 if ($face->{type} == 0) { # FT_FACE
841 my $id = CFPlus::DB::get_tile_id_sync $face->{name}; 953 my $id = DC::DB::get_tile_id_sync $face->{name};
842 954
843 $face->{id} = $id; 955 $face->{id} = $id;
844 $self->{map}->set_tileid ($facenum => $id); 956 $self->{map}->set_tileid ($facenum => $id);
845 957
846 CFPlus::DB::get tilecache => $id, $cb; 958 DC::DB::get tilecache => $id, $cb;
847 959
848 } elsif ($face->{type} & 1) { # with metadata 960 } elsif ($face->{type} & 1) { # with metadata
849 CFPlus::DB::get res_meta => $face->{name}, $cb; 961 DC::DB::get res_meta => $face->{name}, $cb;
850 962
851 } else { # no metadata 963 } else { # no metadata
852 CFPlus::DB::get res_data => $face->{name}, $cb; 964 DC::DB::get res_data => $face->{name}, $cb;
853 } 965 }
854} 966}
855 967
856sub face_update { 968sub face_update {
857 my ($self, $facenum, $face, $changed) = @_; 969 my ($self, $facenum, $face, $changed) = @_;
858 970
859 if ($face->{type} == 0) { 971 if ($face->{type} == 0) {
860 # image, FT_FACE 972 # image, FT_FACE
861 CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } 973 DC::DB::put tilecache => $face->{id} => $face->{data}, sub { }
862 if $changed; 974 if $changed;
863 975
864 $self->have_tile ($face->{id}, delete $face->{data}); 976 $self->have_tile ($face->{id}, delete $face->{data});
865 977
866 } elsif ($face->{type} & 1) { 978 } elsif ($face->{type} & 1) {
868 if ($changed) { # new data 980 if ($changed) { # new data
869 my ($meta, $data) = unpack "(w/a*)*", $face->{data}; 981 my ($meta, $data) = unpack "(w/a*)*", $face->{data};
870 $face->{data} = $meta; 982 $face->{data} = $meta;
871 983
872 # rely on strict ordering here and also on later fetch 984 # rely on strict ordering here and also on later fetch
873 CFPlus::DB::put res_data => $face->{name} => $data, sub { }; 985 DC::DB::put res_data => $face->{name} => $data, sub { };
874 CFPlus::DB::put res_meta => $face->{name} => $meta, sub { }; 986 DC::DB::put res_meta => $face->{name} => $meta, sub { };
875 } 987 }
876 988
877 $face->{data} = $self->{json_coder}->decode ($face->{data}); 989 $face->{data} = $self->{json_coder}->decode ($face->{data});
878 ::add_license ($face); 990 ::add_license ($face);
879 ::message ({ markup => CFPlus::asxml "downloaded resource '$face->{data}{name}', type $face->{type}." }) 991 ::message ({ markup => DC::asxml "downloaded resource '$face->{data}{name}', type $face->{type}." })
880 if $changed; 992 if $changed;
881 993
882 if ($face->{type} == 3) { # FT_MUSIC 994 if ($face->{type} == 3) { # FT_MUSIC
883 &::audio_music_push ($facenum); 995 &::audio_music_push ($facenum);
884 } elsif ($face->{type} == 5) { # FT_SOUND 996 } elsif ($face->{type} == 5) { # FT_SOUND
885 &::audio_sound_push ($facenum); 997 &::audio_sound_push ($facenum);
886 } 998 }
887 999
888 } else { 1000 } else {
889 # flat resource case, FT_RSRC 1001 # flat resource case, FT_RSRC
890 CFPlus::DB::put res_data => $face->{name} => $face->{data}, sub { } 1002 DC::DB::put res_data => $face->{name} => $face->{data}, sub { }
891 if $changed; 1003 if $changed;
892 } 1004 }
893 1005
894 if (my $cbs = $self->{face_cb}{$facenum}) { 1006 if (my $cbs = $self->{face_cb}{$facenum}) {
895 $_->($face, $changed) for @$cbs; 1007 $_->($face, $changed) for @$cbs;
906 my ($self, $tile, $data) = @_; 1018 my ($self, $tile, $data) = @_;
907 1019
908 return unless $self->{map}; 1020 return unless $self->{map};
909 1021
910 my $tex = $self->{texture}[$tile] ||= 1022 my $tex = $self->{texture}[$tile] ||=
911 new CFPlus::Texture 1023 new DC::Texture
912 tile => $tile, 1024 tile => $tile,
913 image => $data, delete_image => 1, 1025 image => $data, delete_image => 1,
914 minify => 1, mipmap => 1; 1026 minify => 1;
915 1027
916 if (my $cbs = delete $self->{tile_cb}{$tile}) { 1028 if (my $cbs = delete $self->{tile_cb}{$tile}) {
917 $_->($tex) for @$cbs; 1029 $_->($tex) for @$cbs;
918 } 1030 }
919} 1031}
924 my ($self, $num, $cb) = @_; 1036 my ($self, $num, $cb) = @_;
925 1037
926 push @{$self->{face_cb}{$num}}, $cb; 1038 push @{$self->{face_cb}{$num}}, $cb;
927 1039
928 defined wantarray 1040 defined wantarray
929 ? CFPlus::guard { 1041 ? Guard::guard {
930 @{$self->{face_cb}{$num}} 1042 @{$self->{face_cb}{$num}}
931 = grep $_ != $cb, 1043 = grep $_ != $cb,
932 @{$self->{face_cb}{$num}}; 1044 @{$self->{face_cb}{$num}};
933 } 1045 }
934 : () 1046 : ()
962 my ($self, $flags, $prompt) = @_; 1074 my ($self, $flags, $prompt) = @_;
963 1075
964 $prompt = $LAST_QUERY unless length $prompt; 1076 $prompt = $LAST_QUERY unless length $prompt;
965 $LAST_QUERY = $prompt; 1077 $LAST_QUERY = $prompt;
966 1078
967 $self->{query}-> ($self, $flags, $prompt); 1079 $self->{query}->($self, $flags, $prompt);
968} 1080}
969 1081
970sub sanitise_xml($) { 1082sub sanitise_xml($) {
971 local $_ = shift; 1083 local $_ = shift;
972 1084
973 # we now weed out all tags we do not support 1085 # we now weed out all tags we do not support
974 s%<(?!/?i>|/?u>|/?b>|fg |/fg>)%&lt;%g; 1086 s{ <(?! /?i> | /?u> | /?b> | /?big | /?small | /?s | /?tt | fg\ | /fg>)
1087 }{
1088 "&lt;"
1089 }gex;
1090
975 # now all entities 1091 # now all entities
976 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g; 1092 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
977 1093
978 # handle some elements 1094 # handle some elements
979 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; 1095 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
980 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; 1096 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
1097
1098 s/\s+$//;
981 1099
982 $_ 1100 $_
983} 1101}
984 1102
985our %NAME_TO_COLOR = ( 1103our %NAME_TO_COLOR = (
998 tan => 12, 1116 tan => 12,
999); 1117);
1000 1118
1001our @CF_COLOR = ( 1119our @CF_COLOR = (
1002 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 1120 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1003 [1.00, 1.00, 1.00], 1121 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1004 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] 1122 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55],
1005 [1.00, 0.00, 0.00], 1123 [1.00, 0.00, 0.00],
1006 [1.00, 0.54, 0.00], 1124 [1.00, 0.54, 0.00],
1007 [0.11, 0.56, 1.00], 1125 [0.11, 0.56, 1.00],
1008 [0.93, 0.46, 0.00], 1126 [0.93, 0.46, 0.00],
1009 [0.18, 0.54, 0.34], 1127 [0.18, 0.54, 0.34],
1028 $self->logprint ("msg: ", $text); 1146 $self->logprint ("msg: ", $text);
1029 return if $color < 0; # negative color == ignore if not understood 1147 return if $color < 0; # negative color == ignore if not understood
1030 1148
1031 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1149 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1032 1150
1033 ## try to create single paragraphs of multiple lines sent by the server
1034 # no longer neecssary with TRT servers
1035 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1036
1037 for (split /\n/, $text) {
1038 ::message ({ 1151 ::message ({
1039 fg => $fg, 1152 fg => $fg,
1040 markup => $_, 1153 markup => $text,
1041 type => $type, 1154 type => $type,
1042 extra => [@extra], 1155 extra => [@extra],
1043 color_flags => $color, #d# ugly, kill 1156 color_flags => $color, #d# ugly, kill
1044 }); 1157 });
1045 1158
1046 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1159# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1047 # actually, this is an ugly design. _we_ should control the channels, 1160# # actually, this is an ugly design. _we_ should control the channels,
1048 # not some random other widget, as the channels are clearly protocol-specific. 1161# # 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 1162# # then we could also react to flags such as CLEAR without resorting to
1050 # hacks such as color_flags, above. 1163# # hacks such as color_flags, above.
1051 }
1052 1164
1053 $self->{statusbox}->add ($text, 1165 $self->{statusbox}->add ($text,
1054 group => $text, 1166 group => $text,
1055 fg => $fg, 1167 fg => $fg,
1056 timeout => $color >= 2 ? 180 : 10, 1168 timeout => $color >= 2 ? 180 : 10,
1057 tooltip_font => $::FONT_FIXED, 1169 tooltip_font => $::FONT_FIXED,
1058 ); 1170 ) if $type eq "info";
1059 } 1171 }
1060} 1172}
1061 1173
1062sub spell_add { 1174sub spell_add {
1063 my ($self, $spell) = @_; 1175 my ($self, $spell) = @_;
1067 $spell->{message} =~ s/\n+$//; 1179 $spell->{message} =~ s/\n+$//;
1068 $spell->{message} ||= "Server did not provide a description for this spell."; 1180 $spell->{message} ||= "Server did not provide a description for this spell.";
1069 1181
1070 $::SPELL_LIST->add_spell ($spell); 1182 $::SPELL_LIST->add_spell ($spell);
1071 1183
1072 $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); 1184 $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}); 1185 $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message});
1074} 1186}
1075 1187
1076sub spell_delete { 1188sub spell_delete {
1077 my ($self, $spell) = @_; 1189 my ($self, $spell) = @_;
1078 1190
1089sub addme_success { 1201sub addme_success {
1090 my ($self) = @_; 1202 my ($self) = @_;
1091 1203
1092 my %skill_help; 1204 my %skill_help;
1093 1205
1094 for my $node (CFPlus::Pod::find skill_description => "*") { 1206 for my $node (DC::Pod::find skill_description => "*") {
1095 my (undef, @par) = CFPlus::Pod::section_of $node; 1207 my (undef, @par) = DC::Pod::section_of $node;
1096 $skill_help{$node->{kw}[0]} = CFPlus::Pod::as_label @par; 1208 $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par;
1097 }; 1209 };
1098 1210
1099 for my $skill (values %{$self->{skill_info}}) { 1211 for my $skill (values %{$self->{skill_info}}) {
1100 $self->{map_widget}->add_command ("ready_skill $skill", 1212 $self->{map_widget}->add_command ("ready_skill $skill",
1101 (CFPlus::asxml "Ready the skill '$skill'\n\n") 1213 (DC::asxml "Ready the skill '$skill'\n\n")
1102 . $skill_help{$skill}); 1214 . $skill_help{$skill});
1103 $self->{map_widget}->add_command ("use_skill $skill", 1215 $self->{map_widget}->add_command ("use_skill $skill",
1104 (CFPlus::asxml "Immediately use the skill '$skill'\n\n") 1216 (DC::asxml "Immediately use the skill '$skill'\n\n")
1105 . $skill_help{$skill}); 1217 . $skill_help{$skill});
1106 } 1218 }
1107} 1219}
1108 1220
1109sub eof { 1221sub eof {
1113 1225
1114 ::stop_game (); 1226 ::stop_game ();
1115} 1227}
1116 1228
1117sub update_floorbox { 1229sub update_floorbox {
1118 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { 1230 $DC::UI::ROOT->on_refresh ($::FLOORBOX => sub {
1119 return unless $::CONN; 1231 return unless $::CONN;
1120 1232
1121 $::FLOORBOX->clear; 1233 $::FLOORBOX->clear;
1122 1234
1123 my @add; 1235 my @add;
1124 1236
1125 my $row; 1237 my $row;
1126 for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { 1238 for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) {
1239 next if $_->{tag} & 0x80000000;
1127 if ($row < 6) { 1240 if ($row < 6) {
1128 local $_->{face_widget}; # hack to force recreation of widget 1241 local $_->{face_widget}; # hack to force recreation of widget
1129 local $_->{desc_widget}; # hack to force recreation of widget 1242 local $_->{desc_widget}; # hack to force recreation of widget
1130 CFPlus::Item::update_widgets $_; 1243 DC::Item::update_widgets $_;
1131 1244
1132 push @add, 1245 push @add,
1133 0, $row, $_->{face_widget}, 1246 0, $row, $_->{face_widget},
1134 1, $row, $_->{desc_widget}; 1247 1, $row, $_->{desc_widget};
1135 1248
1136 $row++; 1249 $row++;
1137 } else { 1250 } else {
1138 push @add, 1, $row, new CFPlus::UI::Button 1251 push @add, 1, $row, new DC::UI::Button
1139 text => "More...", 1252 text => "More...",
1140 on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, 1253 on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 },
1141 ; 1254 ;
1142 last; 1255 last;
1143 } 1256 }
1144 } 1257 }
1145 if ($::CONN->{open_container}) { 1258 if ($::CONN->{open_container}) {
1146 push @add, 1, $row++, new CFPlus::UI::Button 1259 push @add, 1, $row++, new DC::UI::Button
1147 text => "Close container", 1260 text => "Close container",
1148 on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } 1261 on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") }
1149 ; 1262 ;
1150 } 1263 }
1151 1264
1152 $::FLOORBOX->add_at (@add); 1265 $::FLOORBOX->add_at (@add);
1153 }); 1266 });
1154 1267
1155 $::WANT_REFRESH->start; 1268 $::WANT_REFRESH = 1;
1156} 1269}
1157 1270
1158sub set_opencont { 1271sub set_opencont {
1159 my ($conn, $tag, $name) = @_; 1272 my ($conn, $tag, $name) = @_;
1160 $conn->{open_container} = $tag; 1273 $conn->{open_container} = $tag;
1161 update_floorbox; 1274 update_floorbox;
1162 1275
1163 $::INVR_HB->clear (); 1276 $::INVR_HB->clear;
1164 $::INVR_HB->add (new CFPlus::UI::Label align => 0, expand => 1, text => $name); 1277 $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name);
1165 1278
1166 if ($tag != 0) { # Floor isn't closable, is it? 1279 if ($tag != 0) { # Floor isn't closable, is it?
1167 $::INVR_HB->add (new CFPlus::UI::Button 1280 $::INVR_HB->add (new DC::UI::Button
1168 text => "Close container", 1281 text => "Close container",
1169 tooltip => "Close the currently open container (if one is open)", 1282 tooltip => "Close the currently open container (if one is open)",
1170 on_activate => sub { 1283 on_activate => sub {
1171 $::CONN->send ("apply $tag") # $::CONN->{open_container}") 1284 $::CONN->send ("apply $tag") # $::CONN->{open_container}")
1172 if $tag != 0; 1285 if $tag != 0;
1179} 1292}
1180 1293
1181sub update_containers { 1294sub update_containers {
1182 my ($self) = @_; 1295 my ($self) = @_;
1183 1296
1184 $CFPlus::UI::ROOT->on_refresh ("update_containers_$self" => sub { 1297 $DC::UI::ROOT->on_refresh ("update_containers_$self" => sub {
1185 my $todo = delete $self->{update_container} 1298 my $todo = delete $self->{update_container}
1186 or return; 1299 or return;
1187 1300
1188 for my $tag (keys %$todo) { 1301 for my $tag (keys %$todo) {
1189 update_floorbox if $tag == 0 or $tag == $self->{open_container}; 1302 update_floorbox if $tag == 0 or $tag == $self->{open_container};
1224} 1337}
1225 1338
1226sub item_update { 1339sub item_update {
1227 my ($self, $item) = @_; 1340 my ($self, $item) = @_;
1228 1341
1229 #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; 1342 #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n";
1230 1343
1231 CFPlus::Item::update_widgets $item; 1344 DC::Item::update_widgets $item;
1232 1345
1233 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { 1346 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) {
1234 set_opencont ($::CONN, 0, "Floor"); 1347 set_opencont ($::CONN, 0, "Floor");
1235 1348
1236 } elsif ($item->{flags} & F_OPEN) { 1349 } elsif ($item->{flags} & F_OPEN) {
1237 set_opencont ($::CONN, $item->{tag}, CFPlus::Item::desc_string $item); 1350 set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item);
1238 1351
1239 } else { 1352 } else {
1240 $self->{update_container}{$item->{container}}++; 1353 $self->{update_container}{$item->{container}}++;
1241 $self->update_containers; 1354 $self->update_containers;
1242 } 1355 }
1253 1366
1254 my $weight = .001 * $self->{player}{weight}; 1367 my $weight = .001 * $self->{player}{weight};
1255 my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; 1368 my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM};
1256 1369
1257 $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); 1370 $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight);
1258 $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); 1371 $::STATWIDS->{m_weight}->set_text (sprintf "Max Weight: %.1fkg", $limit);
1259 $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); 1372 $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit);
1260} 1373}
1261 1374
1262sub update_server_info { 1375sub update_server_info {
1263 my ($self) = @_; 1376 my ($self) = @_;
1264 1377
1265 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); 1378 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>");
1266 1379
1380 my $version = JSON::XS->new->encode ($self->{s_version});
1381
1267 $::SERVER_INFO->set_markup ( 1382 $::SERVER_INFO->set_markup (
1268 "server <tt>$self->{host}:$self->{port}</tt>\n" 1383 "server <tt>$self->{host}:$self->{port}</tt>\n"
1269 . "protocol version <tt>$self->{version}</tt>\n" 1384 . "protocol version <tt>$version</tt>\n"
1270 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1271 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1272 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1273 . "editing support $yesno[!!$self->{editor_support}]\n" 1385 . "editing support $yesno[!!$self->{editor_support}]\n"
1274 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1275 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1276 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 1386 . "client support $yesno[$self->{cfplus_ext} > 0]"
1277 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1387 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1278 . "map size $self->{mapw}×$self->{maph}\n" 1388 . "map size $self->{mapw}×$self->{maph}\n"
1279 ); 1389 );
1280 1390
1281} 1391}
1301 0 1411 0
1302 }); 1412 });
1303 1413
1304 $self->update_server_info; 1414 $self->update_server_info;
1305 1415
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; 1416 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1309 $self->send_command ("pickup $::CFG->{pickup}"); 1417 $self->send_pickup ($::CFG->{pickup});
1310} 1418}
1311 1419
1312sub lookat { 1420sub lookat {
1313 my ($self, $x, $y) = @_; 1421 my ($self, $x, $y) = @_;
1314 1422
1316 $self->send_ext_req (lookat => $x, $y, sub { 1424 $self->send_ext_req (lookat => $x, $y, sub {
1317 my (%msg) = @_; 1425 my (%msg) = @_;
1318 1426
1319 if (exists $msg{npc_dialog}) { 1427 if (exists $msg{npc_dialog}) {
1320 # start npc chat dialog 1428 # start npc chat dialog
1321 $self->{npc_dialog} = new CFPlus::NPCDialog:: 1429 $self->{w}{npc_dialog} = new DC::NPCDialog::
1322 token => $msg{npc_dialog}, 1430 token => $msg{npc_dialog},
1323 title => "$msg{npc_dialog}[0] (NPC)", 1431 title => "$msg{npc_dialog}[0] (NPC)",
1324 conn => $self, 1432 conn => $self,
1325 ; 1433 ;
1326 } 1434 }
1331} 1439}
1332 1440
1333sub destroy { 1441sub destroy {
1334 my ($self) = @_; 1442 my ($self) = @_;
1335 1443
1336 (delete $self->{npc_dialog})->destroy 1444 $_->destroy
1337 if $self->{npc_dialog}; 1445 for values %{ $self->{w} };
1338 1446
1339 $self->SUPER::destroy; 1447 $self->SUPER::destroy;
1340 1448
1341 %$self = (); 1449 %$self = ();
1342} 1450}
1343 1451
1344package CFPlus::NPCDialog; 1452package DC::NPCDialog;
1345 1453
1346our @ISA = 'CFPlus::UI::Toplevel'; 1454our @ISA = 'DC::UI::Toplevel';
1347 1455
1348sub new { 1456sub new {
1349 my $class = shift; 1457 my $class = shift;
1350 1458
1351 my $self = $class->SUPER::new ( 1459 my $self = $class->SUPER::new (
1358 kw => { hi => 0, yes => 0, no => 0 }, 1466 kw => { hi => 0, yes => 0, no => 0 },
1359 has_close_button => 1, 1467 has_close_button => 1,
1360 @_, 1468 @_,
1361 ); 1469 );
1362 1470
1363 CFPlus::weaken (my $this = $self); 1471 DC::weaken (my $this = $self);
1364 1472
1365 $self->connect (delete => sub { $this->destroy; 1 }); 1473 $self->connect (delete => sub { $this->destroy; 1 });
1366 1474
1367 # better use a pane... 1475 # better use a pane...
1368 $self->add (my $hbox = new CFPlus::UI::HBox); 1476 $self->add (my $hbox = new DC::UI::HBox);
1369 $hbox->add ($self->{textview} = new CFPlus::UI::TextScroller expand => 1); 1477 $hbox->add ($self->{textview} = new DC::UI::TextScroller expand => 1);
1370 1478
1371 $hbox->add (my $vbox = new CFPlus::UI::VBox); 1479 $hbox->add (my $vbox = new DC::UI::VBox);
1372 1480
1373 $vbox->add (new CFPlus::UI::Label text => "Message Entry:"); 1481 $vbox->add (new DC::UI::Label text => "Message Entry:");
1374 $vbox->add ($self->{entry} = new CFPlus::UI::Entry 1482 $vbox->add ($self->{entry} = new DC::UI::Entry
1375 tooltip => "#npc_message_entry", 1483 tooltip => "#npc_message_entry",
1376 on_activate => sub { 1484 on_activate => sub {
1377 my ($entry, $text) = @_; 1485 my ($entry, $text) = @_;
1378 1486
1379 return unless $text =~ /\S/; 1487 return unless $text =~ /\S/;
1383 1491
1384 0 1492 0
1385 }, 1493 },
1386 ); 1494 );
1387 1495
1388 $vbox->add ($self->{options} = new CFPlus::UI::VBox); 1496 $vbox->add ($self->{options} = new DC::UI::VBox);
1389 1497
1390 $self->{bye_button} = new CFPlus::UI::Button 1498 $self->{bye_button} = new DC::UI::Button
1391 text => "Bye (close)", 1499 text => "Bye (close)",
1392 tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", 1500 tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.",
1393 on_activate => sub { $this->destroy; 1 }, 1501 on_activate => sub { $this->destroy; 1 },
1394 ; 1502 ;
1395 1503
1414}; 1522};
1415 1523
1416sub update_options { 1524sub update_options {
1417 my ($self) = @_; 1525 my ($self) = @_;
1418 1526
1419 CFPlus::weaken $self; 1527 DC::weaken $self;
1420 1528
1421 $self->{options}->clear; 1529 $self->{options}->clear;
1422 $self->{options}->add ($self->{bye_button}); 1530 $self->{options}->add ($self->{bye_button});
1423 1531
1424 for my $kw (sort keys %{ $self->{kw} }) { 1532 for my $kw (sort keys %{ $self->{kw} }) {
1425 $self->{options}->add (new CFPlus::UI::Button 1533 $self->{options}->add (new DC::UI::Button
1426 text => $kw, 1534 text => $kw,
1427 on_activate => sub { 1535 on_activate => sub {
1428 $self->send ($kw); 1536 $self->send ($kw);
1429 0 1537 0
1430 }, 1538 },
1433} 1541}
1434 1542
1435sub feed { 1543sub feed {
1436 my ($self, $type, @arg) = @_; 1544 my ($self, $type, @arg) = @_;
1437 1545
1438 CFPlus::weaken $self; 1546 DC::weaken $self;
1439 1547
1440 if ($type eq "update") { 1548 if ($type eq "update") {
1441 my (%info) = @arg; 1549 my (%info) = @arg;
1442 1550
1443 $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; 1551 $self->{kw}{$_} = 1 for @{$info{add_topics} || []};
1444 $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; 1552 $self->{kw}{$_} = 0 for @{$info{del_topics} || []};
1445 1553
1446 if (exists $info{msg}) { 1554 if (exists $info{msg}) {
1447 my $text = "\n" . CFPlus::Protocol::sanitise_xml $info{msg}; 1555 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} }; 1556 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} };
1449 my @link; 1557 my @link;
1450 $text =~ s{ 1558 $text =~ s{
1451 ($match) 1559 ($match)
1452 }{ 1560 }{
1453 my $kw = $1; 1561 my $kw = $1;
1454 1562
1455 push @link, new CFPlus::UI::Label 1563 push @link, new DC::UI::Label
1456 markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>", 1564 markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>",
1457 can_hover => 1, 1565 can_hover => 1,
1458 can_events => 1, 1566 can_events => 1,
1459 padding_x => 0, 1567 padding_x => 0,
1460 padding_y => 0, 1568 padding_y => 0,
1478} 1586}
1479 1587
1480sub send { 1588sub send {
1481 my ($self, $msg) = @_; 1589 my ($self, $msg) = @_;
1482 1590
1483 $self->{textview}->add_paragraph ({ markup => "\n" . CFPlus::asxml $msg }); 1591 $self->{textview}->add_paragraph ({
1592 markup =>
1593 "\n<span foreground='#ffff00'><b>"
1594 . (DC::asxml $msg)
1595 . "</b></span>"
1596 });
1484 $self->{textview}->scroll_to_bottom; 1597 $self->{textview}->scroll_to_bottom;
1485 1598
1486 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1599 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1487} 1600}
1488 1601
1491 1604
1492 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 1605 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1
1493 1606
1494 if ($self->{conn}) { 1607 if ($self->{conn}) {
1495 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; 1608 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id};
1496 delete $self->{conn}{npc_dialog}; 1609 delete $self->{conn}{w}{npc_dialog};
1497 $self->{conn}->disconnect_ext ($self->{id}); 1610 $self->{conn}->disconnect_ext ($self->{id});
1498 } 1611 }
1499 1612
1500 $self->SUPER::destroy; 1613 $self->SUPER::destroy;
1501} 1614}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines