ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.198 by root, Tue May 20 02:49:56 2008 UTC vs.
Revision 1.227 by root, Tue Nov 20 14:32:12 2012 UTC

1package DC::Protocol; 1package DC::Protocol;
2 2
3use utf8; 3use common::sense;
4use strict; 4
5use Guard ();
5 6
6use Deliantra::Protocol::Constants; 7use Deliantra::Protocol::Constants;
7 8
8use DC; 9use DC;
9use DC::DB; 10use DC::DB;
12use DC::Macro; 13use DC::Macro;
13use DC::Item; 14use DC::Item;
14 15
15use base 'Deliantra::Protocol::Base'; 16use base 'Deliantra::Protocol::Base';
16 17
18our $TEX_DIALOGUE = new_from_resource DC::Texture
19 "dialogue.png", minify => 1, mipmap => 1;
20
21our $TEX_NOFACE = new_from_resource DC::Texture
22 "noface.png", minify => 1, mipmap => 1, wrap => 1;
23
24sub MIN_TEXTURE_UNUSED() { 1 }#d#
25
17sub new { 26sub 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 );
28 36
29 $self->{map_widget}->clr_commands; 37 $self->update_fx_want;
30 38
31 my @cmd_help = map { 39 my $exp_guard = $self->addme_guard;
32 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 40 my $skl_guard = $self->addme_guard;
33 or die "unparseable command help: $_->[DC::Pod::N_KW][0]"; 41 my $spl_guard = $self->addme_guard;
42 $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub {
43 my ($exp, $skl, $spl) = @_;
34 44
35 my $cmd = $1; 45 $self->register_face_handler ($exp, sub {
36 my @args = split /\|/, $2; 46 my ($face) = @_;
37 @args = (".*") unless @args;
38 47
39 my (undef, @par) = DC::Pod::section_of $_; 48 undef $exp_guard;
40 my $text = DC::Pod::as_label @par; 49 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
50 $_->() for values %{ $self->{on_exp_update} };
51 });
41 52
42 $_ = $_ eq ".*" ? "" : " $_" 53 $self->register_face_handler ($skl, sub {
43 for @args; 54 my ($face) = @_;
44 55
45 map ["$cmd$_", $text], 56 undef $skl_guard;
46 sort { (length $a) <=> (length $b) } 57 my $info = $self->{json_coder}->decode (delete $face->{data});
47 @args 58 $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info };
48 } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } 59 });
49 DC::Pod::find command => "*"; 60
61 $self->register_face_handler ($spl, sub {
62 my ($face) = @_;
63
64 undef $spl_guard;
65 my $info = $self->{json_coder}->decode (delete $face->{data});
66 $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info };
67 });
68
69 ()
70 });
71
72 $::COMPLETER->reset;
50 73
51 $self->{json_coder} 74 $self->{json_coder}
52 ->convert_blessed 75 ->convert_blessed
53 ->filter_json_single_key_object ("\fw" => sub { 76 ->filter_json_single_key_object ("\fw" => sub {
54 $self->{widget}{$_[0]} 77 $self->{widget}{$_[0]}
67 for values %{delete $ws->{w} || {}}; 90 for values %{delete $ws->{w} || {}};
68 } 91 }
69 92
70 delete $self->{items}; 93 delete $self->{items};
71 $::INV->clear; 94 $::INV->clear;
95 $::INVR->clear;
72 $::INVR_HB->clear; 96 $::INVR_HB->clear;
73 $::FLOORBOX->clear; 97 $::FLOORBOX->clear;
74 }); 98 });
75 99
76 $self->{map_widget}->add_command (@$_)
77 for @cmd_help;
78
79 { 100 {
80 $self->{dialogue} = my $tex = new_from_file DC::Texture 101 $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}}); 102 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
83 } 103 }
84 104
85 { 105 {
86 $self->{noface} = my $tex = new_from_file DC::Texture 106 $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}}); 107 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
89 } 108 }
109
110# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
111# $self->{expire_w} = AE::timer 1, 1, sub {
112# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
113#
114# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
115# warn DC::SvREFCNT $self->{texture}[$_];
116# $self->{texture}[$_]->unload;
117# warn "expire texture $_\n";#d#
118# }
119#
120# ($self->{expire_count} += $count) < @{ $self->{texture} }
121# or $self->{expire_count} = DC::DB::FIRST_TILE_ID;
122# warn "count is $count\n";#d#
123# };
90 124
91 $self->{open_container} = 0; 125 $self->{open_container} = 0;
92 126
93 # per server 127 # per server
94 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 128 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
95 129
96 $self 130 $self
97} 131}
132
133 #$self->send_exti_req (nickmon => 1, sub { use Data::Dump; ddx \@_ });#d#
134#sub ext_nicklist { shift; use Data::Dump; ddx \@_; } #d#
98 135
99sub update_fx_want { 136sub update_fx_want {
100 my ($self) = @_; 137 my ($self) = @_;
101 138
102 $self->send_exti_msg (fx_want => { 139 $self->send_exti_msg (fx_want => {
107} 144}
108 145
109sub ext_capabilities { 146sub ext_capabilities {
110 my ($self, %cap) = @_; 147 my ($self, %cap) = @_;
111 148
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
127 if (my $ts = $cap{tileset}) { 149 if (my $ts = $cap{tileset}) {
128 if (my ($default) = grep $_->[2] & 1, @$ts) { 150 if (my ($default) = grep $_->[2] & 1, @$ts) {
129 $self->{tileset} = $default; 151 $self->{tileset} = $default;
130 $self->{tilesize} = $default->[3]; 152 $self->{tilesize} = $default->[3];
131 $self->setup_req (tileset => $default->[0]); 153 $self->setup_req (tileset => $default->[0]);
139} 161}
140 162
141sub ext_ambient_music { 163sub ext_ambient_music {
142 my ($self, $songs) = @_; 164 my ($self, $songs) = @_;
143 &::audio_music_set_ambient ($songs); 165 &::audio_music_set_ambient ($songs);
166}
167
168sub ext_command_list {
169 my ($self, @faces) = @_;
170
171 my $handler = $self->{command_facehandler} = {};
172 my $commands = $::COMPLETER->{command_list} = {};
173
174 for my $idx (@faces) {
175 $handler->{$idx} = $self->register_face_handler ($idx, sub {
176 my ($face) = @_;
177
178 $commands->{$idx} =
179 $face->{cache} ||= $self->{json_coder}->decode ($face->{data});
180 });
181 }
144} 182}
145 183
146############################################################################# 184#############################################################################
147 185
148sub widget_associate { 186sub widget_associate {
255 my %wkw = ( 293 my %wkw = (
256 root => $DC::UI::ROOT, 294 root => $DC::UI::ROOT,
257 tooltip => $DC::UI::TOOLTIP, 295 tooltip => $DC::UI::TOOLTIP,
258 296
259 mapwidget => $::MAPWIDGET, 297 mapwidget => $::MAPWIDGET,
298 menubar => $::MENUBAR,
299 menupopup => $::MENUPOPUP,
300 pickup_enable => $::PICKUP_ENABLE,
260 buttonbar => $::BUTTONBAR, 301 buttonbar => $::BUTTONBAR,
261 metaserver => $::METASERVER, 302 metaserver => $::METASERVER,
262 buttonbar => $::BUTTONBAR, 303 buttonbar => $::BUTTONBAR,
263 login_button => $::LOGIN_BUTTON, 304 login_button => $::LOGIN_BUTTON,
264 quit_dialog => $::QUIT_DIALOG, 305 quit_dialog => $::QUIT_DIALOG,
281 322
282 floorbox => $::FLOORBOX, 323 floorbox => $::FLOORBOX,
283 help_window => $::HELP_WINDOW, 324 help_window => $::HELP_WINDOW,
284 message_window => $::MESSAGE_WINDOW, 325 message_window => $::MESSAGE_WINDOW,
285 message_dist => $::MESSAGE_DIST, 326 message_dist => $::MESSAGE_DIST,
286 statusbox => $::SDTATUSBOX, 327 statusbox => $::STATUSBOX,
287 328
288 inv => $::INV, 329 inv => $::INV,
289 invr => $::INVR, 330 invr => $::INVR,
290 invr_hb => $::INVR_HB, 331 invr_hb => $::INVR_HB,
291 ); 332 );
375 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) 416 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_})
376 : () 417 : ()
377 } 418 }
378 sort { $a <=> $b } keys %{$self->{spell_paths}}; 419 sort { $a <=> $b } keys %{$self->{spell_paths}};
379 420
380 join "", @diff 421 "\u$name: " . (join ", ", @diff)
381} 422}
382 423
383# all stats that are chacked against changes 424# all stats that are chacked against changes
384my @statchange = ( 425my @statchange = (
385 [&CS_STAT_STR => \&_stat_numdiff, "Str"], 426 [&CS_STAT_STR => \&_stat_numdiff, "Str"],
428 469
429 if (my @diffs = 470 if (my @diffs =
430 ( 471 (
431 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), 472 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()),
432 map { 473 map {
433 $stats->{$_} && $prev->{$_} 474 $stats->{$_} && $prev->{$_}
434 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 475 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
435 } sort { $a <=> $b } keys %{$self->{skill_info}} 476 } sort { $a <=> $b } keys %{$self->{skill_info}}
436 ) 477 )
437 ) { 478 ) {
438 my $msg = join " ", @diffs; 479 my $msg = join " ", @diffs;
440 } 481 }
441 482
442 if ( 483 if (
443 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange 484 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
444 ) { 485 ) {
445 my $msg = "<b>stat change</b>: " . (join " ", @diffs); 486 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); 487 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20);
447 } 488 }
448 489
449 $self->update_stats_window ($stats, $prev); 490 $self->update_stats_window ($stats, $prev);
450 491
488 529
489 $::GAUGES->{hp} ->set_value ($hp, $hp_m); 530 $::GAUGES->{hp} ->set_value ($hp, $hp_m);
490 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 531 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
491 $::GAUGES->{food} ->set_value ($fo, $fo_m); 532 $::GAUGES->{food} ->set_value ($fo, $fo_m);
492 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 533 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
493 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 534 $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d#
494 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 535 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
495 $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); 536 $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64});
496 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); 537 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
497 my $title = $stats->{+CS_STAT_TITLE}; 538 my $title = $stats->{+CS_STAT_TITLE};
498 $title =~ s/^Player: //; 539 $title =~ s/^Player: //;
499 $::STATWIDS->{title} ->set_text ("Title: " . $title); 540 $::STATWIDS->{title} ->set_text ("Title: " . $title);
500 541
512 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 553 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
513 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); 554 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP});
514 555
515 $self->update_weight; 556 $self->update_weight;
516 557
517 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 558 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
518 for keys %RES_TBL; 559 for keys %RES_TBL;
519 560
520 my $sktbl = $::STATWIDS->{skill_tbl}; 561 my $sktbl = $::STATWIDS->{skill_tbl};
521 my @skills = keys %{ $self->{skill_info} }; 562 my @skills = keys %{ $self->{skill_info} };
522 563
541 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), 582 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
542 ]; 583 ];
543 584
544 my @add = @$sw; 585 my @add = @$sw;
545 586
546 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 587 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>";
547 588
548 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 589 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); 590 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
550 591
551 my ($x, $y) = (0, 1); 592 my ($x, $y) = (0, 1);
613 my $sw = $self->{skillwid}{$idx}; 654 my $sw = $self->{skillwid}{$idx};
614 $sw->[0]->set_text (::formsep ($val->[1])); 655 $sw->[0]->set_text (::formsep ($val->[1]));
615 $sw->[1]->set_text ($val->[0] * 1); 656 $sw->[1]->set_text ($val->[0] * 1);
616 $sw->[2]->set_value (@$val); 657 $sw->[2]->set_value (@$val);
617 658
618 $::GAUGES->{sklprg}->set_label ("$name %d%%"); 659 $::GAUGES->{skillexp}->set_label ("$name %d%%");
619 $::GAUGES->{sklprg}->set_value (@$val); 660 $::GAUGES->{skillexp}->set_value (@$val);
620 } 661 }
621} 662}
622 663
623sub user_send { 664sub user_send {
624 my ($self, $command) = @_; 665 my ($self, $command) = @_;
637} 678}
638 679
639sub map_scroll { 680sub map_scroll {
640 my ($self, $dx, $dy) = @_; 681 my ($self, $dx, $dy) = @_;
641 682
642 $self->{map}->scroll ($dx, $dy); 683 $self->{map_widget}->scroll ($dx, $dy);
643} 684}
644 685
645sub feed_map1a { 686sub feed_map1a {
646 my ($self, $data) = @_; 687 my ($self, $data) = @_;
647 688
648 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 689 my $missing = $self->{map}->map1a_update ($data);
649 my $delay; 690 my $delay;
650 691
651 for my $tile (@$missing) { 692 for my $tile (@$missing) {
652 next if $self->{delay}{$tile}; 693 next if $self->{delay}{$tile};
653 694
654 $delay = 1; 695 $delay = 1;
655 696
656 if (my $tex = $::CONN->{texture}[$tile]) { 697 if (my $tex = $self->{texture}[$tile]) {
657 $tex->upload; 698 $tex->upload;
658 } else { 699 } else {
659 $self->{delay}{$tile} = 1; 700 $self->{delay}{$tile} = 1;
660 701
661 # we assume the face is in-flight and will eventually come 702 # we assume the face is in-flight and will eventually arrive
662 push @{$self->{tile_cb}{$tile}}, sub { 703 push @{$self->{tile_cb}{$tile}}, sub {
663 delete $self->{delay}{$tile}; 704 delete $self->{delay}{$tile};
664 $_[0]->upload; 705 $_[0]->upload;
665 }; 706 };
666 } 707 }
667 } 708 }
668 709
669 if ($delay) { 710 if ($delay) {
670 # delay the map drawing a tiny bit in the hope of getting the missing fetched 711 # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched
671 EV::once undef, 0, 0.03, sub { 712 EV::once undef, 0, 0.03, sub {
672 $self->{map_widget}->update 713 $self->{map_widget}->update
673 if $self->{map_widget}; 714 if $self->{map_widget};
674 }; 715 };
675 } else { 716 } else {
963 1004
964 my $tex = $self->{texture}[$tile] ||= 1005 my $tex = $self->{texture}[$tile] ||=
965 new DC::Texture 1006 new DC::Texture
966 tile => $tile, 1007 tile => $tile,
967 image => $data, delete_image => 1, 1008 image => $data, delete_image => 1,
968 minify => 1, mipmap => 1; 1009 minify => 1;
969 1010
970 if (my $cbs = delete $self->{tile_cb}{$tile}) { 1011 if (my $cbs = delete $self->{tile_cb}{$tile}) {
971 $_->($tex) for @$cbs; 1012 $_->($tex) for @$cbs;
972 } 1013 }
973} 1014}
978 my ($self, $num, $cb) = @_; 1019 my ($self, $num, $cb) = @_;
979 1020
980 push @{$self->{face_cb}{$num}}, $cb; 1021 push @{$self->{face_cb}{$num}}, $cb;
981 1022
982 defined wantarray 1023 defined wantarray
983 ? DC::guard { 1024 ? Guard::guard {
984 @{$self->{face_cb}{$num}} 1025 @{$self->{face_cb}{$num}}
985 = grep $_ != $cb, 1026 = grep $_ != $cb,
986 @{$self->{face_cb}{$num}}; 1027 @{$self->{face_cb}{$num}};
987 } 1028 }
988 : () 1029 : ()
1016 my ($self, $flags, $prompt) = @_; 1057 my ($self, $flags, $prompt) = @_;
1017 1058
1018 $prompt = $LAST_QUERY unless length $prompt; 1059 $prompt = $LAST_QUERY unless length $prompt;
1019 $LAST_QUERY = $prompt; 1060 $LAST_QUERY = $prompt;
1020 1061
1021 $self->{query}-> ($self, $flags, $prompt); 1062 $self->{query}->($self, $flags, $prompt);
1022} 1063}
1023 1064
1024sub sanitise_xml($) { 1065sub sanitise_xml($) {
1025 local $_ = shift; 1066 local $_ = shift;
1026 1067
1058 tan => 12, 1099 tan => 12,
1059); 1100);
1060 1101
1061our @CF_COLOR = ( 1102our @CF_COLOR = (
1062 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 1103 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1063 [1.00, 1.00, 1.00], 1104 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1064 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] 1105 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55],
1065 [1.00, 0.00, 0.00], 1106 [1.00, 0.00, 0.00],
1066 [1.00, 0.54, 0.00], 1107 [1.00, 0.54, 0.00],
1067 [0.11, 0.56, 1.00], 1108 [0.11, 0.56, 1.00],
1068 [0.93, 0.46, 0.00], 1109 [0.93, 0.46, 0.00],
1069 [0.18, 0.54, 0.34], 1110 [0.18, 0.54, 0.34],
1088 $self->logprint ("msg: ", $text); 1129 $self->logprint ("msg: ", $text);
1089 return if $color < 0; # negative color == ignore if not understood 1130 return if $color < 0; # negative color == ignore if not understood
1090 1131
1091 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1132 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1092 1133
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 ({ 1134 ::message ({
1099 fg => $fg, 1135 fg => $fg,
1100 markup => $_, 1136 markup => $text,
1101 type => $type, 1137 type => $type,
1102 extra => [@extra], 1138 extra => [@extra],
1103 color_flags => $color, #d# ugly, kill 1139 color_flags => $color, #d# ugly, kill
1104 }); 1140 });
1105 1141
1106 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1142# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1107 # actually, this is an ugly design. _we_ should control the channels, 1143# # actually, this is an ugly design. _we_ should control the channels,
1108 # not some random other widget, as the channels are clearly protocol-specific. 1144# # 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 1145# # then we could also react to flags such as CLEAR without resorting to
1110 # hacks such as color_flags, above. 1146# # hacks such as color_flags, above.
1111 }
1112 1147
1113 $self->{statusbox}->add ($text, 1148 $self->{statusbox}->add ($text,
1114 group => $text, 1149 group => $text,
1115 fg => $fg, 1150 fg => $fg,
1116 timeout => $color >= 2 ? 180 : 10, 1151 timeout => $color >= 2 ? 180 : 10,
1126 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 1161 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
1127 $spell->{message} =~ s/\n+$//; 1162 $spell->{message} =~ s/\n+$//;
1128 $spell->{message} ||= "Server did not provide a description for this spell."; 1163 $spell->{message} ||= "Server did not provide a description for this spell.";
1129 1164
1130 $::SPELL_LIST->add_spell ($spell); 1165 $::SPELL_LIST->add_spell ($spell);
1131 1166 delete $::COMPLETER->{command_list}{spells};
1132 $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message});
1133 $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message});
1134} 1167}
1135 1168
1136sub spell_delete { 1169sub spell_delete {
1137 my ($self, $spell) = @_; 1170 my ($self, $spell) = @_;
1138 1171
1139 $::SPELL_LIST->remove_spell ($spell); 1172 $::SPELL_LIST->remove_spell ($spell);
1173 delete $::COMPLETER->{command_list}{spells};
1140} 1174}
1141 1175
1142sub setup { 1176sub setup {
1143 my ($self, $setup) = @_; 1177 my ($self, $setup) = @_;
1144 1178
1167} 1201}
1168 1202
1169sub eof { 1203sub eof {
1170 my ($self) = @_; 1204 my ($self) = @_;
1171 1205
1172 $self->{map_widget}->clr_commands; 1206 $::COMPLETER->reset;
1173 1207
1174 ::stop_game (); 1208 ::stop_game ();
1175} 1209}
1176 1210
1177sub update_floorbox { 1211sub update_floorbox {
1323sub update_server_info { 1357sub update_server_info {
1324 my ($self) = @_; 1358 my ($self) = @_;
1325 1359
1326 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); 1360 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>");
1327 1361
1362 my $version = JSON::XS->new->encode ($self->{s_version});
1363
1328 $::SERVER_INFO->set_markup ( 1364 $::SERVER_INFO->set_markup (
1329 "server <tt>$self->{host}:$self->{port}</tt>\n" 1365 "server <tt>$self->{host}:$self->{port}</tt>\n"
1330 . "protocol version <tt>$self->{version}</tt>\n" 1366 . "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" 1367 . "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]" 1368 . "client support $yesno[$self->{cfplus_ext} > 0]"
1338 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1369 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1339 . "map size $self->{mapw}×$self->{maph}\n" 1370 . "map size $self->{mapw}×$self->{maph}\n"
1340 ); 1371 );
1341 1372
1363 }); 1394 });
1364 1395
1365 $self->update_server_info; 1396 $self->update_server_info;
1366 1397
1367 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1398 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1368 $self->send_command ("pickup $::CFG->{pickup}"); 1399 $self->send_pickup ($::CFG->{pickup});
1369} 1400}
1370 1401
1371sub lookat { 1402sub lookat {
1372 my ($self, $x, $y) = @_; 1403 my ($self, $x, $y) = @_;
1373 1404
1375 $self->send_ext_req (lookat => $x, $y, sub { 1406 $self->send_ext_req (lookat => $x, $y, sub {
1376 my (%msg) = @_; 1407 my (%msg) = @_;
1377 1408
1378 if (exists $msg{npc_dialog}) { 1409 if (exists $msg{npc_dialog}) {
1379 # start npc chat dialog 1410 # start npc chat dialog
1380 $self->{npc_dialog} = new DC::NPCDialog:: 1411 $self->{w}{npc_dialog} = new DC::NPCDialog::
1381 token => $msg{npc_dialog}, 1412 token => $msg{npc_dialog},
1382 title => "$msg{npc_dialog}[0] (NPC)", 1413 title => "$msg{npc_dialog}[0] (NPC)",
1383 conn => $self, 1414 conn => $self,
1384 ; 1415 ;
1385 } 1416 }
1390} 1421}
1391 1422
1392sub destroy { 1423sub destroy {
1393 my ($self) = @_; 1424 my ($self) = @_;
1394 1425
1395 (delete $self->{npc_dialog})->destroy 1426 $_->destroy
1396 if $self->{npc_dialog}; 1427 for values %{ $self->{w} };
1397 1428
1398 $self->SUPER::destroy; 1429 $self->SUPER::destroy;
1399 1430
1400 %$self = (); 1431 %$self = ();
1401} 1432}
1537} 1568}
1538 1569
1539sub send { 1570sub send {
1540 my ($self, $msg) = @_; 1571 my ($self, $msg) = @_;
1541 1572
1542 $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); 1573 $self->{textview}->add_paragraph ({
1574 markup =>
1575 "\n<span foreground='#ffff00'><b>"
1576 . (DC::asxml $msg)
1577 . "</b></span>"
1578 });
1543 $self->{textview}->scroll_to_bottom; 1579 $self->{textview}->scroll_to_bottom;
1544 1580
1545 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1581 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1546} 1582}
1547 1583
1550 1586
1551 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 1587 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1
1552 1588
1553 if ($self->{conn}) { 1589 if ($self->{conn}) {
1554 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; 1590 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id};
1555 delete $self->{conn}{npc_dialog}; 1591 delete $self->{conn}{w}{npc_dialog};
1556 $self->{conn}->disconnect_ext ($self->{id}); 1592 $self->{conn}->disconnect_ext ($self->{id});
1557 } 1593 }
1558 1594
1559 $self->SUPER::destroy; 1595 $self->SUPER::destroy;
1560} 1596}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines