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.201 by root, Wed Sep 3 06:35:55 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;
13use DC::Item; 14use DC::Item;
14 15
15use base 'Deliantra::Protocol::Base'; 16use base 'Deliantra::Protocol::Base';
16 17
17our $TEX_DIALOGUE = new_from_resource DC::Texture 18our $TEX_DIALOGUE = new_from_resource DC::Texture
18 "dialogue.png", minify => 1, mipmap => 1; 19 "dialogue.png", minify => 1, mipmap => 1;
19 20
20our $TEX_NOFACE = new_from_resource DC::Texture 21our $TEX_NOFACE = new_from_resource DC::Texture
21 "noface.png", minify => 1, mipmap => 1; 22 "noface.png", minify => 1, mipmap => 1, wrap => 1;
23
24sub MIN_TEXTURE_UNUSED() { 1 }#d#
22 25
23sub new { 26sub new {
24 my ($class, %arg) = @_; 27 my ($class, %arg) = @_;
25 28
26 my $self = $class->SUPER::new (%arg, 29 my $self = $class->SUPER::new (%arg,
27 setup_req => { 30 setup_req => {
28 extmap => 1, 31 extmap => 1,
29 excmd => 1,
30 widget => 2, 32 widget => 2,
31 %{$arg{setup_req} || {}}, 33 %{$arg{setup_req} || {}},
32 }, 34 },
33 ); 35 );
34 36
35 $self->{map_widget}->clr_commands; 37 $self->update_fx_want;
36 38
37 my @cmd_help = map { 39 my $exp_guard = $self->addme_guard;
38 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 40 my $skl_guard = $self->addme_guard;
39 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) = @_;
40 44
41 my $cmd = $1; 45 $self->register_face_handler ($exp, sub {
42 my @args = split /\|/, $2; 46 my ($face) = @_;
43 @args = (".*") unless @args;
44 47
45 my (undef, @par) = DC::Pod::section_of $_; 48 undef $exp_guard;
46 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 });
47 52
48 $_ = $_ eq ".*" ? "" : " $_" 53 $self->register_face_handler ($skl, sub {
49 for @args; 54 my ($face) = @_;
50 55
51 map ["$cmd$_", $text], 56 undef $skl_guard;
52 sort { (length $a) <=> (length $b) } 57 my $info = $self->{json_coder}->decode (delete $face->{data});
53 @args 58 $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info };
54 } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } 59 });
55 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;
56 73
57 $self->{json_coder} 74 $self->{json_coder}
58 ->convert_blessed 75 ->convert_blessed
59 ->filter_json_single_key_object ("\fw" => sub { 76 ->filter_json_single_key_object ("\fw" => sub {
60 $self->{widget}{$_[0]} 77 $self->{widget}{$_[0]}
73 for values %{delete $ws->{w} || {}}; 90 for values %{delete $ws->{w} || {}};
74 } 91 }
75 92
76 delete $self->{items}; 93 delete $self->{items};
77 $::INV->clear; 94 $::INV->clear;
95 $::INVR->clear;
78 $::INVR_HB->clear; 96 $::INVR_HB->clear;
79 $::FLOORBOX->clear; 97 $::FLOORBOX->clear;
80 }); 98 });
81 99
82 $self->{map_widget}->add_command (@$_)
83 for @cmd_help;
84
85 { 100 {
86 $self->{dialogue} = my $tex = $TEX_DIALOGUE; 101 $self->{dialogue} = my $tex = $TEX_DIALOGUE;
87 $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}});
88 } 103 }
89 104
90 { 105 {
91 $self->{noface} = my $tex = $TEX_NOFACE; 106 $self->{noface} = my $tex = $TEX_NOFACE;
92 $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}});
93 } 108 }
94 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# };
124
95 $self->{open_container} = 0; 125 $self->{open_container} = 0;
96 126
97 # per server 127 # per server
98 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 128 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
99 129
100 $self 130 $self
101} 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#
102 135
103sub update_fx_want { 136sub update_fx_want {
104 my ($self) = @_; 137 my ($self) = @_;
105 138
106 $self->send_exti_msg (fx_want => { 139 $self->send_exti_msg (fx_want => {
111} 144}
112 145
113sub ext_capabilities { 146sub ext_capabilities {
114 my ($self, %cap) = @_; 147 my ($self, %cap) = @_;
115 148
116 $self->update_fx_want;
117
118 $self->send_exti_req (resource => "exp_table", sub {
119 my ($exp_table) = @_;
120
121 $self->register_face_handler ($exp_table, sub {
122 my ($face) = @_;
123
124 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
125 $_->() for values %{ $self->{on_exp_update} || {} };
126 });
127
128 ()
129 });
130
131 if (my $ts = $cap{tileset}) { 149 if (my $ts = $cap{tileset}) {
132 if (my ($default) = grep $_->[2] & 1, @$ts) { 150 if (my ($default) = grep $_->[2] & 1, @$ts) {
133 $self->{tileset} = $default; 151 $self->{tileset} = $default;
134 $self->{tilesize} = $default->[3]; 152 $self->{tilesize} = $default->[3];
135 $self->setup_req (tileset => $default->[0]); 153 $self->setup_req (tileset => $default->[0]);
143} 161}
144 162
145sub ext_ambient_music { 163sub ext_ambient_music {
146 my ($self, $songs) = @_; 164 my ($self, $songs) = @_;
147 &::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 }
148} 182}
149 183
150############################################################################# 184#############################################################################
151 185
152sub widget_associate { 186sub widget_associate {
259 my %wkw = ( 293 my %wkw = (
260 root => $DC::UI::ROOT, 294 root => $DC::UI::ROOT,
261 tooltip => $DC::UI::TOOLTIP, 295 tooltip => $DC::UI::TOOLTIP,
262 296
263 mapwidget => $::MAPWIDGET, 297 mapwidget => $::MAPWIDGET,
298 menubar => $::MENUBAR,
299 menupopup => $::MENUPOPUP,
300 pickup_enable => $::PICKUP_ENABLE,
264 buttonbar => $::BUTTONBAR, 301 buttonbar => $::BUTTONBAR,
265 metaserver => $::METASERVER, 302 metaserver => $::METASERVER,
266 buttonbar => $::BUTTONBAR, 303 buttonbar => $::BUTTONBAR,
267 login_button => $::LOGIN_BUTTON, 304 login_button => $::LOGIN_BUTTON,
268 quit_dialog => $::QUIT_DIALOG, 305 quit_dialog => $::QUIT_DIALOG,
285 322
286 floorbox => $::FLOORBOX, 323 floorbox => $::FLOORBOX,
287 help_window => $::HELP_WINDOW, 324 help_window => $::HELP_WINDOW,
288 message_window => $::MESSAGE_WINDOW, 325 message_window => $::MESSAGE_WINDOW,
289 message_dist => $::MESSAGE_DIST, 326 message_dist => $::MESSAGE_DIST,
290 statusbox => $::SDTATUSBOX, 327 statusbox => $::STATUSBOX,
291 328
292 inv => $::INV, 329 inv => $::INV,
293 invr => $::INVR, 330 invr => $::INVR,
294 invr_hb => $::INVR_HB, 331 invr_hb => $::INVR_HB,
295 ); 332 );
379 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) 416 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_})
380 : () 417 : ()
381 } 418 }
382 sort { $a <=> $b } keys %{$self->{spell_paths}}; 419 sort { $a <=> $b } keys %{$self->{spell_paths}};
383 420
384 join "", @diff 421 "\u$name: " . (join ", ", @diff)
385} 422}
386 423
387# all stats that are chacked against changes 424# all stats that are chacked against changes
388my @statchange = ( 425my @statchange = (
389 [&CS_STAT_STR => \&_stat_numdiff, "Str"], 426 [&CS_STAT_STR => \&_stat_numdiff, "Str"],
432 469
433 if (my @diffs = 470 if (my @diffs =
434 ( 471 (
435 ($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" : ()),
436 map { 473 map {
437 $stats->{$_} && $prev->{$_} 474 $stats->{$_} && $prev->{$_}
438 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 475 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
439 } sort { $a <=> $b } keys %{$self->{skill_info}} 476 } sort { $a <=> $b } keys %{$self->{skill_info}}
440 ) 477 )
441 ) { 478 ) {
442 my $msg = join " ", @diffs; 479 my $msg = join " ", @diffs;
444 } 481 }
445 482
446 if ( 483 if (
447 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange 484 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
448 ) { 485 ) {
449 my $msg = "<b>stat change</b>: " . (join " ", @diffs); 486 my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs);
450 $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);
451 } 488 }
452 489
453 $self->update_stats_window ($stats, $prev); 490 $self->update_stats_window ($stats, $prev);
454 491
492 529
493 $::GAUGES->{hp} ->set_value ($hp, $hp_m); 530 $::GAUGES->{hp} ->set_value ($hp, $hp_m);
494 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 531 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
495 $::GAUGES->{food} ->set_value ($fo, $fo_m); 532 $::GAUGES->{food} ->set_value ($fo, $fo_m);
496 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 533 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
497 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 534 $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d#
498 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 535 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
499 $::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});
500 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); 537 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
501 my $title = $stats->{+CS_STAT_TITLE}; 538 my $title = $stats->{+CS_STAT_TITLE};
502 $title =~ s/^Player: //; 539 $title =~ s/^Player: //;
503 $::STATWIDS->{title} ->set_text ("Title: " . $title); 540 $::STATWIDS->{title} ->set_text ("Title: " . $title);
504 541
516 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 553 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
517 $::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});
518 555
519 $self->update_weight; 556 $self->update_weight;
520 557
521 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 558 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
522 for keys %RES_TBL; 559 for keys %RES_TBL;
523 560
524 my $sktbl = $::STATWIDS->{skill_tbl}; 561 my $sktbl = $::STATWIDS->{skill_tbl};
525 my @skills = keys %{ $self->{skill_info} }; 562 my @skills = keys %{ $self->{skill_info} };
526 563
545 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),
546 ]; 583 ];
547 584
548 my @add = @$sw; 585 my @add = @$sw;
549 586
550 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>";
551 588
552 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);
553 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);
554 591
555 my ($x, $y) = (0, 1); 592 my ($x, $y) = (0, 1);
617 my $sw = $self->{skillwid}{$idx}; 654 my $sw = $self->{skillwid}{$idx};
618 $sw->[0]->set_text (::formsep ($val->[1])); 655 $sw->[0]->set_text (::formsep ($val->[1]));
619 $sw->[1]->set_text ($val->[0] * 1); 656 $sw->[1]->set_text ($val->[0] * 1);
620 $sw->[2]->set_value (@$val); 657 $sw->[2]->set_value (@$val);
621 658
622 $::GAUGES->{sklprg}->set_label ("$name %d%%"); 659 $::GAUGES->{skillexp}->set_label ("$name %d%%");
623 $::GAUGES->{sklprg}->set_value (@$val); 660 $::GAUGES->{skillexp}->set_value (@$val);
624 } 661 }
625} 662}
626 663
627sub user_send { 664sub user_send {
628 my ($self, $command) = @_; 665 my ($self, $command) = @_;
647} 684}
648 685
649sub feed_map1a { 686sub feed_map1a {
650 my ($self, $data) = @_; 687 my ($self, $data) = @_;
651 688
652 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 689 my $missing = $self->{map}->map1a_update ($data);
653 my $delay; 690 my $delay;
654 691
655 for my $tile (@$missing) { 692 for my $tile (@$missing) {
656 next if $self->{delay}{$tile}; 693 next if $self->{delay}{$tile};
657 694
658 $delay = 1; 695 $delay = 1;
659 696
660 if (my $tex = $::CONN->{texture}[$tile]) { 697 if (my $tex = $self->{texture}[$tile]) {
661 $tex->upload; 698 $tex->upload;
662 } else { 699 } else {
663 $self->{delay}{$tile} = 1; 700 $self->{delay}{$tile} = 1;
664 701
665 # we assume the face is in-flight and will eventually come 702 # we assume the face is in-flight and will eventually arrive
666 push @{$self->{tile_cb}{$tile}}, sub { 703 push @{$self->{tile_cb}{$tile}}, sub {
667 delete $self->{delay}{$tile}; 704 delete $self->{delay}{$tile};
668 $_[0]->upload; 705 $_[0]->upload;
669 }; 706 };
670 } 707 }
671 } 708 }
672 709
673 if ($delay) { 710 if ($delay) {
674 # 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
675 EV::once undef, 0, 0.03, sub { 712 EV::once undef, 0, 0.03, sub {
676 $self->{map_widget}->update 713 $self->{map_widget}->update
677 if $self->{map_widget}; 714 if $self->{map_widget};
678 }; 715 };
679 } else { 716 } else {
967 1004
968 my $tex = $self->{texture}[$tile] ||= 1005 my $tex = $self->{texture}[$tile] ||=
969 new DC::Texture 1006 new DC::Texture
970 tile => $tile, 1007 tile => $tile,
971 image => $data, delete_image => 1, 1008 image => $data, delete_image => 1,
972 minify => 1, mipmap => 1; 1009 minify => 1;
973 1010
974 if (my $cbs = delete $self->{tile_cb}{$tile}) { 1011 if (my $cbs = delete $self->{tile_cb}{$tile}) {
975 $_->($tex) for @$cbs; 1012 $_->($tex) for @$cbs;
976 } 1013 }
977} 1014}
982 my ($self, $num, $cb) = @_; 1019 my ($self, $num, $cb) = @_;
983 1020
984 push @{$self->{face_cb}{$num}}, $cb; 1021 push @{$self->{face_cb}{$num}}, $cb;
985 1022
986 defined wantarray 1023 defined wantarray
987 ? DC::guard { 1024 ? Guard::guard {
988 @{$self->{face_cb}{$num}} 1025 @{$self->{face_cb}{$num}}
989 = grep $_ != $cb, 1026 = grep $_ != $cb,
990 @{$self->{face_cb}{$num}}; 1027 @{$self->{face_cb}{$num}};
991 } 1028 }
992 : () 1029 : ()
1020 my ($self, $flags, $prompt) = @_; 1057 my ($self, $flags, $prompt) = @_;
1021 1058
1022 $prompt = $LAST_QUERY unless length $prompt; 1059 $prompt = $LAST_QUERY unless length $prompt;
1023 $LAST_QUERY = $prompt; 1060 $LAST_QUERY = $prompt;
1024 1061
1025 $self->{query}-> ($self, $flags, $prompt); 1062 $self->{query}->($self, $flags, $prompt);
1026} 1063}
1027 1064
1028sub sanitise_xml($) { 1065sub sanitise_xml($) {
1029 local $_ = shift; 1066 local $_ = shift;
1030 1067
1062 tan => 12, 1099 tan => 12,
1063); 1100);
1064 1101
1065our @CF_COLOR = ( 1102our @CF_COLOR = (
1066 [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],
1067 [1.00, 1.00, 1.00], 1104 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1068 [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],
1069 [1.00, 0.00, 0.00], 1106 [1.00, 0.00, 0.00],
1070 [1.00, 0.54, 0.00], 1107 [1.00, 0.54, 0.00],
1071 [0.11, 0.56, 1.00], 1108 [0.11, 0.56, 1.00],
1072 [0.93, 0.46, 0.00], 1109 [0.93, 0.46, 0.00],
1073 [0.18, 0.54, 0.34], 1110 [0.18, 0.54, 0.34],
1092 $self->logprint ("msg: ", $text); 1129 $self->logprint ("msg: ", $text);
1093 return if $color < 0; # negative color == ignore if not understood 1130 return if $color < 0; # negative color == ignore if not understood
1094 1131
1095 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1132 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1096 1133
1097 ## try to create single paragraphs of multiple lines sent by the server
1098 # no longer neecssary with TRT servers
1099 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1100
1101 for (split /\n/, $text) {
1102 ::message ({ 1134 ::message ({
1103 fg => $fg, 1135 fg => $fg,
1104 markup => $_, 1136 markup => $text,
1105 type => $type, 1137 type => $type,
1106 extra => [@extra], 1138 extra => [@extra],
1107 color_flags => $color, #d# ugly, kill 1139 color_flags => $color, #d# ugly, kill
1108 }); 1140 });
1109 1141
1110 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1142# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1111 # actually, this is an ugly design. _we_ should control the channels, 1143# # actually, this is an ugly design. _we_ should control the channels,
1112 # 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.
1113 # 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
1114 # hacks such as color_flags, above. 1146# # hacks such as color_flags, above.
1115 }
1116 1147
1117 $self->{statusbox}->add ($text, 1148 $self->{statusbox}->add ($text,
1118 group => $text, 1149 group => $text,
1119 fg => $fg, 1150 fg => $fg,
1120 timeout => $color >= 2 ? 180 : 10, 1151 timeout => $color >= 2 ? 180 : 10,
1130 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 1161 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
1131 $spell->{message} =~ s/\n+$//; 1162 $spell->{message} =~ s/\n+$//;
1132 $spell->{message} ||= "Server did not provide a description for this spell."; 1163 $spell->{message} ||= "Server did not provide a description for this spell.";
1133 1164
1134 $::SPELL_LIST->add_spell ($spell); 1165 $::SPELL_LIST->add_spell ($spell);
1135 1166 delete $::COMPLETER->{command_list}{spells};
1136 $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message});
1137 $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message});
1138} 1167}
1139 1168
1140sub spell_delete { 1169sub spell_delete {
1141 my ($self, $spell) = @_; 1170 my ($self, $spell) = @_;
1142 1171
1143 $::SPELL_LIST->remove_spell ($spell); 1172 $::SPELL_LIST->remove_spell ($spell);
1173 delete $::COMPLETER->{command_list}{spells};
1144} 1174}
1145 1175
1146sub setup { 1176sub setup {
1147 my ($self, $setup) = @_; 1177 my ($self, $setup) = @_;
1148 1178
1171} 1201}
1172 1202
1173sub eof { 1203sub eof {
1174 my ($self) = @_; 1204 my ($self) = @_;
1175 1205
1176 $self->{map_widget}->clr_commands; 1206 $::COMPLETER->reset;
1177 1207
1178 ::stop_game (); 1208 ::stop_game ();
1179} 1209}
1180 1210
1181sub update_floorbox { 1211sub update_floorbox {
1327sub update_server_info { 1357sub update_server_info {
1328 my ($self) = @_; 1358 my ($self) = @_;
1329 1359
1330 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>");
1331 1361
1362 my $version = JSON::XS->new->encode ($self->{s_version});
1363
1332 $::SERVER_INFO->set_markup ( 1364 $::SERVER_INFO->set_markup (
1333 "server <tt>$self->{host}:$self->{port}</tt>\n" 1365 "server <tt>$self->{host}:$self->{port}</tt>\n"
1334 . "protocol version <tt>$self->{version}</tt>\n" 1366 . "protocol version <tt>$version</tt>\n"
1335 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1336 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1337 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1338 . "editing support $yesno[!!$self->{editor_support}]\n" 1367 . "editing support $yesno[!!$self->{editor_support}]\n"
1339 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1340 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1341 . "client support $yesno[$self->{cfplus_ext} > 0]" 1368 . "client support $yesno[$self->{cfplus_ext} > 0]"
1342 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1369 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1343 . "map size $self->{mapw}×$self->{maph}\n" 1370 . "map size $self->{mapw}×$self->{maph}\n"
1344 ); 1371 );
1345 1372
1367 }); 1394 });
1368 1395
1369 $self->update_server_info; 1396 $self->update_server_info;
1370 1397
1371 $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;
1372 $self->send_command ("pickup $::CFG->{pickup}"); 1399 $self->send_pickup ($::CFG->{pickup});
1373
1374 $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]",
1375 DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d#
1376} 1400}
1377 1401
1378sub lookat { 1402sub lookat {
1379 my ($self, $x, $y) = @_; 1403 my ($self, $x, $y) = @_;
1380 1404
1382 $self->send_ext_req (lookat => $x, $y, sub { 1406 $self->send_ext_req (lookat => $x, $y, sub {
1383 my (%msg) = @_; 1407 my (%msg) = @_;
1384 1408
1385 if (exists $msg{npc_dialog}) { 1409 if (exists $msg{npc_dialog}) {
1386 # start npc chat dialog 1410 # start npc chat dialog
1387 $self->{npc_dialog} = new DC::NPCDialog:: 1411 $self->{w}{npc_dialog} = new DC::NPCDialog::
1388 token => $msg{npc_dialog}, 1412 token => $msg{npc_dialog},
1389 title => "$msg{npc_dialog}[0] (NPC)", 1413 title => "$msg{npc_dialog}[0] (NPC)",
1390 conn => $self, 1414 conn => $self,
1391 ; 1415 ;
1392 } 1416 }
1397} 1421}
1398 1422
1399sub destroy { 1423sub destroy {
1400 my ($self) = @_; 1424 my ($self) = @_;
1401 1425
1402 (delete $self->{npc_dialog})->destroy 1426 $_->destroy
1403 if $self->{npc_dialog}; 1427 for values %{ $self->{w} };
1404 1428
1405 $self->SUPER::destroy; 1429 $self->SUPER::destroy;
1406 1430
1407 %$self = (); 1431 %$self = ();
1408} 1432}
1544} 1568}
1545 1569
1546sub send { 1570sub send {
1547 my ($self, $msg) = @_; 1571 my ($self, $msg) = @_;
1548 1572
1549 $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 });
1550 $self->{textview}->scroll_to_bottom; 1579 $self->{textview}->scroll_to_bottom;
1551 1580
1552 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1581 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1553} 1582}
1554 1583
1557 1586
1558 #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
1559 1588
1560 if ($self->{conn}) { 1589 if ($self->{conn}) {
1561 $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};
1562 delete $self->{conn}{npc_dialog}; 1591 delete $self->{conn}{w}{npc_dialog};
1563 $self->{conn}->disconnect_ext ($self->{id}); 1592 $self->{conn}->disconnect_ext ($self->{id});
1564 } 1593 }
1565 1594
1566 $self->SUPER::destroy; 1595 $self->SUPER::destroy;
1567} 1596}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines