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.234 by root, Thu May 25 16:24:44 2006 UTC vs.
Revision 1.241 by root, Fri May 26 20:50:35 2006 UTC

5 5
6use Scalar::Util (); 6use Scalar::Util ();
7use List::Util (); 7use List::Util ();
8 8
9use CFClient; 9use CFClient;
10use CFClient::Texture;
10 11
11our ($FOCUS, $HOVER, $GRAB); # various widgets 12our ($FOCUS, $HOVER, $GRAB); # various widgets
12 13
13our $ROOT; 14our $ROOT;
14our $TOOLTIP; 15our $TOOLTIP;
228sub set_invisible { 229sub set_invisible {
229 my ($self) = @_; 230 my ($self) = @_;
230 231
231 # broken show/hide model 232 # broken show/hide model
232 233
234 delete $self->{root};
233 delete $self->{visible}; 235 delete $self->{visible};
234 236
235 undef $GRAB if $GRAB == $self; 237 undef $GRAB if $GRAB == $self;
236 undef $HOVER if $HOVER == $self; 238 undef $HOVER if $HOVER == $self;
237 239
458sub set_parent { 460sub set_parent {
459 my ($self, $parent) = @_; 461 my ($self, $parent) = @_;
460 462
461 Scalar::Util::weaken ($self->{parent} = $parent); 463 Scalar::Util::weaken ($self->{parent} = $parent);
462 464
465 $self->{root} = $parent->{root};
466 $self->{visible} = $parent->{visible} + 1;
467
463 # TODO: req_w _does_change after ->reconfigure 468 # TODO: req_w _does_change after ->reconfigure
464 $self->check_size 469 $self->check_size
465 unless exists $self->{req_w}; 470 unless exists $self->{req_w};
466 471
467 $self->show; 472 $self->show;
618 delete $child->{parent}; 623 delete $child->{parent};
619 $child->hide; 624 $child->hide;
620 625
621 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 626 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
622 627
623 $self->check_size; 628 $self->check_size (1);
624 $self->update; 629 $self->update;
625} 630}
626 631
627sub clear { 632sub clear {
628 my ($self) = @_; 633 my ($self) = @_;
871 $self->{vp}->add ($self->{scrolled}); 876 $self->{vp}->add ($self->{scrolled});
872 $self->add ($self->{vp}); 877 $self->add ($self->{vp});
873 $self->add ($self->{slider}); 878 $self->add ($self->{slider});
874 879
875 $self 880 $self
881}
882
883sub update {
884 my ($self) = @_;
885
886 $self->SUPER::update;
887
888 # todo: overwrite size_allocate of child
889 my $child = $self->{vp}->child;
890 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
876} 891}
877 892
878sub size_allocate { 893sub size_allocate {
879 my ($self, $w, $h) = @_; 894 my ($self, $w, $h) = @_;
880 895
1101 col_expand => [], 1116 col_expand => [],
1102 @_, 1117 @_,
1103 ) 1118 )
1104} 1119}
1105 1120
1121sub children {
1122 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1123}
1124
1106sub add { 1125sub add {
1107 my ($self, $x, $y, $child) = @_; 1126 my ($self, $x, $y, $child) = @_;
1108 1127
1109 $child->set_parent ($self); 1128 $child->set_parent ($self);
1110 $self->{children}[$y][$x] = $child; 1129 $self->{children}[$y][$x] = $child;
1111 1130
1112 $child->check_size; 1131 $self->check_size (1);
1113} 1132}
1114 1133
1115sub children {
1116 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1117}
1118
1119# TODO: move to container class maybe? send childs a signal on removal? 1134# TODO: move to container class maybe? send children a signal on removal?
1120sub clear { 1135sub clear {
1121 my ($self) = @_; 1136 my ($self) = @_;
1122 1137
1123 my @children = $self->children; 1138 my @children = $self->children;
1124 delete $self->{children}; 1139 delete $self->{children};
1126 for (@children) { 1141 for (@children) {
1127 delete $_->{parent}; 1142 delete $_->{parent};
1128 $_->hide; 1143 $_->hide;
1129 } 1144 }
1130 1145
1146 $self->check_size (1);
1131 $self->update; 1147 $self->update;
1132} 1148}
1133 1149
1134sub get_wh { 1150sub get_wh {
1135 my ($self) = @_; 1151 my ($self) = @_;
1167sub size_allocate { 1183sub size_allocate {
1168 my ($self, $w, $h) = @_; 1184 my ($self, $w, $h) = @_;
1169 1185
1170 my ($ws, $hs) = $self->get_wh; 1186 my ($ws, $hs) = $self->get_wh;
1171 1187
1172 my $req_w = sum @$ws; 1188 my $req_w = (sum @$ws) || 1;
1173 my $req_h = sum @$hs; 1189 my $req_h = (sum @$hs) || 1;
1174 1190
1175 # TODO: nicer code && do row_expand 1191 # TODO: nicer code && do row_expand
1176 my @col_expand = @{$self->{col_expand}}; 1192 my @col_expand = @{$self->{col_expand}};
1177 @col_expand = (1) x @$ws unless @col_expand; 1193 @col_expand = (1) x @$ws unless @col_expand;
1178 my $col_expand = (sum @col_expand) || 1; 1194 my $col_expand = (sum @col_expand) || 1;
2132} 2148}
2133 2149
2134sub set_range { 2150sub set_range {
2135 my ($self, $range) = @_; 2151 my ($self, $range) = @_;
2136 2152
2137 $self->{range} = $range; 2153 ($range, $self->{range}) = ($self->{range}, $range);
2138 2154
2139 $self->update; 2155 $self->update
2156 if "@$range" ne "@{$self->{range}}";
2140} 2157}
2141 2158
2142sub set_value { 2159sub set_value {
2143 my ($self, $value) = @_; 2160 my ($self, $value) = @_;
2144 2161
2709 $self->SUPER::DESTROY; 2726 $self->SUPER::DESTROY;
2710} 2727}
2711 2728
2712############################################################################# 2729#############################################################################
2713 2730
2714package CFClient::UI::InventoryItem;
2715
2716our @ISA = CFClient::UI::HBox::;
2717
2718sub new {
2719 my $class = shift;
2720
2721 my %args = @_;
2722
2723 my $item = delete $args{item};
2724
2725 my $desc = CFClient::Item::desc_string $item;
2726
2727 my $self = $class->SUPER::new (
2728 can_hover => 1,
2729 can_events => 1,
2730 tooltip => ((CFClient::UI::Label::escape $desc)
2731 . "\n<small>leftclick - examine\nshift+leftclick - move/pickup/drop\nmiddle click - apply\nrightclick - menu</small>"),
2732 connect_button_down => sub {
2733 my ($self, $ev, $x, $y) = @_;
2734
2735 # todo: maybe put examine on 1? but should just be a tooltip :(
2736 if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) {
2737 my $targ = $::CONN->{player}{tag};
2738
2739 if ($item->{container} == $::CONN->{player}{tag}) {
2740 $targ = $main::OPENCONT;
2741 }
2742
2743 $::CONN->send ("move $targ $item->{tag} 0");
2744 } elsif ($ev->{button} == 1) {
2745 $::CONN->send ("examine $item->{tag}");
2746 } elsif ($ev->{button} == 2) {
2747 $::CONN->send ("apply $item->{tag}");
2748 } elsif ($ev->{button} == 3) {
2749 my @menu_items = (
2750 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2751 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2752 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2753 (
2754 $item->{flags} & Crossfire::Protocol::F_LOCKED
2755 ? (
2756 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2757 )
2758 : (
2759 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2760 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2761 )
2762 ),
2763 );
2764
2765 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2766 }
2767
2768 1
2769 },
2770 %args
2771 );
2772
2773
2774 $self->add (new CFClient::UI::Face
2775 can_events => 0,
2776 face => $item->{face},
2777 anim => $item->{anim},
2778 animspeed => $item->{animspeed},
2779 );
2780
2781 $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0);
2782
2783 $self->{item} = $item;
2784
2785 $self->update_item;
2786
2787 $self
2788}
2789
2790sub update_item {
2791 my ($self) = @_;
2792
2793 my $desc = CFClient::Item::desc_string ($self->{item});
2794
2795 $self->{name_lbl}->set_text ($desc);
2796}
2797
2798#############################################################################
2799
2800package CFClient::UI::Inventory; 2731package CFClient::UI::Inventory;
2801 2732
2802our @ISA = CFClient::UI::ScrolledWindow::; 2733our @ISA = CFClient::UI::ScrolledWindow::;
2803 2734
2804sub new { 2735sub new {
2833 $self->{scrolled}->add (1, $row, $item->{desc_widget}); 2764 $self->{scrolled}->add (1, $row, $item->{desc_widget});
2834 $self->{scrolled}->add (2, $row, $item->{weight_widget}); 2765 $self->{scrolled}->add (2, $row, $item->{weight_widget});
2835 2766
2836 $row++; 2767 $row++;
2837 } 2768 }
2838
2839# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2840} 2769}
2841 2770
2842sub size_request { 2771sub size_request {
2843 my ($self) = @_; 2772 my ($self) = @_;
2844 ($self->{req_w}, $self->{req_h}); 2773 ($self->{req_w}, $self->{req_h});
3036 2965
3037sub new { 2966sub new {
3038 my $class = shift; 2967 my $class = shift;
3039 2968
3040 $class->SUPER::new ( 2969 $class->SUPER::new (
2970 visible => 1,
3041 @_, 2971 @_,
3042 ) 2972 )
3043} 2973}
3044 2974
3045sub configure { 2975sub configure {
3103sub add { 3033sub add {
3104 my ($self, @children) = @_; 3034 my ($self, @children) = @_;
3105 3035
3106 for (my @widgets = @children; my $w = pop @widgets; ) { 3036 for (my @widgets = @children; my $w = pop @widgets; ) {
3107 push @widgets, $w->children; 3037 push @widgets, $w->children;
3108 $w->{root} = $self; 3038 $w->{root} = $self;
3109 $w->{visible} = 1; 3039 $w->{visible} = $self->{visible} + 1;
3110 } 3040 }
3111 3041
3112 for my $child (@children) { 3042 for my $child (@children) {
3113 $child->{is_toplevel} = 1; 3043 $child->{is_toplevel} = 1;
3114 3044

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines