1 | package DC::Protocol; |
1 | package DC::Protocol; |
2 | |
2 | |
3 | use utf8; |
3 | use common::sense; |
4 | use strict; |
4 | |
|
|
5 | use Guard (); |
5 | |
6 | |
6 | use Deliantra::Protocol::Constants; |
7 | use Deliantra::Protocol::Constants; |
7 | |
8 | |
8 | use DC; |
9 | use DC; |
9 | use DC::DB; |
10 | use DC::DB; |
… | |
… | |
12 | use DC::Macro; |
13 | use DC::Macro; |
13 | use DC::Item; |
14 | use DC::Item; |
14 | |
15 | |
15 | use base 'Deliantra::Protocol::Base'; |
16 | use base 'Deliantra::Protocol::Base'; |
16 | |
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# |
|
|
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 | widget => 2, |
32 | widget => 2, |
25 | %{$arg{setup_req} || {}}, |
33 | %{$arg{setup_req} || {}}, |
26 | }, |
34 | }, |
27 | ); |
35 | ); |
|
|
36 | |
|
|
37 | $self->update_fx_want; |
|
|
38 | |
|
|
39 | my $guard = $self->addme_guard; |
|
|
40 | $self->send_exti_req (resource => "exp_table", sub { |
|
|
41 | my ($idx) = @_; |
|
|
42 | |
|
|
43 | $self->register_face_handler ($idx, sub { |
|
|
44 | my ($face) = @_; |
|
|
45 | |
|
|
46 | undef $guard; |
|
|
47 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
48 | $_->() for values %{ $self->{on_exp_update} }; |
|
|
49 | }); |
|
|
50 | |
|
|
51 | () |
|
|
52 | }); |
|
|
53 | |
|
|
54 | my $guard = $self->addme_guard; |
|
|
55 | $self->send_exti_req (resource => "skill_info", sub { |
|
|
56 | my ($idx) = @_; |
|
|
57 | |
|
|
58 | $self->register_face_handler ($idx, sub { |
|
|
59 | my ($face) = @_; |
|
|
60 | |
|
|
61 | undef $guard; |
|
|
62 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
63 | $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info }; |
|
|
64 | }); |
|
|
65 | |
|
|
66 | () |
|
|
67 | }); |
|
|
68 | |
|
|
69 | my $guard = $self->addme_guard; |
|
|
70 | $self->send_exti_req (resource => "spell_paths", sub { |
|
|
71 | my ($idx) = @_; |
|
|
72 | |
|
|
73 | $self->register_face_handler ($idx, sub { |
|
|
74 | my ($face) = @_; |
|
|
75 | |
|
|
76 | undef $guard; |
|
|
77 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
78 | $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info }; |
|
|
79 | }); |
|
|
80 | |
|
|
81 | () |
|
|
82 | }); |
28 | |
83 | |
29 | $self->{map_widget}->clr_commands; |
84 | $self->{map_widget}->clr_commands; |
30 | |
85 | |
31 | my @cmd_help = map { |
86 | my @cmd_help = map { |
32 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
87 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
… | |
… | |
67 | for values %{delete $ws->{w} || {}}; |
122 | for values %{delete $ws->{w} || {}}; |
68 | } |
123 | } |
69 | |
124 | |
70 | delete $self->{items}; |
125 | delete $self->{items}; |
71 | $::INV->clear; |
126 | $::INV->clear; |
|
|
127 | $::INVR->clear; |
72 | $::INVR_HB->clear; |
128 | $::INVR_HB->clear; |
73 | $::FLOORBOX->clear; |
129 | $::FLOORBOX->clear; |
74 | }); |
130 | }); |
75 | |
131 | |
76 | $self->{map_widget}->add_command (@$_) |
132 | $self->{map_widget}->add_command (@$_) |
77 | for @cmd_help; |
133 | for @cmd_help; |
78 | |
134 | |
79 | { |
135 | { |
80 | $self->{dialogue} = my $tex = new_from_file DC::Texture |
136 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
81 | DC::find_rcfile "dialogue.png", minify => 1, mipmap => 1; |
|
|
82 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
137 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
83 | } |
138 | } |
84 | |
139 | |
85 | { |
140 | { |
86 | $self->{noface} = my $tex = new_from_file DC::Texture |
141 | $self->{noface} = my $tex = $TEX_NOFACE; |
87 | DC::find_rcfile "noface.png", minify => 1, mipmap => 1; |
|
|
88 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
142 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
89 | } |
143 | } |
|
|
144 | |
|
|
145 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
146 | # $self->{expire_w} = AE::timer 1, 1, sub { |
|
|
147 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
148 | # |
|
|
149 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
150 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
151 | # $self->{texture}[$_]->unload; |
|
|
152 | # warn "expire texture $_\n";#d# |
|
|
153 | # } |
|
|
154 | # |
|
|
155 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
156 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
157 | # warn "count is $count\n";#d# |
|
|
158 | # }; |
90 | |
159 | |
91 | $self->{open_container} = 0; |
160 | $self->{open_container} = 0; |
92 | |
161 | |
93 | # per server |
162 | # per server |
94 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
163 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
… | |
… | |
106 | }); |
175 | }); |
107 | } |
176 | } |
108 | |
177 | |
109 | sub ext_capabilities { |
178 | sub ext_capabilities { |
110 | my ($self, %cap) = @_; |
179 | my ($self, %cap) = @_; |
111 | |
|
|
112 | $self->update_fx_want; |
|
|
113 | |
|
|
114 | $self->send_exti_req (resource => "exp_table", sub { |
|
|
115 | my ($exp_table) = @_; |
|
|
116 | |
|
|
117 | $self->register_face_handler ($exp_table, sub { |
|
|
118 | my ($face) = @_; |
|
|
119 | |
|
|
120 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
121 | $_->() for values %{ $self->{on_exp_update} || {} }; |
|
|
122 | }); |
|
|
123 | |
|
|
124 | () |
|
|
125 | }); |
|
|
126 | |
180 | |
127 | if (my $ts = $cap{tileset}) { |
181 | if (my $ts = $cap{tileset}) { |
128 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
182 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
129 | $self->{tileset} = $default; |
183 | $self->{tileset} = $default; |
130 | $self->{tilesize} = $default->[3]; |
184 | $self->{tilesize} = $default->[3]; |
… | |
… | |
255 | my %wkw = ( |
309 | my %wkw = ( |
256 | root => $DC::UI::ROOT, |
310 | root => $DC::UI::ROOT, |
257 | tooltip => $DC::UI::TOOLTIP, |
311 | tooltip => $DC::UI::TOOLTIP, |
258 | |
312 | |
259 | mapwidget => $::MAPWIDGET, |
313 | mapwidget => $::MAPWIDGET, |
|
|
314 | menubar => $::MENUBAR, |
|
|
315 | menupopup => $::MENUPOPUP, |
|
|
316 | pickup_enable => $::PICKUP_ENABLE, |
260 | buttonbar => $::BUTTONBAR, |
317 | buttonbar => $::BUTTONBAR, |
261 | metaserver => $::METASERVER, |
318 | metaserver => $::METASERVER, |
262 | buttonbar => $::BUTTONBAR, |
319 | buttonbar => $::BUTTONBAR, |
263 | login_button => $::LOGIN_BUTTON, |
320 | login_button => $::LOGIN_BUTTON, |
264 | quit_dialog => $::QUIT_DIALOG, |
321 | quit_dialog => $::QUIT_DIALOG, |
… | |
… | |
281 | |
338 | |
282 | floorbox => $::FLOORBOX, |
339 | floorbox => $::FLOORBOX, |
283 | help_window => $::HELP_WINDOW, |
340 | help_window => $::HELP_WINDOW, |
284 | message_window => $::MESSAGE_WINDOW, |
341 | message_window => $::MESSAGE_WINDOW, |
285 | message_dist => $::MESSAGE_DIST, |
342 | message_dist => $::MESSAGE_DIST, |
286 | statusbox => $::SDTATUSBOX, |
343 | statusbox => $::STATUSBOX, |
287 | |
344 | |
288 | inv => $::INV, |
345 | inv => $::INV, |
289 | invr => $::INVR, |
346 | invr => $::INVR, |
290 | invr_hb => $::INVR_HB, |
347 | invr_hb => $::INVR_HB, |
291 | ); |
348 | ); |
… | |
… | |
375 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
432 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
376 | : () |
433 | : () |
377 | } |
434 | } |
378 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
435 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
379 | |
436 | |
380 | join "", @diff |
437 | "\u$name: " . (join ", ", @diff) |
381 | } |
438 | } |
382 | |
439 | |
383 | # all stats that are chacked against changes |
440 | # all stats that are chacked against changes |
384 | my @statchange = ( |
441 | my @statchange = ( |
385 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
442 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
428 | |
485 | |
429 | if (my @diffs = |
486 | if (my @diffs = |
430 | ( |
487 | ( |
431 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
488 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
432 | map { |
489 | map { |
433 | $stats->{$_} && $prev->{$_} |
490 | $stats->{$_} && $prev->{$_} |
434 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
491 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
435 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
492 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
436 | ) |
493 | ) |
437 | ) { |
494 | ) { |
438 | my $msg = join " ", @diffs; |
495 | my $msg = join " ", @diffs; |
… | |
… | |
440 | } |
497 | } |
441 | |
498 | |
442 | if ( |
499 | if ( |
443 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
500 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
444 | ) { |
501 | ) { |
445 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
502 | my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs); |
446 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
503 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
447 | } |
504 | } |
448 | |
505 | |
449 | $self->update_stats_window ($stats, $prev); |
506 | $self->update_stats_window ($stats, $prev); |
450 | |
507 | |
… | |
… | |
488 | |
545 | |
489 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
546 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
490 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
547 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
491 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
548 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
492 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
549 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
493 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
550 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
494 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
551 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
495 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
552 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
496 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
553 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
497 | my $title = $stats->{+CS_STAT_TITLE}; |
554 | my $title = $stats->{+CS_STAT_TITLE}; |
498 | $title =~ s/^Player: //; |
555 | $title =~ s/^Player: //; |
499 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
556 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
500 | |
557 | |
… | |
… | |
512 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
569 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
513 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
570 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
514 | |
571 | |
515 | $self->update_weight; |
572 | $self->update_weight; |
516 | |
573 | |
517 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
574 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}}) |
518 | for keys %RES_TBL; |
575 | for keys %RES_TBL; |
519 | |
576 | |
520 | my $sktbl = $::STATWIDS->{skill_tbl}; |
577 | my $sktbl = $::STATWIDS->{skill_tbl}; |
521 | my @skills = keys %{ $self->{skill_info} }; |
578 | my @skills = keys %{ $self->{skill_info} }; |
522 | |
579 | |
… | |
… | |
541 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
598 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
542 | ]; |
599 | ]; |
543 | |
600 | |
544 | my @add = @$sw; |
601 | my @add = @$sw; |
545 | |
602 | |
546 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
603 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
547 | |
604 | |
548 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
605 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
549 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
606 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
550 | |
607 | |
551 | my ($x, $y) = (0, 1); |
608 | my ($x, $y) = (0, 1); |
… | |
… | |
613 | my $sw = $self->{skillwid}{$idx}; |
670 | my $sw = $self->{skillwid}{$idx}; |
614 | $sw->[0]->set_text (::formsep ($val->[1])); |
671 | $sw->[0]->set_text (::formsep ($val->[1])); |
615 | $sw->[1]->set_text ($val->[0] * 1); |
672 | $sw->[1]->set_text ($val->[0] * 1); |
616 | $sw->[2]->set_value (@$val); |
673 | $sw->[2]->set_value (@$val); |
617 | |
674 | |
618 | $::GAUGES->{sklprg}->set_label ("$name %d%%"); |
675 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
619 | $::GAUGES->{sklprg}->set_value (@$val); |
676 | $::GAUGES->{skillexp}->set_value (@$val); |
620 | } |
677 | } |
621 | } |
678 | } |
622 | |
679 | |
623 | sub user_send { |
680 | sub user_send { |
624 | my ($self, $command) = @_; |
681 | my ($self, $command) = @_; |
… | |
… | |
637 | } |
694 | } |
638 | |
695 | |
639 | sub map_scroll { |
696 | sub map_scroll { |
640 | my ($self, $dx, $dy) = @_; |
697 | my ($self, $dx, $dy) = @_; |
641 | |
698 | |
642 | $self->{map}->scroll ($dx, $dy); |
699 | $self->{map_widget}->scroll ($dx, $dy); |
643 | } |
700 | } |
644 | |
701 | |
645 | sub feed_map1a { |
702 | sub feed_map1a { |
646 | my ($self, $data) = @_; |
703 | my ($self, $data) = @_; |
647 | |
704 | |
648 | my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
705 | my $missing = $self->{map}->map1a_update ($data); |
649 | my $delay; |
706 | my $delay; |
650 | |
707 | |
651 | for my $tile (@$missing) { |
708 | for my $tile (@$missing) { |
652 | next if $self->{delay}{$tile}; |
709 | next if $self->{delay}{$tile}; |
653 | |
710 | |
654 | $delay = 1; |
711 | $delay = 1; |
655 | |
712 | |
656 | if (my $tex = $::CONN->{texture}[$tile]) { |
713 | if (my $tex = $self->{texture}[$tile]) { |
657 | $tex->upload; |
714 | $tex->upload; |
658 | } else { |
715 | } else { |
659 | $self->{delay}{$tile} = 1; |
716 | $self->{delay}{$tile} = 1; |
660 | |
717 | |
661 | # we assume the face is in-flight and will eventually come |
718 | # we assume the face is in-flight and will eventually arrive |
662 | push @{$self->{tile_cb}{$tile}}, sub { |
719 | push @{$self->{tile_cb}{$tile}}, sub { |
663 | delete $self->{delay}{$tile}; |
720 | delete $self->{delay}{$tile}; |
664 | $_[0]->upload; |
721 | $_[0]->upload; |
665 | }; |
722 | }; |
666 | } |
723 | } |
667 | } |
724 | } |
668 | |
725 | |
669 | if ($delay) { |
726 | if ($delay) { |
670 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
727 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
671 | EV::once undef, 0, 0.03, sub { |
728 | EV::once undef, 0, 0.03, sub { |
672 | $self->{map_widget}->update |
729 | $self->{map_widget}->update |
673 | if $self->{map_widget}; |
730 | if $self->{map_widget}; |
674 | }; |
731 | }; |
675 | } else { |
732 | } else { |
… | |
… | |
963 | |
1020 | |
964 | my $tex = $self->{texture}[$tile] ||= |
1021 | my $tex = $self->{texture}[$tile] ||= |
965 | new DC::Texture |
1022 | new DC::Texture |
966 | tile => $tile, |
1023 | tile => $tile, |
967 | image => $data, delete_image => 1, |
1024 | image => $data, delete_image => 1, |
968 | minify => 1, mipmap => 1; |
1025 | minify => 1; |
969 | |
1026 | |
970 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
1027 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
971 | $_->($tex) for @$cbs; |
1028 | $_->($tex) for @$cbs; |
972 | } |
1029 | } |
973 | } |
1030 | } |
… | |
… | |
978 | my ($self, $num, $cb) = @_; |
1035 | my ($self, $num, $cb) = @_; |
979 | |
1036 | |
980 | push @{$self->{face_cb}{$num}}, $cb; |
1037 | push @{$self->{face_cb}{$num}}, $cb; |
981 | |
1038 | |
982 | defined wantarray |
1039 | defined wantarray |
983 | ? DC::guard { |
1040 | ? Guard::guard { |
984 | @{$self->{face_cb}{$num}} |
1041 | @{$self->{face_cb}{$num}} |
985 | = grep $_ != $cb, |
1042 | = grep $_ != $cb, |
986 | @{$self->{face_cb}{$num}}; |
1043 | @{$self->{face_cb}{$num}}; |
987 | } |
1044 | } |
988 | : () |
1045 | : () |
… | |
… | |
1016 | my ($self, $flags, $prompt) = @_; |
1073 | my ($self, $flags, $prompt) = @_; |
1017 | |
1074 | |
1018 | $prompt = $LAST_QUERY unless length $prompt; |
1075 | $prompt = $LAST_QUERY unless length $prompt; |
1019 | $LAST_QUERY = $prompt; |
1076 | $LAST_QUERY = $prompt; |
1020 | |
1077 | |
1021 | $self->{query}-> ($self, $flags, $prompt); |
1078 | $self->{query}->($self, $flags, $prompt); |
1022 | } |
1079 | } |
1023 | |
1080 | |
1024 | sub sanitise_xml($) { |
1081 | sub sanitise_xml($) { |
1025 | local $_ = shift; |
1082 | local $_ = shift; |
1026 | |
1083 | |
… | |
… | |
1088 | $self->logprint ("msg: ", $text); |
1145 | $self->logprint ("msg: ", $text); |
1089 | return if $color < 0; # negative color == ignore if not understood |
1146 | return if $color < 0; # negative color == ignore if not understood |
1090 | |
1147 | |
1091 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1148 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1092 | |
1149 | |
1093 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
1094 | # no longer neecssary with TRT servers |
|
|
1095 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1096 | |
|
|
1097 | for (split /\n/, $text) { |
|
|
1098 | ::message ({ |
1150 | ::message ({ |
1099 | fg => $fg, |
1151 | fg => $fg, |
1100 | markup => $_, |
1152 | markup => $text, |
1101 | type => $type, |
1153 | type => $type, |
1102 | extra => [@extra], |
1154 | extra => [@extra], |
1103 | color_flags => $color, #d# ugly, kill |
1155 | color_flags => $color, #d# ugly, kill |
1104 | }); |
1156 | }); |
1105 | |
1157 | |
1106 | $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1158 | # $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1107 | # actually, this is an ugly design. _we_ should control the channels, |
1159 | # # actually, this is an ugly design. _we_ should control the channels, |
1108 | # not some random other widget, as the channels are clearly protocol-specific. |
1160 | # # not some random other widget, as the channels are clearly protocol-specific. |
1109 | # then we could also react to flags such as CLEAR without resorting to |
1161 | # # then we could also react to flags such as CLEAR without resorting to |
1110 | # hacks such as color_flags, above. |
1162 | # # hacks such as color_flags, above. |
1111 | } |
|
|
1112 | |
1163 | |
1113 | $self->{statusbox}->add ($text, |
1164 | $self->{statusbox}->add ($text, |
1114 | group => $text, |
1165 | group => $text, |
1115 | fg => $fg, |
1166 | fg => $fg, |
1116 | timeout => $color >= 2 ? 180 : 10, |
1167 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
1323 | sub update_server_info { |
1374 | sub update_server_info { |
1324 | my ($self) = @_; |
1375 | my ($self) = @_; |
1325 | |
1376 | |
1326 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1377 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1327 | |
1378 | |
|
|
1379 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1380 | |
1328 | $::SERVER_INFO->set_markup ( |
1381 | $::SERVER_INFO->set_markup ( |
1329 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1382 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1330 | . "protocol version <tt>$self->{version}</tt>\n" |
1383 | . "protocol version <tt>$version</tt>\n" |
1331 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
1332 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
1333 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
|
|
1334 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1384 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1335 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
1336 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
|
|
1337 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1385 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1338 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1386 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1339 | . "map size $self->{mapw}×$self->{maph}\n" |
1387 | . "map size $self->{mapw}×$self->{maph}\n" |
1340 | ); |
1388 | ); |
1341 | |
1389 | |
… | |
… | |
1363 | }); |
1411 | }); |
1364 | |
1412 | |
1365 | $self->update_server_info; |
1413 | $self->update_server_info; |
1366 | |
1414 | |
1367 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1415 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1368 | $self->send_command ("pickup $::CFG->{pickup}"); |
1416 | $self->send_pickup ($::CFG->{pickup}); |
1369 | } |
1417 | } |
1370 | |
1418 | |
1371 | sub lookat { |
1419 | sub lookat { |
1372 | my ($self, $x, $y) = @_; |
1420 | my ($self, $x, $y) = @_; |
1373 | |
1421 | |
… | |
… | |
1375 | $self->send_ext_req (lookat => $x, $y, sub { |
1423 | $self->send_ext_req (lookat => $x, $y, sub { |
1376 | my (%msg) = @_; |
1424 | my (%msg) = @_; |
1377 | |
1425 | |
1378 | if (exists $msg{npc_dialog}) { |
1426 | if (exists $msg{npc_dialog}) { |
1379 | # start npc chat dialog |
1427 | # start npc chat dialog |
1380 | $self->{npc_dialog} = new DC::NPCDialog:: |
1428 | $self->{w}{npc_dialog} = new DC::NPCDialog:: |
1381 | token => $msg{npc_dialog}, |
1429 | token => $msg{npc_dialog}, |
1382 | title => "$msg{npc_dialog}[0] (NPC)", |
1430 | title => "$msg{npc_dialog}[0] (NPC)", |
1383 | conn => $self, |
1431 | conn => $self, |
1384 | ; |
1432 | ; |
1385 | } |
1433 | } |
… | |
… | |
1390 | } |
1438 | } |
1391 | |
1439 | |
1392 | sub destroy { |
1440 | sub destroy { |
1393 | my ($self) = @_; |
1441 | my ($self) = @_; |
1394 | |
1442 | |
1395 | (delete $self->{npc_dialog})->destroy |
1443 | $_->destroy |
1396 | if $self->{npc_dialog}; |
1444 | for values %{ $self->{w} }; |
1397 | |
1445 | |
1398 | $self->SUPER::destroy; |
1446 | $self->SUPER::destroy; |
1399 | |
1447 | |
1400 | %$self = (); |
1448 | %$self = (); |
1401 | } |
1449 | } |
… | |
… | |
1537 | } |
1585 | } |
1538 | |
1586 | |
1539 | sub send { |
1587 | sub send { |
1540 | my ($self, $msg) = @_; |
1588 | my ($self, $msg) = @_; |
1541 | |
1589 | |
1542 | $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); |
1590 | $self->{textview}->add_paragraph ({ |
|
|
1591 | markup => |
|
|
1592 | "\n<span foreground='#ffff00'><b>" |
|
|
1593 | . (DC::asxml $msg) |
|
|
1594 | . "</b></span>" |
|
|
1595 | }); |
1543 | $self->{textview}->scroll_to_bottom; |
1596 | $self->{textview}->scroll_to_bottom; |
1544 | |
1597 | |
1545 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1598 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1546 | } |
1599 | } |
1547 | |
1600 | |
… | |
… | |
1550 | |
1603 | |
1551 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1604 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1552 | |
1605 | |
1553 | if ($self->{conn}) { |
1606 | if ($self->{conn}) { |
1554 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1607 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1555 | delete $self->{conn}{npc_dialog}; |
1608 | delete $self->{conn}{w}{npc_dialog}; |
1556 | $self->{conn}->disconnect_ext ($self->{id}); |
1609 | $self->{conn}->disconnect_ext ($self->{id}); |
1557 | } |
1610 | } |
1558 | |
1611 | |
1559 | $self->SUPER::destroy; |
1612 | $self->SUPER::destroy; |
1560 | } |
1613 | } |