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

# User Rev Content
1 root 1.4 package DC::UI::Inventory;
2 root 1.1
3 root 1.6 use common::sense;
4 root 1.1
5 root 1.4 use DC::Macro;
6     use DC::Item;
7 root 1.1
8 root 1.4 our @ISA = DC::UI::Table::;
9 root 1.1
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 root 1.4 DC::Item::update_widgets $item;
35 root 1.1
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 root 1.2 $self->add_at (@adds);
44 root 1.1 }
45    
46     sub set_sort_order {
47     my ($self, $order) = @_;
48    
49     $self->{sort} = $order ||= sub {
50     sort {
51 root 1.5 $b->{count} <=> $a->{count}
52 root 1.1 } @_
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