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.271 by root, Fri Jun 2 22:13:47 2006 UTC vs.
Revision 1.273 by root, Sat Jun 3 02:32:35 2006 UTC

371sub size_allocate { 371sub size_allocate {
372 # nothing to be done 372 # nothing to be done
373} 373}
374 374
375sub children { 375sub children {
376 # nop
377}
378
379sub visible_children {
380 $_[0]->children
376} 381}
377 382
378sub set_max_size { 383sub set_max_size {
379 my ($self, $w, $h) = @_; 384 my ($self, $w, $h) = @_;
380 385
663our @ISA = CFClient::UI::Base::; 668our @ISA = CFClient::UI::Base::;
664 669
665sub new { 670sub 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
680sub add { 687sub 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})
948package CFClient::UI::ScrolledWindow; 955package CFClient::UI::ScrolledWindow;
949 956
950our @ISA = CFClient::UI::HBox::; 957our @ISA = CFClient::UI::HBox::;
951 958
952sub new { 959sub new {
953 my $class = shift; 960 my ($class, %arg) = @_;
961
962 my $child = delete $arg{child};
954 963
955 my $self; 964 my $self;
956 965
957 my $slider = new CFClient::UI::Slider 966 my $slider = new CFClient::UI::Slider
958 vertical => 1, 967 vertical => 1,
963 ; 972 ;
964 973
965 $self = $class->SUPER::new ( 974 $self = $class->SUPER::new (
966 vp => (new CFClient::UI::ViewPort expand => 1), 975 vp => (new CFClient::UI::ViewPort expand => 1),
967 slider => $slider, 976 slider => $slider,
968 @_, 977 %arg,
969 ); 978 );
970 979
971 $self->{vp}->add ($self->{scrolled});
972 $self->add ($self->{vp});
973 $self->add ($self->{slider}); 980 $self->SUPER::add ($self->{vp}, $self->{slider});
981 $self->add ($child) if $child;
974 982
975 $self 983 $self
984}
985
986sub add {
987 my ($self, $widget) = @_;
988
989 $self->{vp}->add ($self->{child} = $widget);
976} 990}
977 991
978sub update { 992sub update {
979 my ($self) = @_; 993 my ($self) = @_;
980 994
2854 $self->SUPER::DESTROY; 2868 $self->SUPER::DESTROY;
2855} 2869}
2856 2870
2857############################################################################# 2871#############################################################################
2858 2872
2873package CFClient::UI::Buttonbar;
2874
2875our @ISA = CFClient::UI::HBox::;
2876
2877# TODO: should actualyl wrap buttons and other goodies.
2878
2879#############################################################################
2880
2859package CFClient::UI::Menu; 2881package CFClient::UI::Menu;
2860 2882
2861our @ISA = CFClient::UI::FancyFrame::; 2883our @ISA = CFClient::UI::FancyFrame::;
2862 2884
2863use CFClient::OpenGL; 2885use CFClient::OpenGL;
2928 } else { 2950 } else {
2929 return 0 2951 return 0
2930 } 2952 }
2931 2953
2932 1 2954 1
2955}
2956
2957#############################################################################
2958
2959package CFClient::UI::Multiplexer;
2960
2961our @ISA = CFClient::UI::Container::;
2962
2963sub new {
2964 my $class = shift;
2965
2966 my $self = $class->SUPER::new (
2967 @_,
2968 );
2969
2970 $self->{current} = $self->{children}[0]
2971 if @{ $self->{children} };
2972
2973 $self
2974}
2975
2976sub add {
2977 my ($self, @widgets) = @_;
2978
2979 $self->SUPER::add (@widgets);
2980
2981 $self->{current} = $self->{children}[0]
2982 if @{ $self->{children} };
2983}
2984
2985sub set_current_page {
2986 my ($self, $page_or_widget) = @_;
2987
2988 my $widget = ref $page_or_widget
2989 ? $page_or_widget
2990 : $self->{children}[$page_or_widget];
2991
2992 $self->{current} = $widget;
2993 $self->{current}->configure (0, 0, $self->{w}, $self->{h});
2994
2995 $self->_emit (page_changed => $self->{current});
2996
2997 $self->realloc;
2998}
2999
3000sub visible_children {
3001 $_[0]{current}
3002}
3003
3004sub size_request {
3005 my ($self) = @_;
3006
3007 $self->{current}->size_request
3008}
3009
3010sub size_allocate {
3011 my ($self, $w, $h) = @_;
3012
3013 $self->{current}->configure (0, 0, $w, $h);
3014}
3015
3016sub _draw {
3017 my ($self) = @_;
3018
3019 $self->{current}->draw;
3020}
3021
3022#############################################################################
3023
3024package CFClient::UI::Notebook;
3025
3026our @ISA = CFClient::UI::VBox::;
3027
3028sub new {
3029 my $class = shift;
3030
3031 my $self = $class->SUPER::new (
3032 buttonbar => (new CFClient::UI::Buttonbar),
3033 multiplexer => (new CFClient::UI::Multiplexer expand => 1),
3034 # filter => # will be put between multiplexer and $self
3035 @_,
3036 );
3037
3038 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3039 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3040
3041 $self
3042}
3043
3044sub add {
3045 my ($self, $title, $widget, $tooltip) = @_;
3046
3047 Scalar::Util::weaken $self;
3048
3049 $self->{buttonbar}->add (new CFClient::UI::Button
3050 markup => $title,
3051 tooltip => $tooltip,
3052 on_activate => sub { $self->set_current_page ($widget) },
3053 );
3054
3055 $self->{multiplexer}->add ($widget);
3056}
3057
3058sub set_current_page {
3059 my ($self, $page) = @_;
3060
3061 $self->{multiplexer}->set_current_page ($page);
3062 $self->_emit (page_changed => $self->{multiplexer}{current});
2933} 3063}
2934 3064
2935############################################################################# 3065#############################################################################
2936 3066
2937package CFClient::UI::Statusbox; 3067package CFClient::UI::Statusbox;
3050 3180
3051sub new { 3181sub new {
3052 my $class = shift; 3182 my $class = shift;
3053 3183
3054 my $self = $class->SUPER::new ( 3184 my $self = $class->SUPER::new (
3055 scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), 3185 child => (new CFClient::UI::Table col_expand => [0, 1, 0]),
3056 @_, 3186 @_,
3057 ); 3187 );
3058 3188
3059 $self 3189 $self
3060} 3190}
3061 3191
3062sub set_items { 3192sub set_items {
3063 my ($self, $items) = @_; 3193 my ($self, $items) = @_;
3064 3194
3065 $self->{scrolled}->clear; 3195 $self->{child}->clear;
3066 return unless $items; 3196 return unless $items;
3067 3197
3068 my @items = sort { 3198 my @items = sort {
3069 ($a->{type} <=> $b->{type}) 3199 ($a->{type} <=> $b->{type})
3070 or ($a->{name} cmp $b->{name}) 3200 or ($a->{name} cmp $b->{name})
3074 3204
3075 my $row = 0; 3205 my $row = 0;
3076 for my $item (@items) { 3206 for my $item (@items) {
3077 CFClient::Item::update_widgets $item; 3207 CFClient::Item::update_widgets $item;
3078 3208
3079 $self->{scrolled}->add (0, $row, $item->{face_widget}); 3209 $self->{child}->add (0, $row, $item->{face_widget});
3080 $self->{scrolled}->add (1, $row, $item->{desc_widget}); 3210 $self->{child}->add (1, $row, $item->{desc_widget});
3081 $self->{scrolled}->add (2, $row, $item->{weight_widget}); 3211 $self->{child}->add (2, $row, $item->{weight_widget});
3082 3212
3083 $row++; 3213 $row++;
3084 } 3214 }
3085} 3215}
3086 3216
3283 3413
3284############################################################################# 3414#############################################################################
3285 3415
3286package CFClient::UI::SpellList; 3416package CFClient::UI::SpellList;
3287 3417
3288our @ISA = CFClient::UI::FancyFrame::; 3418our @ISA = CFClient::UI::Table::;
3289 3419
3290sub new { 3420sub new {
3291 my $class = shift; 3421 my $class = shift;
3292 3422
3293 my $self = $class->SUPER::new (binding => [], commands => [], @_); 3423 my $self = $class->SUPER::new (
3294 3424 binding => [],
3295 $self->add (new CFClient::UI::ScrolledWindow 3425 commands => [],
3296 scrolled => $self->{spellbox} = new CFClient::UI::Table); 3426 @_,
3297 3427 )
3298 $self;
3299} 3428}
3300 3429
3301# XXX: Do sorting? Argl... 3430# XXX: Do sorting? Argl...
3302sub add_spell { 3431sub add_spell {
3303 my ($self, $spell) = @_; 3432 my ($self, $spell) = @_;
3304 $self->{spells}->{$spell->{name}} = $spell; 3433 $self->{spells}->{$spell->{name}} = $spell;
3305 3434
3306 $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face 3435 $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face
3307 face => $spell->{face}, 3436 face => $spell->{face},
3308 can_hover => 1, 3437 can_hover => 1,
3309 can_events => 1, 3438 can_events => 1,
3310 tooltip => $spell->{message}); 3439 tooltip => $spell->{message});
3311 3440
3312 $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label 3441 $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label
3313 text => $spell->{name}, 3442 text => $spell->{name},
3314 can_hover => 1, 3443 can_hover => 1,
3315 can_events => 1, 3444 can_events => 1,
3316 tooltip => $spell->{message}, 3445 tooltip => $spell->{message},
3317 expand => 1); 3446 expand => 1);
3318 3447
3319 $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label 3448 $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label
3320 text => (sprintf "lvl: %2d sp: %2d dmg: %2d", 3449 text => (sprintf "lvl: %2d sp: %2d dmg: %2d",
3321 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), 3450 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}),
3322 expand => 1); 3451 expand => 1);
3323 3452
3324 $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button 3453 $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button
3325 text => "bind to key", 3454 text => "bind to key",
3326 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); 3455 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) });
3327} 3456}
3328 3457
3329sub rebuild_spell_list { 3458sub rebuild_spell_list {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines