… | |
… | |
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 | |
30 | $_ = $_ eq ".*" ? "" : " $_" |
33 | $_ = $_ eq ".*" ? "" : " $_" |
31 | for @args; |
34 | for @args; |
32 | |
35 | |
33 | my $text = CFClient::pod_to_pango $head2->content; |
36 | my $text = CFClient::pod_to_pango $head2->content; |
34 | |
37 | |
35 | $self->{map_widget}->add_command ("$cmd$_", $text) |
38 | push @cmd_help, ["$cmd$_", $text] |
36 | for sort { (length $a) <=> (length $b) } |
39 | for sort { (length $a) <=> (length $b) } |
37 | @args; |
40 | @args; |
|
|
41 | } |
|
|
42 | |
|
|
43 | \@cmd_help |
38 | } |
44 | }; |
|
|
45 | |
|
|
46 | $self->{map_widget}->add_command (@$_) |
|
|
47 | for @$cmd_help; |
39 | |
48 | |
40 | $self->{noface} = new_from_file CFClient::Texture |
49 | $self->{noface} = new_from_file CFClient::Texture |
41 | CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; |
50 | CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; |
42 | |
51 | |
43 | $self->{open_container} = 0; |
52 | $self->{open_container} = 0; |
… | |
… | |
66 | } |
75 | } |
67 | |
76 | |
68 | sub user_send { |
77 | sub user_send { |
69 | my ($self, $command) = @_; |
78 | my ($self, $command) = @_; |
70 | |
79 | |
|
|
80 | if ($self->{record}) { |
|
|
81 | push @{$self->{record}}, $command; |
|
|
82 | } |
|
|
83 | |
71 | $self->send_command ($command); |
84 | $self->send_command ($command); |
72 | ::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}; |
73 | } |
97 | } |
74 | |
98 | |
75 | sub map_scroll { |
99 | sub map_scroll { |
76 | my ($self, $dx, $dy) = @_; |
100 | my ($self, $dx, $dy) = @_; |
77 | |
101 | |
… | |
… | |
253 | unless ($id) { |
277 | unless ($id) { |
254 | # create new id for face |
278 | # create new id for face |
255 | # I love transactions |
279 | # I love transactions |
256 | for (1..100) { |
280 | for (1..100) { |
257 | my $txn = $CFClient::DB_ENV->txn_begin; |
281 | my $txn = $CFClient::DB_ENV->txn_begin; |
258 | my $status = $self->{facemap}->db_get (id => $id, BerkeleyDB::DB_RMW); |
282 | my $status = $self->{facemap}->db_get (id => $id); |
259 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
283 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
260 | $id = ($id || 16) + 1; |
284 | $id = ($id || 16) + 1; |
261 | if ($self->{facemap}->put (id => $id) == 0 |
285 | if ($self->{facemap}->put (id => $id) == 0 |
262 | && $self->{facemap}->put ($hash => $id) == 0) { |
286 | && $self->{facemap}->put ($hash => $id) == 0) { |
263 | $txn->txn_commit; |
287 | $txn->txn_commit; |
264 | |
288 | |
265 | goto gotid; |
289 | goto gotid; |
266 | } |
290 | } |
267 | } |
291 | } |
268 | $txn->abort; |
292 | $txn->txn_abort; |
269 | } |
293 | } |
270 | |
294 | |
271 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
295 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
272 | } |
296 | } |
273 | |
297 | |
… | |
… | |
323 | my ($self, $flags, $prompt) = @_; |
347 | my ($self, $flags, $prompt) = @_; |
324 | |
348 | |
325 | $prompt = $LAST_QUERY unless length $prompt; |
349 | $prompt = $LAST_QUERY unless length $prompt; |
326 | $LAST_QUERY = $prompt; |
350 | $LAST_QUERY = $prompt; |
327 | |
351 | |
328 | my $dialog = new CFClient::UI::FancyFrame |
352 | $self->{query}-> ($self, $flags, $prompt); |
329 | title => "Query", |
|
|
330 | child => my $vbox = new CFClient::UI::VBox; |
|
|
331 | |
|
|
332 | $vbox->add (new CFClient::UI::Label |
|
|
333 | max_w => $::WIDTH * 0.4, |
|
|
334 | ellipsise => 0, |
|
|
335 | text => $prompt); |
|
|
336 | |
|
|
337 | if ($flags & CS_QUERY_YESNO) { |
|
|
338 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
|
|
339 | $hbox->add (new CFClient::UI::Button |
|
|
340 | text => "No", |
|
|
341 | connect_activate => sub { |
|
|
342 | $self->send ("reply n"); |
|
|
343 | $dialog->destroy; |
|
|
344 | $self->{map_widget}->focus_in; |
|
|
345 | } |
|
|
346 | ); |
|
|
347 | $hbox->add (new CFClient::UI::Button |
|
|
348 | text => "Yes", |
|
|
349 | connect_activate => sub { |
|
|
350 | $self->send ("reply y"); |
|
|
351 | $dialog->destroy; |
|
|
352 | }, |
|
|
353 | ); |
|
|
354 | |
|
|
355 | $dialog->focus_in; |
|
|
356 | |
|
|
357 | } elsif ($flags & CS_QUERY_SINGLECHAR) { |
|
|
358 | $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)"; |
|
|
359 | $vbox->add (my $entry = new CFClient::UI::Entry |
|
|
360 | connect_changed => sub { |
|
|
361 | $self->send ("reply $_[1]"); |
|
|
362 | $dialog->destroy; |
|
|
363 | }, |
|
|
364 | ); |
|
|
365 | |
|
|
366 | $entry->focus_in; |
|
|
367 | |
|
|
368 | } else { |
|
|
369 | $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)"; |
|
|
370 | |
|
|
371 | $vbox->add (my $entry = new CFClient::UI::Entry |
|
|
372 | $flags & CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), |
|
|
373 | connect_activate => sub { |
|
|
374 | $self->send ("reply $_[1]"); |
|
|
375 | $dialog->destroy; |
|
|
376 | }, |
|
|
377 | ); |
|
|
378 | |
|
|
379 | $entry->focus_in; |
|
|
380 | } |
|
|
381 | |
|
|
382 | $dialog->show_centered; |
|
|
383 | } |
353 | } |
384 | |
354 | |
385 | sub drawinfo { |
355 | sub drawinfo { |
386 | my ($self, $color, $text) = @_; |
356 | my ($self, $color, $text) = @_; |
387 | |
357 | |
… | |
… | |
411 | join "\n", map "$time $_", split /\n/, $text); |
381 | join "\n", map "$time $_", split /\n/, $text); |
412 | |
382 | |
413 | $self->{statusbox}->add ($text, |
383 | $self->{statusbox}->add ($text, |
414 | group => $text, |
384 | group => $text, |
415 | fg => $color[$color], |
385 | fg => $color[$color], |
416 | timeout => 10, |
386 | timeout => $color >= 2 ? 60 : 10, |
417 | tooltip_font => $::FONT_FIXED, |
387 | tooltip_font => $::FONT_FIXED, |
418 | ); |
388 | ); |
419 | } |
389 | } |
420 | |
390 | |
421 | sub drawextinfo { |
391 | sub drawextinfo { |
… | |
… | |
427 | sub spell_add { |
397 | sub spell_add { |
428 | my ($self, $spell) = @_; |
398 | my ($self, $spell) = @_; |
429 | |
399 | |
430 | # TODO |
400 | # TODO |
431 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
401 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
|
|
402 | $::SETUP_SPELLS->add_spell ($spell); |
|
|
403 | |
432 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
404 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
433 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
405 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
434 | } |
406 | } |
435 | |
407 | |
436 | sub spell_delete { |
408 | sub spell_delete { |
437 | my ($self, $spell) = @_; |
409 | my ($self, $spell) = @_; |
|
|
410 | $::SETUP_SPELLS->remove_spell ($spell); |
438 | } |
411 | } |
439 | |
412 | |
440 | sub addme_success { |
413 | sub addme_success { |
441 | my ($self) = @_; |
414 | my ($self) = @_; |
442 | |
415 | |
443 | $self->send ("command output-sync $::CFG->{output_sync}"); |
416 | my $skill_help = CFClient::load_pod CFClient::find_rcfile "pod/skill_help.pod", skill_help => 1, sub { |
444 | $self->send ("command output-count $::CFG->{output_count}"); |
417 | my ($pom) = @_; |
445 | |
418 | |
446 | my $parser = new Pod::POM; |
|
|
447 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod"); |
|
|
448 | |
|
|
449 | my %skill_tooltip; |
419 | my %skill_help; |
450 | |
420 | |
451 | for my $head2 ($pod->head1->[-2]->head2) { |
421 | for my $head2 ($pom->head1->[3]->head2) { |
452 | $skill_tooltip{$head2->title} = CFClient::pod_to_pango $head2->content; |
422 | $skill_help{$head2->title} = CFClient::pod_to_pango $head2->content; |
|
|
423 | } |
|
|
424 | |
|
|
425 | \%skill_help |
453 | } |
426 | }; |
454 | |
427 | |
455 | for my $skill (values %{$self->{skill_info}}) { |
428 | for my $skill (values %{$self->{skill_info}}) { |
456 | $self->{map_widget}->add_command ("ready_skill $skill", |
429 | $self->{map_widget}->add_command ("ready_skill $skill", |
457 | (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
430 | (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
458 | . $skill_tooltip{$skill}); |
431 | . $skill_help->{$skill}); |
459 | $self->{map_widget}->add_command ("use_skill $skill", |
432 | $self->{map_widget}->add_command ("use_skill $skill", |
460 | (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
433 | (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
461 | . $skill_tooltip{$skill}); |
434 | . $skill_help->{$skill}); |
462 | } |
435 | } |
463 | } |
436 | } |
464 | |
437 | |
465 | sub eof { |
438 | sub eof { |
466 | my ($self) = @_; |
439 | my ($self) = @_; |
… | |
… | |
491 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
464 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
492 | |
465 | |
493 | $self->send ("requestinfo image_sums $face $face"); |
466 | $self->send ("requestinfo image_sums $face $face"); |
494 | |
467 | |
495 | $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
468 | $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
496 | group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); |
469 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
497 | } elsif (!exists $self->{num_faces}) { |
470 | } elsif (!exists $self->{num_faces}) { |
498 | $self->send ("requestinfo image_info"); |
471 | $self->send ("requestinfo image_info"); |
499 | |
472 | |
500 | $self->{num_faces} = 0; |
473 | $self->{num_faces} = 0; |
501 | |
474 | |
502 | $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
475 | $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
503 | group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); |
476 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
504 | } |
477 | } |
505 | } |
478 | } |
506 | |
479 | |
507 | sub update_floorbox { |
480 | sub update_floorbox { |
508 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
481 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
… | |
… | |
532 | } |
505 | } |
533 | |
506 | |
534 | sub set_opencont { |
507 | sub set_opencont { |
535 | my ($conn, $tag, $name) = @_; |
508 | my ($conn, $tag, $name) = @_; |
536 | $conn->{open_container} = $tag; |
509 | $conn->{open_container} = $tag; |
537 | $::INVR_LBL->set_text ($name); |
510 | |
|
|
511 | $::INV_RIGHT_HB->clear (); |
|
|
512 | $::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name); |
|
|
513 | |
|
|
514 | if ($tag != 0) { # Floor isn't closable, is it? |
|
|
515 | $::INV_RIGHT_HB->add (new CFClient::UI::Button |
|
|
516 | text => "Close container", |
|
|
517 | tooltip => "Close the currently open container (if one is open)", |
|
|
518 | on_activate => sub { |
|
|
519 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
|
|
520 | if $tag != 0; |
|
|
521 | #if $CONN->{open_container} != 0; |
|
|
522 | }, |
|
|
523 | ); |
|
|
524 | } |
|
|
525 | |
538 | $::INVR->set_items ($conn->{container}{$tag}); |
526 | $::INVR->set_items ($conn->{container}{$tag}); |
539 | } |
527 | } |
540 | |
528 | |
541 | sub update_container { |
529 | sub update_container { |
542 | my ($tag) = @_; |
530 | my ($tag) = @_; |
… | |
… | |
571 | if ($tag == 0) { |
559 | if ($tag == 0) { |
572 | update_floorbox; |
560 | update_floorbox; |
573 | update_container (0); |
561 | update_container (0); |
574 | } elsif ($tag == $self->{player}{tag}) { |
562 | } elsif ($tag == $self->{player}{tag}) { |
575 | $::INV->set_items ($self->{container}{$tag}) |
563 | $::INV->set_items ($self->{container}{$tag}) |
|
|
564 | } else { |
|
|
565 | update_container ($tag); |
576 | } |
566 | } |
577 | |
567 | |
578 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
568 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
579 | } |
569 | } |
580 | |
570 | |
… | |
… | |
588 | update_floorbox; |
578 | update_floorbox; |
589 | update_container ($_->{tag}); |
579 | update_container ($_->{tag}); |
590 | } elsif ($_->{container} == $self->{player}{tag}) { |
580 | } elsif ($_->{container} == $self->{player}{tag}) { |
591 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
581 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
592 | } else { |
582 | } else { |
593 | update_container ($_->{tag}); |
583 | update_container ($_->{container}); |
594 | } |
584 | } |
595 | } |
585 | } |
596 | } |
586 | } |
597 | |
587 | |
598 | sub item_update { |
588 | sub item_update { |
… | |
… | |
623 | } |
613 | } |
624 | |
614 | |
625 | sub player_update { |
615 | sub player_update { |
626 | my ($self, $player) = @_; |
616 | my ($self, $player) = @_; |
627 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
617 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
|
|
618 | |
|
|
619 | # do it here because it is ignored earlier, and there is no "login" event |
|
|
620 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
|
|
621 | $self->send_command ("output-count $::CFG->{output_count}"); |
628 | } |
622 | } |
629 | |
623 | |
630 | 1; |
624 | 1; |