--- deliantra/Deliantra-Client/DC.pm 2006/05/30 02:55:45 1.79 +++ deliantra/Deliantra-Client/DC.pm 2006/06/02 16:27:27 1.86 @@ -206,6 +206,8 @@ use strict; use Crossfire::Protocol::Constants; +my $last_enter_count = 1; + sub desc_string { my ($self) = @_; @@ -240,21 +242,46 @@ $weight < 0 ? "?" : $weight * 0.001 } +sub do_n_dialog { + my ($cb) = @_; + + my $w = new CFClient::UI::FancyFrame; + $w->add (my $vb = new CFClient::UI::VBox x => "center", y => "center"); + $vb->add (new CFClient::UI::Label text => "Enter item count:"); + $vb->add (my $entry = new CFClient::UI::Entry + text => $last_enter_count, + on_activate => sub { + my ($entry) = @_; + $last_enter_count = $entry->get_text; + $cb->($last_enter_count); + $w->hide; + $w = undef; + } + ); + $entry->focus_in; + $w->show; + +} + sub update_widgets { my ($self) = @_; my $button_cb = sub { my (undef, $ev, $x, $y) = @_; - if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { - my $targ = $::CONN->{player}{tag}; + my $targ = $::CONN->{player}{tag}; - if ($self->{container} == $::CONN->{player}{tag}) { - $targ = $::CONN->{open_container}; - } + if ($self->{container} == $::CONN->{player}{tag}) { + $targ = $::CONN->{open_container}; + } + if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { $::CONN->send ("move $targ $self->{tag} 0") if $targ || !($self->{flags} & F_LOCKED); + } elsif (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 2) { + $self->{flags} & F_LOCKED + ? $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) + : $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) } elsif ($ev->{button} == 1) { $::CONN->send ("examine $self->{tag}"); } elsif ($ev->{button} == 2) { @@ -272,6 +299,11 @@ : ( ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }], ["drop", sub { $::CONN->send ("move $::CONN->{open_container} $self->{tag} 0") }], + ["move n", + sub { + do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") }) + } + ] ) ), ); @@ -286,6 +318,7 @@ . "Left click - examine item\n" . "Shift-Left click - " . ($self->{container} ? "move or drop" : "take") . " item\n" . "Middle click - apply\n" + . "Shift-Middle click - lock/unlock\n" . "Right click - further options" . "\n"; @@ -334,36 +367,30 @@ ); } -package CFClient::Recorder; - -our $RECORD_WINDOW; - -my $CMDBOX; -my $CURRENT_CMDS; -my $REC_BTN; +package CFClient::Binder; my @ALLOWED_MODIFIER_KEYS = ( - (CFClient::SDLK_LSHIFT) => "LSHIFT", - (CFClient::SDLK_LCTRL ) => "LCTRL", - (CFClient::SDLK_LALT ) => "LALT", - (CFClient::SDLK_LMETA ) => "LMETA", - - (CFClient::SDLK_RSHIFT) => "RSHIFT", - (CFClient::SDLK_RCTRL ) => "RCTRL", - (CFClient::SDLK_RALT ) => "RALT", - (CFClient::SDLK_RMETA ) => "RMETA", + CFClient::SDLK_LSHIFT, + CFClient::SDLK_LCTRL , + CFClient::SDLK_LALT , + CFClient::SDLK_LMETA , + + CFClient::SDLK_RSHIFT, + CFClient::SDLK_RCTRL , + CFClient::SDLK_RALT , + CFClient::SDLK_RMETA , ); my %ALLOWED_MODIFIERS = ( - (CFClient::KMOD_LSHIFT) => "LSHIFT", - (CFClient::KMOD_LCTRL ) => "LCTRL", - (CFClient::KMOD_LALT ) => "LALT", - (CFClient::KMOD_LMETA ) => "LMETA", - - (CFClient::KMOD_RSHIFT) => "RSHIFT", - (CFClient::KMOD_RCTRL ) => "RCTRL", - (CFClient::KMOD_RALT ) => "RALT", - (CFClient::KMOD_RMETA ) => "RMETA", + CFClient::KMOD_LSHIFT => "LSHIFT", + CFClient::KMOD_LCTRL => "LCTRL", + CFClient::KMOD_LALT => "LALT", + CFClient::KMOD_LMETA => "LMETA", + + CFClient::KMOD_RSHIFT => "RSHIFT", + CFClient::KMOD_RCTRL => "RCTRL", + CFClient::KMOD_RALT => "RALT", + CFClient::KMOD_RMETA => "RMETA", ); my %DIRECT_BIND_CHARS = map { $_ => 1 } qw/0 1 2 3 4 5 6 7 8 9/; @@ -386,14 +413,14 @@ ); # this binding dialog asks for a key-combo to be pressed -# and if successful it binds the modifier+symbol to the -# supplied actions in $cmd. -# (Bindings are stored in $::CFG->{bindings}->{$mod}->{$sym}) +# and if successful it calls the $cb with $mod and $sym as args. sub open_binding_dialog { - my ($cmd) = @_; + my ($cb) = @_; my $w = new CFClient::UI::FancyFrame - title => "Bind Action"; + title => "Bind Action", + x => "center", + y => "center"; $w->add (my $vb = new CFClient::UI::VBox); $vb->add (new CFClient::UI::Label @@ -426,14 +453,12 @@ $entry->focus_out; - $::CFG->{bindings}->{$mod}->{$sym} = $cmd; - $::STATUSBOX->add ("Bound actions to '".keycombo_to_name ($mod, $sym)."'. Don't forget 'Save Config'!"); + $cb->($mod, $sym); $w->destroy }); $entry->focus_in; - $w->center; $w->show; } @@ -442,108 +467,53 @@ my $mods = join '+', map { $ALLOWED_MODIFIERS{$_} } - grep { $_ & $mod } + grep { ($_ + 0) & ($mod + 0) } keys %ALLOWED_MODIFIERS; $mods .= "+" if $mods ne ''; return $mods . CFClient::SDL_GetKeyName ($sym); } -sub clear_command_list { - $CMDBOX->clear () if $CMDBOX; -} - -sub set_command_list { - my ($list) = @_; +package CFClient::Pickup; +# some pickup constants +sub PU_NOTHING { 0x00000000 } + +sub PU_DEBUG { 0x10000000 } +sub PU_INHIBIT { 0x20000000 } +sub PU_STOP { 0x40000000 } +sub PU_NEWMODE { 0x80000000 } + +sub PU_RATIO { 0x0000000F } + +sub PU_FOOD { 0x00000010 } +sub PU_DRINK { 0x00000020 } +sub PU_VALUABLES { 0x00000040 } +sub PU_BOW { 0x00000080 } + +sub PU_ARROW { 0x00000100 } +sub PU_HELMET { 0x00000200 } +sub PU_SHIELD { 0x00000400 } +sub PU_ARMOUR { 0x00000800 } + +sub PU_BOOTS { 0x00001000 } +sub PU_GLOVES { 0x00002000 } +sub PU_CLOAK { 0x00004000 } +sub PU_KEY { 0x00008000 } + +sub PU_MISSILEWEAPON { 0x00010000 } +sub PU_ALLWEAPON { 0x00020000 } +sub PU_MAGICAL { 0x00040000 } +sub PU_POTION { 0x00080000 } + +sub PU_SPELLBOOK { 0x00100000 } +sub PU_SKILLSCROLL { 0x00200000 } +sub PU_READABLES { 0x00400000 } +sub PU_MAGIC_DEVICE { 0x00800000 } - return unless $CMDBOX; +sub PU_NOT_CURSED { 0x01000000 } - $CMDBOX->clear (); - $CURRENT_CMDS = $list; +sub PU_JEWELS { 0x02000000 } - my $idx = 0; - - for (@$list) { - $CMDBOX->add (my $hb = new CFClient::UI::HBox); - - my $i = $idx; - $hb->add (new CFClient::UI::Button - text => "delete", - tooltip => "Deletes the action from the record", - on_activate => sub { - $CMDBOX->remove ($hb); - $list->[$i] = undef; - }); - - $hb->add (new CFClient::UI::Label text => $_); - - $idx++ - } -} - -# if $show is 1 the recorder will be shown -sub start { - my ($show) = @_; - - $RECORD_WINDOW->show if $show; - - $REC_BTN->set_text ("stop recording"); - $REC_BTN->{recording} = 1; - clear_command_list; - $::CONN->start_record; -} - -# if $autobind is 1 the recorder will be automatically -# jump into the binding query and hide the recorder window -sub stop { - my ($autobind) = @_; - - $REC_BTN->set_text ("start recording"); - $REC_BTN->{recording} = 0; - - my $rec = $::CONN->stop_record; - return unless ref $rec eq 'ARRAY'; - set_command_list ($rec); - - if ($autobind) { - open_binding_dialog ([ grep { defined $_ } @$CURRENT_CMDS ]); - $RECORD_WINDOW->hide; - } -} - -sub make_window { - $RECORD_WINDOW = new CFClient::UI::FancyFrame - req_y => 1, - req_x => -1, - title => "Action Recorder"; - - $RECORD_WINDOW->add (my $vb = new CFClient::UI::VBox); - $vb->add ($REC_BTN = new CFClient::UI::Button - text => "start recording", - tooltip => "Start/Stops recording of actions." - ."(CTRL+Insert Starts the recorder, Insert Stops recorder and binds automatically)" - ."All subsequent actions after the recording started will be captured." - ."The actions are displayed after the record was stopped." - ."To bind the action you have to click on the 'Bind' button", - on_activate => sub { - my ($btn) = @_; - - unless ($btn->{recording}) { - start; - } else { - stop; - } - }); - $vb->add ($CMDBOX = new CFClient::UI::VBox); - $vb->add (new CFClient::UI::Button - text => "bind", - tooltip => "This opens a query where you have to press the key combination to bind the recorded actions", - on_activate => sub { - open_binding_dialog ([ grep { defined $_ } @$CURRENT_CMDS ]); - }); - - $RECORD_WINDOW -} 1;