… | |
… | |
458 | sub set_parent { |
458 | sub set_parent { |
459 | my ($self, $parent) = @_; |
459 | my ($self, $parent) = @_; |
460 | |
460 | |
461 | Scalar::Util::weaken ($self->{parent} = $parent); |
461 | Scalar::Util::weaken ($self->{parent} = $parent); |
462 | |
462 | |
|
|
463 | $self->{root} = $parent->{root}; |
|
|
464 | $self->{visible} = $parent->{visible}; |
|
|
465 | |
463 | # TODO: req_w _does_change after ->reconfigure |
466 | # TODO: req_w _does_change after ->reconfigure |
464 | $self->check_size |
467 | $self->check_size |
465 | unless exists $self->{req_w}; |
468 | unless exists $self->{req_w}; |
466 | |
469 | |
467 | $self->show; |
470 | $self->show; |
… | |
… | |
618 | delete $child->{parent}; |
621 | delete $child->{parent}; |
619 | $child->hide; |
622 | $child->hide; |
620 | |
623 | |
621 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
624 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
622 | |
625 | |
623 | $self->check_size; |
626 | $self->check_size (1); |
624 | $self->update; |
627 | $self->update; |
625 | } |
628 | } |
626 | |
629 | |
627 | sub clear { |
630 | sub clear { |
628 | my ($self) = @_; |
631 | my ($self) = @_; |
… | |
… | |
1101 | col_expand => [], |
1104 | col_expand => [], |
1102 | @_, |
1105 | @_, |
1103 | ) |
1106 | ) |
1104 | } |
1107 | } |
1105 | |
1108 | |
|
|
1109 | sub children { |
|
|
1110 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
1111 | } |
|
|
1112 | |
1106 | sub add { |
1113 | sub add { |
1107 | my ($self, $x, $y, $child) = @_; |
1114 | my ($self, $x, $y, $child) = @_; |
1108 | |
1115 | |
1109 | $child->set_parent ($self); |
1116 | $child->set_parent ($self); |
1110 | $self->{children}[$y][$x] = $child; |
1117 | $self->{children}[$y][$x] = $child; |
1111 | |
1118 | |
1112 | $child->check_size; |
1119 | $self->check_size (1); |
1113 | } |
1120 | } |
1114 | |
1121 | |
1115 | sub children { |
|
|
1116 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
1117 | } |
|
|
1118 | |
|
|
1119 | # TODO: move to container class maybe? send childs a signal on removal? |
1122 | # TODO: move to container class maybe? send children a signal on removal? |
1120 | sub clear { |
1123 | sub clear { |
1121 | my ($self) = @_; |
1124 | my ($self) = @_; |
1122 | |
1125 | |
1123 | my @children = $self->children; |
1126 | my @children = $self->children; |
1124 | delete $self->{children}; |
1127 | delete $self->{children}; |
… | |
… | |
1126 | for (@children) { |
1129 | for (@children) { |
1127 | delete $_->{parent}; |
1130 | delete $_->{parent}; |
1128 | $_->hide; |
1131 | $_->hide; |
1129 | } |
1132 | } |
1130 | |
1133 | |
|
|
1134 | $self->check_size (1); |
1131 | $self->update; |
1135 | $self->update; |
1132 | } |
1136 | } |
1133 | |
1137 | |
1134 | sub get_wh { |
1138 | sub get_wh { |
1135 | my ($self) = @_; |
1139 | my ($self) = @_; |
… | |
… | |
2705 | |
2709 | |
2706 | $self->{timer}->cancel |
2710 | $self->{timer}->cancel |
2707 | if $self->{timer}; |
2711 | if $self->{timer}; |
2708 | |
2712 | |
2709 | $self->SUPER::DESTROY; |
2713 | $self->SUPER::DESTROY; |
2710 | } |
|
|
2711 | |
|
|
2712 | ############################################################################# |
|
|
2713 | |
|
|
2714 | package CFClient::UI::InventoryItem; |
|
|
2715 | |
|
|
2716 | our @ISA = CFClient::UI::HBox::; |
|
|
2717 | |
|
|
2718 | sub new { |
|
|
2719 | my $class = shift; |
|
|
2720 | |
|
|
2721 | my %args = @_; |
|
|
2722 | |
|
|
2723 | my $item = delete $args{item}; |
|
|
2724 | |
|
|
2725 | my $desc = CFClient::Item::desc_string $item; |
|
|
2726 | |
|
|
2727 | my $self = $class->SUPER::new ( |
|
|
2728 | can_hover => 1, |
|
|
2729 | can_events => 1, |
|
|
2730 | tooltip => ((CFClient::UI::Label::escape $desc) |
|
|
2731 | . "\n<small>leftclick - examine\nshift+leftclick - move/pickup/drop\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
2732 | connect_button_down => sub { |
|
|
2733 | my ($self, $ev, $x, $y) = @_; |
|
|
2734 | |
|
|
2735 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
2736 | if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { |
|
|
2737 | my $targ = $::CONN->{player}{tag}; |
|
|
2738 | |
|
|
2739 | if ($item->{container} == $::CONN->{player}{tag}) { |
|
|
2740 | $targ = $main::OPENCONT; |
|
|
2741 | } |
|
|
2742 | |
|
|
2743 | $::CONN->send ("move $targ $item->{tag} 0"); |
|
|
2744 | } elsif ($ev->{button} == 1) { |
|
|
2745 | $::CONN->send ("examine $item->{tag}"); |
|
|
2746 | } elsif ($ev->{button} == 2) { |
|
|
2747 | $::CONN->send ("apply $item->{tag}"); |
|
|
2748 | } elsif ($ev->{button} == 3) { |
|
|
2749 | my @menu_items = ( |
|
|
2750 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
|
|
2751 | ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }], |
|
|
2752 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2753 | ( |
|
|
2754 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2755 | ? ( |
|
|
2756 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }], |
|
|
2757 | ) |
|
|
2758 | : ( |
|
|
2759 | ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }], |
|
|
2760 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
|
|
2761 | ) |
|
|
2762 | ), |
|
|
2763 | ); |
|
|
2764 | |
|
|
2765 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
|
|
2766 | } |
|
|
2767 | |
|
|
2768 | 1 |
|
|
2769 | }, |
|
|
2770 | %args |
|
|
2771 | ); |
|
|
2772 | |
|
|
2773 | |
|
|
2774 | $self->add (new CFClient::UI::Face |
|
|
2775 | can_events => 0, |
|
|
2776 | face => $item->{face}, |
|
|
2777 | anim => $item->{anim}, |
|
|
2778 | animspeed => $item->{animspeed}, |
|
|
2779 | ); |
|
|
2780 | |
|
|
2781 | $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0); |
|
|
2782 | |
|
|
2783 | $self->{item} = $item; |
|
|
2784 | |
|
|
2785 | $self->update_item; |
|
|
2786 | |
|
|
2787 | $self |
|
|
2788 | } |
|
|
2789 | |
|
|
2790 | sub update_item { |
|
|
2791 | my ($self) = @_; |
|
|
2792 | |
|
|
2793 | my $desc = CFClient::Item::desc_string ($self->{item}); |
|
|
2794 | |
|
|
2795 | $self->{name_lbl}->set_text ($desc); |
|
|
2796 | } |
2714 | } |
2797 | |
2715 | |
2798 | ############################################################################# |
2716 | ############################################################################# |
2799 | |
2717 | |
2800 | package CFClient::UI::Inventory; |
2718 | package CFClient::UI::Inventory; |