1 | package CFClient::Protocol; |
1 | package CFPlus::Protocol; |
2 | |
2 | |
3 | use utf8; |
3 | use utf8; |
4 | use strict; |
4 | use strict; |
5 | |
5 | |
6 | use Crossfire::Protocol::Constants; |
6 | use Crossfire::Protocol::Constants; |
7 | |
7 | |
8 | use CFClient; |
8 | use CFPlus; |
9 | use CFClient::UI; |
9 | use CFPlus::UI; |
|
|
10 | use CFPlus::Pod; |
|
|
11 | use CFPlus::Macro; |
|
|
12 | use CFPlus::Item; |
|
|
13 | |
|
|
14 | use Crossfire::Protocol::Base 0.95; |
10 | |
15 | |
11 | use base 'Crossfire::Protocol::Base'; |
16 | use base 'Crossfire::Protocol::Base'; |
12 | |
17 | |
13 | sub new { |
18 | sub new { |
14 | my $class = shift; |
19 | my $class = shift; |
15 | |
20 | |
16 | my $self = $class->SUPER::new (@_); |
21 | my $self = $class->SUPER::new (@_, setup_req => { extmap => 1 }); |
17 | |
22 | |
18 | $self->{map_widget}->clr_commands; |
23 | $self->{map_widget}->clr_commands; |
19 | |
24 | |
20 | my $cmd_help = CFClient::load_pod CFClient::find_rcfile "pod/command_help.pod", command_help => 1, sub { |
25 | my @cmd_help = map { |
21 | my ($pom) = @_; |
|
|
22 | |
|
|
23 | my @cmd_help; |
|
|
24 | |
|
|
25 | for my $head2 ($pom->head1->[-2]->head2) { |
|
|
26 | $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
26 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
27 | or next; |
27 | or die "unparseable command help: $_->{kw}[0]"; |
28 | |
28 | |
29 | my $cmd = $1; |
29 | my $cmd = $1; |
30 | my @args = split /\|/, $2; |
30 | my @args = split /\|/, $2; |
31 | @args = (".*") unless @args; |
31 | @args = (".*") unless @args; |
32 | |
32 | |
|
|
33 | my (undef, @par) = CFPlus::Pod::section_of $_; |
|
|
34 | my $text = CFPlus::Pod::as_label @par; |
|
|
35 | |
33 | $_ = $_ eq ".*" ? "" : " $_" |
36 | $_ = $_ eq ".*" ? "" : " $_" |
34 | for @args; |
37 | for @args; |
35 | |
38 | |
36 | my $text = CFClient::pod_to_pango $head2->content; |
39 | map ["$cmd$_", $text], |
37 | |
|
|
38 | push @cmd_help, ["$cmd$_", $text] |
|
|
39 | for sort { (length $a) <=> (length $b) } |
40 | sort { (length $a) <=> (length $b) } |
40 | @args; |
41 | @args |
|
|
42 | } sort { $a->{par} <=> $b->{par} } |
|
|
43 | CFPlus::Pod::find command => "*"; |
|
|
44 | |
|
|
45 | $self->connect_ext (event_capabilities => sub { |
|
|
46 | my ($cap) = @_; |
|
|
47 | |
|
|
48 | if (my $ts = $cap->{tileset}) { |
|
|
49 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
|
|
50 | $self->{tileset} = $default; |
|
|
51 | $self->{tilesize} = $default->[3]; |
|
|
52 | $self->setup_req (tileset => $default->[0]); |
|
|
53 | |
|
|
54 | my $w = int $self->{mapw} * 32 / $self->{tilesize}; |
|
|
55 | my $h = int $self->{maph} * 32 / $self->{tilesize}; |
|
|
56 | |
|
|
57 | $self->setup_req (mapsize => "${w}x${h}"); |
|
|
58 | } |
41 | } |
59 | } |
42 | |
|
|
43 | \@cmd_help |
|
|
44 | }; |
60 | }); |
45 | |
61 | |
46 | $self->{map_widget}->add_command (@$_) |
62 | $self->{map_widget}->add_command (@$_) |
47 | for @$cmd_help; |
63 | for @cmd_help; |
48 | |
64 | |
49 | $self->{noface} = new_from_file CFClient::Texture |
65 | $self->{noface} = new_from_file CFPlus::Texture |
50 | CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; |
66 | CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; |
|
|
67 | |
|
|
68 | { |
|
|
69 | $self->{dialogue} = my $tex = new_from_file CFPlus::Texture |
|
|
70 | CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1; |
|
|
71 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
72 | } |
51 | |
73 | |
52 | $self->{open_container} = 0; |
74 | $self->{open_container} = 0; |
53 | |
75 | |
54 | # "global" |
76 | # "global" |
55 | $self->{tilecache} = CFClient::db_table "tilecache"; |
77 | $self->{tilecache} = CFPlus::db_table "tilecache" |
|
|
78 | or die "tilecache: unable to open database table"; |
56 | $self->{facemap} = CFClient::db_table "facemap"; |
79 | $self->{facemap} = CFPlus::db_table "facemap" |
|
|
80 | or die "facemap: unable to open database table"; |
57 | |
81 | |
58 | # per server |
82 | # per server |
59 | $self->{mapcache} = CFClient::db_table "mapcache_$self->{host}_$self->{port}"; |
83 | $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}" |
|
|
84 | or die "mapcache_$self->{host}_$self->{port}: unable to open database table"; |
60 | |
85 | |
61 | $self |
86 | $self |
62 | } |
87 | } |
63 | |
88 | |
64 | sub logprint { |
89 | sub logprint { |
… | |
… | |
242 | $::STATWIDS->{st_dam} ->set_text (sprintf "%d" , $stats->{+CS_STAT_DAM}); |
267 | $::STATWIDS->{st_dam} ->set_text (sprintf "%d" , $stats->{+CS_STAT_DAM}); |
243 | $::STATWIDS->{st_arm} ->set_text (sprintf "%d" , $stats->{+CS_STAT_RES_PHYS}); |
268 | $::STATWIDS->{st_arm} ->set_text (sprintf "%d" , $stats->{+CS_STAT_RES_PHYS}); |
244 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
269 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
245 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
270 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
246 | |
271 | |
247 | $::STATWIDS->{m_weight}->set_text (sprintf "Max weight: %.1fkg", $stats->{+CS_STAT_WEIGHT_LIM} / 1000); |
272 | $self->update_weight; |
248 | |
273 | |
249 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
274 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
250 | for keys %RES_TBL; |
275 | for keys %RES_TBL; |
251 | |
276 | |
252 | my $sktbl = $::STATWIDS->{skill_tbl}; |
277 | my $sktbl = $::STATWIDS->{skill_tbl}; |
253 | my @skills = keys %{ $self->{skill_info} }; |
278 | my @skills = keys %{ $self->{skill_info} }; |
254 | |
279 | |
255 | if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) { |
280 | if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) { |
256 | $sktbl->clear; |
281 | $sktbl->clear; |
257 | |
282 | |
258 | $sktbl->add (0, 0, new CFClient::UI::Label text => "Experience", align => 1); |
283 | $sktbl->add (0, 0, new CFPlus::UI::Label text => "Experience", align => 1); |
259 | $sktbl->add (1, 0, new CFClient::UI::Label text => "Lvl.", align => 1); |
284 | $sktbl->add (1, 0, new CFPlus::UI::Label text => "Lvl.", align => 1); |
260 | $sktbl->add (2, 0, new CFClient::UI::Label text => "Skill", expand => 1); |
285 | $sktbl->add (2, 0, new CFPlus::UI::Label text => "Skill", expand => 1); |
261 | $sktbl->add (3, 0, new CFClient::UI::Label text => "Experience", align => 1); |
286 | $sktbl->add (3, 0, new CFPlus::UI::Label text => "Experience", align => 1); |
262 | $sktbl->add (4, 0, new CFClient::UI::Label text => "Lvl.", align => 1); |
287 | $sktbl->add (4, 0, new CFPlus::UI::Label text => "Lvl.", align => 1); |
263 | $sktbl->add (5, 0, new CFClient::UI::Label text => "Skill", expand => 1); |
288 | $sktbl->add (5, 0, new CFPlus::UI::Label text => "Skill", expand => 1); |
264 | |
289 | |
|
|
290 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
|
|
291 | |
|
|
292 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
|
|
293 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
|
|
294 | |
265 | my ($x, $y) = (0, 0); |
295 | my ($x, $y) = (0, 1); |
266 | for ( |
296 | for ( |
267 | sort { $stats->{$b->[0]}[1] <=> $stats->{$a->[0]}[1] or $a->[1] cmp $b->[1] } |
297 | sort { $stats->{$b->[0]}[1] <=> $stats->{$a->[0]}[1] or $a->[1] cmp $b->[1] } |
268 | map [$_, $self->{skill_info}{$_}], |
298 | map [$_, $self->{skill_info}{$_}], |
269 | grep exists $stats->{$_}, |
299 | grep exists $stats->{$_}, |
270 | @skills |
300 | @skills |
271 | ) { |
301 | ) { |
272 | my ($idx, $name) = @$_; |
302 | my ($idx, $name) = @$_; |
273 | |
303 | |
|
|
304 | my $spell_cb = sub { |
|
|
305 | my ($widget, $ev) = @_; |
|
|
306 | |
|
|
307 | if ($ev->{button} == 1) { |
|
|
308 | $::CONN->user_send ("ready_skill $name"); |
|
|
309 | } elsif ($ev->{button} == 2) { |
|
|
310 | $::CONN->user_send ("use_skill $name"); |
|
|
311 | } elsif ($ev->{button} == 3) { |
|
|
312 | my $shortname = CFPlus::shorten $name, 14; |
|
|
313 | (new CFPlus::UI::Menu |
|
|
314 | items => [ |
|
|
315 | ["bind <i>ready_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["ready_skill $name"] }], |
|
|
316 | ["bind <i>use_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["use_skill $name"] }], |
|
|
317 | ], |
|
|
318 | )->popup ($ev); |
|
|
319 | } else { |
|
|
320 | return 0; |
|
|
321 | } |
|
|
322 | |
|
|
323 | 1 |
|
|
324 | }; |
|
|
325 | |
274 | $sktbl->add ($x * 3 + 0, $y, $self->{stat_widget_exp}{$idx} = new CFClient::UI::Label |
326 | $sktbl->add ($x * 3 + 0, $y, $self->{stat_widget_exp}{$idx} = new CFPlus::UI::Label |
275 | text => "0", align => 1, font => $::FONT_FIXED, fg => [1, 1, 0]); |
327 | text => "0", align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP); |
276 | $sktbl->add ($x * 3 + 1, $y, $self->{stat_widget_lvl}{$idx} = new CFClient::UI::Label |
328 | $sktbl->add ($x * 3 + 1, $y, $self->{stat_widget_lvl}{$idx} = new CFPlus::UI::Label |
277 | text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4); |
329 | text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL); |
278 | $sktbl->add ($x * 3 + 2, $y, new CFClient::UI::Label text => $name); |
330 | $sktbl->add ($x * 3 + 2, $y, new CFPlus::UI::Label text => $name, on_button_down => $spell_cb, |
|
|
331 | can_events => 1, can_hover => 1, tooltip => (CFPlus::Pod::section_label skill_description => $name) . $TOOLTIP_ALL); |
279 | |
332 | |
280 | $x++ and ($x, $y) = (0, $y + 1); |
333 | $x++ and ($x, $y) = (0, $y + 1); |
281 | } |
334 | } |
282 | } |
335 | } |
283 | |
336 | |
… | |
… | |
285 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
338 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
286 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
339 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
287 | } |
340 | } |
288 | } |
341 | } |
289 | |
342 | |
|
|
343 | sub macro_send { |
|
|
344 | my ($self, $macro) = @_; |
|
|
345 | |
|
|
346 | for my $cmd (@{ $macro->{action} }) { |
|
|
347 | $self->send_command ($cmd); |
|
|
348 | } |
|
|
349 | } |
|
|
350 | |
290 | sub user_send { |
351 | sub user_send { |
291 | my ($self, $command) = @_; |
352 | my ($self, $command) = @_; |
292 | |
353 | |
|
|
354 | $self->{record}->($command) |
293 | if ($self->{record}) { |
355 | if $self->{record}; |
294 | push @{$self->{record}}, $command; |
|
|
295 | } |
|
|
296 | |
356 | |
297 | $self->logprint ("send: ", $command); |
357 | $self->logprint ("send: ", $command); |
298 | $self->send_command ($command); |
358 | $self->send_command ($command); |
299 | ::status ($command); |
359 | ::status ($command); |
300 | } |
360 | } |
301 | |
361 | |
302 | sub start_record { |
362 | sub record { |
303 | my ($self) = @_; |
363 | my ($self, $cb) = @_; |
304 | |
364 | |
305 | $self->{record} = []; |
365 | $self->{record} = $cb; |
306 | } |
|
|
307 | |
|
|
308 | sub stop_record { |
|
|
309 | my ($self) = @_; |
|
|
310 | return delete $self->{record}; |
|
|
311 | } |
366 | } |
312 | |
367 | |
313 | sub map_scroll { |
368 | sub map_scroll { |
314 | my ($self, $dx, $dy) = @_; |
369 | my ($self, $dx, $dy) = @_; |
315 | |
370 | |
… | |
… | |
317 | } |
372 | } |
318 | |
373 | |
319 | sub feed_map1a { |
374 | sub feed_map1a { |
320 | my ($self, $data) = @_; |
375 | my ($self, $data) = @_; |
321 | |
376 | |
322 | $self->{map}->map1a_update ($data); |
377 | $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
323 | $self->{map_widget}->update; |
378 | $self->{map_widget}->update; |
324 | } |
379 | } |
325 | |
380 | |
326 | sub magicmap { |
381 | sub magicmap { |
327 | my ($self, $w, $h, $x, $y, $data) = @_; |
382 | my ($self, $w, $h, $x, $y, $data) = @_; |
… | |
… | |
497 | |
552 | |
498 | unless ($id) { |
553 | unless ($id) { |
499 | # create new id for face |
554 | # create new id for face |
500 | # I love transactions |
555 | # I love transactions |
501 | for (1..100) { |
556 | for (1..100) { |
502 | my $txn = $CFClient::DB_ENV->txn_begin; |
557 | my $txn = $CFPlus::DB_ENV->txn_begin; |
503 | my $status = $self->{facemap}->db_get (id => $id); |
558 | my $status = $self->{facemap}->db_get (id => $id); |
504 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
559 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
505 | $id = ($id || 64) + 1; |
560 | $id = ($id || 64) + 1; |
506 | if ($self->{facemap}->put (id => $id) == 0 |
561 | if ($self->{facemap}->put (id => $id) == 0 |
507 | && $self->{facemap}->put ($hash => $id) == 0) { |
562 | && $self->{facemap}->put ($hash => $id) == 0) { |
… | |
… | |
511 | } |
566 | } |
512 | } |
567 | } |
513 | $txn->txn_abort; |
568 | $txn->txn_abort; |
514 | } |
569 | } |
515 | |
570 | |
516 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
571 | CFPlus::fatal "maximum number of transaction retries reached - database problems?"; |
517 | } |
572 | } |
518 | |
573 | |
519 | gotid: |
574 | gotid: |
520 | $face->{id} = $id; |
575 | $face->{id} = $id; |
521 | $self->{map}->set_face ($facenum => $id); |
576 | $self->{map}->set_face ($facenum => $id); |
… | |
… | |
544 | sub set_texture { |
599 | sub set_texture { |
545 | my ($self, $id, $data) = @_; |
600 | my ($self, $id, $data) = @_; |
546 | |
601 | |
547 | $self->{texture}[$id] ||= do { |
602 | $self->{texture}[$id] ||= do { |
548 | my $tex = |
603 | my $tex = |
549 | new_from_image CFClient::Texture |
604 | new_from_image CFPlus::Texture |
550 | $data, minify => 1, mipmap => 1; |
605 | $data, minify => 1, mipmap => 1; |
551 | |
606 | |
552 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
607 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
553 | $self->{map_widget}->update; |
608 | $self->{map_widget}->update; |
554 | |
609 | |
… | |
… | |
585 | [0.11, 0.56, 1.00], |
640 | [0.11, 0.56, 1.00], |
586 | [0.93, 0.46, 0.00], |
641 | [0.93, 0.46, 0.00], |
587 | [0.18, 0.54, 0.34], |
642 | [0.18, 0.54, 0.34], |
588 | [0.56, 0.73, 0.56], |
643 | [0.56, 0.73, 0.56], |
589 | [0.80, 0.80, 0.80], |
644 | [0.80, 0.80, 0.80], |
590 | [0.55, 0.41, 0.13], |
645 | [0.75, 0.61, 0.20], |
591 | [0.99, 0.77, 0.26], |
646 | [0.99, 0.77, 0.26], |
592 | [0.74, 0.65, 0.41], |
647 | [0.74, 0.65, 0.41], |
593 | ); |
648 | ); |
594 | |
649 | |
|
|
650 | my $fg = $color[$color % @color]; |
|
|
651 | |
595 | $self->logprint ("info: ", $text); |
652 | $self->logprint ("info: ", $text); |
596 | |
|
|
597 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
|
|
598 | |
653 | |
599 | # try to create single paragraphs of multiple lines sent by the server |
654 | # try to create single paragraphs of multiple lines sent by the server |
600 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
655 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
601 | |
656 | |
602 | $text = CFClient::UI::Label::escape $text; |
657 | $text = CFPlus::asxml $text; |
603 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
658 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
604 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
659 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
605 | |
660 | |
606 | $self->{logview}->add_paragraph ($color[$color], $_) |
661 | ::message ({ fg => $fg, markup => $_ }) |
607 | for map "$time $_", split /\n/, $text; |
662 | for split /\n/, $text; |
608 | $self->{logview}->scroll_to_bottom; |
|
|
609 | |
663 | |
610 | $self->{statusbox}->add ($text, |
664 | $self->{statusbox}->add ($text, |
611 | group => $text, |
665 | group => $text, |
612 | fg => $color[$color], |
666 | fg => $fg, |
613 | timeout => $color >= 2 ? 60 : 10, |
667 | timeout => $color >= 2 ? 180 : 10, |
614 | tooltip_font => $::FONT_FIXED, |
668 | tooltip_font => $::FONT_FIXED, |
615 | ); |
669 | ); |
616 | } |
670 | } |
617 | |
671 | |
618 | sub drawextinfo { |
672 | sub drawextinfo { |
… | |
… | |
622 | } |
676 | } |
623 | |
677 | |
624 | sub spell_add { |
678 | sub spell_add { |
625 | my ($self, $spell) = @_; |
679 | my ($self, $spell) = @_; |
626 | |
680 | |
627 | # try to create single paragraphs of multiple lines sent by the server |
681 | # try to create single paragraphs out of the multiple lines sent by the server |
628 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
682 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
629 | $spell->{message} =~ s/\n+$//; |
683 | $spell->{message} =~ s/\n+$//; |
630 | $spell->{message} ||= "Server did not provide a description for this spell."; |
684 | $spell->{message} ||= "Server did not provide a description for this spell."; |
631 | |
685 | |
632 | $::SPELL_PAGE->add_spell ($spell); |
686 | $::SPELL_LIST->add_spell ($spell); |
633 | |
687 | |
634 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
688 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); |
635 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
689 | $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message}); |
636 | } |
690 | } |
637 | |
691 | |
638 | sub spell_delete { |
692 | sub spell_delete { |
639 | my ($self, $spell) = @_; |
693 | my ($self, $spell) = @_; |
640 | |
694 | |
641 | $::SPELL_PAGE->remove_spell ($spell); |
695 | $::SPELL_LIST->remove_spell ($spell); |
|
|
696 | } |
|
|
697 | |
|
|
698 | sub setup { |
|
|
699 | my ($self, $setup) = @_; |
|
|
700 | |
|
|
701 | $self->{map_widget}->set_tilesize ($self->{tilesize}); |
|
|
702 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
642 | } |
703 | } |
643 | |
704 | |
644 | sub addme_success { |
705 | sub addme_success { |
645 | my ($self) = @_; |
706 | my ($self) = @_; |
646 | |
707 | |
647 | my $skill_help = CFClient::load_pod CFClient::find_rcfile "pod/skill_help.pod", skill_help => 1, sub { |
|
|
648 | my ($pom) = @_; |
|
|
649 | |
|
|
650 | my %skill_help; |
708 | my %skill_help; |
651 | |
709 | |
652 | for my $head2 ($pom->head1->[3]->head2) { |
710 | for my $node (CFPlus::Pod::find skill_description => "*") { |
653 | $skill_help{$head2->title} = CFClient::pod_to_pango $head2->content; |
711 | my (undef, @par) = CFPlus::Pod::section_of $node; |
654 | } |
712 | $skill_help{$node->{kw}[0]} = CFPlus::Pod::as_label @par; |
655 | |
|
|
656 | \%skill_help |
|
|
657 | }; |
713 | }; |
658 | |
714 | |
659 | for my $skill (values %{$self->{skill_info}}) { |
715 | for my $skill (values %{$self->{skill_info}}) { |
660 | $self->{map_widget}->add_command ("ready_skill $skill", |
716 | $self->{map_widget}->add_command ("ready_skill $skill", |
661 | (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
717 | (CFPlus::asxml "Ready the skill '$skill'\n\n") |
662 | . $skill_help->{$skill}); |
718 | . $skill_help{$skill}); |
663 | $self->{map_widget}->add_command ("use_skill $skill", |
719 | $self->{map_widget}->add_command ("use_skill $skill", |
664 | (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
720 | (CFPlus::asxml "Immediately use the skill '$skill'\n\n") |
665 | . $skill_help->{$skill}); |
721 | . $skill_help{$skill}); |
666 | } |
722 | } |
667 | } |
723 | } |
668 | |
724 | |
669 | sub eof { |
725 | sub eof { |
670 | my ($self) = @_; |
726 | my ($self) = @_; |
… | |
… | |
694 | |
750 | |
695 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
751 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
696 | |
752 | |
697 | $self->send ("requestinfo image_sums $face $face"); |
753 | $self->send ("requestinfo image_sums $face $face"); |
698 | |
754 | |
699 | $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
755 | $self->{statusbox}->add (CFPlus::asxml "prefetching $todo", |
700 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
756 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
701 | } elsif (!exists $self->{num_faces}) { |
757 | } elsif (!exists $self->{num_faces}) { |
702 | $self->send ("requestinfo image_info"); |
758 | $self->send ("requestinfo image_info"); |
703 | |
759 | |
704 | $self->{num_faces} = 0; |
760 | $self->{num_faces} = 0; |
705 | |
761 | |
706 | $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
762 | $self->{statusbox}->add (CFPlus::asxml "starting to prefetch", |
707 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
763 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
708 | } |
764 | } |
709 | } |
765 | } |
710 | |
766 | |
711 | sub update_floorbox { |
767 | sub update_floorbox { |
712 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
768 | $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
713 | return unless $::CONN; |
769 | return unless $::CONN; |
714 | |
770 | |
715 | $::FLOORBOX->clear; |
771 | $::FLOORBOX->clear; |
716 | |
772 | |
717 | my $row; |
773 | my $row; |
718 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{0} }) { |
774 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
719 | if ($row < 6) { |
775 | if ($row < 6) { |
720 | local $_->{face_widget}; # hack to force recreation of widget |
776 | local $_->{face_widget}; # hack to force recreation of widget |
721 | local $_->{desc_widget}; # hack to force recreation of widget |
777 | local $_->{desc_widget}; # hack to force recreation of widget |
722 | CFClient::Item::update_widgets $_; |
778 | CFPlus::Item::update_widgets $_; |
723 | |
779 | |
724 | $::FLOORBOX->add (0, $row, $_->{face_widget}); |
780 | $::FLOORBOX->add (0, $row, $_->{face_widget}); |
725 | $::FLOORBOX->add (1, $row, $_->{desc_widget}); |
781 | $::FLOORBOX->add (1, $row, $_->{desc_widget}); |
726 | |
782 | |
727 | $row++; |
783 | $row++; |
728 | } else { |
784 | } else { |
729 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
785 | $::FLOORBOX->add (1, $row, new CFPlus::UI::Button |
730 | text => "More...", |
786 | text => "More...", |
731 | on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, |
787 | on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, |
732 | ); |
788 | ); |
733 | last; |
789 | last; |
734 | } |
790 | } |
735 | } |
791 | } |
|
|
792 | if ($::CONN->{open_container}) { |
|
|
793 | $::FLOORBOX->add (1, $row++, new CFPlus::UI::Button |
|
|
794 | text => "Close container", |
|
|
795 | on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } |
|
|
796 | ); |
|
|
797 | } |
736 | }); |
798 | }); |
737 | |
799 | |
738 | $::WANT_REFRESH++; |
800 | $::WANT_REFRESH++; |
739 | } |
801 | } |
740 | |
802 | |
741 | sub set_opencont { |
803 | sub set_opencont { |
742 | my ($conn, $tag, $name) = @_; |
804 | my ($conn, $tag, $name) = @_; |
743 | $conn->{open_container} = $tag; |
805 | $conn->{open_container} = $tag; |
|
|
806 | update_floorbox; |
744 | |
807 | |
745 | $::INV_RIGHT_HB->clear (); |
808 | $::INV_RIGHT_HB->clear (); |
746 | $::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name); |
809 | $::INV_RIGHT_HB->add (new CFPlus::UI::Label align => 0, expand => 1, text => $name); |
747 | |
810 | |
748 | if ($tag != 0) { # Floor isn't closable, is it? |
811 | if ($tag != 0) { # Floor isn't closable, is it? |
749 | $::INV_RIGHT_HB->add (new CFClient::UI::Button |
812 | $::INV_RIGHT_HB->add (new CFPlus::UI::Button |
750 | text => "Close container", |
813 | text => "Close container", |
751 | tooltip => "Close the currently open container (if one is open)", |
814 | tooltip => "Close the currently open container (if one is open)", |
752 | on_activate => sub { |
815 | on_activate => sub { |
753 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
816 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
754 | if $tag != 0; |
817 | if $tag != 0; |
… | |
… | |
762 | } |
825 | } |
763 | |
826 | |
764 | sub update_containers { |
827 | sub update_containers { |
765 | my ($self) = @_; |
828 | my ($self) = @_; |
766 | |
829 | |
767 | $CFClient::UI::ROOT->on_refresh ("update_containers_$self" => sub { |
830 | $CFPlus::UI::ROOT->on_refresh ("update_containers_$self" => sub { |
768 | my $todo = delete $self->{update_container} |
831 | my $todo = delete $self->{update_container} |
769 | or return; |
832 | or return; |
770 | |
833 | |
771 | for my $tag (keys %$todo) { |
834 | for my $tag (keys %$todo) { |
|
|
835 | update_floorbox if $tag == 0 or $tag == $self->{open_container}; |
772 | if ($tag == 0) { |
836 | if ($tag == 0) { |
773 | update_floorbox; |
|
|
774 | $::INVR->set_items ($self->{container}{0}) |
837 | $::INVR->set_items ($self->{container}{0}) |
775 | if $tag == $self->{open_container}; |
838 | if $tag == $self->{open_container}; |
776 | } elsif ($tag == $self->{player}{tag}) { |
839 | } elsif ($tag == $self->{player}{tag}) { |
777 | $::INV->set_items ($self->{container}{$tag}) |
840 | $::INV->set_items ($self->{container}{$tag}) |
778 | } else { |
841 | } else { |
… | |
… | |
809 | sub item_update { |
872 | sub item_update { |
810 | my ($self, $item) = @_; |
873 | my ($self, $item) = @_; |
811 | |
874 | |
812 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
875 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
813 | |
876 | |
814 | CFClient::Item::update_widgets $item; |
877 | CFPlus::Item::update_widgets $item; |
815 | |
878 | |
816 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
879 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
817 | set_opencont ($::CONN, 0, "Floor"); |
880 | set_opencont ($::CONN, 0, "Floor"); |
818 | |
881 | |
819 | } elsif ($item->{flags} & F_OPEN) { |
882 | } elsif ($item->{flags} & F_OPEN) { |
820 | set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item); |
883 | set_opencont ($::CONN, $item->{tag}, CFPlus::Item::desc_string $item); |
821 | |
884 | |
822 | } else { |
885 | } else { |
823 | $self->{update_container}{$item->{container}}++; |
886 | $self->{update_container}{$item->{container}}++; |
824 | $self->update_containers; |
887 | $self->update_containers; |
825 | } |
888 | } |
826 | } |
889 | } |
827 | |
890 | |
828 | sub player_update { |
891 | sub player_update { |
829 | my ($self, $player) = @_; |
892 | my ($self, $player) = @_; |
|
|
893 | |
|
|
894 | $self->update_weight; |
|
|
895 | } |
|
|
896 | |
|
|
897 | sub update_weight { |
|
|
898 | my ($self) = @_; |
|
|
899 | |
|
|
900 | my $weight = .001 * $self->{player}{weight}; |
|
|
901 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
|
|
902 | |
830 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
903 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
|
|
904 | $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); |
|
|
905 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
831 | } |
906 | } |
832 | |
907 | |
833 | sub update_server_info { |
908 | sub update_server_info { |
834 | my ($self) = @_; |
909 | my ($self) = @_; |
835 | |
910 | |
… | |
… | |
838 | $::SERVER_INFO->set_markup ( |
913 | $::SERVER_INFO->set_markup ( |
839 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
914 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
840 | . "protocol version <tt>$self->{version}</tt>\n" |
915 | . "protocol version <tt>$self->{version}</tt>\n" |
841 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
916 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
842 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
917 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
918 | . "editing support $yesno[!!$self->{editor_support}]\n" |
|
|
919 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
843 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
920 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
844 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
921 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
845 | . "map size $self->{mapw}×$self->{maph}\n" |
922 | . "map size $self->{mapw}×$self->{maph}\n" |
846 | ); |
923 | ); |
|
|
924 | |
|
|
925 | ::setup_build_button ($self->{editor_support}->{builder_ui}); |
847 | } |
926 | } |
848 | |
927 | |
849 | sub logged_in { |
928 | sub logged_in { |
850 | my ($self) = @_; |
929 | my ($self) = @_; |
851 | |
930 | |
852 | $self->send_ext_req (cfplus_support => "1", sub { |
931 | $self->send_ext_req (cfplus_support => version => 1, sub { |
853 | $self->{cfplus_ext} = $_[0]; |
932 | $self->{cfplus_ext} = $_[0]{version}; |
854 | $self->update_server_info; |
933 | $self->update_server_info; |
|
|
934 | |
|
|
935 | if ($self->{cfplus_ext} >= 2) { |
|
|
936 | $self->send_ext_req ("editor_support", sub { |
|
|
937 | $self->{editor_support} = $_[0]; |
|
|
938 | $self->update_server_info; |
|
|
939 | |
|
|
940 | 0 |
|
|
941 | }); |
|
|
942 | } |
|
|
943 | |
|
|
944 | 0 |
855 | }); |
945 | }); |
856 | |
946 | |
857 | $self->update_server_info; |
947 | $self->update_server_info; |
858 | |
948 | |
859 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
949 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
860 | $self->send_command ("output-count $::CFG->{output_count}"); |
950 | $self->send_command ("output-count $::CFG->{output_count}"); |
|
|
951 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
861 | $self->send_command ("pickup $::CFG->{pickup}"); |
952 | $self->send_command ("pickup $::CFG->{pickup}"); |
|
|
953 | } |
|
|
954 | |
|
|
955 | sub buildat { |
|
|
956 | my ($self, $builditem, $x, $y) = @_; |
|
|
957 | |
|
|
958 | if ($self->{cfplus_ext}) { |
|
|
959 | $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem)); |
|
|
960 | } |
862 | } |
961 | } |
863 | |
962 | |
864 | sub lookat { |
963 | sub lookat { |
865 | my ($self, $x, $y) = @_; |
964 | my ($self, $x, $y) = @_; |
866 | |
965 | |
867 | if ($self->{cfplus_ext}) { |
966 | if ($self->{cfplus_ext}) { |
868 | $self->send_ext_req (lookat => "$x $y", sub { |
967 | $self->send_ext_req (lookat => dx => $x, dy => $y, sub { |
869 | my %res = split /\x00/, $_[0]; |
968 | my ($msg) = @_; |
870 | |
969 | |
871 | if (exists $res{npc_dialog}) { |
970 | if (exists $msg->{npc_dialog}) { |
872 | # start npc chat dialog |
971 | # start npc chat dialog |
873 | $self->{npc_dialog} = new CFClient::NPCDialog:: |
972 | $self->{npc_dialog} = new CFPlus::NPCDialog:: |
874 | dx => $x, |
973 | dx => $x, |
875 | dy => $y, |
974 | dy => $y, |
876 | title => "$res{npc_dialog} (NPC)", |
975 | title => "$msg->{npc_dialog} (NPC)", |
877 | conn => $self, |
976 | conn => $self, |
878 | ; |
977 | ; |
879 | } |
978 | } |
880 | }); |
979 | }); |
881 | } |
980 | } |
… | |
… | |
884 | } |
983 | } |
885 | |
984 | |
886 | sub destroy { |
985 | sub destroy { |
887 | my ($self) = @_; |
986 | my ($self) = @_; |
888 | |
987 | |
889 | $self->{npc_dialog}->destroy |
988 | (delete $self->{npc_dialog})->destroy |
890 | if $self->{npc_dialog}; |
989 | if $self->{npc_dialog}; |
891 | |
990 | |
892 | $self->SUPER::destroy; |
991 | $self->SUPER::destroy; |
893 | } |
992 | } |
894 | |
993 | |
895 | package CFClient::NPCDialog; |
994 | package CFPlus::NPCDialog; |
896 | |
995 | |
897 | our @ISA = 'CFClient::UI::FancyFrame'; |
996 | our @ISA = 'CFPlus::UI::Toplevel'; |
898 | |
997 | |
899 | sub new { |
998 | sub new { |
900 | my $class = shift; |
999 | my $class = shift; |
901 | |
1000 | |
902 | my $self = $class->SUPER::new ( |
1001 | my $self = $class->SUPER::new ( |
… | |
… | |
905 | name => "npc_dialog", |
1004 | name => "npc_dialog", |
906 | force_w => $::WIDTH * 0.7, |
1005 | force_w => $::WIDTH * 0.7, |
907 | force_h => $::HEIGHT * 0.7, |
1006 | force_h => $::HEIGHT * 0.7, |
908 | title => "NPC Dialog", |
1007 | title => "NPC Dialog", |
909 | kw => { hi => 0, yes => 0, no => 0 }, |
1008 | kw => { hi => 0, yes => 0, no => 0 }, |
|
|
1009 | has_close_button => 1, |
910 | @_, |
1010 | @_, |
911 | ); |
1011 | ); |
912 | |
1012 | |
913 | Scalar::Util::weaken (my $this = $self); |
1013 | CFPlus::weaken (my $this = $self); |
|
|
1014 | |
|
|
1015 | $self->connect (delete => sub { $this->destroy; 1 }); |
914 | |
1016 | |
915 | # better use a pane... |
1017 | # better use a pane... |
916 | $self->add (my $hbox = new CFClient::UI::HBox); |
1018 | $self->add (my $hbox = new CFPlus::UI::HBox); |
917 | $hbox->add ($self->{textview} = new CFClient::UI::TextScroller expand => 1); |
1019 | $hbox->add ($self->{textview} = new CFPlus::UI::TextScroller expand => 1); |
918 | |
1020 | |
919 | $hbox->add (my $vbox = new CFClient::UI::VBox); |
1021 | $hbox->add (my $vbox = new CFPlus::UI::VBox); |
920 | |
1022 | |
921 | $vbox->add (new CFClient::UI::Label text => "Message Entry:"); |
1023 | $vbox->add (new CFPlus::UI::Label text => "Message Entry:"); |
922 | $vbox->add ($self->{entry} = new CFClient::UI::Entry |
1024 | $vbox->add ($self->{entry} = new CFPlus::UI::Entry |
923 | tooltip => "Enter a message you want to tell the NPC and press <b>return</b>.\n\n" |
1025 | tooltip => "#npc_message_entry", |
924 | . "Sometimes you have to tell an NPC something you cannot find out during " |
|
|
925 | . "a normal conversation (such as a password). In those cases you have to use " |
|
|
926 | . "this text entry. You can also enter responses manually instead of using the response " |
|
|
927 | . "buttons below.", |
|
|
928 | on_activate => sub { |
1026 | on_activate => sub { |
929 | my ($entry, $text) = @_; |
1027 | my ($entry, $text) = @_; |
930 | |
1028 | |
931 | return unless $text =~ /\S/; |
1029 | return unless $text =~ /\S/; |
932 | |
1030 | |
… | |
… | |
935 | |
1033 | |
936 | 0 |
1034 | 0 |
937 | }, |
1035 | }, |
938 | ); |
1036 | ); |
939 | |
1037 | |
940 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
1038 | $vbox->add ($self->{options} = new CFPlus::UI::VBox); |
941 | |
1039 | |
942 | $self->{bye_button} = new CFClient::UI::Button |
1040 | $self->{bye_button} = new CFPlus::UI::Button |
943 | text => "Bye (close)", |
1041 | text => "Bye (close)", |
944 | tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", |
1042 | tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", |
945 | on_activate => sub { $this->destroy; 0 }, |
1043 | on_activate => sub { $this->destroy; 1 }, |
946 | ; |
1044 | ; |
947 | |
1045 | |
948 | $self->update_options; |
1046 | $self->update_options; |
949 | |
1047 | |
950 | $self->{token} = $self->{conn}->ext_token; |
1048 | $self->{id} = $self->{conn}->send_ext_req ( |
951 | $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) }); |
1049 | npc_dialog_begin => dx => $self->{dx}, dy => $self->{dy}, |
952 | $self->{conn}->send ("ext npc_dialog_begin $self->{token} $self->{dx} $self->{dy}"); |
1050 | sub { $this && $this->feed (@_) } |
|
|
1051 | ); |
953 | |
1052 | |
954 | $self->{entry}->grab_focus; |
1053 | $self->{entry}->grab_focus; |
955 | |
1054 | |
956 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n"); |
1055 | $self->{textview}->add_paragraph ({ |
|
|
1056 | fg => [1, 1, 0, 1], |
|
|
1057 | markup => "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n", |
|
|
1058 | }); |
957 | |
1059 | |
958 | $self->show; |
1060 | $self->show; |
959 | $self |
1061 | $self |
960 | }; |
1062 | }; |
961 | |
1063 | |
962 | sub update_options { |
1064 | sub update_options { |
963 | my ($self) = @_; |
1065 | my ($self) = @_; |
964 | |
1066 | |
965 | Scalar::Util::weaken $self; |
1067 | CFPlus::weaken $self; |
966 | |
1068 | |
967 | $self->{options}->clear; |
1069 | $self->{options}->clear; |
968 | $self->{options}->add ($self->{bye_button}); |
1070 | $self->{options}->add ($self->{bye_button}); |
969 | |
1071 | |
970 | for my $kw (sort keys %{ $self->{kw} }) { |
1072 | for my $kw (sort keys %{ $self->{kw} }) { |
971 | $self->{options}->add (new CFClient::UI::Button |
1073 | $self->{options}->add (new CFPlus::UI::Button |
972 | text => $kw, |
1074 | text => $kw, |
973 | on_activate => sub { |
1075 | on_activate => sub { |
974 | $self->send ($kw); |
1076 | $self->send ($kw); |
975 | 0 |
1077 | 0 |
976 | }, |
1078 | }, |
977 | ); |
1079 | ); |
978 | } |
1080 | } |
979 | } |
1081 | } |
980 | |
1082 | |
981 | sub feed { |
1083 | sub feed { |
982 | my ($self, $data) = @_; |
1084 | my ($self, $msg) = @_; |
983 | |
1085 | |
984 | Scalar::Util::weaken $self; |
1086 | CFPlus::weaken $self; |
985 | |
1087 | |
986 | my ($type, $msg) = split / /, $data, 2; |
1088 | if ($msg->{msgtype} eq "reply") { |
|
|
1089 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
|
|
1090 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
987 | |
1091 | |
988 | if ($type eq "msg") { |
1092 | my $text = "\n" . CFPlus::asxml $msg->{msg}; |
989 | my ($msg, @kw) = split /\x00/, $msg; |
|
|
990 | $self->{kw}{$_} = 1 for @kw; |
|
|
991 | |
|
|
992 | $msg = "\n" . CFClient::UI::Label::escape $msg; |
|
|
993 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1093 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
994 | my @link; |
1094 | my @link; |
995 | $msg =~ s{ |
1095 | $text =~ s{ |
996 | ($match) |
1096 | ($match) |
997 | }{ |
1097 | }{ |
998 | my $kw = $1; |
1098 | my $kw = $1; |
999 | |
1099 | |
1000 | push @link, new CFClient::UI::Label |
1100 | push @link, new CFPlus::UI::Label |
1001 | markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>", |
1101 | markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>", |
1002 | can_hover => 1, |
1102 | can_hover => 1, |
1003 | can_events => 1, |
1103 | can_events => 1, |
1004 | padding_x => 0, |
1104 | padding_x => 0, |
1005 | padding_y => 0, |
1105 | padding_y => 0, |
1006 | on_button_up => sub { |
1106 | on_button_up => sub { |
1007 | $self->send ($kw); |
1107 | $self->send ($kw); |
1008 | }; |
1108 | }; |
1009 | |
1109 | |
1010 | chr 0xfffc |
1110 | "\x{fffc}" |
1011 | }giex; |
1111 | }giex; |
1012 | |
1112 | |
1013 | $self->{textview}->add_paragraph ([1, 1, 1, 1], [$msg, @link]); |
1113 | $self->{textview}->add_paragraph ({ markup => $text, widget => \@link }); |
1014 | $self->{textview}->scroll_to_bottom; |
1114 | $self->{textview}->scroll_to_bottom; |
1015 | $self->update_options; |
1115 | $self->update_options; |
1016 | } else { |
1116 | } else { |
1017 | $self->destroy; |
1117 | $self->destroy; |
1018 | } |
1118 | } |
… | |
… | |
1021 | } |
1121 | } |
1022 | |
1122 | |
1023 | sub send { |
1123 | sub send { |
1024 | my ($self, $msg) = @_; |
1124 | my ($self, $msg) = @_; |
1025 | |
1125 | |
1026 | $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); |
1126 | $self->{textview}->add_paragraph ({ markup => "\n" . CFPlus::asxml $msg }); |
1027 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg); |
|
|
1028 | $self->{textview}->scroll_to_bottom; |
1127 | $self->{textview}->scroll_to_bottom; |
|
|
1128 | |
|
|
1129 | $self->{conn}->send_ext_msg (npc_dialog_tell => msgid => $self->{id}, msg => $msg); |
1029 | } |
1130 | } |
1030 | |
1131 | |
1031 | sub destroy { |
1132 | sub destroy { |
1032 | my ($self) = @_; |
1133 | my ($self) = @_; |
1033 | |
1134 | |
1034 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1135 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1035 | |
1136 | |
|
|
1137 | if ($self->{conn}) { |
1036 | $self->{conn}->send ("ext npc_dialog_end $self->{token}") if $self->{token}; |
1138 | $self->{conn}->send_ext_msg (npc_dialog_end => msgid => $self->{id}) if $self->{id}; |
1037 | delete $self->{conn}{npc_dialog}; |
1139 | delete $self->{conn}{npc_dialog}; |
1038 | $self->{conn}->disconnect_ext ($self->{token}); |
1140 | $self->{conn}->disconnect_ext ($self->{id}); |
|
|
1141 | } |
1039 | |
1142 | |
1040 | $self->SUPER::destroy; |
1143 | $self->SUPER::destroy; |
1041 | } |
1144 | } |
1042 | |
1145 | |
1043 | 1; |
1146 | 1 |
|
|
1147 | |