--- deliantra/Deliantra-Client/DC/UI.pm 2006/05/03 19:56:05 1.184 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/05/08 20:40:31 1.187 @@ -257,7 +257,9 @@ $_->reconfigure for $self->children; - $_->check_size; + $self->check_size; + $self->size_allocate ($self->{w}, $self->{h}); + $self->update; } sub set_max_size { @@ -1324,12 +1326,6 @@ $self->SUPER::update; } -sub reconfigure { - my ($self) = @_; - - delete $self->{texture}; -} - sub set_text { my ($self, $text) = @_; @@ -1392,8 +1388,9 @@ $self->{fontsize} = $fontsize; delete $self->{texture}; - $self->check_size; + $self->update; + $self->check_size; } sub _draw { @@ -2485,6 +2482,7 @@ sub _draw { my ($self) = @_; + return unless $::CONN;#d# manage and cache textures differently my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; # TODO animation @@ -2502,6 +2500,111 @@ ############################################################################# +package CFClient::UI::InventoryItem; + +our @ISA = CFClient::UI::HBox::; + +sub new { + my $class = shift; + + my %args = @_; + + my $item = $args{item}; + + my $desc = $item->{nrof} < 2 + ? $item->{name} + : "$item->{nrof} $item->{name_pl}"; + + + my $self = $class->SUPER::new ( + can_hover => 1, + can_events => 1, + tooltip => (CFClient::UI::Label->escape ($desc) + . "\nleftclick - pick up\nmiddle click - apply\nrightclick - menu"), + connect_button_down => sub { + my ($self, $ev, $x, $y) = @_; + + # todo: maybe put examine on 1? but should just be a tooltip :( + if ($ev->{button} == 1) { + $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); + } elsif ($ev->{button} == 2) { + $::CONN->send ("apply $item->{tag}"); + } elsif ($ev->{button} == 3) { + CFClient::UI::Menu->new ( + items => [ + ["examine", sub { $::CONN->send ("examine $item->{tag}") }], + [ + $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", + sub { $::CONN->send ("lock $item->{tag}") }, + ], + ["mark", sub { $::CONN->send ("mark $item->{tag}") }], + ["apply", sub { $::CONN->send ("apply $item->{tag}") }], + ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }], + ], + )->popup ($ev); + } + + 1 + }, + %args + ); + $self->add(new CFClient::UI::Face + can_events => 0, + face => $item->{face}, + anim => $item->{anim}, + animspeed => $item->{animspeed}); + $self->add(new CFClient::UI::Label + can_events => 0, + text => $desc); + + $self +} + +############################################################################# + +package CFClient::UI::Inventory; + +our @ISA = CFClient::UI::ScrolledWindow::; + +sub new { + my $class = shift; + + my $self = $class->SUPER::new ( + scrolled => (new CFClient::UI::VBox), + @_, + ); + + $self +} + +sub set_items { + my ($self, $items) = @_; + + $self->{scrolled}->clear; + return unless $items; + + my @items = sort { $a->{type} <=> $b->{type} } @$items; + + $self->{real_items} = \@items; + + for my $item (@items) { + my $desc = $item->{nrof} < 2 + ? $item->{name} + : "$item->{nrof} $item->{name_pl}"; + + $self->{scrolled}->add (new CFClient::UI::InventoryItem item => $item); + } + +# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; +} + +sub size_request { + my ($self) = @_; + ($self->{req_w}, $self->{req_h}); +} + +############################################################################# + package CFClient::UI::Menu; our @ISA = CFClient::UI::FancyFrame::; @@ -2583,11 +2686,36 @@ sub check_size { my ($self) = @_; - $self->configure (0, 0, $::WIDTH, $::HEIGHT); + $self->configure (0, 0, $self->{w}, $self->{h}); } sub size_request { - ($::WIDTH, $::HEIGHT) + my ($self) = @_; + + ($self->{w}, $self->{h}) +} + +sub size_allocate { + my ($self, $w, $h) = @_; + + my $old_w = $self->{old_w}; + my $old_h = $self->{old_h}; + + if ($old_w && $old_h) { + for my $child ($self->children) { + $child->{x} = int 0.5 + $child->{x} * $w / $old_w; + $child->{w} = int 0.5 + $child->{w} * $w / $old_w; + $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w}; + $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w}; + $child->{y} = int 0.5 + $child->{y} * $h / $old_h; + $child->{h} = int 0.5 + $child->{h} * $h / $old_h; + $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h}; + $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h}; + } + } + + $self->{old_w} = $w; + $self->{old_h} = $h; } sub configure { @@ -2595,12 +2723,12 @@ $self->SUPER::configure ($x, $y, $w, $h); - for my $child (@{$self->{children}}) { + for my $child ($self->children) { my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; $X = List::Util::max 0, List::Util::min $w - $W, $X; $Y = List::Util::max 0, List::Util::min $h - $H, $Y; - $child->configure ($X, $Y, $W,$H); + $child->configure ($X, $Y, $W, $H); } } @@ -2654,111 +2782,6 @@ } ############################################################################# - -package CFClient::UI::InventoryItem; - -our @ISA = CFClient::UI::HBox::; - -sub new { - my $class = shift; - - my %args = @_; - - my $item = $args{item}; - - my $desc = $item->{nrof} < 2 - ? $item->{name} - : "$item->{nrof} $item->{name_pl}"; - - - my $self = $class->SUPER::new ( - can_hover => 1, - can_events => 1, - tooltip => (CFClient::UI::Label->escape ($desc) - . "\nleftclick - pick up\nmiddle click - apply\nrightclick - menu"), - connect_button_down => sub { - my ($self, $ev, $x, $y) = @_; - - # todo: maybe put examine on 1? but should just be a tooltip :( - if ($ev->{button} == 1) { - $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); - } elsif ($ev->{button} == 2) { - $::CONN->send ("apply $item->{tag}"); - } elsif ($ev->{button} == 3) { - CFClient::UI::Menu->new ( - items => [ - ["examine", sub { $::CONN->send ("examine $item->{tag}") }], - [ - $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", - sub { $::CONN->send ("lock $item->{tag}") }, - ], - ["mark", sub { $::CONN->send ("mark $item->{tag}") }], - ["apply", sub { $::CONN->send ("apply $item->{tag}") }], - ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }], - ], - )->popup ($ev); - } - - 1 - }, - %args - ); - $self->add(new CFClient::UI::Face - can_events => 0, - face => $item->{face}, - anim => $item->{anim}, - animspeed => $item->{animspeed}); - $self->add(new CFClient::UI::Label - can_events => 0, - text => $desc); - - $self -} - -############################################################################# - -package CFClient::UI::Inventory; - -our @ISA = CFClient::UI::ScrolledWindow::; - -sub new { - my $class = shift; - - my $self = $class->SUPER::new ( - scrolled => (new CFClient::UI::VBox), - @_, - ); - - $self -} - -sub set_items { - my ($self, $items) = @_; - - $self->{scrolled}->clear; - return unless $items; - - my @items = sort { $a->{type} <=> $b->{type} } @$items; - - $self->{real_items} = \@items; - - for my $item (@items) { - my $desc = $item->{nrof} < 2 - ? $item->{name} - : "$item->{nrof} $item->{name_pl}"; - - $self->{scrolled}->add (new CFClient::UI::InventoryItem item => $item); - } - -# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; -} - -sub size_request { - my ($self) = @_; - ($self->{req_w}, $self->{req_h}); -} - -############################################################################# package CFClient::UI;