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