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.313 by root, Sat Jun 24 00:24:09 2006 UTC vs.
Revision 1.314 by root, Mon Jun 26 21:59:04 2006 UTC

986 $self->add ($child) if $child; 986 $self->add ($child) if $child;
987 987
988 $self 988 $self
989} 989}
990 990
991#TODO# update range on size_allocate depending on child
992
991sub add { 993sub add {
992 my ($self, $widget) = @_; 994 my ($self, $widget) = @_;
993 995
994 $self->{vp}->add ($self->{child} = $widget); 996 $self->{vp}->add ($self->{child} = $widget);
995} 997}
996 998
999sub update_slider {
1000 my ($self) = @_;
1001
1002 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $self->{vp}->child->{h}, $self->{vp}{h}, 1]);
1003}
1004
997sub update { 1005sub update {
998 my ($self) = @_; 1006 my ($self) = @_;
999 1007
1000 $self->SUPER::update; 1008 $self->SUPER::update;
1001 1009
1002 # todo: overwrite size_allocate of child 1010 $self->update_slider;
1003 my $child = $self->{vp}->child;
1004 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
1005} 1011}
1006 1012
1007sub invoke_size_allocate { 1013sub invoke_size_allocate {
1008 my ($self, $w, $h) = @_; 1014 my ($self, $w, $h) = @_;
1009 1015
1010 my $child = $self->{vp}->child; 1016 $self->update_slider;
1011 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
1012 1017
1013 $self->SUPER::invoke_size_allocate ($w, $h) 1018 $self->SUPER::invoke_size_allocate ($w, $h)
1014} 1019}
1015
1016#TODO# update range on size_allocate depending on child
1017# update viewport offset on scroll
1018 1020
1019############################################################################# 1021#############################################################################
1020 1022
1021package CFClient::UI::Frame; 1023package CFClient::UI::Frame;
1022 1024
3473 } 3475 }
3474} 3476}
3475 3477
3476############################################################################# 3478#############################################################################
3477 3479
3478package CFClient::UI::BindEditor;
3479
3480our @ISA = CFClient::UI::FancyFrame::;
3481
3482sub new {
3483 my $class = shift;
3484
3485 my $self = $class->SUPER::new (binding => [], commands => [], @_);
3486
3487 $self->add (my $vb = new CFClient::UI::VBox);
3488
3489
3490 $vb->add ($self->{rec_btn} = new CFClient::UI::Button
3491 text => "start recording",
3492 tooltip => "Start/Stops recording of actions."
3493 ."All subsequent actions after the recording started will be captured."
3494 ."The actions are displayed after the record was stopped."
3495 ."To bind the action you have to click on the 'Bind' button",
3496 on_activate => sub {
3497 unless ($self->{recording}) {
3498 $self->start;
3499 } else {
3500 $self->stop;
3501 }
3502 });
3503
3504 $vb->add (new CFClient::UI::Label text => "Actions:");
3505 $vb->add ($self->{cmdbox} = new CFClient::UI::VBox);
3506
3507 $vb->add (new CFClient::UI::Label text => "Bound to: ");
3508 $vb->add (my $hb = new CFClient::UI::HBox);
3509 $hb->add ($self->{keylbl} = new CFClient::UI::Label expand => 1);
3510 $hb->add (new CFClient::UI::Button
3511 text => "bind",
3512 tooltip => "This opens a query where you have to press the key combination to bind the recorded actions",
3513 on_activate => sub {
3514 $self->ask_for_bind;
3515 });
3516
3517 $vb->add (my $hb = new CFClient::UI::HBox);
3518 $hb->add (new CFClient::UI::Button
3519 text => "ok",
3520 expand => 1,
3521 tooltip => "This closes the binding editor and saves the binding",
3522 on_activate => sub {
3523 $self->hide;
3524 $self->commit;
3525 });
3526
3527 $hb->add (new CFClient::UI::Button
3528 text => "cancel",
3529 expand => 1,
3530 tooltip => "This closes the binding editor without saving",
3531 on_activate => sub {
3532 $self->hide;
3533 $self->{binding_cancel}->()
3534 if $self->{binding_cancel};
3535 });
3536
3537 $self->update_binding_widgets;
3538
3539 $self
3540}
3541
3542sub cfg_bind {
3543 my ($self, $mod, $sym, $cmds) = @_;
3544 $::CFG->{profile}{default}{bindings}{$mod}{$sym} = $cmds;
3545 ::update_bindings ();
3546}
3547
3548sub cfg_unbind {
3549 my ($self, $mod, $sym, $cmds) = @_;
3550 delete $::CFG->{profile}{default}{bindings}{$mod}{$sym};
3551 ::update_bindings ();
3552}
3553
3554sub commit {
3555 my ($self) = @_;
3556 my ($mod, $sym, $cmds) = $self->get_binding;
3557 if ($sym != 0 && @$cmds > 0) {
3558 $::STATUSBOX->add ("Bound actions to '".CFClient::Binder::keycombo_to_name ($mod, $sym)
3559 ."'. Don't forget 'Save Config'!");
3560 $self->{binding_change}->($mod, $sym, $cmds)
3561 if $self->{binding_change};
3562 } else {
3563 $::STATUSBOX->add ("No action bound, no key or action specified!");
3564 $self->{binding_cancel}->()
3565 if $self->{binding_cancel};
3566 }
3567}
3568
3569sub start {
3570 my ($self) = @_;
3571
3572 $self->{rec_btn}->set_text ("stop recording");
3573 $self->{recording} = 1;
3574 $self->clear_command_list;
3575 $::CONN->start_record if $::CONN;
3576}
3577
3578sub stop {
3579 my ($self) = @_;
3580
3581 $self->{rec_btn}->set_text ("start recording");
3582 $self->{recording} = 0;
3583
3584 my $rec;
3585 $rec = $::CONN->stop_record if $::CONN;
3586 return unless ref $rec eq 'ARRAY';
3587 $self->set_command_list ($rec);
3588}
3589
3590
3591sub ask_for_bind_and_commit {
3592 my ($self) = @_;
3593 $self->ask_for_bind (1);
3594}
3595
3596sub ask_for_bind {
3597 my ($self, $commit, $end_cb) = @_;
3598
3599 CFClient::Binder::open_binding_dialog (sub {
3600 my ($mod, $sym) = @_;
3601 $self->{binding} = [$mod, $sym]; # XXX: how to stop that memleak?
3602 $self->update_binding_widgets;
3603 $self->commit if $commit;
3604 $end_cb->() if $end_cb;
3605 });
3606}
3607
3608# $mod and $sym are the modifiers and key symbol
3609# $cmds is a array ref of strings (the commands)
3610# $cb is the callback that is executed on OK
3611# $ccb is the callback that is executed on CANCEL and
3612# when the binding was unsuccessful on OK
3613sub set_binding {
3614 my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_;
3615
3616 $self->clear_command_list;
3617 $self->{recording} = 0;
3618 $self->{rec_btn}->set_text ("start recording");
3619
3620 $self->{binding} = [$mod, $sym];
3621 $self->{commands} = $cmds;
3622
3623 $self->{binding_change} = $cb;
3624 $self->{binding_cancel} = $ccb;
3625
3626 $self->update_binding_widgets;
3627}
3628
3629# this is a shortcut method that asks for a binding
3630# and then just binds it.
3631sub do_quick_binding {
3632 my ($self, $cmds, $end_cb) = @_;
3633 $self->set_binding (undef, undef, $cmds, sub { $self->cfg_bind (@_) });
3634 $self->ask_for_bind (1, $end_cb);
3635}
3636
3637sub update_binding_widgets {
3638 my ($self) = @_;
3639 my ($mod, $sym, $cmds) = $self->get_binding;
3640 $self->{keylbl}->set_text (CFClient::Binder::keycombo_to_name ($mod, $sym));
3641 $self->set_command_list ($cmds);
3642}
3643
3644sub get_binding {
3645 my ($self) = @_;
3646 return (
3647 $self->{binding}->[0],
3648 $self->{binding}->[1],
3649 [ grep { defined $_ } @{$self->{commands}} ]
3650 );
3651}
3652
3653sub clear_command_list {
3654 my ($self) = @_;
3655 $self->{cmdbox}->clear ();
3656}
3657
3658sub set_command_list {
3659 my ($self, $cmds) = @_;
3660
3661 $self->{cmdbox}->clear ();
3662 $self->{commands} = $cmds;
3663
3664 my $idx = 0;
3665
3666 for (@$cmds) {
3667 $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox);
3668
3669 my $i = $idx;
3670 $hb->add (new CFClient::UI::Label text => $_);
3671 $hb->add (new CFClient::UI::Button
3672 text => "delete",
3673 tooltip => "Deletes the action from the record",
3674 on_activate => sub {
3675 $self->{cmdbox}->remove ($hb);
3676 $cmds->[$i] = undef;
3677 });
3678
3679
3680 $idx++
3681 }
3682}
3683
3684#############################################################################
3685
3686package CFClient::UI::SpellList; 3480package CFClient::UI::SpellList;
3687 3481
3688our @ISA = CFClient::UI::Table::; 3482our @ISA = CFClient::UI::Table::;
3689 3483
3690sub new { 3484sub new {
3739 } elsif ($ev->{button} == 2) { 3533 } elsif ($ev->{button} == 2) {
3740 $::CONN->user_send ("invoke $spell->{name}"); 3534 $::CONN->user_send ("invoke $spell->{name}");
3741 } elsif ($ev->{button} == 3) { 3535 } elsif ($ev->{button} == 3) {
3742 (new CFClient::UI::Menu 3536 (new CFClient::UI::Menu
3743 items => [ 3537 items => [
3744 ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], 3538 ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }],
3745 ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], 3539 ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }],
3746 ], 3540 ],
3747 )->popup ($ev); 3541 )->popup ($ev);
3748 } else { 3542 } else {
3749 return 0; 3543 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines