… | |
… | |
206 | %$self = (); |
206 | %$self = (); |
207 | } |
207 | } |
208 | |
208 | |
209 | sub show { |
209 | sub show { |
210 | my ($self) = @_; |
210 | my ($self) = @_; |
211 | |
|
|
212 | for (my @w = $self; @w; ) { |
|
|
213 | my $w = pop @w; |
|
|
214 | push @w, $w->children; |
|
|
215 | $w->{visible} = 1; |
|
|
216 | } |
|
|
217 | |
|
|
218 | return if $self->{parent}; |
211 | return if $self->{parent}; |
219 | |
212 | |
220 | $CFClient::UI::ROOT->add ($self); |
213 | $CFClient::UI::ROOT->add ($self); |
221 | } |
214 | } |
222 | |
215 | |
|
|
216 | sub show_centered { |
|
|
217 | my ($self) = @_; |
|
|
218 | return if $self->{parent}; |
|
|
219 | |
|
|
220 | $self->show; |
|
|
221 | |
|
|
222 | $CFClient::UI::ROOT->on_post_alloc ( |
|
|
223 | "centered $self" => sub { |
|
|
224 | $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5); |
|
|
225 | }, |
|
|
226 | ); |
|
|
227 | } |
|
|
228 | |
223 | sub hide { |
229 | sub hide { |
224 | my ($self) = @_; |
230 | my ($self) = @_; |
225 | |
|
|
226 | for (my @w = $self; @w; ) { |
|
|
227 | my $w = pop @w; |
|
|
228 | push @w, $w->children; |
|
|
229 | $w->{visible} = 1; |
|
|
230 | } |
|
|
231 | |
231 | |
232 | undef $GRAB if $GRAB == $self; |
232 | undef $GRAB if $GRAB == $self; |
233 | undef $HOVER if $HOVER == $self; |
233 | undef $HOVER if $HOVER == $self; |
234 | |
234 | |
235 | $self->{parent}->remove ($self) |
235 | $self->{parent}->remove ($self) |
… | |
… | |
2541 | |
2541 | |
2542 | sub size_request { |
2542 | sub size_request { |
2543 | (32, 8) |
2543 | (32, 8) |
2544 | } |
2544 | } |
2545 | |
2545 | |
|
|
2546 | sub update { |
|
|
2547 | my ($self) = @_; |
|
|
2548 | |
|
|
2549 | return unless $self->{visible}; |
|
|
2550 | |
|
|
2551 | $self->SUPER::update; |
|
|
2552 | } |
|
|
2553 | |
2546 | sub _draw { |
2554 | sub _draw { |
2547 | my ($self) = @_; |
2555 | my ($self) = @_; |
2548 | |
2556 | |
2549 | return unless $::CONN;#d# manage and cache textures differently |
2557 | return unless $::CONN;#d# manage and cache textures differently |
2550 | |
2558 | |
… | |
… | |
2620 | |
2628 | |
2621 | my $self = $class->SUPER::new ( |
2629 | my $self = $class->SUPER::new ( |
2622 | can_hover => 1, |
2630 | can_hover => 1, |
2623 | can_events => 1, |
2631 | can_events => 1, |
2624 | tooltip => ((CFClient::UI::Label::escape $desc) |
2632 | tooltip => ((CFClient::UI::Label::escape $desc) |
2625 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2633 | . "\n<small>leftclick - examine\nshift+leftclick - move/pickup/drop\nmiddle click - apply\nrightclick - menu</small>"), |
2626 | connect_button_down => sub { |
2634 | connect_button_down => sub { |
2627 | my ($self, $ev, $x, $y) = @_; |
2635 | my ($self, $ev, $x, $y) = @_; |
2628 | |
2636 | |
2629 | # todo: maybe put examine on 1? but should just be a tooltip :( |
2637 | # todo: maybe put examine on 1? but should just be a tooltip :( |
2630 | if ($ev->{button} == 1) { |
2638 | if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { |
2631 | my $targ = $::CONN->{player}{tag}; |
2639 | my $targ = $::CONN->{player}{tag}; |
2632 | |
2640 | |
2633 | if ($item->{container} == $::CONN->{player}{tag}) { |
2641 | if ($item->{container} == $::CONN->{player}{tag}) { |
2634 | $targ = $main::OPENCONT; |
2642 | $targ = $main::OPENCONT; |
2635 | } |
2643 | } |
2636 | |
2644 | |
2637 | $::CONN->send ("move $targ $item->{tag} 0"); |
2645 | $::CONN->send ("move $targ $item->{tag} 0"); |
|
|
2646 | } elsif ($ev->{button} == 1) { |
|
|
2647 | $::CONN->send ("examine $item->{tag}"); |
2638 | } elsif ($ev->{button} == 2) { |
2648 | } elsif ($ev->{button} == 2) { |
2639 | $::CONN->send ("apply $item->{tag}"); |
2649 | $::CONN->send ("apply $item->{tag}"); |
2640 | } elsif ($ev->{button} == 3) { |
2650 | } elsif ($ev->{button} == 3) { |
2641 | my @menu_items = ( |
2651 | my @menu_items = ( |
2642 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2652 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
… | |
… | |
2695 | |
2705 | |
2696 | sub new { |
2706 | sub new { |
2697 | my $class = shift; |
2707 | my $class = shift; |
2698 | |
2708 | |
2699 | my $self = $class->SUPER::new ( |
2709 | my $self = $class->SUPER::new ( |
2700 | scrolled => (new CFClient::UI::VBox), |
2710 | scrolled => (new CFClient::UI::Table), |
2701 | @_, |
2711 | @_, |
2702 | ); |
2712 | ); |
2703 | |
2713 | |
2704 | $self |
2714 | $self |
2705 | } |
2715 | } |
… | |
… | |
2716 | } @$items; |
2726 | } @$items; |
2717 | |
2727 | |
2718 | $self->{real_items} = \@items; |
2728 | $self->{real_items} = \@items; |
2719 | |
2729 | |
2720 | for my $item (@items) { |
2730 | for my $item (@items) { |
|
|
2731 | $item->{item} = $item; |
2721 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
2732 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
2722 | $item->update_item (); |
2733 | $item->update_item (); |
2723 | } |
2734 | } |
2724 | |
2735 | |
|
|
2736 | my $i = 0; |
|
|
2737 | for (@items) { |
2725 | $self->{scrolled}->add (@items); |
2738 | $self->{scrolled}->add (0, $i, $_); |
|
|
2739 | my $nrof = $_->{item}->{nrof} || 1; |
|
|
2740 | $self->{scrolled}->add (1, $i++, new CFClient::UI::Label text => ($_->{item}->{weight} * $nrof) / 1000); |
|
|
2741 | } |
2726 | |
2742 | |
2727 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2743 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2728 | } |
2744 | } |
2729 | |
2745 | |
2730 | sub size_request { |
2746 | sub size_request { |
… | |
… | |
3002 | $child->{x} = int $child->{x}; |
3018 | $child->{x} = int $child->{x}; |
3003 | $child->{y} = int $child->{y}; |
3019 | $child->{y} = int $child->{y}; |
3004 | } |
3020 | } |
3005 | |
3021 | |
3006 | $self->SUPER::add (@children); |
3022 | $self->SUPER::add (@children); |
|
|
3023 | |
|
|
3024 | while (@children) { |
|
|
3025 | my $w = pop @children; |
|
|
3026 | push @children, $w->children; |
|
|
3027 | $w->{visible} = 1; |
|
|
3028 | } |
|
|
3029 | } |
|
|
3030 | |
|
|
3031 | sub remove { |
|
|
3032 | my ($self, @children) = @_; |
|
|
3033 | |
|
|
3034 | $self->SUPER::remove (@children); |
|
|
3035 | |
|
|
3036 | while (@children) { |
|
|
3037 | my $w = pop @children; |
|
|
3038 | push @children, $w->children; |
|
|
3039 | delete $w->{visible}; |
|
|
3040 | } |
3007 | } |
3041 | } |
3008 | |
3042 | |
3009 | sub on_refresh { |
3043 | sub on_refresh { |
3010 | my ($self, $id, $cb) = @_; |
3044 | my ($self, $id, $cb) = @_; |
3011 | |
3045 | |