… | |
… | |
579 | } |
579 | } |
580 | |
580 | |
581 | sub container_add { |
581 | sub container_add { |
582 | my ($self, $tag, $items) = @_; |
582 | my ($self, $tag, $items) = @_; |
583 | |
583 | |
584 | #d# print "container_add: container $tag ($self->{player}{tag})\n"; |
584 | $self->{update_container}{$tag}++; |
|
|
585 | $self->update_containers; |
|
|
586 | } |
585 | |
587 | |
|
|
588 | sub update_containers { |
|
|
589 | my ($self) = @_; |
|
|
590 | |
|
|
591 | $CFClient::UI::ROOT->on_refresh ("update_containers_$self" => sub { |
|
|
592 | for my $tag (keys %{ delete $self->{update_container} }) { |
586 | if ($tag == 0) { |
593 | if ($tag == 0) { |
587 | update_floorbox; |
594 | update_floorbox; |
588 | update_container (0); |
595 | update_container (0); |
589 | } elsif ($tag == $self->{player}{tag}) { |
596 | } elsif ($tag == $self->{player}{tag}) { |
590 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $self->{player}->{weight} / 1000); |
|
|
591 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
597 | $::INV->set_items ($self->{container}{$tag}) |
592 | } else { |
598 | } else { |
593 | update_container ($tag); |
599 | update_container ($tag); |
|
|
600 | } |
|
|
601 | } |
594 | } |
602 | }); |
595 | |
|
|
596 | # $self-<{player}{tag} => player inv |
|
|
597 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
|
|
598 | } |
603 | } |
599 | |
604 | |
600 | sub container_clear { |
605 | sub container_clear { |
601 | my ($self, $tag) = @_; |
606 | my ($self, $tag) = @_; |
602 | |
607 | |
603 | #d# print "container_clear: container $tag ($self->{player}{tag})\n"; |
608 | $self->{update_container}{$tag}++; |
604 | |
609 | $self->update_containers; |
605 | if ($tag == 0) { |
|
|
606 | update_floorbox; |
|
|
607 | update_container (0); |
|
|
608 | } elsif ($tag == $self->{player}{tag}) { |
|
|
609 | $::INV->set_items ($self->{container}{$tag}) |
|
|
610 | } else { |
|
|
611 | update_container ($tag); |
|
|
612 | } |
|
|
613 | |
|
|
614 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
|
|
615 | } |
610 | } |
616 | |
611 | |
617 | sub item_delete { |
612 | sub item_delete { |
618 | my ($self, @items) = @_; |
613 | my ($self, @items) = @_; |
619 | |
614 | |
|
|
615 | $self->{update_container}{$_->{tag}}++ |
620 | for (@items) { |
616 | for @items; |
621 | #d# print "item_delete: $_->{tag} from $_->{container} ($self->{player}{tag})\n"; |
|
|
622 | |
|
|
623 | if ($_->{container} == 0) { |
|
|
624 | update_floorbox; |
|
|
625 | update_container ($_->{tag}); |
|
|
626 | } elsif ($_->{container} == $self->{player}{tag}) { |
|
|
627 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
|
|
628 | } else { |
|
|
629 | update_container ($_->{container}); |
|
|
630 | } |
|
|
631 | } |
617 | |
|
|
618 | $self->update_containers; |
632 | } |
619 | } |
633 | |
620 | |
634 | sub item_update { |
621 | sub item_update { |
635 | my ($self, $item) = @_; |
622 | my ($self, $item) = @_; |
636 | |
623 | |
… | |
… | |
646 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
633 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
647 | set_opencont ($::CONN, 0, "Floor"); |
634 | set_opencont ($::CONN, 0, "Floor"); |
648 | |
635 | |
649 | } elsif ($item->{flags} & F_OPEN) { |
636 | } elsif ($item->{flags} & F_OPEN) { |
650 | set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item); |
637 | set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item); |
|
|
638 | |
651 | } else { |
639 | } else { |
|
|
640 | $self->{update_container}{$item->{container}}++; |
|
|
641 | $self->update_containers; |
652 | if ($item->{container} == 0) { |
642 | # if ($item->{container} == 0) { |
653 | update_floorbox; |
643 | # update_floorbox; |
654 | update_container (0); |
644 | # update_container (0); |
655 | } elsif ($item->{container} == $self->{player}{tag}) { |
645 | # } elsif ($item->{container} == $self->{player}{tag}) { |
656 | $::INV->set_items ($self->{container}{$item->{container}}) |
646 | # $::INV->set_items ($self->{container}{$item->{container}}) |
657 | } |
647 | # } |
658 | } |
648 | } |
659 | } |
649 | } |
660 | |
650 | |
661 | sub player_update { |
651 | sub player_update { |
662 | my ($self, $player) = @_; |
652 | my ($self, $player) = @_; |