… | |
… | |
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 CFClient::UI; |
9 | use CFClient::UI; |
9 | |
10 | |
10 | use base 'Crossfire::Protocol::Base'; |
11 | use base 'Crossfire::Protocol::Base'; |
11 | |
12 | |
12 | sub new { |
13 | sub new { |
… | |
… | |
14 | |
15 | |
15 | my $self = $class->SUPER::new (@_); |
16 | my $self = $class->SUPER::new (@_); |
16 | |
17 | |
17 | $self->{map_widget}->clr_commands; |
18 | $self->{map_widget}->clr_commands; |
18 | |
19 | |
19 | my $parser = new Pod::POM; |
20 | my $cmd_help = CFClient::load_pod CFClient::find_rcfile "pod/command_help.pod", command_help => 1, sub { |
20 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/command_help.pod"); |
21 | my ($pom) = @_; |
21 | |
22 | |
|
|
23 | my @cmd_help; |
|
|
24 | |
22 | for my $head2 ($pod->head1->[-2]->head2) { |
25 | for my $head2 ($pom->head1->[-2]->head2) { |
23 | $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
26 | $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
24 | or next; |
27 | or next; |
25 | |
28 | |
26 | my $cmd = $1; |
29 | my $cmd = $1; |
27 | my @args = split /\|/, $2; |
30 | my @args = split /\|/, $2; |
28 | @args = (".*") unless @args; |
31 | @args = (".*") unless @args; |
29 | |
32 | |
|
|
33 | $_ = $_ eq ".*" ? "" : " $_" |
|
|
34 | for @args; |
|
|
35 | |
30 | my $text = CFClient::pod_to_pango $head2->content; |
36 | my $text = CFClient::pod_to_pango $head2->content; |
31 | |
37 | |
32 | for my $arg (@args) { |
38 | push @cmd_help, ["$cmd$_", $text] |
33 | $arg = $arg eq ".*" ? "" : " $arg"; |
39 | for sort { (length $a) <=> (length $b) } |
34 | |
40 | @args; |
35 | $self->{map_widget}->add_command ("$cmd$arg", $text); |
|
|
36 | } |
41 | } |
|
|
42 | |
|
|
43 | \@cmd_help |
37 | } |
44 | }; |
|
|
45 | |
|
|
46 | $self->{map_widget}->add_command (@$_) |
|
|
47 | for @$cmd_help; |
38 | |
48 | |
39 | $self->{noface} = new_from_file CFClient::Texture |
49 | $self->{noface} = new_from_file CFClient::Texture |
40 | CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; |
50 | CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; |
41 | |
51 | |
42 | $self->{open_container} = 0; |
52 | $self->{open_container} = 0; |
… | |
… | |
65 | } |
75 | } |
66 | |
76 | |
67 | sub user_send { |
77 | sub user_send { |
68 | my ($self, $command) = @_; |
78 | my ($self, $command) = @_; |
69 | |
79 | |
|
|
80 | if ($self->{record}) { |
|
|
81 | push @{$self->{record}}, $command; |
|
|
82 | } |
|
|
83 | |
70 | $self->send_command ($command); |
84 | $self->send_command ($command); |
71 | ::status $command; |
85 | ::status $command; |
|
|
86 | } |
|
|
87 | |
|
|
88 | sub start_record { |
|
|
89 | my ($self) = @_; |
|
|
90 | |
|
|
91 | $self->{record} = []; |
|
|
92 | } |
|
|
93 | |
|
|
94 | sub stop_record { |
|
|
95 | my ($self) = @_; |
|
|
96 | return delete $self->{record}; |
72 | } |
97 | } |
73 | |
98 | |
74 | sub map_scroll { |
99 | sub map_scroll { |
75 | my ($self, $dx, $dy) = @_; |
100 | my ($self, $dx, $dy) = @_; |
76 | |
101 | |
… | |
… | |
252 | unless ($id) { |
277 | unless ($id) { |
253 | # create new id for face |
278 | # create new id for face |
254 | # I love transactions |
279 | # I love transactions |
255 | for (1..100) { |
280 | for (1..100) { |
256 | my $txn = $CFClient::DB_ENV->txn_begin; |
281 | my $txn = $CFClient::DB_ENV->txn_begin; |
257 | my $status = $self->{facemap}->db_get (id => $id, BerkeleyDB::DB_RMW); |
282 | my $status = $self->{facemap}->db_get (id => $id); |
258 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
283 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
259 | $id = ($id || 16) + 1; |
284 | $id = ($id || 16) + 1; |
260 | if ($self->{facemap}->put (id => $id) == 0 |
285 | if ($self->{facemap}->put (id => $id) == 0 |
261 | && $self->{facemap}->put ($hash => $id) == 0) { |
286 | && $self->{facemap}->put ($hash => $id) == 0) { |
262 | $txn->txn_commit; |
287 | $txn->txn_commit; |
263 | |
288 | |
264 | goto gotid; |
289 | goto gotid; |
265 | } |
290 | } |
266 | } |
291 | } |
267 | $txn->abort; |
292 | $txn->txn_abort; |
268 | } |
293 | } |
269 | |
294 | |
270 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
295 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
271 | } |
296 | } |
272 | |
297 | |
… | |
… | |
322 | my ($self, $flags, $prompt) = @_; |
347 | my ($self, $flags, $prompt) = @_; |
323 | |
348 | |
324 | $prompt = $LAST_QUERY unless length $prompt; |
349 | $prompt = $LAST_QUERY unless length $prompt; |
325 | $LAST_QUERY = $prompt; |
350 | $LAST_QUERY = $prompt; |
326 | |
351 | |
327 | my $dialog = new CFClient::UI::FancyFrame |
352 | $self->{query}-> ($self, $flags, $prompt); |
328 | title => "Query", |
|
|
329 | child => my $vbox = new CFClient::UI::VBox; |
|
|
330 | |
|
|
331 | $vbox->add (new CFClient::UI::Label |
|
|
332 | max_w => $::WIDTH * 0.4, |
|
|
333 | ellipsise => 0, |
|
|
334 | text => $prompt); |
|
|
335 | |
|
|
336 | if ($flags & CS_QUERY_YESNO) { |
|
|
337 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
|
|
338 | $hbox->add (new CFClient::UI::Button |
|
|
339 | text => "No", |
|
|
340 | connect_activate => sub { |
|
|
341 | $self->send ("reply n"); |
|
|
342 | $dialog->destroy; |
|
|
343 | $self->{map_widget}->focus_in; |
|
|
344 | } |
|
|
345 | ); |
|
|
346 | $hbox->add (new CFClient::UI::Button |
|
|
347 | text => "Yes", |
|
|
348 | connect_activate => sub { |
|
|
349 | $self->send ("reply y"); |
|
|
350 | $dialog->destroy; |
|
|
351 | }, |
|
|
352 | ); |
|
|
353 | |
|
|
354 | $dialog->focus_in; |
|
|
355 | |
|
|
356 | } elsif ($flags & CS_QUERY_SINGLECHAR) { |
|
|
357 | $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)"; |
|
|
358 | $vbox->add (my $entry = new CFClient::UI::Entry |
|
|
359 | connect_changed => sub { |
|
|
360 | $self->send ("reply $_[1]"); |
|
|
361 | $dialog->destroy; |
|
|
362 | }, |
|
|
363 | ); |
|
|
364 | |
|
|
365 | $entry->focus_in; |
|
|
366 | |
|
|
367 | } else { |
|
|
368 | $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)"; |
|
|
369 | |
|
|
370 | $vbox->add (my $entry = new CFClient::UI::Entry |
|
|
371 | $flags & CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), |
|
|
372 | connect_activate => sub { |
|
|
373 | $self->send ("reply $_[1]"); |
|
|
374 | $dialog->destroy; |
|
|
375 | }, |
|
|
376 | ); |
|
|
377 | |
|
|
378 | $entry->focus_in; |
|
|
379 | } |
|
|
380 | |
|
|
381 | $dialog->show_centered; |
|
|
382 | } |
353 | } |
383 | |
354 | |
384 | sub drawinfo { |
355 | sub drawinfo { |
385 | my ($self, $color, $text) = @_; |
356 | my ($self, $color, $text) = @_; |
386 | |
357 | |
… | |
… | |
400 | [0.74, 0.65, 0.41], |
371 | [0.74, 0.65, 0.41], |
401 | ); |
372 | ); |
402 | |
373 | |
403 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
374 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
404 | |
375 | |
|
|
376 | # try to create single paragraphs of multiple lines sent by the server |
|
|
377 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
378 | |
405 | $text = CFClient::UI::Label::escape $text; |
379 | $text = CFClient::UI::Label::escape $text; |
406 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
380 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
407 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
381 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
408 | |
382 | |
409 | $self->{logview}->add_paragraph ($color[$color], |
383 | $self->{logview}->add_paragraph ($color[$color], |
410 | join "\n", map "$time $_", split /\n/, $text); |
384 | join "\n", map "$time $_", split /\n/, $text); |
411 | |
385 | |
412 | $self->{statusbox}->add ($text, |
386 | $self->{statusbox}->add ($text, |
413 | group => $text, |
387 | group => $text, |
414 | fg => $color[$color], |
388 | fg => $color[$color], |
415 | timeout => 10, |
389 | timeout => $color >= 2 ? 60 : 10, |
416 | tooltip_font => $::FONT_FIXED, |
390 | tooltip_font => $::FONT_FIXED, |
417 | ); |
391 | ); |
418 | } |
392 | } |
419 | |
393 | |
420 | sub drawextinfo { |
394 | sub drawextinfo { |
… | |
… | |
424 | } |
398 | } |
425 | |
399 | |
426 | sub spell_add { |
400 | sub spell_add { |
427 | my ($self, $spell) = @_; |
401 | my ($self, $spell) = @_; |
428 | |
402 | |
429 | # TODO |
403 | # try to create single paragraphs of multiple lines sent by the server |
430 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
404 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
405 | $spell->{message} =~ s/\n+$//; |
|
|
406 | $spell->{message} ||= "Server did not provide a description for this spell."; |
|
|
407 | |
|
|
408 | $::SETUP_SPELLS->add_spell ($spell); |
|
|
409 | |
431 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
410 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
432 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
411 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
433 | } |
412 | } |
434 | |
413 | |
435 | sub spell_delete { |
414 | sub spell_delete { |
436 | my ($self, $spell) = @_; |
415 | my ($self, $spell) = @_; |
|
|
416 | $::SETUP_SPELLS->remove_spell ($spell); |
437 | } |
417 | } |
438 | |
418 | |
439 | sub addme_success { |
419 | sub addme_success { |
440 | my ($self) = @_; |
420 | my ($self) = @_; |
441 | |
421 | |
442 | $self->send ("command output-sync $::CFG->{output_sync}"); |
422 | my $skill_help = CFClient::load_pod CFClient::find_rcfile "pod/skill_help.pod", skill_help => 1, sub { |
443 | $self->send ("command output-count $::CFG->{output_count}"); |
423 | my ($pom) = @_; |
444 | |
424 | |
445 | my $parser = new Pod::POM; |
|
|
446 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod"); |
|
|
447 | |
|
|
448 | my %skill_tooltip; |
425 | my %skill_help; |
449 | |
426 | |
450 | for my $head2 ($pod->head1->[-2]->head2) { |
427 | for my $head2 ($pom->head1->[3]->head2) { |
451 | $skill_tooltip{$head2->title} = CFClient::pod_to_pango $head2->content; |
428 | $skill_help{$head2->title} = CFClient::pod_to_pango $head2->content; |
|
|
429 | } |
|
|
430 | |
|
|
431 | \%skill_help |
452 | } |
432 | }; |
453 | |
433 | |
454 | for my $skill (values %{$self->{skill_info}}) { |
434 | for my $skill (values %{$self->{skill_info}}) { |
455 | $self->{map_widget}->add_command ("ready_skill $skill", |
435 | $self->{map_widget}->add_command ("ready_skill $skill", |
456 | (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
436 | (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
457 | . $skill_tooltip{$skill}); |
437 | . $skill_help->{$skill}); |
458 | $self->{map_widget}->add_command ("use_skill $skill", |
438 | $self->{map_widget}->add_command ("use_skill $skill", |
459 | (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
439 | (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
460 | . $skill_tooltip{$skill}); |
440 | . $skill_help->{$skill}); |
461 | } |
441 | } |
462 | } |
442 | } |
463 | |
443 | |
464 | sub eof { |
444 | sub eof { |
465 | my ($self) = @_; |
445 | my ($self) = @_; |
… | |
… | |
490 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
470 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
491 | |
471 | |
492 | $self->send ("requestinfo image_sums $face $face"); |
472 | $self->send ("requestinfo image_sums $face $face"); |
493 | |
473 | |
494 | $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
474 | $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
495 | group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); |
475 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
496 | } elsif (!exists $self->{num_faces}) { |
476 | } elsif (!exists $self->{num_faces}) { |
497 | $self->send ("requestinfo image_info"); |
477 | $self->send ("requestinfo image_info"); |
498 | |
478 | |
499 | $self->{num_faces} = 0; |
479 | $self->{num_faces} = 0; |
500 | |
480 | |
501 | $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
481 | $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
502 | group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); |
482 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
503 | } |
483 | } |
504 | } |
484 | } |
505 | |
485 | |
506 | sub update_floorbox { |
486 | sub update_floorbox { |
507 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
487 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
… | |
… | |
509 | |
489 | |
510 | $::FLOORBOX->clear; |
490 | $::FLOORBOX->clear; |
511 | |
491 | |
512 | my $row; |
492 | my $row; |
513 | for (@{ $::CONN->{container}{0} }) { |
493 | for (@{ $::CONN->{container}{0} }) { |
514 | if ($row < 7) { |
494 | if ($row < 6) { |
515 | local $_->{face_widget}; # hack to force recreation of widget |
495 | local $_->{face_widget}; # hack to force recreation of widget |
516 | local $_->{desc_widget}; # hack to force recreation of widget |
496 | local $_->{desc_widget}; # hack to force recreation of widget |
517 | CFClient::Item::update_widgets $_; |
497 | CFClient::Item::update_widgets $_; |
518 | |
498 | |
519 | $::FLOORBOX->add (0, $row, $_->{face_widget}); |
499 | $::FLOORBOX->add (0, $row, $_->{face_widget}); |
520 | $::FLOORBOX->add (1, $row, $_->{desc_widget}); |
500 | $::FLOORBOX->add (1, $row, $_->{desc_widget}); |
521 | |
501 | |
522 | $row++; |
502 | $row++; |
523 | } else { |
503 | } else { |
524 | $::FLOORBOX->add (1, $row, new CFClient::UI::Label text => "More..."); |
504 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
|
|
505 | text => "More...", |
|
|
506 | on_activate => sub { $::INV_WINDOW->toggle_visibility }, |
|
|
507 | ); |
525 | last; |
508 | last; |
526 | } |
509 | } |
527 | } |
510 | } |
528 | }); |
511 | }); |
529 | |
512 | |
… | |
… | |
531 | } |
514 | } |
532 | |
515 | |
533 | sub set_opencont { |
516 | sub set_opencont { |
534 | my ($conn, $tag, $name) = @_; |
517 | my ($conn, $tag, $name) = @_; |
535 | $conn->{open_container} = $tag; |
518 | $conn->{open_container} = $tag; |
536 | $::INVR_LBL->set_text ($name); |
519 | |
|
|
520 | $::INV_RIGHT_HB->clear (); |
|
|
521 | $::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name); |
|
|
522 | |
|
|
523 | if ($tag != 0) { # Floor isn't closable, is it? |
|
|
524 | $::INV_RIGHT_HB->add (new CFClient::UI::Button |
|
|
525 | text => "Close container", |
|
|
526 | tooltip => "Close the currently open container (if one is open)", |
|
|
527 | on_activate => sub { |
|
|
528 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
|
|
529 | if $tag != 0; |
|
|
530 | #if $CONN->{open_container} != 0; |
|
|
531 | }, |
|
|
532 | ); |
|
|
533 | } |
|
|
534 | |
537 | $::INVR->set_items ($conn->{container}{$tag}); |
535 | $::INVR->set_items ($conn->{container}{$tag}); |
538 | } |
536 | } |
539 | |
537 | |
540 | sub update_container { |
538 | sub update_container { |
541 | my ($tag) = @_; |
539 | my ($tag) = @_; |
… | |
… | |
570 | if ($tag == 0) { |
568 | if ($tag == 0) { |
571 | update_floorbox; |
569 | update_floorbox; |
572 | update_container (0); |
570 | update_container (0); |
573 | } elsif ($tag == $self->{player}{tag}) { |
571 | } elsif ($tag == $self->{player}{tag}) { |
574 | $::INV->set_items ($self->{container}{$tag}) |
572 | $::INV->set_items ($self->{container}{$tag}) |
|
|
573 | } else { |
|
|
574 | update_container ($tag); |
575 | } |
575 | } |
576 | |
576 | |
577 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
577 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
578 | } |
578 | } |
579 | |
579 | |
… | |
… | |
587 | update_floorbox; |
587 | update_floorbox; |
588 | update_container ($_->{tag}); |
588 | update_container ($_->{tag}); |
589 | } elsif ($_->{container} == $self->{player}{tag}) { |
589 | } elsif ($_->{container} == $self->{player}{tag}) { |
590 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
590 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
591 | } else { |
591 | } else { |
592 | update_container ($_->{tag}); |
592 | update_container ($_->{container}); |
593 | } |
593 | } |
594 | } |
594 | } |
595 | } |
595 | } |
596 | |
596 | |
597 | sub item_update { |
597 | sub item_update { |
… | |
… | |
621 | } |
621 | } |
622 | } |
622 | } |
623 | |
623 | |
624 | sub player_update { |
624 | sub player_update { |
625 | my ($self, $player) = @_; |
625 | my ($self, $player) = @_; |
|
|
626 | |
626 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
627 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
627 | } |
628 | } |
628 | |
629 | |
|
|
630 | sub logged_in { |
|
|
631 | my ($self) = @_; |
|
|
632 | |
|
|
633 | $self->send_ext_req (cfplus => "version", "1", sub { |
|
|
634 | $self->{cfplus_ext} = $_[0]; |
|
|
635 | }); |
|
|
636 | |
|
|
637 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
|
|
638 | $self->send_command ("output-count $::CFG->{output_count}"); |
|
|
639 | $self->send_command ("pickup $::CFG->{pickup}"); |
|
|
640 | |
|
|
641 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
|
|
642 | |
|
|
643 | $::SERVER_INFO->set_markup ( |
|
|
644 | "server name:port <tt>$self->{host}:$self->{port}</tt>\n" |
|
|
645 | . "protocol version <tt>$self->{version}</tt>\n" |
|
|
646 | . "mapinfo support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
647 | . "extcmd support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
648 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]\n" |
|
|
649 | ); |
|
|
650 | } |
|
|
651 | |
629 | 1; |
652 | 1; |