ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.260 by elmex, Tue May 30 14:35:09 2006 UTC vs.
Revision 1.263 by elmex, Wed May 31 14:04:52 2006 UTC

3221 3221
3222 my $self = $class->SUPER::new (binding => [], commands => [], @_); 3222 my $self = $class->SUPER::new (binding => [], commands => [], @_);
3223 3223
3224 $self->add (my $vb = new CFClient::UI::VBox); 3224 $self->add (my $vb = new CFClient::UI::VBox);
3225 3225
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 3226
3236 $vb->add (new CFClient::UI::Label text => "Actions:");
3237 $vb->add ($self->{rec_btn} = new CFClient::UI::Button 3227 $vb->add ($self->{rec_btn} = new CFClient::UI::Button
3238 text => "start recording", 3228 text => "start recording",
3239 tooltip => "Start/Stops recording of actions." 3229 tooltip => "Start/Stops recording of actions."
3240 ."All subsequent actions after the recording started will be captured." 3230 ."All subsequent actions after the recording started will be captured."
3241 ."The actions are displayed after the record was stopped." 3231 ."The actions are displayed after the record was stopped."
3246 } else { 3236 } else {
3247 $self->stop; 3237 $self->stop;
3248 } 3238 }
3249 }); 3239 });
3250 3240
3241 $vb->add (new CFClient::UI::Label text => "Actions:");
3251 $vb->add ($self->{cmdbox} = new CFClient::UI::VBox); 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 });
3252 3253
3253 $vb->add (my $hb = new CFClient::UI::HBox); 3254 $vb->add (my $hb = new CFClient::UI::HBox);
3254 $hb->add (new CFClient::UI::Button 3255 $hb->add (new CFClient::UI::Button
3255 text => "ok", 3256 text => "ok",
3257 expand => 1,
3256 tooltip => "This closes the binding editor and saves the binding", 3258 tooltip => "This closes the binding editor and saves the binding",
3257 on_activate => sub { 3259 on_activate => sub {
3258 $self->hide; 3260 $self->hide;
3259 $self->commit; 3261 $self->commit;
3260 }); 3262 });
3261 3263
3262 $hb->add (new CFClient::UI::Button 3264 $hb->add (new CFClient::UI::Button
3263 text => "cancel", 3265 text => "cancel",
3266 expand => 1,
3264 tooltip => "This closes the binding editor without saving", 3267 tooltip => "This closes the binding editor without saving",
3265 on_activate => sub { 3268 on_activate => sub {
3266 $self->hide; 3269 $self->hide;
3267 $self->{binding_cancel}->() 3270 $self->{binding_cancel}->()
3268 if $self->{binding_cancel}; 3271 if $self->{binding_cancel};
3280 $::STATUSBOX->add ("Bound actions to '".CFClient::Binder::keycombo_to_name ($mod, $sym) 3283 $::STATUSBOX->add ("Bound actions to '".CFClient::Binder::keycombo_to_name ($mod, $sym)
3281 ."'. Don't forget 'Save Config'!"); 3284 ."'. Don't forget 'Save Config'!");
3282 $self->{binding_change}->($mod, $sym, $cmds) 3285 $self->{binding_change}->($mod, $sym, $cmds)
3283 if $self->{binding_change}; 3286 if $self->{binding_change};
3284 } else { 3287 } else {
3285 $::STATUSBOX->add ("No action bound, no keys specified!"); 3288 $::STATUSBOX->add ("No action bound, no key or action specified!");
3286 $self->{binding_cancel}->() 3289 $self->{binding_cancel}->()
3287 if $self->{binding_cancel}; 3290 if $self->{binding_cancel};
3288 } 3291 }
3289} 3292}
3290 3293
3307 $rec = $::CONN->stop_record if $::CONN; 3310 $rec = $::CONN->stop_record if $::CONN;
3308 return unless ref $rec eq 'ARRAY'; 3311 return unless ref $rec eq 'ARRAY';
3309 $self->set_command_list ($rec); 3312 $self->set_command_list ($rec);
3310} 3313}
3311 3314
3315# if $commit is true, the binding will be set after the user entered a key combo
3312sub ask_for_bind { 3316sub ask_for_bind {
3313 my ($self, $commit) = @_; 3317 my ($self, $commit) = @_;
3314 3318
3315 CFClient::Binder::open_binding_dialog (sub { 3319 CFClient::Binder::open_binding_dialog (sub {
3316 my ($mod, $sym) = @_; 3320 my ($mod, $sym) = @_;
3318 $self->update_binding_widgets; 3322 $self->update_binding_widgets;
3319 $self->commit if $commit; 3323 $self->commit if $commit;
3320 }); 3324 });
3321} 3325}
3322 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
3323sub set_binding { 3332sub set_binding {
3324 my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_; 3333 my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_;
3325 3334
3326 $self->clear_command_list; 3335 $self->clear_command_list;
3327 $self->{recording} = 0; 3336 $self->{recording} = 0;
3332 3341
3333 $self->{binding_change} = $cb; 3342 $self->{binding_change} = $cb;
3334 $self->{binding_cancel} = $ccb; 3343 $self->{binding_cancel} = $ccb;
3335 3344
3336 $self->update_binding_widgets; 3345 $self->update_binding_widgets;
3346}
3347
3348# this is a shortcut method that asks for a binding
3349# and then just binds it.
3350sub 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);
3337} 3356}
3338 3357
3339sub update_binding_widgets { 3358sub update_binding_widgets {
3340 my ($self) = @_; 3359 my ($self) = @_;
3341 my ($mod, $sym, $cmds) = $self->get_binding; 3360 my ($mod, $sym, $cmds) = $self->get_binding;
3367 3386
3368 for (@$cmds) { 3387 for (@$cmds) {
3369 $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox); 3388 $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox);
3370 3389
3371 my $i = $idx; 3390 my $i = $idx;
3391 $hb->add (new CFClient::UI::Label text => $_);
3372 $hb->add (new CFClient::UI::Button 3392 $hb->add (new CFClient::UI::Button
3373 text => "delete", 3393 text => "delete",
3374 tooltip => "Deletes the action from the record", 3394 tooltip => "Deletes the action from the record",
3375 on_activate => sub { 3395 on_activate => sub {
3376 $self->{cmdbox}->remove ($hb); 3396 $self->{cmdbox}->remove ($hb);
3377 $cmds->[$i] = undef; 3397 $cmds->[$i] = undef;
3378 }); 3398 });
3379 3399
3380 $hb->add (new CFClient::UI::Label text => $_);
3381 3400
3382 $idx++ 3401 $idx++
3383 } 3402 }
3384} 3403}
3385 3404
3405
3406#############################################################################
3407
3408package CFClient::UI::SpellList;
3409
3410our @ISA = CFClient::UI::FancyFrame::;
3411
3412sub 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...
3424sub 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
3451sub rebuild_spell_list {
3452 my ($self) = @_;
3453 $self->{tbl_idx} = 0;
3454 $self->add_spell ($_) for values %{$self->{spells}};
3455}
3456
3457sub remove_spell {
3458 my ($self, $spell) = @_;
3459 delete $self->{spells}->{$spell->{name}};
3460 $self->rebuild_spell_list;
3461}
3386 3462
3387############################################################################# 3463#############################################################################
3388 3464
3389package CFClient::UI; 3465package CFClient::UI;
3390 3466

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines