… | |
… | |
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 | |
|
|
3216 | package CFClient::UI::SpellList; |
|
|
3217 | |
|
|
3218 | our @ISA = CFClient::UI::FancyFrame::; |
|
|
3219 | |
|
|
3220 | sub new { |
|
|
3221 | my $class = shift; |
|
|
3222 | |
|
|
3223 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
|
|
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 | |
3215 | package CFClient::UI::BindEditor; |
3273 | package CFClient::UI::BindEditor; |
3216 | |
3274 | |
3217 | our @ISA = CFClient::UI::FancyFrame::; |
3275 | our @ISA = CFClient::UI::FancyFrame::; |
3218 | |
3276 | |
3219 | sub new { |
3277 | sub new { |
… | |
… | |
3310 | $rec = $::CONN->stop_record if $::CONN; |
3368 | $rec = $::CONN->stop_record if $::CONN; |
3311 | return unless ref $rec eq 'ARRAY'; |
3369 | return unless ref $rec eq 'ARRAY'; |
3312 | $self->set_command_list ($rec); |
3370 | $self->set_command_list ($rec); |
3313 | } |
3371 | } |
3314 | |
3372 | |
|
|
3373 | # if $commit is true, the binding will be set after the user entered a key combo |
3315 | sub ask_for_bind { |
3374 | sub ask_for_bind { |
3316 | my ($self, $commit) = @_; |
3375 | my ($self, $commit) = @_; |
3317 | |
3376 | |
3318 | CFClient::Binder::open_binding_dialog (sub { |
3377 | CFClient::Binder::open_binding_dialog (sub { |
3319 | my ($mod, $sym) = @_; |
3378 | my ($mod, $sym) = @_; |
… | |
… | |
3321 | $self->update_binding_widgets; |
3380 | $self->update_binding_widgets; |
3322 | $self->commit if $commit; |
3381 | $self->commit if $commit; |
3323 | }); |
3382 | }); |
3324 | } |
3383 | } |
3325 | |
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 |
3326 | sub set_binding { |
3390 | sub set_binding { |
3327 | my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_; |
3391 | my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_; |
3328 | |
3392 | |
3329 | $self->clear_command_list; |
3393 | $self->clear_command_list; |
3330 | $self->{recording} = 0; |
3394 | $self->{recording} = 0; |
… | |
… | |
3335 | |
3399 | |
3336 | $self->{binding_change} = $cb; |
3400 | $self->{binding_change} = $cb; |
3337 | $self->{binding_cancel} = $ccb; |
3401 | $self->{binding_cancel} = $ccb; |
3338 | |
3402 | |
3339 | $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); |
3340 | } |
3414 | } |
3341 | |
3415 | |
3342 | sub update_binding_widgets { |
3416 | sub update_binding_widgets { |
3343 | my ($self) = @_; |
3417 | my ($self) = @_; |
3344 | my ($mod, $sym, $cmds) = $self->get_binding; |
3418 | my ($mod, $sym, $cmds) = $self->get_binding; |
… | |
… | |
3370 | |
3444 | |
3371 | for (@$cmds) { |
3445 | for (@$cmds) { |
3372 | $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox); |
3446 | $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox); |
3373 | |
3447 | |
3374 | my $i = $idx; |
3448 | my $i = $idx; |
|
|
3449 | $hb->add (new CFClient::UI::Label text => $_); |
3375 | $hb->add (new CFClient::UI::Button |
3450 | $hb->add (new CFClient::UI::Button |
3376 | text => "delete", |
3451 | text => "delete", |
3377 | tooltip => "Deletes the action from the record", |
3452 | tooltip => "Deletes the action from the record", |
3378 | on_activate => sub { |
3453 | on_activate => sub { |
3379 | $self->{cmdbox}->remove ($hb); |
3454 | $self->{cmdbox}->remove ($hb); |
3380 | $cmds->[$i] = undef; |
3455 | $cmds->[$i] = undef; |
3381 | }); |
3456 | }); |
3382 | |
3457 | |
3383 | $hb->add (new CFClient::UI::Label text => $_); |
|
|
3384 | |
3458 | |
3385 | $idx++ |
3459 | $idx++ |
3386 | } |
3460 | } |
3387 | } |
3461 | } |
3388 | |
|
|
3389 | |
3462 | |
3390 | ############################################################################# |
3463 | ############################################################################# |
3391 | |
3464 | |
3392 | package CFClient::UI; |
3465 | package CFClient::UI; |
3393 | |
3466 | |