… | |
… | |
371 | sub size_allocate { |
371 | sub size_allocate { |
372 | # nothing to be done |
372 | # nothing to be done |
373 | } |
373 | } |
374 | |
374 | |
375 | sub children { |
375 | sub children { |
|
|
376 | # nop |
|
|
377 | } |
|
|
378 | |
|
|
379 | sub visible_children { |
|
|
380 | $_[0]->children |
376 | } |
381 | } |
377 | |
382 | |
378 | sub set_max_size { |
383 | sub set_max_size { |
379 | my ($self, $w, $h) = @_; |
384 | my ($self, $w, $h) = @_; |
380 | |
385 | |
… | |
… | |
663 | our @ISA = CFClient::UI::Base::; |
668 | our @ISA = CFClient::UI::Base::; |
664 | |
669 | |
665 | sub new { |
670 | sub new { |
666 | my ($class, %arg) = @_; |
671 | my ($class, %arg) = @_; |
667 | |
672 | |
668 | my $children = delete $arg{children} || []; |
673 | my $children = delete $arg{children}; |
669 | |
674 | |
670 | my $self = $class->SUPER::new ( |
675 | my $self = $class->SUPER::new ( |
671 | children => [], |
676 | children => [], |
672 | can_events => 0, |
677 | can_events => 0, |
673 | %arg, |
678 | %arg, |
674 | ); |
679 | ); |
|
|
680 | |
675 | $self->add ($_) for @$children; |
681 | $self->add (@$children) |
|
|
682 | if $children; |
676 | |
683 | |
677 | $self |
684 | $self |
678 | } |
685 | } |
679 | |
686 | |
680 | sub add { |
687 | sub add { |
… | |
… | |
728 | $x -= $self->{x}; |
735 | $x -= $self->{x}; |
729 | $y -= $self->{y}; |
736 | $y -= $self->{y}; |
730 | |
737 | |
731 | my $res; |
738 | my $res; |
732 | |
739 | |
733 | for (reverse @{ $self->{children} }) { |
740 | for (reverse $self->visible_children) { |
734 | $res = $_->find_widget ($x, $y) |
741 | $res = $_->find_widget ($x, $y) |
735 | and return $res; |
742 | and return $res; |
736 | } |
743 | } |
737 | |
744 | |
738 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
745 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
… | |
… | |
2854 | $self->SUPER::DESTROY; |
2861 | $self->SUPER::DESTROY; |
2855 | } |
2862 | } |
2856 | |
2863 | |
2857 | ############################################################################# |
2864 | ############################################################################# |
2858 | |
2865 | |
|
|
2866 | package CFClient::UI::Buttonbar; |
|
|
2867 | |
|
|
2868 | our @ISA = CFClient::UI::HBox::; |
|
|
2869 | |
|
|
2870 | # TODO: should actualyl wrap buttons and other goodies. |
|
|
2871 | |
|
|
2872 | ############################################################################# |
|
|
2873 | |
2859 | package CFClient::UI::Menu; |
2874 | package CFClient::UI::Menu; |
2860 | |
2875 | |
2861 | our @ISA = CFClient::UI::FancyFrame::; |
2876 | our @ISA = CFClient::UI::FancyFrame::; |
2862 | |
2877 | |
2863 | use CFClient::OpenGL; |
2878 | use CFClient::OpenGL; |
… | |
… | |
2928 | } else { |
2943 | } else { |
2929 | return 0 |
2944 | return 0 |
2930 | } |
2945 | } |
2931 | |
2946 | |
2932 | 1 |
2947 | 1 |
|
|
2948 | } |
|
|
2949 | |
|
|
2950 | ############################################################################# |
|
|
2951 | |
|
|
2952 | package CFClient::UI::Multiplexer; |
|
|
2953 | |
|
|
2954 | our @ISA = CFClient::UI::Container::; |
|
|
2955 | |
|
|
2956 | sub new { |
|
|
2957 | my $class = shift; |
|
|
2958 | |
|
|
2959 | my $self = $class->SUPER::new ( |
|
|
2960 | @_, |
|
|
2961 | ); |
|
|
2962 | |
|
|
2963 | $self->{current} = $self->{children}[0] |
|
|
2964 | if @{ $self->{children} }; |
|
|
2965 | |
|
|
2966 | $self |
|
|
2967 | } |
|
|
2968 | |
|
|
2969 | sub add { |
|
|
2970 | my ($self, @widgets) = @_; |
|
|
2971 | |
|
|
2972 | $self->SUPER::add (@widgets); |
|
|
2973 | |
|
|
2974 | $self->{current} = $self->{children}[0] |
|
|
2975 | if @{ $self->{children} }; |
|
|
2976 | } |
|
|
2977 | |
|
|
2978 | sub set_current_page { |
|
|
2979 | my ($self, $page_or_widget) = @_; |
|
|
2980 | |
|
|
2981 | my $widget = ref $page_or_widget |
|
|
2982 | ? $page_or_widget |
|
|
2983 | : $self->{children}[$page_or_widget]; |
|
|
2984 | |
|
|
2985 | $self->{current} = $widget; |
|
|
2986 | $self->{current}->configure (0, 0, $self->{w}, $self->{h}); |
|
|
2987 | |
|
|
2988 | $self->_emit (page_changed => $self->{current}); |
|
|
2989 | |
|
|
2990 | $self->realloc; |
|
|
2991 | } |
|
|
2992 | |
|
|
2993 | sub visible_children { |
|
|
2994 | $_[0]{current} |
|
|
2995 | } |
|
|
2996 | |
|
|
2997 | sub size_request { |
|
|
2998 | my ($self) = @_; |
|
|
2999 | |
|
|
3000 | $self->{current}->size_request |
|
|
3001 | } |
|
|
3002 | |
|
|
3003 | sub size_allocate { |
|
|
3004 | my ($self, $w, $h) = @_; |
|
|
3005 | |
|
|
3006 | $self->{current}->configure (0, 0, $w, $h); |
|
|
3007 | } |
|
|
3008 | |
|
|
3009 | sub _draw { |
|
|
3010 | my ($self) = @_; |
|
|
3011 | |
|
|
3012 | $self->{current}->draw; |
|
|
3013 | } |
|
|
3014 | |
|
|
3015 | ############################################################################# |
|
|
3016 | |
|
|
3017 | package CFClient::UI::Notebook; |
|
|
3018 | |
|
|
3019 | our @ISA = CFClient::UI::VBox::; |
|
|
3020 | |
|
|
3021 | sub new { |
|
|
3022 | my $class = shift; |
|
|
3023 | |
|
|
3024 | my $self = $class->SUPER::new ( |
|
|
3025 | buttonbar => (new CFClient::UI::Buttonbar), |
|
|
3026 | multiplexer => (new CFClient::UI::Multiplexer expand => 1), |
|
|
3027 | @_, |
|
|
3028 | ); |
|
|
3029 | |
|
|
3030 | $self->SUPER::add ($self->{buttonbar}, $self->{multiplexer}); |
|
|
3031 | |
|
|
3032 | $self |
|
|
3033 | } |
|
|
3034 | |
|
|
3035 | sub add { |
|
|
3036 | my ($self, $title, $widget, $tooltip) = @_; |
|
|
3037 | |
|
|
3038 | Scalar::Util::weaken $self; |
|
|
3039 | |
|
|
3040 | $self->{buttonbar}->add (new CFClient::UI::Button |
|
|
3041 | markup => $title, |
|
|
3042 | tooltip => $tooltip, |
|
|
3043 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3044 | ); |
|
|
3045 | |
|
|
3046 | $self->{multiplexer}->add ($widget); |
|
|
3047 | } |
|
|
3048 | |
|
|
3049 | sub set_current_page { |
|
|
3050 | my ($self, $page) = @_; |
|
|
3051 | |
|
|
3052 | $self->{multiplexer}->set_current_page ($page); |
|
|
3053 | $self->_emit (page_changed => $self->{multiplexer}{current}); |
2933 | } |
3054 | } |
2934 | |
3055 | |
2935 | ############################################################################# |
3056 | ############################################################################# |
2936 | |
3057 | |
2937 | package CFClient::UI::Statusbox; |
3058 | package CFClient::UI::Statusbox; |
… | |
… | |
3283 | |
3404 | |
3284 | ############################################################################# |
3405 | ############################################################################# |
3285 | |
3406 | |
3286 | package CFClient::UI::SpellList; |
3407 | package CFClient::UI::SpellList; |
3287 | |
3408 | |
3288 | our @ISA = CFClient::UI::FancyFrame::; |
3409 | our @ISA = CFClient::UI::ScrolledWindow::; |
3289 | |
3410 | |
3290 | sub new { |
3411 | sub new { |
3291 | my $class = shift; |
3412 | my $class = shift; |
3292 | |
3413 | |
3293 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
3414 | my $self = $class->SUPER::new ( |
3294 | |
3415 | binding => [], |
3295 | $self->add (new CFClient::UI::ScrolledWindow |
3416 | commands => [], |
3296 | scrolled => $self->{spellbox} = new CFClient::UI::Table); |
3417 | scrolled => (new CFClient::UI::Table), |
3297 | |
3418 | @_, |
3298 | $self; |
3419 | ) |
3299 | } |
3420 | } |
3300 | |
3421 | |
3301 | # XXX: Do sorting? Argl... |
3422 | # XXX: Do sorting? Argl... |
3302 | sub add_spell { |
3423 | sub add_spell { |
3303 | my ($self, $spell) = @_; |
3424 | my ($self, $spell) = @_; |
3304 | $self->{spells}->{$spell->{name}} = $spell; |
3425 | $self->{spells}->{$spell->{name}} = $spell; |
3305 | |
3426 | |
3306 | $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3427 | $self->{scrolled}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
3307 | face => $spell->{face}, |
3428 | face => $spell->{face}, |
3308 | can_hover => 1, |
3429 | can_hover => 1, |
3309 | can_events => 1, |
3430 | can_events => 1, |
3310 | tooltip => $spell->{message}); |
3431 | tooltip => $spell->{message}); |
3311 | |
3432 | |
3312 | $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3433 | $self->{scrolled}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
3313 | text => $spell->{name}, |
3434 | text => $spell->{name}, |
3314 | can_hover => 1, |
3435 | can_hover => 1, |
3315 | can_events => 1, |
3436 | can_events => 1, |
3316 | tooltip => $spell->{message}, |
3437 | tooltip => $spell->{message}, |
3317 | expand => 1); |
3438 | expand => 1); |
3318 | |
3439 | |
3319 | $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3440 | $self->{scrolled}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
3320 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3441 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
3321 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3442 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
3322 | expand => 1); |
3443 | expand => 1); |
3323 | |
3444 | |
3324 | $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3445 | $self->{scrolled}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
3325 | text => "bind to key", |
3446 | text => "bind to key", |
3326 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3447 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
3327 | } |
3448 | } |
3328 | |
3449 | |
3329 | sub rebuild_spell_list { |
3450 | sub rebuild_spell_list { |