--- deliantra/Deliantra-Client/DC.pm 2006/05/30 08:12:50 1.80 +++ deliantra/Deliantra-Client/DC.pm 2006/05/30 14:35:08 1.81 @@ -334,24 +334,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 = ( @@ -386,11 +380,9 @@ ); # 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", @@ -428,8 +420,7 @@ $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 }); @@ -443,109 +434,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