ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/Inventory.pm
Revision: 1.1
Committed: Sat Dec 9 02:21:25 2006 UTC (17 years, 6 months ago) by root
Branch: MAIN
CVS Tags: rel-0_97, rel-0_98
Log Message:
- slightly cleaned up and "outsourced" components
- completely rewrote keybind bindings
  - not functional yet
  - buggy a shell
  - hits perlbug

File Contents

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