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.163 by root, Wed Aug 22 21:17:32 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 xwidget1 => 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 (__w_ => sub { 106 ->filter_json_single_key_object ("\fw" => sub {
56 $self->{widget}{$_[0]} 107 $self->{widget}{$_[0]}
108 })
109 ->filter_json_single_key_object ("\fc" => sub {
110 my ($id) = @_;
111 sub {
112 $self->send_exti_msg (w_e => $id, @_);
113 }
57 }); 114 });
58 115
59 # destroy widgets on logout 116 # destroy widgets on logout
60 $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 {
61 for my $ws (values %{delete $self->{widgetset} || {}}) { 118 for my $ws (values %{delete $self->{widgetset} || {}}) {
62 $_->destroy 119 $_->destroy
63 for values %{delete $ws->{w} || {}}; 120 for values %{delete $ws->{w} || {}};
64 } 121 }
122
123 delete $self->{items};
124 $::INV->clear;
125 $::INVR->clear;
126 $::INVR_HB->clear;
127 $::FLOORBOX->clear;
65 }); 128 });
66 129
67 $self->{map_widget}->add_command (@$_) 130 $self->{map_widget}->add_command (@$_)
68 for @cmd_help; 131 for @cmd_help;
69 132
70 { 133 {
71 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture 134 $self->{dialogue} = my $tex = $TEX_DIALOGUE;
72 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
73 $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}});
74 } 136 }
75 137
76 { 138 {
77 $self->{noface} = my $tex = new_from_file CFPlus::Texture 139 $self->{noface} = my $tex = $TEX_NOFACE;
78 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
79 $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}});
80 } 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# };
81 157
82 $self->{open_container} = 0; 158 $self->{open_container} = 0;
83 159
84 # per server 160 # per server
85 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 161 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
86 162
87 $self 163 $self
88} 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#
89 168
90sub update_fx_want { 169sub update_fx_want {
91 my ($self) = @_; 170 my ($self) = @_;
92 171
93 $self->send_exti_msg (fx_want => { 172 $self->send_exti_msg (fx_want => {
98} 177}
99 178
100sub ext_capabilities { 179sub ext_capabilities {
101 my ($self, %cap) = @_; 180 my ($self, %cap) = @_;
102 181
103 #$self->send ("setup sound 0"); # we use a different protocol
104 $self->update_fx_want;
105
106 $self->send_exti_req (resource => "exp_table", sub {
107 my ($exp_table) = @_;
108
109 $self->register_face_handler ($exp_table, sub {
110 my ($face) = @_;
111
112 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
113 $_->() for values %{ $self->{on_exp_update} || {} };
114 });
115
116 ()
117 });
118
119 if (my $ts = $cap{tileset}) { 182 if (my $ts = $cap{tileset}) {
120 if (my ($default) = grep $_->[2] & 1, @$ts) { 183 if (my ($default) = grep $_->[2] & 1, @$ts) {
121 $self->{tileset} = $default; 184 $self->{tileset} = $default;
122 $self->{tilesize} = $default->[3]; 185 $self->{tilesize} = $default->[3];
123 $self->setup_req (tileset => $default->[0]); 186 $self->setup_req (tileset => $default->[0]);
138############################################################################# 201#############################################################################
139 202
140sub widget_associate { 203sub widget_associate {
141 my ($self, $ws, $id, $widget) = @_; 204 my ($self, $ws, $id, $widget) = @_;
142 205
143 if ($widget) { 206 $widget ||= new DC::UI::Bin;
207
144 $widget->{s_id} = $id; 208 $widget->{s_id} = $id;
145 $self->{widget}{$id} = $widget; 209 $self->{widget}{$id} = $widget;
146 210
147 if ($ws) { 211 if ($ws) {
148 $widget->{s_ws} = $ws; 212 $widget->{s_ws} = $ws;
149 $self->{widgetset}{$ws}{w}{$id} = $widget; 213 $self->{widgetset}{$ws}{w}{$id} = $widget;
150 } 214 }
151 215
152 $widget->connect (on_destroy => sub { 216 $widget->connect (on_destroy => sub {
153 my ($widget) = @_; 217 my ($widget) = @_;
154 218
155 delete $self->{widget}{$widget->{s_id}}; 219 delete $self->{widget}{$widget->{s_id}};
156 delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}} 220 delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}}
157 if exists $widget->{s_ws}; 221 if exists $widget->{s_ws};
158 }); 222 });
159
160 1
161 } else {
162 $self->send_exti_msg (w_e => $id, undef);
163
164 0
165 }
166} 223}
167 224
168# widgetset new 225# widgetset new
169sub ext_ws_n { 226sub ext_ws_n {
170 my ($self, $id) = @_; 227 my ($self, $id) = @_;
187 244
188# widgetset create 245# widgetset create
189sub ext_ws_c { 246sub ext_ws_c {
190 my ($self, $ws, $id, $class, $args) = @_; 247 my ($self, $ws, $id, $class, $args) = @_;
191 248
192 for my $ev (grep /^on_/, keys %$args) {
193 my $rid = $args->{$ev};
194 $args->{$ev} = sub {
195 my $id = shift->{s_id};
196 $self->send_exti_msg (w_e => $id, $rid, @_);
197
198 1
199 };
200 }
201
202 $self->widget_associate ( 249 $self->widget_associate (
203 $ws, $id => scalar eval { 250 $ws, $id => scalar eval {
204 local $SIG{__DIE__}; 251 local $SIG{__DIE__};
205 "CFPlus::UI::$class"->new (%$args) 252 "DC::UI::$class"->new (%$args)
253 }
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}));
206 } 299 });
207 ) or warn "server failed creating client-side widget " . (CFPlus::to_json $class) . ": $@\n"; 300 } else {
301 $done_cb->(0);
302 }
208} 303}
209 304
210# widgetset associate 305# widgetset associate
211sub ext_ws_a { 306sub ext_ws_a {
212 my ($self, %ass) = @_; 307 my ($self, %ass) = @_;
213 308
214 # everything that has a name, wether conceivably useful or not 309 # everything that has a name, wether conceivably useful or not
215 my %wkw = ( 310 my %wkw = (
216 root => $CFPlus::UI::ROOT, 311 root => $DC::UI::ROOT,
217 tooltip => $CFPlus::UI::TOOLTIP, 312 tooltip => $DC::UI::TOOLTIP,
218 313
219 mapwidget => $::MAPWIDGET, 314 mapwidget => $::MAPWIDGET,
315 menubar => $::MENUBAR,
316 menupopup => $::MENUPOPUP,
317 pickup_enable => $::PICKUP_ENABLE,
220 buttonbar => $::BUTTONBAR, 318 buttonbar => $::BUTTONBAR,
221 metaserver => $::METASERVER, 319 metaserver => $::METASERVER,
222 buttonbar => $::BUTTONBAR, 320 buttonbar => $::BUTTONBAR,
223 login_button => $::LOGIN_BUTTON, 321 login_button => $::LOGIN_BUTTON,
224 quit_dialog => $::QUIT_DIALOG, 322 quit_dialog => $::QUIT_DIALOG,
240 spell_list => $::SPELL_LIST, 338 spell_list => $::SPELL_LIST,
241 339
242 floorbox => $::FLOORBOX, 340 floorbox => $::FLOORBOX,
243 help_window => $::HELP_WINDOW, 341 help_window => $::HELP_WINDOW,
244 message_window => $::MESSAGE_WINDOW, 342 message_window => $::MESSAGE_WINDOW,
343 message_dist => $::MESSAGE_DIST,
245 statusbox => $::SDTATUSBOX, 344 statusbox => $::STATUSBOX,
246 345
247 inv => $::INV, 346 inv => $::INV,
248 invr => $::INVR, 347 invr => $::INVR,
249 invr_hb => $::INVR_HB, 348 invr_hb => $::INVR_HB,
250 ); 349 );
251 350
252 while (my ($id, $name) = each %ass) { 351 while (my ($id, $name) = each %ass) {
253 $self->widget_associate (undef, $id => $wkw{$name}) 352 $self->widget_associate (undef, $id => $wkw{$name});
254 or warn "server failed to associate non-existent well-known widget $name\n";
255 } 353 }
256} 354}
257 355
258# widget call 356# widget call
259sub ext_w_c { 357sub ext_w_c {
260 my ($self, $id, $rid, $method, @args) = @_; 358 my ($self, $id, $rcb, $method, @args) = @_;
261 359
262 my $w = $self->{widget}{$id} 360 my $w = $self->{widget}{$id}
263 or return; 361 or return;
264 362
265 if ($rid) { 363 if ($rcb) {
266 $self->send_exti_msg (w_r => $rid, $w->$method (@args)); 364 $rcb->($w->$method (@args));
267 } else { 365 } else {
268 $w->$method (@args); 366 $w->$method (@args);
269 } 367 }
270} 368}
271 369
287 } 385 }
288} 386}
289 387
290# widget get 388# widget get
291sub ext_w_g { 389sub ext_w_g {
292 my ($self, $id, $rid, $attr) = @_; 390 my ($self, $id, $rid, @attr) = @_;
293 391
294 my $w = $self->{widget}{$id} 392 my $w = $self->{widget}{$id}
295 or return; 393 or return;
296 394
297 $self->send_exti_msg (w_r => $rid, [map $w->{$_}, @$attr]); 395 $self->send_exti_msg (w_e => $rid, map $w->{$_}, @attr);
298} 396}
299 397
300# message window 398# message window
301sub ext_channel_info { 399sub ext_channel_info {
302 my ($self, $info) = @_; 400 my ($self, $info) = @_;
303 $self->{channels}->{$info->{id}} = $info; 401 $self->{channels}->{$info->{id}} = $info;
304 $::MESSAGE_WINDOW->add_channel ($info); 402 $::MESSAGE_DIST->add_channel ($info);
305} 403}
306 404
307############################################################################# 405#############################################################################
308 406
309sub logprint { 407sub logprint {
310 my ($self, @a) = @_; 408 my ($self, @a) = @_;
311 409
312 CFPlus::DB::logprint "$Crossfire::VARDIR/log.$self->{host}" => (join "", @a), sub { }; 410 DC::DB::logprint "$Deliantra::VARDIR/log.$self->{host}" => (join "", @a), sub { };
313} 411}
314 412
315sub _stat_numdiff { 413sub _stat_numdiff {
316 my ($self, $name, $old, $new) = @_; 414 my ($self, $name, $old, $new) = @_;
317 415
335 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) 433 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_})
336 : () 434 : ()
337 } 435 }
338 sort { $a <=> $b } keys %{$self->{spell_paths}}; 436 sort { $a <=> $b } keys %{$self->{spell_paths}};
339 437
340 join "", @diff 438 "\u$name: " . (join ", ", @diff)
341} 439}
342 440
343# all stats that are chacked against changes 441# all stats that are chacked against changes
344my @statchange = ( 442my @statchange = (
345 [&CS_STAT_STR => \&_stat_numdiff, "Str"], 443 [&CS_STAT_STR => \&_stat_numdiff, "Str"],
388 486
389 if (my @diffs = 487 if (my @diffs =
390 ( 488 (
391 ($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" : ()),
392 map { 490 map {
393 $stats->{$_} && $prev->{$_} 491 $stats->{$_} && $prev->{$_}
394 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 492 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
395 } sort { $a <=> $b } keys %{$self->{skill_info}} 493 } sort { $a <=> $b } keys %{$self->{skill_info}}
396 ) 494 )
397 ) { 495 ) {
398 my $msg = join " ", @diffs; 496 my $msg = join " ", @diffs;
400 } 498 }
401 499
402 if ( 500 if (
403 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange 501 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
404 ) { 502 ) {
405 my $msg = "<b>stat change</b>: " . (join " ", @diffs); 503 my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs);
406 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 10); 504 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20);
407 } 505 }
408 506
409 $self->update_stats_window ($stats, $prev); 507 $self->update_stats_window ($stats, $prev);
410 508
411 $self->{prev_stats} = { %$stats }; 509 $self->{prev_stats} = { %$stats };
448 546
449 $::GAUGES->{hp} ->set_value ($hp, $hp_m); 547 $::GAUGES->{hp} ->set_value ($hp, $hp_m);
450 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 548 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
451 $::GAUGES->{food} ->set_value ($fo, $fo_m); 549 $::GAUGES->{food} ->set_value ($fo, $fo_m);
452 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 550 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
453 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 551 $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d#
454 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 552 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
455 $::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});
456 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); 554 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
457 my $title = $stats->{+CS_STAT_TITLE}; 555 my $title = $stats->{+CS_STAT_TITLE};
458 $title =~ s/^Player: //; 556 $title =~ s/^Player: //;
459 $::STATWIDS->{title} ->set_text ("Title: " . $title); 557 $::STATWIDS->{title} ->set_text ("Title: " . $title);
460 558
472 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 570 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
473 $::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});
474 572
475 $self->update_weight; 573 $self->update_weight;
476 574
477 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 575 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
478 for keys %RES_TBL; 576 for keys %RES_TBL;
479 577
480 my $sktbl = $::STATWIDS->{skill_tbl}; 578 my $sktbl = $::STATWIDS->{skill_tbl};
481 my @skills = keys %{ $self->{skill_info} }; 579 my @skills = keys %{ $self->{skill_info} };
482 580
489 $self->{stat_order} = join ",", map $_->[0], @order; 587 $self->{stat_order} = join ",", map $_->[0], @order;
490 588
491 $sktbl->clear; 589 $sktbl->clear;
492 590
493 my $sw = $self->{skillwid}{""} ||= [ 591 my $sw = $self->{skillwid}{""} ||= [
494 0, 0, (new CFPlus::UI::Label text => "Experience", align => 1), 592 0, 0, (new DC::UI::Label text => "Experience", align => 1),
495 1, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), 593 1, 0, (new DC::UI::Label text => "Lvl.", align => 1),
496 2, 0, (new CFPlus::UI::Label text => "Progress", align => 0), 594 2, 0, (new DC::UI::Label text => "Progress"),
497 3, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), 595 3, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
498 4, 0, (new CFPlus::UI::Label text => "Experience", align => 1), 596 4, 0, (new DC::UI::Label text => "Experience", align => 1),
499 5, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), 597 5, 0, (new DC::UI::Label text => "Lvl.", align => 1),
500 6, 0, (new CFPlus::UI::Label text => "Progress", align => 0), 598 6, 0, (new DC::UI::Label text => "Progress"),
501 7, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), 599 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
502 ]; 600 ];
503 601
504 my @add = @$sw; 602 my @add = @$sw;
505 603
506 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>";
507 605
508 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);
509 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);
510 608
511 my ($x, $y) = (0, 1); 609 my ($x, $y) = (0, 1);
518 if ($ev->{button} == 1) { 616 if ($ev->{button} == 1) {
519 $::CONN->user_send ("ready_skill $name"); 617 $::CONN->user_send ("ready_skill $name");
520 } elsif ($ev->{button} == 2) { 618 } elsif ($ev->{button} == 2) {
521 $::CONN->user_send ("use_skill $name"); 619 $::CONN->user_send ("use_skill $name");
522 } elsif ($ev->{button} == 3) { 620 } elsif ($ev->{button} == 3) {
523 my $shortname = CFPlus::shorten $name, 14; 621 my $shortname = DC::shorten $name, 14;
524 (new CFPlus::UI::Menu 622 (new DC::UI::Menu
525 items => [ 623 items => [
526 ["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"] }],
527 ["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"] }],
528 ], 626 ],
529 )->popup ($ev); 627 )->popup ($ev);
530 } else { 628 } else {
531 return 0; 629 return 0;
532 } 630 }
534 1 632 1
535 }; 633 };
536 634
537 my $sw = $self->{skillwid}{$idx} ||= [ 635 my $sw = $self->{skillwid}{$idx} ||= [
538 # exp 636 # exp
539 (new CFPlus::UI::Label 637 (new DC::UI::Label
540 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),
541 639
542 # level 640 # level
543 (new CFPlus::UI::Label 641 (new DC::UI::Label
544 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),
545 643
546 # progress 644 # progress
547 (new CFPlus::UI::ExperienceProgress), 645 (new DC::UI::ExperienceProgress),
548 646
549 # label 647 # label
550 (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,
551 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),
552 ]; 650 ];
553 651
554 push @add, 652 push @add,
555 $x * 4 + 0, $y, $sw->[0], 653 $x * 4 + 0, $y, $sw->[0],
556 $x * 4 + 1, $y, $sw->[1], 654 $x * 4 + 1, $y, $sw->[1],
566 664
567 for (@order) { 665 for (@order) {
568 my ($idx, $name) = @$_; 666 my ($idx, $name) = @$_;
569 my $val = $stats->{$idx}; 667 my $val = $stats->{$idx};
570 668
571 next if $prev->{$idx}[1] == $val->[1]; 669 next if $prev->{$idx}[1] eq $val->[1];
572 670
573 my $sw = $self->{skillwid}{$idx}; 671 my $sw = $self->{skillwid}{$idx};
574 $sw->[0]->set_text (::formsep ($val->[1])); 672 $sw->[0]->set_text (::formsep ($val->[1]));
575 $sw->[1]->set_text ($val->[0] * 1); 673 $sw->[1]->set_text ($val->[0] * 1);
576 $sw->[2]->set_value (@$val); 674 $sw->[2]->set_value (@$val);
577 675
578 #$::GAUGES->{sklprg}->set_label ($name); 676 $::GAUGES->{skillexp}->set_label ("$name %d%%");
579 $::GAUGES->{sklprg}->set_value (@$val); 677 $::GAUGES->{skillexp}->set_value (@$val);
580 }
581}
582
583sub macro_send {
584 my ($self, $macro) = @_;
585
586 for my $cmd (@{ $macro->{action} }) {
587 $self->send_command ($cmd);
588 } 678 }
589} 679}
590 680
591sub user_send { 681sub user_send {
592 my ($self, $command) = @_; 682 my ($self, $command) = @_;
594 $self->{record}->($command) 684 $self->{record}->($command)
595 if $self->{record}; 685 if $self->{record};
596 686
597 $self->logprint ("send: ", $command); 687 $self->logprint ("send: ", $command);
598 $self->send_command ($command); 688 $self->send_command ($command);
599 ::status ($command);
600} 689}
601 690
602sub record { 691sub record {
603 my ($self, $cb) = @_; 692 my ($self, $cb) = @_;
604 693
606} 695}
607 696
608sub map_scroll { 697sub map_scroll {
609 my ($self, $dx, $dy) = @_; 698 my ($self, $dx, $dy) = @_;
610 699
611 $self->{map}->scroll ($dx, $dy); 700 $self->{map_widget}->scroll ($dx, $dy);
612} 701}
613 702
614sub feed_map1a { 703sub feed_map1a {
615 my ($self, $data) = @_; 704 my ($self, $data) = @_;
616 705
617 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 706 my $missing = $self->{map}->map1a_update ($data);
618 my $delay; 707 my $delay;
619 708
620 for my $tile (@$missing) { 709 for my $tile (@$missing) {
621 next if $self->{delay}{$tile}; 710 next if $self->{delay}{$tile};
622 711
623 $delay = 1; 712 $delay = 1;
624 713
625 if (my $tex = $::CONN->{texture}[$tile]) { 714 if (my $tex = $self->{texture}[$tile]) {
626 $tex->upload; 715 $tex->upload;
627 } else { 716 } else {
628 $self->{delay}{$tile} = 1; 717 $self->{delay}{$tile} = 1;
629 718
630 # we assume the face is in-flight and will eventually come 719 # we assume the face is in-flight and will eventually arrive
631 push @{$self->{tile_cb}{$tile}}, sub { 720 push @{$self->{tile_cb}{$tile}}, sub {
632 delete $self->{delay}{$tile}; 721 delete $self->{delay}{$tile};
633 $_[0]->upload; 722 $_[0]->upload;
634 }; 723 };
635 } 724 }
636 } 725 }
637 726
638 if ($delay) { 727 if ($delay) {
639 # 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
640 Event->timer (after => 0.03, cb => sub { 729 EV::once undef, 0, 0.03, sub {
641 $_[0]->w->cancel;
642 $self->{map_widget}->update 730 $self->{map_widget}->update
643 if $self->{map_widget}; 731 if $self->{map_widget};
644 }); 732 };
645 } else { 733 } else {
646 $self->{map_widget}->update; 734 $self->{map_widget}->update;
647 } 735 }
648} 736}
649 737
654} 742}
655 743
656sub flush_map { 744sub flush_map {
657 my ($self) = @_; 745 my ($self) = @_;
658 746
659 my $map_info = delete $self->{map_info} 747 return unless $self->{map_info};
660 or return;
661 748
749 for my $map_info (values %{ $self->{map_cache} || {} }) {
662 my ($hash, $x, $y, $w, $h) = @$map_info; 750 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
663 751
664 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 752 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
665 $self->{map_cache_new}{$hash} = \$data; 753
754 if ($data ne $$rdata) {
755 $map_info->[1] = \$data;
756 my $cdata = Compress::LZF::compress $data;
666 CFPlus::DB::put $self->{mapcache} => $hash => $data, sub { }; 757 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
758 }
759 }
667} 760}
668 761
669sub map_clear { 762sub map_clear {
670 my ($self) = @_; 763 my ($self) = @_;
671 764
672 $self->flush_map; 765 $self->flush_map;
766 delete $self->{map_info};
673 delete $self->{neigh_map}; 767 delete $self->{neigh_map};
674 768
675 $self->{map}->clear; 769 $self->{map}->clear;
676 delete $self->{map_widget}{magicmap}; 770 delete $self->{map_widget}{magicmap};
677} 771}
684 do { 778 do {
685 $tile = pop @{$self->{bg_fetch}} 779 $tile = pop @{$self->{bg_fetch}}
686 or return; 780 or return;
687 } while $self->{texture}[$tile]; 781 } while $self->{texture}[$tile];
688 782
689 CFPlus::DB::get tilecache => $tile, sub { 783 DC::DB::get tilecache => $tile, sub {
690 my ($data) = @_; 784 my ($data) = @_;
691 785
692 return unless $self->{map}; # stop when destroyed 786 return unless $self->{map}; # stop when destroyed
693 787
694 if (defined $data) { 788 if (defined $data) {
698 792
699 $self->bg_fetch; 793 $self->bg_fetch;
700 }; 794 };
701} 795}
702 796
703sub load_map($$$) { 797sub load_map($$$$$$) {
704 my ($self, $hash, $x, $y) = @_; 798 my ($self, $hash, $x, $y, $w, $h) = @_;
705 799
706 my $gen = $self->{map_change_gen}; 800 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
707 801
708 my $cb = sub { 802 my $cb = sub {
709 return unless $gen == $self->{map_change_gen}; 803 $map_info->[1] = \$_[0];
710 804
711 my ($data) = @_;
712
713 if (defined $data) {
714 $self->{map_cache_new}{$hash} = \$data;
715
716 my $data = Compress::LZF::decompress $data;
717
718 my $inprogress = @{ $self->{bg_fetch} || [] }; 805 my $inprogress = @{ $self->{bg_fetch} || [] };
719 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 806 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
720 $self->bg_fetch unless $inprogress; 807 $self->bg_fetch unless $inprogress;
721 }
722 }; 808 };
723 809
724 if (my $rdata = $self->{map_cache_old}{$hash}) { 810 if (my $map_info = $self->{map_cache_old}{$hash}) {
725 $cb->($$rdata); 811 $cb->(${ $map_info->[1] });
726 } else { 812 } else {
813 my $gen = $self->{map_change_gen};
814
727 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 };
728 } 820 }
729} 821}
730 822
731# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 823# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
732# (server resource,s latency, bandwidth), so this hack is warranted. 824# (server resources, latency, bandwidth), so this hack is warranted.
733# 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
734sub send_mapinfo { 826sub send_mapinfo {
735 my ($self, $data, $cb) = @_; 827 my ($self, $data, $cb) = @_;
736 828
737 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)$%) {
762} 854}
763 855
764# this method does a "flood fill" into every tile direction 856# this method does a "flood fill" into every tile direction
765# it assumes that tiles are arranged in a rectangular grid, 857# it assumes that tiles are arranged in a rectangular grid,
766# 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.
767# failure to comply are harmless and result in display errors 859# failure to comply is harmless and results in display errors
768# at worst. 860# at worst.
769sub flood_fill { 861sub flood_fill {
770 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 862 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
771 863
772 # the server does not allow map paths > 6 864 # the server does not allow map paths > 6
808 return if $mode ne "spatial"; 900 return if $mode ne "spatial";
809 901
810 $x += $self->{map}->ox; 902 $x += $self->{map}->ox;
811 $y += $self->{map}->oy; 903 $y += $self->{map}->oy;
812 904
813 $self->load_map ($hash, $x, $y) 905 $self->load_map ($hash, $x, $y, $w, $h)
814 unless $self->{neigh_map}{$hash}[5]++;#d# 906 unless $self->{neigh_map}{$hash}[5]++;#d#
815 907
816 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 908 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
817 909
818 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 910 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
826 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 918 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
827 919
828 $self->flush_map; 920 $self->flush_map;
829 921
830 ++$self->{map_change_gen}; 922 ++$self->{map_change_gen};
831 $self->{map_cache_old} = delete $self->{map_cache_new}; 923 $self->{map_cache_old} = delete $self->{map_cache};
832 924
833 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 925 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
834 926
835 my $mapmapw = $self->{mapmap}->{w}; 927 my $mapmapw = $self->{mapmap}->{w};
836 my $mapmaph = $self->{mapmap}->{h}; 928 my $mapmaph = $self->{mapmap}->{h};
848 $self->{map_info} = [$hash, $x, $y, $w, $h]; 940 $self->{map_info} = [$hash, $x, $y, $w, $h];
849 941
850 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 942 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
851 $::STATWIDS->{map}->set_text ("Map: " . $map); 943 $::STATWIDS->{map}->set_text ("Map: " . $map);
852 944
853 $self->load_map ($hash, $x, $y); 945 $self->load_map ($hash, $x, $y, $w, $h);
854 $self->flood_fill (0, 0, 0, "", $hash, $flags); 946 $self->flood_fill (0, 0, 0, "", $hash, $flags);
855} 947}
856 948
857sub face_find { 949sub face_find {
858 my ($self, $facenum, $face, $cb) = @_; 950 my ($self, $facenum, $face, $cb) = @_;
859 951
860 if ($face->{type} == 0) { # FT_FACE 952 if ($face->{type} == 0) { # FT_FACE
861 my $id = CFPlus::DB::get_tile_id_sync $face->{name}; 953 my $id = DC::DB::get_tile_id_sync $face->{name};
862 954
863 $face->{id} = $id; 955 $face->{id} = $id;
864 $self->{map}->set_tileid ($facenum => $id); 956 $self->{map}->set_tileid ($facenum => $id);
865 957
866 CFPlus::DB::get tilecache => $id, $cb; 958 DC::DB::get tilecache => $id, $cb;
867 959
868 } elsif ($face->{type} & 1) { # with metadata 960 } elsif ($face->{type} & 1) { # with metadata
869 CFPlus::DB::get res_meta => $face->{name}, $cb; 961 DC::DB::get res_meta => $face->{name}, $cb;
870 962
871 } else { # no metadata 963 } else { # no metadata
872 CFPlus::DB::get res_data => $face->{name}, $cb; 964 DC::DB::get res_data => $face->{name}, $cb;
873 } 965 }
874} 966}
875 967
876sub face_update { 968sub face_update {
877 my ($self, $facenum, $face, $changed) = @_; 969 my ($self, $facenum, $face, $changed) = @_;
878 970
879 if ($face->{type} == 0) { 971 if ($face->{type} == 0) {
880 # image, FT_FACE 972 # image, FT_FACE
881 CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } 973 DC::DB::put tilecache => $face->{id} => $face->{data}, sub { }
882 if $changed; 974 if $changed;
883 975
884 $self->have_tile ($face->{id}, delete $face->{data}); 976 $self->have_tile ($face->{id}, delete $face->{data});
885 977
886 } elsif ($face->{type} & 1) { 978 } elsif ($face->{type} & 1) {
887 # split metadata case, FT_MUSIC, FT_SOUND 979 # split metadata case, FT_MUSIC, FT_SOUND
888 if ($changed) { # new data 980 if ($changed) { # new data
889 my ($meta, $data) = unpack "(w/a*)*", $face->{data}; 981 my ($meta, $data) = unpack "(w/a*)*", $face->{data};
890 $face->{data} = $meta; 982 $face->{data} = $meta;
891 983
984 # rely on strict ordering here and also on later fetch
892 CFPlus::DB::put res_data => $face->{name} => $data, sub { }; 985 DC::DB::put res_data => $face->{name} => $data, sub { };
893 CFPlus::DB::put res_meta => $face->{name} => $meta, sub { }; 986 DC::DB::put res_meta => $face->{name} => $meta, sub { };
894 } 987 }
895 988
896 $face->{data} = $self->{json_coder}->decode ($face->{data}); 989 $face->{data} = $self->{json_coder}->decode ($face->{data});
897
898 ::add_license ($face); 990 ::add_license ($face);
991 ::message ({ markup => DC::asxml "downloaded resource '$face->{data}{name}', type $face->{type}." })
992 if $changed;
899 993
900 if ($face->{type} == 3) { # FT_MUSIC 994 if ($face->{type} == 3) { # FT_MUSIC
901 ::message ({ markup => "downloaded song #$facenum" })
902 if $changed;
903
904 &::audio_music_push ($facenum); 995 &::audio_music_push ($facenum);
905 } elsif ($face->{type} == 5) { # FT_SOUND 996 } elsif ($face->{type} == 5) { # FT_SOUND
906 ::message ({ markup => "downloaded sound #$facenum" })
907 if $changed;
908
909 &::audio_sound_push ($facenum); 997 &::audio_sound_push ($facenum);
910 } 998 }
911 999
912 } else { 1000 } else {
913 # flat resource case, FT_RSRC 1001 # flat resource case, FT_RSRC
914 CFPlus::DB::put res_data => $face->{name} => $face->{data}, sub { } 1002 DC::DB::put res_data => $face->{name} => $face->{data}, sub { }
915 if $changed; 1003 if $changed;
916 } 1004 }
917 1005
918 if (my $cbs = $self->{face_cb}{$facenum}) { 1006 if (my $cbs = $self->{face_cb}{$facenum}) {
919 $_->($face, $changed) for @$cbs; 1007 $_->($face, $changed) for @$cbs;
930 my ($self, $tile, $data) = @_; 1018 my ($self, $tile, $data) = @_;
931 1019
932 return unless $self->{map}; 1020 return unless $self->{map};
933 1021
934 my $tex = $self->{texture}[$tile] ||= 1022 my $tex = $self->{texture}[$tile] ||=
935 new CFPlus::Texture 1023 new DC::Texture
936 tile => $tile, 1024 tile => $tile,
937 image => $data, delete_image => 1, 1025 image => $data, delete_image => 1,
938 minify => 1, mipmap => 1; 1026 minify => 1;
939 1027
940 if (my $cbs = delete $self->{tile_cb}{$tile}) { 1028 if (my $cbs = delete $self->{tile_cb}{$tile}) {
941 $_->($tex) for @$cbs; 1029 $_->($tex) for @$cbs;
942 } 1030 }
943} 1031}
948 my ($self, $num, $cb) = @_; 1036 my ($self, $num, $cb) = @_;
949 1037
950 push @{$self->{face_cb}{$num}}, $cb; 1038 push @{$self->{face_cb}{$num}}, $cb;
951 1039
952 defined wantarray 1040 defined wantarray
953 ? CFPlus::guard { 1041 ? Guard::guard {
954 @{$self->{face_cb}{$num}} 1042 @{$self->{face_cb}{$num}}
955 = grep $_ != $cb, 1043 = grep $_ != $cb,
956 @{$self->{face_cb}{$num}}; 1044 @{$self->{face_cb}{$num}};
957 } 1045 }
958 : () 1046 : ()
986 my ($self, $flags, $prompt) = @_; 1074 my ($self, $flags, $prompt) = @_;
987 1075
988 $prompt = $LAST_QUERY unless length $prompt; 1076 $prompt = $LAST_QUERY unless length $prompt;
989 $LAST_QUERY = $prompt; 1077 $LAST_QUERY = $prompt;
990 1078
991 $self->{query}-> ($self, $flags, $prompt); 1079 $self->{query}->($self, $flags, $prompt);
992} 1080}
993 1081
994sub sanitise_xml($) { 1082sub sanitise_xml($) {
995 local $_ = shift; 1083 local $_ = shift;
996 1084
997 # we now weed out all tags we do not support 1085 # we now weed out all tags we do not support
998 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
999 # now all entities 1091 # now all entities
1000 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;
1001 1093
1002 # handle some elements 1094 # handle some elements
1003 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; 1095 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
1004 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+$//;
1005 1099
1006 $_ 1100 $_
1007} 1101}
1008 1102
1009our %NAME_TO_COLOR = ( 1103our %NAME_TO_COLOR = (
1022 tan => 12, 1116 tan => 12,
1023); 1117);
1024 1118
1025our @CF_COLOR = ( 1119our @CF_COLOR = (
1026 [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],
1027 [1.00, 1.00, 1.00], 1121 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1028 [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],
1029 [1.00, 0.00, 0.00], 1123 [1.00, 0.00, 0.00],
1030 [1.00, 0.54, 0.00], 1124 [1.00, 0.54, 0.00],
1031 [0.11, 0.56, 1.00], 1125 [0.11, 0.56, 1.00],
1032 [0.93, 0.46, 0.00], 1126 [0.93, 0.46, 0.00],
1033 [0.18, 0.54, 0.34], 1127 [0.18, 0.54, 0.34],
1052 $self->logprint ("msg: ", $text); 1146 $self->logprint ("msg: ", $text);
1053 return if $color < 0; # negative color == ignore if not understood 1147 return if $color < 0; # negative color == ignore if not understood
1054 1148
1055 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1149 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1056 1150
1057 ## try to create single paragraphs of multiple lines sent by the server
1058 # no longer neecssary with TRT servers
1059 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1060
1061 ::message ({ 1151 ::message ({
1062 fg => $fg, 1152 fg => $fg,
1063 markup => $_, 1153 markup => $text,
1064 type => $type, 1154 type => $type,
1065 extra => [@extra], 1155 extra => [@extra],
1066 color_flags => $color 1156 color_flags => $color, #d# ugly, kill
1067 }) for split /\n/, $text; 1157 });
1158
1159# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1160# # actually, this is an ugly design. _we_ should control the channels,
1161# # not some random other widget, as the channels are clearly protocol-specific.
1162# # then we could also react to flags such as CLEAR without resorting to
1163# # hacks such as color_flags, above.
1068 1164
1069 $self->{statusbox}->add ($text, 1165 $self->{statusbox}->add ($text,
1070 group => $text, 1166 group => $text,
1071 fg => $fg, 1167 fg => $fg,
1072 timeout => $color >= 2 ? 180 : 10, 1168 timeout => $color >= 2 ? 180 : 10,
1073 tooltip_font => $::FONT_FIXED, 1169 tooltip_font => $::FONT_FIXED,
1074 ); 1170 ) if $type eq "info";
1075 } 1171 }
1076} 1172}
1077 1173
1078sub spell_add { 1174sub spell_add {
1079 my ($self, $spell) = @_; 1175 my ($self, $spell) = @_;
1083 $spell->{message} =~ s/\n+$//; 1179 $spell->{message} =~ s/\n+$//;
1084 $spell->{message} ||= "Server did not provide a description for this spell."; 1180 $spell->{message} ||= "Server did not provide a description for this spell.";
1085 1181
1086 $::SPELL_LIST->add_spell ($spell); 1182 $::SPELL_LIST->add_spell ($spell);
1087 1183
1088 $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});
1089 $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});
1090} 1186}
1091 1187
1092sub spell_delete { 1188sub spell_delete {
1093 my ($self, $spell) = @_; 1189 my ($self, $spell) = @_;
1094 1190
1105sub addme_success { 1201sub addme_success {
1106 my ($self) = @_; 1202 my ($self) = @_;
1107 1203
1108 my %skill_help; 1204 my %skill_help;
1109 1205
1110 for my $node (CFPlus::Pod::find skill_description => "*") { 1206 for my $node (DC::Pod::find skill_description => "*") {
1111 my (undef, @par) = CFPlus::Pod::section_of $node; 1207 my (undef, @par) = DC::Pod::section_of $node;
1112 $skill_help{$node->{kw}[0]} = CFPlus::Pod::as_label @par; 1208 $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par;
1113 }; 1209 };
1114 1210
1115 for my $skill (values %{$self->{skill_info}}) { 1211 for my $skill (values %{$self->{skill_info}}) {
1116 $self->{map_widget}->add_command ("ready_skill $skill", 1212 $self->{map_widget}->add_command ("ready_skill $skill",
1117 (CFPlus::asxml "Ready the skill '$skill'\n\n") 1213 (DC::asxml "Ready the skill '$skill'\n\n")
1118 . $skill_help{$skill}); 1214 . $skill_help{$skill});
1119 $self->{map_widget}->add_command ("use_skill $skill", 1215 $self->{map_widget}->add_command ("use_skill $skill",
1120 (CFPlus::asxml "Immediately use the skill '$skill'\n\n") 1216 (DC::asxml "Immediately use the skill '$skill'\n\n")
1121 . $skill_help{$skill}); 1217 . $skill_help{$skill});
1122 } 1218 }
1123} 1219}
1124 1220
1125sub eof { 1221sub eof {
1129 1225
1130 ::stop_game (); 1226 ::stop_game ();
1131} 1227}
1132 1228
1133sub update_floorbox { 1229sub update_floorbox {
1134 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { 1230 $DC::UI::ROOT->on_refresh ($::FLOORBOX => sub {
1135 return unless $::CONN; 1231 return unless $::CONN;
1136 1232
1137 $::FLOORBOX->clear; 1233 $::FLOORBOX->clear;
1138 1234
1139 my @add; 1235 my @add;
1140 1236
1141 my $row; 1237 my $row;
1142 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;
1143 if ($row < 6) { 1240 if ($row < 6) {
1144 local $_->{face_widget}; # hack to force recreation of widget 1241 local $_->{face_widget}; # hack to force recreation of widget
1145 local $_->{desc_widget}; # hack to force recreation of widget 1242 local $_->{desc_widget}; # hack to force recreation of widget
1146 CFPlus::Item::update_widgets $_; 1243 DC::Item::update_widgets $_;
1147 1244
1148 push @add, 1245 push @add,
1149 0, $row, $_->{face_widget}, 1246 0, $row, $_->{face_widget},
1150 1, $row, $_->{desc_widget}; 1247 1, $row, $_->{desc_widget};
1151 1248
1152 $row++; 1249 $row++;
1153 } else { 1250 } else {
1154 push @add, 1, $row, new CFPlus::UI::Button 1251 push @add, 1, $row, new DC::UI::Button
1155 text => "More...", 1252 text => "More...",
1156 on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, 1253 on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 },
1157 ; 1254 ;
1158 last; 1255 last;
1159 } 1256 }
1160 } 1257 }
1161 if ($::CONN->{open_container}) { 1258 if ($::CONN->{open_container}) {
1162 push @add, 1, $row++, new CFPlus::UI::Button 1259 push @add, 1, $row++, new DC::UI::Button
1163 text => "Close container", 1260 text => "Close container",
1164 on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } 1261 on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") }
1165 ; 1262 ;
1166 } 1263 }
1167 1264
1168 $::FLOORBOX->add_at (@add); 1265 $::FLOORBOX->add_at (@add);
1169 }); 1266 });
1170 1267
1171 $::WANT_REFRESH->start; 1268 $::WANT_REFRESH = 1;
1172} 1269}
1173 1270
1174sub set_opencont { 1271sub set_opencont {
1175 my ($conn, $tag, $name) = @_; 1272 my ($conn, $tag, $name) = @_;
1176 $conn->{open_container} = $tag; 1273 $conn->{open_container} = $tag;
1177 update_floorbox; 1274 update_floorbox;
1178 1275
1179 $::INVR_HB->clear (); 1276 $::INVR_HB->clear;
1180 $::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);
1181 1278
1182 if ($tag != 0) { # Floor isn't closable, is it? 1279 if ($tag != 0) { # Floor isn't closable, is it?
1183 $::INVR_HB->add (new CFPlus::UI::Button 1280 $::INVR_HB->add (new DC::UI::Button
1184 text => "Close container", 1281 text => "Close container",
1185 tooltip => "Close the currently open container (if one is open)", 1282 tooltip => "Close the currently open container (if one is open)",
1186 on_activate => sub { 1283 on_activate => sub {
1187 $::CONN->send ("apply $tag") # $::CONN->{open_container}") 1284 $::CONN->send ("apply $tag") # $::CONN->{open_container}")
1188 if $tag != 0; 1285 if $tag != 0;
1195} 1292}
1196 1293
1197sub update_containers { 1294sub update_containers {
1198 my ($self) = @_; 1295 my ($self) = @_;
1199 1296
1200 $CFPlus::UI::ROOT->on_refresh ("update_containers_$self" => sub { 1297 $DC::UI::ROOT->on_refresh ("update_containers_$self" => sub {
1201 my $todo = delete $self->{update_container} 1298 my $todo = delete $self->{update_container}
1202 or return; 1299 or return;
1203 1300
1204 for my $tag (keys %$todo) { 1301 for my $tag (keys %$todo) {
1205 update_floorbox if $tag == 0 or $tag == $self->{open_container}; 1302 update_floorbox if $tag == 0 or $tag == $self->{open_container};
1240} 1337}
1241 1338
1242sub item_update { 1339sub item_update {
1243 my ($self, $item) = @_; 1340 my ($self, $item) = @_;
1244 1341
1245 #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";
1246 1343
1247 CFPlus::Item::update_widgets $item; 1344 DC::Item::update_widgets $item;
1248 1345
1249 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { 1346 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) {
1250 set_opencont ($::CONN, 0, "Floor"); 1347 set_opencont ($::CONN, 0, "Floor");
1251 1348
1252 } elsif ($item->{flags} & F_OPEN) { 1349 } elsif ($item->{flags} & F_OPEN) {
1253 set_opencont ($::CONN, $item->{tag}, CFPlus::Item::desc_string $item); 1350 set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item);
1254 1351
1255 } else { 1352 } else {
1256 $self->{update_container}{$item->{container}}++; 1353 $self->{update_container}{$item->{container}}++;
1257 $self->update_containers; 1354 $self->update_containers;
1258 } 1355 }
1269 1366
1270 my $weight = .001 * $self->{player}{weight}; 1367 my $weight = .001 * $self->{player}{weight};
1271 my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; 1368 my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM};
1272 1369
1273 $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); 1370 $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight);
1274 $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); 1371 $::STATWIDS->{m_weight}->set_text (sprintf "Max Weight: %.1fkg", $limit);
1275 $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); 1372 $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit);
1276} 1373}
1277 1374
1278sub update_server_info { 1375sub update_server_info {
1279 my ($self) = @_; 1376 my ($self) = @_;
1280 1377
1281 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>");
1282 1379
1380 my $version = JSON::XS->new->encode ($self->{s_version});
1381
1283 $::SERVER_INFO->set_markup ( 1382 $::SERVER_INFO->set_markup (
1284 "server <tt>$self->{host}:$self->{port}</tt>\n" 1383 "server <tt>$self->{host}:$self->{port}</tt>\n"
1285 . "protocol version <tt>$self->{version}</tt>\n" 1384 . "protocol version <tt>$version</tt>\n"
1286 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1287 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1288 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1289 . "editing support $yesno[!!$self->{editor_support}]\n" 1385 . "editing support $yesno[!!$self->{editor_support}]\n"
1290 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1291 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1292 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 1386 . "client support $yesno[$self->{cfplus_ext} > 0]"
1293 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1387 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1294 . "map size $self->{mapw}×$self->{maph}\n" 1388 . "map size $self->{mapw}×$self->{maph}\n"
1295 ); 1389 );
1296 1390
1297} 1391}
1317 0 1411 0
1318 }); 1412 });
1319 1413
1320 $self->update_server_info; 1414 $self->update_server_info;
1321 1415
1322 $self->send_command ("output-sync $::CFG->{output_sync}");
1323 $self->send_command ("output-count $::CFG->{output_count}");
1324 $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;
1325 $self->send_command ("pickup $::CFG->{pickup}"); 1417 $self->send_pickup ($::CFG->{pickup});
1326} 1418}
1327 1419
1328sub lookat { 1420sub lookat {
1329 my ($self, $x, $y) = @_; 1421 my ($self, $x, $y) = @_;
1330 1422
1332 $self->send_ext_req (lookat => $x, $y, sub { 1424 $self->send_ext_req (lookat => $x, $y, sub {
1333 my (%msg) = @_; 1425 my (%msg) = @_;
1334 1426
1335 if (exists $msg{npc_dialog}) { 1427 if (exists $msg{npc_dialog}) {
1336 # start npc chat dialog 1428 # start npc chat dialog
1337 $self->{npc_dialog} = new CFPlus::NPCDialog:: 1429 $self->{w}{npc_dialog} = new DC::NPCDialog::
1338 token => $msg{npc_dialog}, 1430 token => $msg{npc_dialog},
1339 title => "$msg{npc_dialog}[0] (NPC)", 1431 title => "$msg{npc_dialog}[0] (NPC)",
1340 conn => $self, 1432 conn => $self,
1341 ; 1433 ;
1342 } 1434 }
1347} 1439}
1348 1440
1349sub destroy { 1441sub destroy {
1350 my ($self) = @_; 1442 my ($self) = @_;
1351 1443
1352 (delete $self->{npc_dialog})->destroy 1444 $_->destroy
1353 if $self->{npc_dialog}; 1445 for values %{ $self->{w} };
1354 1446
1355 $self->SUPER::destroy; 1447 $self->SUPER::destroy;
1356 1448
1357 %$self = (); 1449 %$self = ();
1358} 1450}
1359 1451
1360package CFPlus::NPCDialog; 1452package DC::NPCDialog;
1361 1453
1362our @ISA = 'CFPlus::UI::Toplevel'; 1454our @ISA = 'DC::UI::Toplevel';
1363 1455
1364sub new { 1456sub new {
1365 my $class = shift; 1457 my $class = shift;
1366 1458
1367 my $self = $class->SUPER::new ( 1459 my $self = $class->SUPER::new (
1374 kw => { hi => 0, yes => 0, no => 0 }, 1466 kw => { hi => 0, yes => 0, no => 0 },
1375 has_close_button => 1, 1467 has_close_button => 1,
1376 @_, 1468 @_,
1377 ); 1469 );
1378 1470
1379 CFPlus::weaken (my $this = $self); 1471 DC::weaken (my $this = $self);
1380 1472
1381 $self->connect (delete => sub { $this->destroy; 1 }); 1473 $self->connect (delete => sub { $this->destroy; 1 });
1382 1474
1383 # better use a pane... 1475 # better use a pane...
1384 $self->add (my $hbox = new CFPlus::UI::HBox); 1476 $self->add (my $hbox = new DC::UI::HBox);
1385 $hbox->add ($self->{textview} = new CFPlus::UI::TextScroller expand => 1); 1477 $hbox->add ($self->{textview} = new DC::UI::TextScroller expand => 1);
1386 1478
1387 $hbox->add (my $vbox = new CFPlus::UI::VBox); 1479 $hbox->add (my $vbox = new DC::UI::VBox);
1388 1480
1389 $vbox->add (new CFPlus::UI::Label text => "Message Entry:"); 1481 $vbox->add (new DC::UI::Label text => "Message Entry:");
1390 $vbox->add ($self->{entry} = new CFPlus::UI::Entry 1482 $vbox->add ($self->{entry} = new DC::UI::Entry
1391 tooltip => "#npc_message_entry", 1483 tooltip => "#npc_message_entry",
1392 on_activate => sub { 1484 on_activate => sub {
1393 my ($entry, $text) = @_; 1485 my ($entry, $text) = @_;
1394 1486
1395 return unless $text =~ /\S/; 1487 return unless $text =~ /\S/;
1399 1491
1400 0 1492 0
1401 }, 1493 },
1402 ); 1494 );
1403 1495
1404 $vbox->add ($self->{options} = new CFPlus::UI::VBox); 1496 $vbox->add ($self->{options} = new DC::UI::VBox);
1405 1497
1406 $self->{bye_button} = new CFPlus::UI::Button 1498 $self->{bye_button} = new DC::UI::Button
1407 text => "Bye (close)", 1499 text => "Bye (close)",
1408 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.",
1409 on_activate => sub { $this->destroy; 1 }, 1501 on_activate => sub { $this->destroy; 1 },
1410 ; 1502 ;
1411 1503
1430}; 1522};
1431 1523
1432sub update_options { 1524sub update_options {
1433 my ($self) = @_; 1525 my ($self) = @_;
1434 1526
1435 CFPlus::weaken $self; 1527 DC::weaken $self;
1436 1528
1437 $self->{options}->clear; 1529 $self->{options}->clear;
1438 $self->{options}->add ($self->{bye_button}); 1530 $self->{options}->add ($self->{bye_button});
1439 1531
1440 for my $kw (sort keys %{ $self->{kw} }) { 1532 for my $kw (sort keys %{ $self->{kw} }) {
1441 $self->{options}->add (new CFPlus::UI::Button 1533 $self->{options}->add (new DC::UI::Button
1442 text => $kw, 1534 text => $kw,
1443 on_activate => sub { 1535 on_activate => sub {
1444 $self->send ($kw); 1536 $self->send ($kw);
1445 0 1537 0
1446 }, 1538 },
1449} 1541}
1450 1542
1451sub feed { 1543sub feed {
1452 my ($self, $type, @arg) = @_; 1544 my ($self, $type, @arg) = @_;
1453 1545
1454 CFPlus::weaken $self; 1546 DC::weaken $self;
1455 1547
1456 if ($type eq "update") { 1548 if ($type eq "update") {
1457 my (%info) = @arg; 1549 my (%info) = @arg;
1458 1550
1459 $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; 1551 $self->{kw}{$_} = 1 for @{$info{add_topics} || []};
1460 $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; 1552 $self->{kw}{$_} = 0 for @{$info{del_topics} || []};
1461 1553
1462 if (exists $info{msg}) { 1554 if (exists $info{msg}) {
1463 my $text = "\n" . CFPlus::Protocol::sanitise_xml $info{msg}; 1555 my $text = "\n" . DC::Protocol::sanitise_xml $info{msg};
1464 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} };
1465 my @link; 1557 my @link;
1466 $text =~ s{ 1558 $text =~ s{
1467 ($match) 1559 ($match)
1468 }{ 1560 }{
1469 my $kw = $1; 1561 my $kw = $1;
1470 1562
1471 push @link, new CFPlus::UI::Label 1563 push @link, new DC::UI::Label
1472 markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>", 1564 markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>",
1473 can_hover => 1, 1565 can_hover => 1,
1474 can_events => 1, 1566 can_events => 1,
1475 padding_x => 0, 1567 padding_x => 0,
1476 padding_y => 0, 1568 padding_y => 0,
1494} 1586}
1495 1587
1496sub send { 1588sub send {
1497 my ($self, $msg) = @_; 1589 my ($self, $msg) = @_;
1498 1590
1499 $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 });
1500 $self->{textview}->scroll_to_bottom; 1597 $self->{textview}->scroll_to_bottom;
1501 1598
1502 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1599 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1503} 1600}
1504 1601
1507 1604
1508 #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
1509 1606
1510 if ($self->{conn}) { 1607 if ($self->{conn}) {
1511 $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};
1512 delete $self->{conn}{npc_dialog}; 1609 delete $self->{conn}{w}{npc_dialog};
1513 $self->{conn}->disconnect_ext ($self->{id}); 1610 $self->{conn}->disconnect_ext ($self->{id});
1514 } 1611 }
1515 1612
1516 $self->SUPER::destroy; 1613 $self->SUPER::destroy;
1517} 1614}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines