ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/Inventory.pm
Revision: 1.6
Committed: Sat Apr 3 02:58:25 2010 UTC (14 years, 2 months ago) by root
Branch: MAIN
CVS Tags: rel-2_11, HEAD
Changes since 1.5: +1 -2 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package DC::UI::Inventory;
2
3 use common::sense;
4
5 use DC::Macro;
6 use DC::Item;
7
8 our @ISA = DC::UI::Table::;
9
10 sub new {
11 my $class = shift;
12
13 my $self = $class->SUPER::new (
14 col_expand => [0, 1, 0],
15 items => [],
16 @_,
17 );
18
19 $self->set_sort_order (undef);
20
21 $self
22 }
23
24 sub update_items {
25 my ($self) = @_;
26
27 $self->clear;
28
29 my @item = $self->{sort}->(@{ $self->{items} });
30
31 my @adds;
32 my $row = 0;
33 for my $item ($self->{sort}->(@{ $self->{items} })) {
34 DC::Item::update_widgets $item;
35
36 push @adds, 0, $row, $item->{face_widget};
37 push @adds, 1, $row, $item->{desc_widget};
38 push @adds, 2, $row, $item->{weight_widget};
39
40 $row++;
41 }
42
43 $self->add_at (@adds);
44 }
45
46 sub set_sort_order {
47 my ($self, $order) = @_;
48
49 $self->{sort} = $order ||= sub {
50 sort {
51 $b->{count} <=> $a->{count}
52 } @_
53 };
54
55 $self->update_items;
56 }
57
58 sub set_items {
59 my ($self, $items) = @_;
60
61 $self->{items} = [$items ? values %$items : ()];
62 $self->update_items;
63 }
64