… | |
… | |
25 | |
25 | |
26 | my $cmd = $1; |
26 | my $cmd = $1; |
27 | my @args = split /\|/, $2; |
27 | my @args = split /\|/, $2; |
28 | @args = (".*") unless @args; |
28 | @args = (".*") unless @args; |
29 | |
29 | |
|
|
30 | $_ = $_ eq ".*" ? "" : " $_" |
|
|
31 | for @args; |
|
|
32 | |
30 | my $text = CFClient::pod_to_pango $head2->content; |
33 | my $text = CFClient::pod_to_pango $head2->content; |
31 | |
34 | |
32 | for my $arg (@args) { |
|
|
33 | $arg = $arg eq ".*" ? "" : " $arg"; |
|
|
34 | |
|
|
35 | $self->{map_widget}->add_command ("$cmd$arg", $text); |
35 | $self->{map_widget}->add_command ("$cmd$_", $text) |
36 | } |
36 | for sort { (length $a) <=> (length $b) } |
|
|
37 | @args; |
37 | } |
38 | } |
38 | |
39 | |
39 | $self->{noface} = new_from_file CFClient::Texture |
40 | $self->{noface} = new_from_file CFClient::Texture |
40 | CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; |
41 | CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; |
41 | |
42 | |
… | |
… | |
65 | } |
66 | } |
66 | |
67 | |
67 | sub user_send { |
68 | sub user_send { |
68 | my ($self, $command) = @_; |
69 | my ($self, $command) = @_; |
69 | |
70 | |
|
|
71 | if ($self->{record}) { |
|
|
72 | push @{$self->{record}}, $command; |
|
|
73 | } |
|
|
74 | |
70 | $self->send_command ($command); |
75 | $self->send_command ($command); |
71 | ::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}; |
72 | } |
88 | } |
73 | |
89 | |
74 | sub map_scroll { |
90 | sub map_scroll { |
75 | my ($self, $dx, $dy) = @_; |
91 | my ($self, $dx, $dy) = @_; |
76 | |
92 | |
… | |
… | |
252 | unless ($id) { |
268 | unless ($id) { |
253 | # create new id for face |
269 | # create new id for face |
254 | # I love transactions |
270 | # I love transactions |
255 | for (1..100) { |
271 | for (1..100) { |
256 | my $txn = $CFClient::DB_ENV->txn_begin; |
272 | my $txn = $CFClient::DB_ENV->txn_begin; |
257 | my $status = $self->{facemap}->db_get (id => $id, BerkeleyDB::DB_RMW); |
273 | my $status = $self->{facemap}->db_get (id => $id); |
258 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
274 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
259 | $id = ($id || 16) + 1; |
275 | $id = ($id || 16) + 1; |
260 | if ($self->{facemap}->put (id => $id) == 0 |
276 | if ($self->{facemap}->put (id => $id) == 0 |
261 | && $self->{facemap}->put ($hash => $id) == 0) { |
277 | && $self->{facemap}->put ($hash => $id) == 0) { |
262 | $txn->txn_commit; |
278 | $txn->txn_commit; |
263 | |
279 | |
264 | goto gotid; |
280 | goto gotid; |
265 | } |
281 | } |
266 | } |
282 | } |
267 | $txn->abort; |
283 | $txn->txn_abort; |
268 | } |
284 | } |
269 | |
285 | |
270 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
286 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
271 | } |
287 | } |
272 | |
288 | |
… | |
… | |
323 | |
339 | |
324 | $prompt = $LAST_QUERY unless length $prompt; |
340 | $prompt = $LAST_QUERY unless length $prompt; |
325 | $LAST_QUERY = $prompt; |
341 | $LAST_QUERY = $prompt; |
326 | |
342 | |
327 | my $dialog = new CFClient::UI::FancyFrame |
343 | my $dialog = new CFClient::UI::FancyFrame |
|
|
344 | x => "center", |
|
|
345 | y => "center", |
328 | title => "Query", |
346 | title => "Query", |
329 | child => my $vbox = new CFClient::UI::VBox; |
347 | child => my $vbox = new CFClient::UI::VBox, |
|
|
348 | ; |
330 | |
349 | |
331 | $vbox->add (new CFClient::UI::Label |
350 | $vbox->add (new CFClient::UI::Label |
332 | max_w => $::WIDTH * 0.4, |
351 | max_w => $::WIDTH * 0.4, |
333 | ellipsise => 0, |
352 | ellipsise => 0, |
334 | text => $prompt); |
353 | text => $prompt); |
335 | |
354 | |
336 | if ($flags & CS_QUERY_YESNO) { |
355 | if ($flags & CS_QUERY_YESNO) { |
337 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
356 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
338 | $hbox->add (new CFClient::UI::Button |
357 | $hbox->add (new CFClient::UI::Button |
339 | text => "No", |
358 | text => "No", |
340 | connect_activate => sub { |
359 | on_activate => sub { |
341 | $self->send ("reply n"); |
360 | $self->send ("reply n"); |
342 | $dialog->destroy; |
361 | $dialog->destroy; |
343 | $self->{map_widget}->focus_in; |
362 | $self->{map_widget}->focus_in; |
344 | } |
363 | } |
345 | ); |
364 | ); |
346 | $hbox->add (new CFClient::UI::Button |
365 | $hbox->add (new CFClient::UI::Button |
347 | text => "Yes", |
366 | text => "Yes", |
348 | connect_activate => sub { |
367 | on_activate => sub { |
349 | $self->send ("reply y"); |
368 | $self->send ("reply y"); |
350 | $dialog->destroy; |
369 | $dialog->destroy; |
351 | }, |
370 | }, |
352 | ); |
371 | ); |
353 | |
372 | |
354 | $dialog->focus_in; |
373 | $dialog->focus_in; |
355 | |
374 | |
356 | } elsif ($flags & CS_QUERY_SINGLECHAR) { |
375 | } elsif ($flags & CS_QUERY_SINGLECHAR) { |
357 | $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)"; |
358 | $vbox->add (my $entry = new CFClient::UI::Entry |
377 | $vbox->add (my $entry = new CFClient::UI::Entry |
359 | connect_changed => sub { |
378 | on_changed => sub { |
360 | $self->send ("reply $_[1]"); |
379 | $self->send ("reply $_[1]"); |
361 | $dialog->destroy; |
380 | $dialog->destroy; |
362 | }, |
381 | }, |
363 | ); |
382 | ); |
364 | |
383 | |
… | |
… | |
367 | } else { |
386 | } else { |
368 | $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)"; |
369 | |
388 | |
370 | $vbox->add (my $entry = new CFClient::UI::Entry |
389 | $vbox->add (my $entry = new CFClient::UI::Entry |
371 | $flags & CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), |
390 | $flags & CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), |
372 | connect_activate => sub { |
391 | on_activate => sub { |
373 | $self->send ("reply $_[1]"); |
392 | $self->send ("reply $_[1]"); |
374 | $dialog->destroy; |
393 | $dialog->destroy; |
375 | }, |
394 | }, |
376 | ); |
395 | ); |
377 | |
396 | |
378 | $entry->focus_in; |
397 | $entry->focus_in; |
379 | } |
398 | } |
380 | |
399 | |
381 | $dialog->show_centered; |
400 | $dialog->show; |
382 | } |
401 | } |
383 | |
402 | |
384 | sub drawinfo { |
403 | sub drawinfo { |
385 | my ($self, $color, $text) = @_; |
404 | my ($self, $color, $text) = @_; |
386 | |
405 | |
… | |
… | |
426 | sub spell_add { |
445 | sub spell_add { |
427 | my ($self, $spell) = @_; |
446 | my ($self, $spell) = @_; |
428 | |
447 | |
429 | # TODO |
448 | # TODO |
430 | # 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 | |
431 | $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}); |
432 | $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}); |
433 | } |
454 | } |
434 | |
455 | |
435 | sub spell_delete { |
456 | sub spell_delete { |
436 | my ($self, $spell) = @_; |
457 | my ($self, $spell) = @_; |
|
|
458 | $::SETUP_SPELLS->remove_spell ($spell); |
437 | } |
459 | } |
438 | |
460 | |
439 | sub addme_success { |
461 | sub addme_success { |
440 | my ($self) = @_; |
462 | my ($self) = @_; |
441 | |
|
|
442 | $self->send ("command output-sync $::CFG->{output_sync}"); |
|
|
443 | $self->send ("command output-count $::CFG->{output_count}"); |
|
|
444 | |
463 | |
445 | my $parser = new Pod::POM; |
464 | my $parser = new Pod::POM; |
446 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod"); |
465 | my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod"); |
447 | |
466 | |
448 | my %skill_tooltip; |
467 | my %skill_tooltip; |
… | |
… | |
531 | } |
550 | } |
532 | |
551 | |
533 | sub set_opencont { |
552 | sub set_opencont { |
534 | my ($conn, $tag, $name) = @_; |
553 | my ($conn, $tag, $name) = @_; |
535 | $conn->{open_container} = $tag; |
554 | $conn->{open_container} = $tag; |
536 | $::INVR_LBL->set_text ($name); |
555 | |
|
|
556 | $::INV_RIGHT_HB->clear (); |
|
|
557 | $::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name); |
|
|
558 | |
|
|
559 | if ($tag != 0) { # Floor isn't closable, is it? |
|
|
560 | $::INV_RIGHT_HB->add (new CFClient::UI::Button |
|
|
561 | text => "Close container", |
|
|
562 | tooltip => "Close the currently open container (if one is open)", |
|
|
563 | on_activate => sub { |
|
|
564 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
|
|
565 | if $tag != 0; |
|
|
566 | #if $CONN->{open_container} != 0; |
|
|
567 | }, |
|
|
568 | ); |
|
|
569 | } |
|
|
570 | |
537 | $::INVR->set_items ($conn->{container}{$tag}); |
571 | $::INVR->set_items ($conn->{container}{$tag}); |
538 | } |
572 | } |
539 | |
573 | |
540 | sub update_container { |
574 | sub update_container { |
541 | my ($tag) = @_; |
575 | my ($tag) = @_; |
… | |
… | |
570 | if ($tag == 0) { |
604 | if ($tag == 0) { |
571 | update_floorbox; |
605 | update_floorbox; |
572 | update_container (0); |
606 | update_container (0); |
573 | } elsif ($tag == $self->{player}{tag}) { |
607 | } elsif ($tag == $self->{player}{tag}) { |
574 | $::INV->set_items ($self->{container}{$tag}) |
608 | $::INV->set_items ($self->{container}{$tag}) |
|
|
609 | } else { |
|
|
610 | update_container ($tag); |
575 | } |
611 | } |
576 | |
612 | |
577 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
613 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
578 | } |
614 | } |
579 | |
615 | |
… | |
… | |
587 | update_floorbox; |
623 | update_floorbox; |
588 | update_container ($_->{tag}); |
624 | update_container ($_->{tag}); |
589 | } elsif ($_->{container} == $self->{player}{tag}) { |
625 | } elsif ($_->{container} == $self->{player}{tag}) { |
590 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
626 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
591 | } else { |
627 | } else { |
592 | update_container ($_->{tag}); |
628 | update_container ($_->{container}); |
593 | } |
629 | } |
594 | } |
630 | } |
595 | } |
631 | } |
596 | |
632 | |
597 | sub item_update { |
633 | sub item_update { |
… | |
… | |
622 | } |
658 | } |
623 | |
659 | |
624 | sub player_update { |
660 | sub player_update { |
625 | my ($self, $player) = @_; |
661 | my ($self, $player) = @_; |
626 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
662 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
|
|
663 | |
|
|
664 | # do it here because it is ignored earlier, and there is no "login" event |
|
|
665 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
|
|
666 | $self->send_command ("output-count $::CFG->{output_count}"); |
627 | } |
667 | } |
628 | |
668 | |
629 | 1; |
669 | 1; |