… | |
… | |
48 | sort { (length $a) <=> (length $b) } |
48 | sort { (length $a) <=> (length $b) } |
49 | @args |
49 | @args |
50 | } sort { $a->{par} <=> $b->{par} } |
50 | } sort { $a->{par} <=> $b->{par} } |
51 | CFPlus::Pod::find command => "*"; |
51 | CFPlus::Pod::find command => "*"; |
52 | |
52 | |
53 | $self->connect_ext (event_music => sub { |
53 | $self->connect_ext (music => sub { |
54 | my ($ev) = @_; |
54 | my (%ev) = @_; |
55 | |
55 | |
56 | return unless $::CFG->{bgm_enable}; |
56 | return unless $::CFG->{bgm_enable}; |
57 | |
57 | |
58 | my $faces = $ev->{faces}; |
58 | my $faces = $ev{faces}; |
59 | my @songs; |
59 | my @songs; |
60 | |
60 | |
61 | # request music from server if appropriate |
61 | # request music from server if appropriate |
62 | if (my $faces = $ev->{faces}) { |
62 | if (my $faces = $ev{faces}) { |
63 | for (@$faces) { |
63 | for (@$faces) { |
64 | my ($face, $pri, $chksum) = @$_; |
64 | my ($face, $pri, $chksum) = @$_; |
65 | utf8::downgrade $chksum; |
65 | utf8::downgrade $chksum; |
66 | |
66 | |
67 | $chksum = unpack "H*", $chksum; |
67 | $chksum = unpack "H*", $chksum; |
… | |
… | |
97 | } |
97 | } |
98 | } |
98 | } |
99 | } |
99 | } |
100 | } |
100 | } |
101 | |
101 | |
102 | if (my $play = $ev->{play}) { |
102 | if (my $play = $ev{play}) { |
103 | &::audio_music_set ($self->{songs} = [map $self->{music_map}{$_}, @$play]); |
103 | &::audio_music_set ($self->{songs} = [map $self->{music_map}{$_}, @$play]); |
104 | } |
104 | } |
105 | }); |
105 | }); |
106 | |
106 | |
107 | $self->connect_ext (event_capabilities => sub { |
107 | $self->connect_ext (capabilities => sub { |
108 | my ($cap) = @_; |
108 | my (%cap) = @_; |
109 | |
109 | |
110 | if (my $ts = $cap->{tileset}) { |
110 | if (my $ts = $cap{tileset}) { |
111 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
111 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
112 | $self->{tileset} = $default; |
112 | $self->{tileset} = $default; |
113 | $self->{tilesize} = $default->[3]; |
113 | $self->{tilesize} = $default->[3]; |
114 | $self->setup_req (tileset => $default->[0]); |
114 | $self->setup_req (tileset => $default->[0]); |
115 | |
115 | |
… | |
… | |
1171 | } |
1171 | } |
1172 | |
1172 | |
1173 | sub logged_in { |
1173 | sub logged_in { |
1174 | my ($self) = @_; |
1174 | my ($self) = @_; |
1175 | |
1175 | |
1176 | $self->send_ext_req (cfplus_support => version => 1, sub { |
1176 | $self->send_ext_req (cfplus_support => version => 2, sub { |
|
|
1177 | my (%msg) = @_; |
|
|
1178 | |
1177 | $self->{cfplus_ext} = $_[0]{version}; |
1179 | $self->{cfplus_ext} = $msg{version}; |
1178 | $self->update_server_info; |
1180 | $self->update_server_info; |
1179 | |
1181 | |
1180 | if ($self->{cfplus_ext} >= 2) { |
1182 | if ($self->{cfplus_ext} >= 2) { |
1181 | $self->send_ext_req ("editor_support", sub { |
1183 | $self->send_ext_req ("editor_support", sub { |
1182 | $self->{editor_support} = $_[0]; |
1184 | $self->{editor_support} = { @_ }; |
1183 | $self->update_server_info; |
1185 | $self->update_server_info; |
1184 | |
1186 | |
1185 | 0 |
1187 | 0 |
1186 | }); |
1188 | }); |
1187 | } |
1189 | } |
… | |
… | |
1207 | |
1209 | |
1208 | sub lookat { |
1210 | sub lookat { |
1209 | my ($self, $x, $y) = @_; |
1211 | my ($self, $x, $y) = @_; |
1210 | |
1212 | |
1211 | if ($self->{cfplus_ext}) { |
1213 | if ($self->{cfplus_ext}) { |
1212 | $self->send_ext_req (lookat => dx => $x, dy => $y, sub { |
1214 | $self->send_ext_req (lookat => $x, $y, sub { |
1213 | my ($msg) = @_; |
1215 | my (%msg) = @_; |
1214 | |
1216 | |
1215 | if (exists $msg->{npc_dialog}) { |
1217 | if (exists $msg{npc_dialog}) { |
1216 | # start npc chat dialog |
1218 | # start npc chat dialog |
1217 | $self->{npc_dialog} = new CFPlus::NPCDialog:: |
1219 | $self->{npc_dialog} = new CFPlus::NPCDialog:: |
1218 | dx => $x, |
1220 | token => $msg{npc_dialog}, |
1219 | dy => $y, |
|
|
1220 | title => "$msg->{npc_dialog} (NPC)", |
1221 | title => "$msg{npc_dialog}[0] (NPC)", |
1221 | conn => $self, |
1222 | conn => $self, |
1222 | ; |
1223 | ; |
1223 | } |
1224 | } |
1224 | }); |
1225 | }); |
1225 | } |
1226 | } |
… | |
… | |
1290 | on_activate => sub { $this->destroy; 1 }, |
1291 | on_activate => sub { $this->destroy; 1 }, |
1291 | ; |
1292 | ; |
1292 | |
1293 | |
1293 | $self->update_options; |
1294 | $self->update_options; |
1294 | |
1295 | |
1295 | $self->{id} = $self->{conn}->send_ext_req ( |
1296 | $self->{id} = "npc-channel-" . $self->{conn}->token; |
1296 | npc_dialog_begin => dx => $self->{dx}, dy => $self->{dy}, |
1297 | $self->{conn}->connect_ext ($self->{id} => sub { |
1297 | sub { $this && $this->feed (@_) } |
1298 | $this->feed (@_) if $this; |
1298 | ); |
1299 | }); |
|
|
1300 | |
|
|
1301 | $self->{conn}->send_ext_msg (npc_dialog_begin => $self->{id}, $self->{token}); |
1299 | |
1302 | |
1300 | $self->{entry}->grab_focus; |
1303 | $self->{entry}->grab_focus; |
1301 | |
1304 | |
1302 | $self->{textview}->add_paragraph ({ |
1305 | $self->{textview}->add_paragraph ({ |
1303 | fg => [1, 1, 0, 1], |
1306 | fg => [1, 1, 0, 1], |
… | |
… | |
1326 | ); |
1329 | ); |
1327 | } |
1330 | } |
1328 | } |
1331 | } |
1329 | |
1332 | |
1330 | sub feed { |
1333 | sub feed { |
1331 | my ($self, $msg) = @_; |
1334 | my ($self, $type, @arg) = @_; |
1332 | |
1335 | |
1333 | CFPlus::weaken $self; |
1336 | CFPlus::weaken $self; |
1334 | |
1337 | |
1335 | if ($msg->{msgtype} eq "reply") { |
1338 | if ($type eq "update") { |
|
|
1339 | my (%info) = @arg; |
|
|
1340 | |
1336 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
1341 | $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; |
1337 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1342 | $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; |
1338 | |
|
|
1339 | my $text = "\n" . CFPlus::Protocol::sanitise_xml $msg->{msg}; |
|
|
1340 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
|
|
1341 | my @link; |
|
|
1342 | $text =~ s{ |
|
|
1343 | ($match) |
|
|
1344 | }{ |
|
|
1345 | my $kw = $1; |
|
|
1346 | |
|
|
1347 | push @link, new CFPlus::UI::Label |
|
|
1348 | markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>", |
|
|
1349 | can_hover => 1, |
|
|
1350 | can_events => 1, |
|
|
1351 | padding_x => 0, |
|
|
1352 | padding_y => 0, |
|
|
1353 | on_button_up => sub { |
|
|
1354 | $self->send ($kw); |
|
|
1355 | }; |
|
|
1356 | |
|
|
1357 | "\x{fffc}" |
|
|
1358 | }giex; |
|
|
1359 | |
1343 | |
|
|
1344 | if (exists $info{msg}) { |
|
|
1345 | my $text = "\n" . CFPlus::Protocol::sanitise_xml $info{msg}; |
|
|
1346 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
|
|
1347 | my @link; |
|
|
1348 | $text =~ s{ |
|
|
1349 | ($match) |
|
|
1350 | }{ |
|
|
1351 | my $kw = $1; |
|
|
1352 | |
|
|
1353 | push @link, new CFPlus::UI::Label |
|
|
1354 | markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>", |
|
|
1355 | can_hover => 1, |
|
|
1356 | can_events => 1, |
|
|
1357 | padding_x => 0, |
|
|
1358 | padding_y => 0, |
|
|
1359 | on_button_up => sub { |
|
|
1360 | $self->send ($kw); |
|
|
1361 | }; |
|
|
1362 | |
|
|
1363 | "\x{fffc}" |
|
|
1364 | }giex; |
|
|
1365 | |
1360 | $self->{textview}->add_paragraph ({ markup => $text, widget => \@link }); |
1366 | $self->{textview}->add_paragraph ({ markup => $text, widget => \@link }); |
1361 | $self->{textview}->scroll_to_bottom; |
1367 | $self->{textview}->scroll_to_bottom; |
|
|
1368 | } |
|
|
1369 | |
1362 | $self->update_options; |
1370 | $self->update_options; |
1363 | } else { |
1371 | } else { |
1364 | $self->destroy; |
1372 | $self->destroy; |
1365 | } |
1373 | } |
1366 | |
1374 | |
… | |
… | |
1371 | my ($self, $msg) = @_; |
1379 | my ($self, $msg) = @_; |
1372 | |
1380 | |
1373 | $self->{textview}->add_paragraph ({ markup => "\n" . CFPlus::asxml $msg }); |
1381 | $self->{textview}->add_paragraph ({ markup => "\n" . CFPlus::asxml $msg }); |
1374 | $self->{textview}->scroll_to_bottom; |
1382 | $self->{textview}->scroll_to_bottom; |
1375 | |
1383 | |
1376 | $self->{conn}->send_ext_msg (npc_dialog_tell => msgid => $self->{id}, msg => $msg); |
1384 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1377 | } |
1385 | } |
1378 | |
1386 | |
1379 | sub destroy { |
1387 | sub destroy { |
1380 | my ($self) = @_; |
1388 | my ($self) = @_; |
1381 | |
1389 | |
1382 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1390 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1383 | |
1391 | |
1384 | if ($self->{conn}) { |
1392 | if ($self->{conn}) { |
1385 | $self->{conn}->send_ext_msg (npc_dialog_end => msgid => $self->{id}) if $self->{id}; |
1393 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1386 | delete $self->{conn}{npc_dialog}; |
1394 | delete $self->{conn}{npc_dialog}; |
1387 | $self->{conn}->disconnect_ext ($self->{id}); |
1395 | $self->{conn}->disconnect_ext ($self->{id}); |
1388 | } |
1396 | } |
1389 | |
1397 | |
1390 | $self->SUPER::destroy; |
1398 | $self->SUPER::destroy; |