--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/25 13:51:48 1.178 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/29 16:17:09 1.181 @@ -2404,7 +2404,7 @@ (32, 8) } -sub draw { +sub _draw { my ($self) = @_; my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; @@ -2577,6 +2577,111 @@ ############################################################################# +package CFClient::UI::Inventory; + +our @ISA = CFClient::UI::Container::; + +use CFClient::OpenGL; + +sub new { + my $class = shift; + + my $self = $class->SUPER::new (@_); + + $self +} + +sub size_allocate { + my ($self, $w, $h) = @_; + + $self->{w} = $w; + $self->{h} = $h; + + $self->check_size; +} + +sub set_items { + my ($self, $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->add (my $hb = new CFClient::UI::HBox); + + $hb->add (my $f = new CFClient::UI::Face + can_events => 0, + face => $item->{face}, + anim => $item->{anim}, + animspeed => $item->{animspeed}, + expand => 1, + ); + $hb->add (new CFClient::UI::Label text => $desc, expand => 1); + } + + $self->{max_pos} = (scalar @items) - 1; + + my $range = $self->{range}; + my $page = $self->{h} / 32; # what information source to use for face size? + # it should be configurable I guess... + $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; + $range->update; +} + +sub size_request { + my ($self) = @_; + (100, 200) +} + +sub set_range { + my ($self, $range) = @_; + + $self->{range} = $range; + $range->connect (changed => sub { $self->update }); + + my $page = $self->{h} / 32; # waht information souce to use for face size? + # it should be configurable i guess... + + $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; + $range->update; + + $self->update; +} + +sub _draw { + my ($self) = @_; + + my ($w, $h) = ($self->{w}, $self->{h}); + + $self->{pos} = int $self->{range}{range}[0]; + + my $y = 0; + my $cnt = 0; + my $hrem = $self->{h}; # horiz. remaining space + + for (my $i = $self->{pos}; $i < @{$self->{children} || []}; $i++) { + my $chld = $self->{children}->[$i]; + + if ($hrem >= $chld->{h}) { + $chld->configure (0, $y, $chld->{w}, $chld->{h}); + + $chld->draw; + + $hrem -= $chld->{h}; + $y += $chld->{h}; + } else { + last + } + } +} + + +############################################################################# + package CFClient::UI; $ROOT = new CFClient::UI::Root;