… | |
… | |
3210 | $self->_draw; |
3210 | $self->_draw; |
3211 | } |
3211 | } |
3212 | |
3212 | |
3213 | ############################################################################# |
3213 | ############################################################################# |
3214 | |
3214 | |
|
|
3215 | package CFClient::UI::BindEditor; |
|
|
3216 | |
|
|
3217 | our @ISA = CFClient::UI::FancyFrame::; |
|
|
3218 | |
|
|
3219 | sub new { |
|
|
3220 | my $class = shift; |
|
|
3221 | |
|
|
3222 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
|
|
3223 | |
|
|
3224 | $self->add (my $vb = new CFClient::UI::VBox); |
|
|
3225 | |
|
|
3226 | |
|
|
3227 | $vb->add ($self->{rec_btn} = new CFClient::UI::Button |
|
|
3228 | text => "start recording", |
|
|
3229 | tooltip => "Start/Stops recording of actions." |
|
|
3230 | ."All subsequent actions after the recording started will be captured." |
|
|
3231 | ."The actions are displayed after the record was stopped." |
|
|
3232 | ."To bind the action you have to click on the 'Bind' button", |
|
|
3233 | on_activate => sub { |
|
|
3234 | unless ($self->{recording}) { |
|
|
3235 | $self->start; |
|
|
3236 | } else { |
|
|
3237 | $self->stop; |
|
|
3238 | } |
|
|
3239 | }); |
|
|
3240 | |
|
|
3241 | $vb->add (new CFClient::UI::Label text => "Actions:"); |
|
|
3242 | $vb->add ($self->{cmdbox} = new CFClient::UI::VBox); |
|
|
3243 | |
|
|
3244 | $vb->add (new CFClient::UI::Label text => "Bound to: "); |
|
|
3245 | $vb->add (my $hb = new CFClient::UI::HBox); |
|
|
3246 | $hb->add ($self->{keylbl} = new CFClient::UI::Label expand => 1); |
|
|
3247 | $hb->add (new CFClient::UI::Button |
|
|
3248 | text => "bind", |
|
|
3249 | tooltip => "This opens a query where you have to press the key combination to bind the recorded actions", |
|
|
3250 | on_activate => sub { |
|
|
3251 | $self->ask_for_bind; |
|
|
3252 | }); |
|
|
3253 | |
|
|
3254 | $vb->add (my $hb = new CFClient::UI::HBox); |
|
|
3255 | $hb->add (new CFClient::UI::Button |
|
|
3256 | text => "ok", |
|
|
3257 | expand => 1, |
|
|
3258 | tooltip => "This closes the binding editor and saves the binding", |
|
|
3259 | on_activate => sub { |
|
|
3260 | $self->hide; |
|
|
3261 | $self->commit; |
|
|
3262 | }); |
|
|
3263 | |
|
|
3264 | $hb->add (new CFClient::UI::Button |
|
|
3265 | text => "cancel", |
|
|
3266 | expand => 1, |
|
|
3267 | tooltip => "This closes the binding editor without saving", |
|
|
3268 | on_activate => sub { |
|
|
3269 | $self->hide; |
|
|
3270 | $self->{binding_cancel}->() |
|
|
3271 | if $self->{binding_cancel}; |
|
|
3272 | }); |
|
|
3273 | |
|
|
3274 | $self->update_binding_widgets; |
|
|
3275 | |
|
|
3276 | $self |
|
|
3277 | } |
|
|
3278 | |
|
|
3279 | sub commit { |
|
|
3280 | my ($self) = @_; |
|
|
3281 | my ($mod, $sym, $cmds) = $self->get_binding; |
|
|
3282 | if ($sym != 0 && @$cmds > 0) { |
|
|
3283 | $::STATUSBOX->add ("Bound actions to '".CFClient::Binder::keycombo_to_name ($mod, $sym) |
|
|
3284 | ."'. Don't forget 'Save Config'!"); |
|
|
3285 | $self->{binding_change}->($mod, $sym, $cmds) |
|
|
3286 | if $self->{binding_change}; |
|
|
3287 | } else { |
|
|
3288 | $::STATUSBOX->add ("No action bound, no key or action specified!"); |
|
|
3289 | $self->{binding_cancel}->() |
|
|
3290 | if $self->{binding_cancel}; |
|
|
3291 | } |
|
|
3292 | } |
|
|
3293 | |
|
|
3294 | sub start { |
|
|
3295 | my ($self) = @_; |
|
|
3296 | |
|
|
3297 | $self->{rec_btn}->set_text ("stop recording"); |
|
|
3298 | $self->{recording} = 1; |
|
|
3299 | $self->clear_command_list; |
|
|
3300 | $::CONN->start_record if $::CONN; |
|
|
3301 | } |
|
|
3302 | |
|
|
3303 | sub stop { |
|
|
3304 | my ($self) = @_; |
|
|
3305 | |
|
|
3306 | $self->{rec_btn}->set_text ("start recording"); |
|
|
3307 | $self->{recording} = 0; |
|
|
3308 | |
|
|
3309 | my $rec; |
|
|
3310 | $rec = $::CONN->stop_record if $::CONN; |
|
|
3311 | return unless ref $rec eq 'ARRAY'; |
|
|
3312 | $self->set_command_list ($rec); |
|
|
3313 | } |
|
|
3314 | |
|
|
3315 | # if $commit is true, the binding will be set after the user entered a key combo |
|
|
3316 | sub ask_for_bind { |
|
|
3317 | my ($self, $commit) = @_; |
|
|
3318 | |
|
|
3319 | CFClient::Binder::open_binding_dialog (sub { |
|
|
3320 | my ($mod, $sym) = @_; |
|
|
3321 | $self->{binding} = [$mod, $sym]; # XXX: how to stop that memleak? |
|
|
3322 | $self->update_binding_widgets; |
|
|
3323 | $self->commit if $commit; |
|
|
3324 | }); |
|
|
3325 | } |
|
|
3326 | |
|
|
3327 | # $mod and $sym are the modifiers and key symbol |
|
|
3328 | # $cmds is a array ref of strings (the commands) |
|
|
3329 | # $cb is the callback that is executed on OK |
|
|
3330 | # $ccb is the callback that is executed on CANCEL and |
|
|
3331 | # when the binding was unsuccessful on OK |
|
|
3332 | sub set_binding { |
|
|
3333 | my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_; |
|
|
3334 | |
|
|
3335 | $self->clear_command_list; |
|
|
3336 | $self->{recording} = 0; |
|
|
3337 | $self->{rec_btn}->set_text ("start recording"); |
|
|
3338 | |
|
|
3339 | $self->{binding} = [$mod, $sym]; |
|
|
3340 | $self->{commands} = $cmds; |
|
|
3341 | |
|
|
3342 | $self->{binding_change} = $cb; |
|
|
3343 | $self->{binding_cancel} = $ccb; |
|
|
3344 | |
|
|
3345 | $self->update_binding_widgets; |
|
|
3346 | } |
|
|
3347 | |
|
|
3348 | # this is a shortcut method that asks for a binding |
|
|
3349 | # and then just binds it. |
|
|
3350 | sub do_quick_binding { |
|
|
3351 | my ($self, $cmds) = @_; |
|
|
3352 | $self->set_binding (undef, undef, $cmds, sub { |
|
|
3353 | $::CFG->{bindings}->{$_[0]}->{$_[1]} = $_[2]; |
|
|
3354 | }); |
|
|
3355 | $self->ask_for_bind (1); |
|
|
3356 | } |
|
|
3357 | |
|
|
3358 | sub update_binding_widgets { |
|
|
3359 | my ($self) = @_; |
|
|
3360 | my ($mod, $sym, $cmds) = $self->get_binding; |
|
|
3361 | $self->{keylbl}->set_text (CFClient::Binder::keycombo_to_name ($mod, $sym)); |
|
|
3362 | $self->set_command_list ($cmds); |
|
|
3363 | } |
|
|
3364 | |
|
|
3365 | sub get_binding { |
|
|
3366 | my ($self) = @_; |
|
|
3367 | return ( |
|
|
3368 | $self->{binding}->[0], |
|
|
3369 | $self->{binding}->[1], |
|
|
3370 | [ grep { defined $_ } @{$self->{commands}} ] |
|
|
3371 | ); |
|
|
3372 | } |
|
|
3373 | |
|
|
3374 | sub clear_command_list { |
|
|
3375 | my ($self) = @_; |
|
|
3376 | $self->{cmdbox}->clear (); |
|
|
3377 | } |
|
|
3378 | |
|
|
3379 | sub set_command_list { |
|
|
3380 | my ($self, $cmds) = @_; |
|
|
3381 | |
|
|
3382 | $self->{cmdbox}->clear (); |
|
|
3383 | $self->{commands} = $cmds; |
|
|
3384 | |
|
|
3385 | my $idx = 0; |
|
|
3386 | |
|
|
3387 | for (@$cmds) { |
|
|
3388 | $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox); |
|
|
3389 | |
|
|
3390 | my $i = $idx; |
|
|
3391 | $hb->add (new CFClient::UI::Label text => $_); |
|
|
3392 | $hb->add (new CFClient::UI::Button |
|
|
3393 | text => "delete", |
|
|
3394 | tooltip => "Deletes the action from the record", |
|
|
3395 | on_activate => sub { |
|
|
3396 | $self->{cmdbox}->remove ($hb); |
|
|
3397 | $cmds->[$i] = undef; |
|
|
3398 | }); |
|
|
3399 | |
|
|
3400 | |
|
|
3401 | $idx++ |
|
|
3402 | } |
|
|
3403 | } |
|
|
3404 | |
|
|
3405 | |
|
|
3406 | ############################################################################# |
|
|
3407 | |
|
|
3408 | package CFClient::UI::SpellList; |
|
|
3409 | |
|
|
3410 | our @ISA = CFClient::UI::FancyFrame::; |
|
|
3411 | |
|
|
3412 | sub new { |
|
|
3413 | my $class = shift; |
|
|
3414 | |
|
|
3415 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
|
|
3416 | |
|
|
3417 | $self->add (new CFClient::UI::ScrolledWindow |
|
|
3418 | scrolled => $self->{spellbox} = new CFClient::UI::Table); |
|
|
3419 | |
|
|
3420 | $self; |
|
|
3421 | } |
|
|
3422 | |
|
|
3423 | # XXX: Do sorting? Argl... |
|
|
3424 | sub add_spell { |
|
|
3425 | my ($self, $spell) = @_; |
|
|
3426 | $self->{spells}->{$spell->{name}} = $spell; |
|
|
3427 | |
|
|
3428 | $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
|
|
3429 | face => $spell->{face}, |
|
|
3430 | can_hover => 1, |
|
|
3431 | can_events => 1, |
|
|
3432 | tooltip => $spell->{message}); |
|
|
3433 | |
|
|
3434 | $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
|
|
3435 | text => $spell->{name}, |
|
|
3436 | can_hover => 1, |
|
|
3437 | can_events => 1, |
|
|
3438 | tooltip => $spell->{message}, |
|
|
3439 | expand => 1); |
|
|
3440 | |
|
|
3441 | $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
|
|
3442 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
|
|
3443 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
|
|
3444 | expand => 1); |
|
|
3445 | |
|
|
3446 | $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
|
|
3447 | text => "bind to key", |
|
|
3448 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
|
|
3449 | } |
|
|
3450 | |
|
|
3451 | sub rebuild_spell_list { |
|
|
3452 | my ($self) = @_; |
|
|
3453 | $self->{tbl_idx} = 0; |
|
|
3454 | $self->add_spell ($_) for values %{$self->{spells}}; |
|
|
3455 | } |
|
|
3456 | |
|
|
3457 | sub remove_spell { |
|
|
3458 | my ($self, $spell) = @_; |
|
|
3459 | delete $self->{spells}->{$spell->{name}}; |
|
|
3460 | $self->rebuild_spell_list; |
|
|
3461 | } |
|
|
3462 | |
|
|
3463 | ############################################################################# |
|
|
3464 | |
3215 | package CFClient::UI; |
3465 | package CFClient::UI; |
3216 | |
3466 | |
3217 | $ROOT = new CFClient::UI::Root; |
3467 | $ROOT = new CFClient::UI::Root; |
3218 | $TOOLTIP = new CFClient::UI::Tooltip z => 900; |
3468 | $TOOLTIP = new CFClient::UI::Tooltip z => 900; |
3219 | |
3469 | |