… | |
… | |
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 $pod = $parser->parse_file (CFClient::find_rcfile "pod/command_help.pod"); |
20 | my $pod = CFClient::load_pod CFClient::find_rcfile "pod/command_help.pod"; |
21 | |
21 | |
22 | for my $head2 ($pod->head1->[-2]->head2) { |
22 | for my $head2 ($pod->head1->[-2]->head2) { |
23 | $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
23 | $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
24 | or next; |
24 | or next; |
25 | |
25 | |
… | |
… | |
66 | } |
66 | } |
67 | |
67 | |
68 | sub user_send { |
68 | sub user_send { |
69 | my ($self, $command) = @_; |
69 | my ($self, $command) = @_; |
70 | |
70 | |
|
|
71 | if ($self->{record}) { |
|
|
72 | push @{$self->{record}}, $command; |
|
|
73 | } |
|
|
74 | |
71 | $self->send_command ($command); |
75 | $self->send_command ($command); |
72 | ::status $command; |
76 | ::status $command; |
|
|
77 | } |
|
|
78 | |
|
|
79 | sub start_record { |
|
|
80 | my ($self) = @_; |
|
|
81 | |
|
|
82 | $self->{record} = []; |
|
|
83 | } |
|
|
84 | |
|
|
85 | sub stop_record { |
|
|
86 | my ($self) = @_; |
|
|
87 | return delete $self->{record}; |
73 | } |
88 | } |
74 | |
89 | |
75 | sub map_scroll { |
90 | sub map_scroll { |
76 | my ($self, $dx, $dy) = @_; |
91 | my ($self, $dx, $dy) = @_; |
77 | |
92 | |
… | |
… | |
253 | unless ($id) { |
268 | unless ($id) { |
254 | # create new id for face |
269 | # create new id for face |
255 | # I love transactions |
270 | # I love transactions |
256 | for (1..100) { |
271 | for (1..100) { |
257 | my $txn = $CFClient::DB_ENV->txn_begin; |
272 | my $txn = $CFClient::DB_ENV->txn_begin; |
258 | my $status = $self->{facemap}->db_get (id => $id, BerkeleyDB::DB_RMW); |
273 | my $status = $self->{facemap}->db_get (id => $id); |
259 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
274 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
260 | $id = ($id || 16) + 1; |
275 | $id = ($id || 16) + 1; |
261 | if ($self->{facemap}->put (id => $id) == 0 |
276 | if ($self->{facemap}->put (id => $id) == 0 |
262 | && $self->{facemap}->put ($hash => $id) == 0) { |
277 | && $self->{facemap}->put ($hash => $id) == 0) { |
263 | $txn->txn_commit; |
278 | $txn->txn_commit; |
264 | |
279 | |
265 | goto gotid; |
280 | goto gotid; |
266 | } |
281 | } |
267 | } |
282 | } |
268 | $txn->abort; |
283 | $txn->txn_abort; |
269 | } |
284 | } |
270 | |
285 | |
271 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
286 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
272 | } |
287 | } |
273 | |
288 | |
… | |
… | |
324 | |
339 | |
325 | $prompt = $LAST_QUERY unless length $prompt; |
340 | $prompt = $LAST_QUERY unless length $prompt; |
326 | $LAST_QUERY = $prompt; |
341 | $LAST_QUERY = $prompt; |
327 | |
342 | |
328 | my $dialog = new CFClient::UI::FancyFrame |
343 | my $dialog = new CFClient::UI::FancyFrame |
|
|
344 | x => "center", |
|
|
345 | y => "center", |
329 | title => "Query", |
346 | title => "Query", |
330 | child => my $vbox = new CFClient::UI::VBox; |
347 | child => my $vbox = new CFClient::UI::VBox, |
|
|
348 | ; |
331 | |
349 | |
332 | $vbox->add (new CFClient::UI::Label |
350 | $vbox->add (new CFClient::UI::Label |
333 | max_w => $::WIDTH * 0.4, |
351 | max_w => $::WIDTH * 0.4, |
334 | ellipsise => 0, |
352 | ellipsise => 0, |
335 | text => $prompt); |
353 | text => $prompt); |
336 | |
354 | |
337 | if ($flags & CS_QUERY_YESNO) { |
355 | if ($flags & CS_QUERY_YESNO) { |
338 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
356 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
339 | $hbox->add (new CFClient::UI::Button |
357 | $hbox->add (new CFClient::UI::Button |
340 | text => "No", |
358 | text => "No", |
341 | connect_activate => sub { |
359 | on_activate => sub { |
342 | $self->send ("reply n"); |
360 | $self->send ("reply n"); |
343 | $dialog->destroy; |
361 | $dialog->destroy; |
344 | $self->{map_widget}->focus_in; |
362 | $self->{map_widget}->focus_in; |
345 | } |
363 | } |
346 | ); |
364 | ); |
347 | $hbox->add (new CFClient::UI::Button |
365 | $hbox->add (new CFClient::UI::Button |
348 | text => "Yes", |
366 | text => "Yes", |
349 | connect_activate => sub { |
367 | on_activate => sub { |
350 | $self->send ("reply y"); |
368 | $self->send ("reply y"); |
351 | $dialog->destroy; |
369 | $dialog->destroy; |
352 | }, |
370 | }, |
353 | ); |
371 | ); |
354 | |
372 | |
355 | $dialog->focus_in; |
373 | $dialog->focus_in; |
356 | |
374 | |
357 | } elsif ($flags & CS_QUERY_SINGLECHAR) { |
375 | } elsif ($flags & CS_QUERY_SINGLECHAR) { |
358 | $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)"; |
376 | $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 |
377 | $vbox->add (my $entry = new CFClient::UI::Entry |
360 | connect_changed => sub { |
378 | on_changed => sub { |
361 | $self->send ("reply $_[1]"); |
379 | $self->send ("reply $_[1]"); |
362 | $dialog->destroy; |
380 | $dialog->destroy; |
363 | }, |
381 | }, |
364 | ); |
382 | ); |
365 | |
383 | |
… | |
… | |
368 | } else { |
386 | } else { |
369 | $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)"; |
387 | $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)"; |
370 | |
388 | |
371 | $vbox->add (my $entry = new CFClient::UI::Entry |
389 | $vbox->add (my $entry = new CFClient::UI::Entry |
372 | $flags & CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), |
390 | $flags & CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), |
373 | connect_activate => sub { |
391 | on_activate => sub { |
374 | $self->send ("reply $_[1]"); |
392 | $self->send ("reply $_[1]"); |
375 | $dialog->destroy; |
393 | $dialog->destroy; |
376 | }, |
394 | }, |
377 | ); |
395 | ); |
378 | |
396 | |
379 | $entry->focus_in; |
397 | $entry->focus_in; |
380 | } |
398 | } |
381 | |
399 | |
382 | $dialog->show_centered; |
400 | $dialog->show; |
383 | } |
401 | } |
384 | |
402 | |
385 | sub drawinfo { |
403 | sub drawinfo { |
386 | my ($self, $color, $text) = @_; |
404 | my ($self, $color, $text) = @_; |
387 | |
405 | |
… | |
… | |
411 | join "\n", map "$time $_", split /\n/, $text); |
429 | join "\n", map "$time $_", split /\n/, $text); |
412 | |
430 | |
413 | $self->{statusbox}->add ($text, |
431 | $self->{statusbox}->add ($text, |
414 | group => $text, |
432 | group => $text, |
415 | fg => $color[$color], |
433 | fg => $color[$color], |
416 | timeout => 10, |
434 | timeout => $color >= 2 ? 60 : 10, |
417 | tooltip_font => $::FONT_FIXED, |
435 | tooltip_font => $::FONT_FIXED, |
418 | ); |
436 | ); |
419 | } |
437 | } |
420 | |
438 | |
421 | sub drawextinfo { |
439 | sub drawextinfo { |
… | |
… | |
427 | sub spell_add { |
445 | sub spell_add { |
428 | my ($self, $spell) = @_; |
446 | my ($self, $spell) = @_; |
429 | |
447 | |
430 | # TODO |
448 | # TODO |
431 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
449 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
|
|
450 | $::SETUP_SPELLS->add_spell ($spell); |
|
|
451 | |
432 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
452 | $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}); |
453 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
434 | } |
454 | } |
435 | |
455 | |
436 | sub spell_delete { |
456 | sub spell_delete { |
437 | my ($self, $spell) = @_; |
457 | my ($self, $spell) = @_; |
|
|
458 | $::SETUP_SPELLS->remove_spell ($spell); |
438 | } |
459 | } |
439 | |
460 | |
440 | sub addme_success { |
461 | sub addme_success { |
441 | my ($self) = @_; |
462 | my ($self) = @_; |
442 | |
463 | |
443 | $self->send ("command output-sync $::CFG->{output_sync}"); |
464 | my $pod = CFClient::load_pod CFClient::find_rcfile "pod/skill_help.pod"; |
444 | $self->send ("command output-count $::CFG->{output_count}"); |
|
|
445 | |
|
|
446 | my $parser = new Pod::POM; |
|
|
447 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod"); |
|
|
448 | |
465 | |
449 | my %skill_tooltip; |
466 | my %skill_tooltip; |
450 | |
467 | |
451 | for my $head2 ($pod->head1->[-2]->head2) { |
468 | for my $head2 ($pod->head1->[-2]->head2) { |
452 | $skill_tooltip{$head2->title} = CFClient::pod_to_pango $head2->content; |
469 | $skill_tooltip{$head2->title} = CFClient::pod_to_pango $head2->content; |
… | |
… | |
491 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
508 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
492 | |
509 | |
493 | $self->send ("requestinfo image_sums $face $face"); |
510 | $self->send ("requestinfo image_sums $face $face"); |
494 | |
511 | |
495 | $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
512 | $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
496 | group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); |
513 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
497 | } elsif (!exists $self->{num_faces}) { |
514 | } elsif (!exists $self->{num_faces}) { |
498 | $self->send ("requestinfo image_info"); |
515 | $self->send ("requestinfo image_info"); |
499 | |
516 | |
500 | $self->{num_faces} = 0; |
517 | $self->{num_faces} = 0; |
501 | |
518 | |
502 | $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
519 | $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
503 | group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); |
520 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
504 | } |
521 | } |
505 | } |
522 | } |
506 | |
523 | |
507 | sub update_floorbox { |
524 | sub update_floorbox { |
508 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
525 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
… | |
… | |
532 | } |
549 | } |
533 | |
550 | |
534 | sub set_opencont { |
551 | sub set_opencont { |
535 | my ($conn, $tag, $name) = @_; |
552 | my ($conn, $tag, $name) = @_; |
536 | $conn->{open_container} = $tag; |
553 | $conn->{open_container} = $tag; |
537 | $::INVR_LBL->set_text ($name); |
554 | |
|
|
555 | $::INV_RIGHT_HB->clear (); |
|
|
556 | $::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name); |
|
|
557 | |
|
|
558 | if ($tag != 0) { # Floor isn't closable, is it? |
|
|
559 | $::INV_RIGHT_HB->add (new CFClient::UI::Button |
|
|
560 | text => "Close container", |
|
|
561 | tooltip => "Close the currently open container (if one is open)", |
|
|
562 | on_activate => sub { |
|
|
563 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
|
|
564 | if $tag != 0; |
|
|
565 | #if $CONN->{open_container} != 0; |
|
|
566 | }, |
|
|
567 | ); |
|
|
568 | } |
|
|
569 | |
538 | $::INVR->set_items ($conn->{container}{$tag}); |
570 | $::INVR->set_items ($conn->{container}{$tag}); |
539 | } |
571 | } |
540 | |
572 | |
541 | sub update_container { |
573 | sub update_container { |
542 | my ($tag) = @_; |
574 | my ($tag) = @_; |
… | |
… | |
571 | if ($tag == 0) { |
603 | if ($tag == 0) { |
572 | update_floorbox; |
604 | update_floorbox; |
573 | update_container (0); |
605 | update_container (0); |
574 | } elsif ($tag == $self->{player}{tag}) { |
606 | } elsif ($tag == $self->{player}{tag}) { |
575 | $::INV->set_items ($self->{container}{$tag}) |
607 | $::INV->set_items ($self->{container}{$tag}) |
|
|
608 | } else { |
|
|
609 | update_container ($tag); |
576 | } |
610 | } |
577 | |
611 | |
578 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
612 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
579 | } |
613 | } |
580 | |
614 | |
… | |
… | |
588 | update_floorbox; |
622 | update_floorbox; |
589 | update_container ($_->{tag}); |
623 | update_container ($_->{tag}); |
590 | } elsif ($_->{container} == $self->{player}{tag}) { |
624 | } elsif ($_->{container} == $self->{player}{tag}) { |
591 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
625 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
592 | } else { |
626 | } else { |
593 | update_container ($_->{tag}); |
627 | update_container ($_->{container}); |
594 | } |
628 | } |
595 | } |
629 | } |
596 | } |
630 | } |
597 | |
631 | |
598 | sub item_update { |
632 | sub item_update { |
… | |
… | |
623 | } |
657 | } |
624 | |
658 | |
625 | sub player_update { |
659 | sub player_update { |
626 | my ($self, $player) = @_; |
660 | my ($self, $player) = @_; |
627 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
661 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
|
|
662 | |
|
|
663 | # do it here because it is ignored earlier, and there is no "login" event |
|
|
664 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
|
|
665 | $self->send_command ("output-count $::CFG->{output_count}"); |
628 | } |
666 | } |
629 | |
667 | |
630 | 1; |
668 | 1; |