--- deliantra/Deliantra-Client/DC.pm 2006/05/29 21:54:15 1.77 +++ deliantra/Deliantra-Client/DC.pm 2006/05/31 12:44:17 1.84 @@ -88,7 +88,7 @@ # -ErrPrefix => "DATABASE", -Verbose => 1, -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover, - -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE | DB_TXN_WRITE_NOSYNC, + -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE, or die "unable to create/open database home $Crossfire::VARDIR/cfplus: $BerkeleyDB::Error"; } @@ -206,6 +206,8 @@ use strict; use Crossfire::Protocol::Constants; +my $last_enter_count = 1; + sub desc_string { my ($self) = @_; @@ -240,20 +242,42 @@ $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}; + } - $::CONN->send ("move $targ $self->{tag} 0"); + if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { + $::CONN->send ("move $targ $self->{tag} 0") + if $targ || !($self->{flags} & F_LOCKED); } elsif ($ev->{button} == 1) { $::CONN->send ("examine $self->{tag}"); } elsif ($ev->{button} == 2) { @@ -271,6 +295,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]") }) + } + ] ) ), ); @@ -333,24 +362,18 @@ ); } -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 = ( @@ -385,14 +408,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 @@ -425,14 +448,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; } @@ -441,109 +462,13 @@ 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) = @_; - - return unless $CMDBOX; - - $CMDBOX->clear (); - $CURRENT_CMDS = $list; - - 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; =back