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