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.261 by elmex, Tue May 30 14:45:56 2006 UTC vs.
Revision 1.263 by elmex, Wed May 31 14:04:52 2006 UTC

3310 $rec = $::CONN->stop_record if $::CONN; 3310 $rec = $::CONN->stop_record if $::CONN;
3311 return unless ref $rec eq 'ARRAY'; 3311 return unless ref $rec eq 'ARRAY';
3312 $self->set_command_list ($rec); 3312 $self->set_command_list ($rec);
3313} 3313}
3314 3314
3315# if $commit is true, the binding will be set after the user entered a key combo
3315sub ask_for_bind { 3316sub ask_for_bind {
3316 my ($self, $commit) = @_; 3317 my ($self, $commit) = @_;
3317 3318
3318 CFClient::Binder::open_binding_dialog (sub { 3319 CFClient::Binder::open_binding_dialog (sub {
3319 my ($mod, $sym) = @_; 3320 my ($mod, $sym) = @_;
3321 $self->update_binding_widgets; 3322 $self->update_binding_widgets;
3322 $self->commit if $commit; 3323 $self->commit if $commit;
3323 }); 3324 });
3324} 3325}
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
3326sub set_binding { 3332sub set_binding {
3327 my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_; 3333 my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_;
3328 3334
3329 $self->clear_command_list; 3335 $self->clear_command_list;
3330 $self->{recording} = 0; 3336 $self->{recording} = 0;
3335 3341
3336 $self->{binding_change} = $cb; 3342 $self->{binding_change} = $cb;
3337 $self->{binding_cancel} = $ccb; 3343 $self->{binding_cancel} = $ccb;
3338 3344
3339 $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);
3340} 3356}
3341 3357
3342sub update_binding_widgets { 3358sub update_binding_widgets {
3343 my ($self) = @_; 3359 my ($self) = @_;
3344 my ($mod, $sym, $cmds) = $self->get_binding; 3360 my ($mod, $sym, $cmds) = $self->get_binding;
3370 3386
3371 for (@$cmds) { 3387 for (@$cmds) {
3372 $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox); 3388 $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox);
3373 3389
3374 my $i = $idx; 3390 my $i = $idx;
3391 $hb->add (new CFClient::UI::Label text => $_);
3375 $hb->add (new CFClient::UI::Button 3392 $hb->add (new CFClient::UI::Button
3376 text => "delete", 3393 text => "delete",
3377 tooltip => "Deletes the action from the record", 3394 tooltip => "Deletes the action from the record",
3378 on_activate => sub { 3395 on_activate => sub {
3379 $self->{cmdbox}->remove ($hb); 3396 $self->{cmdbox}->remove ($hb);
3380 $cmds->[$i] = undef; 3397 $cmds->[$i] = undef;
3381 }); 3398 });
3382 3399
3383 $hb->add (new CFClient::UI::Label text => $_);
3384 3400
3385 $idx++ 3401 $idx++
3386 } 3402 }
3387} 3403}
3388 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}
3389 3462
3390############################################################################# 3463#############################################################################
3391 3464
3392package CFClient::UI; 3465package CFClient::UI;
3393 3466

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines