… | |
… | |
737 | |
737 | |
738 | $self->{view_x} = int $x; |
738 | $self->{view_x} = int $x; |
739 | $self->{view_y} = int $y; |
739 | $self->{view_y} = int $y; |
740 | |
740 | |
741 | $self->update; |
741 | $self->update; |
|
|
742 | } |
|
|
743 | |
|
|
744 | # hmm, this does not work for topleft of $self... but we should not aks for that |
|
|
745 | sub _topleft { |
|
|
746 | my ($self, $x, $y) = @_; |
|
|
747 | |
|
|
748 | $self->SUPER::_topleft ($x - $self->{view_x}, $y - $self->{view_y}) |
|
|
749 | } |
|
|
750 | |
|
|
751 | sub find_widget { |
|
|
752 | my ($self, $x, $y) = @_; |
|
|
753 | |
|
|
754 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
755 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
|
|
756 | ) { |
|
|
757 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
|
|
758 | } else { |
|
|
759 | $self->CFClient::UI::Base::find_widget ($x, $y) |
|
|
760 | } |
742 | } |
761 | } |
743 | |
762 | |
744 | sub _render { |
763 | sub _render { |
745 | my ($self) = @_; |
764 | my ($self) = @_; |
746 | |
765 | |
… | |
… | |
2634 | $self->_draw; |
2653 | $self->_draw; |
2635 | } |
2654 | } |
2636 | |
2655 | |
2637 | ############################################################################# |
2656 | ############################################################################# |
2638 | |
2657 | |
|
|
2658 | package CFClient::UI::InventoryItem; |
|
|
2659 | |
|
|
2660 | our @ISA = CFClient::UI::HBox::; |
|
|
2661 | |
|
|
2662 | sub new { |
|
|
2663 | my $class = shift; |
|
|
2664 | |
|
|
2665 | my %args = @_; |
|
|
2666 | |
|
|
2667 | my $item = $args{item}; |
|
|
2668 | |
|
|
2669 | my $desc = $item->{nrof} < 2 |
|
|
2670 | ? $item->{name} |
|
|
2671 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2672 | |
|
|
2673 | |
|
|
2674 | my $self = $class->SUPER::new ( |
|
|
2675 | can_hover => 1, |
|
|
2676 | can_events => 1, |
|
|
2677 | tooltip => (CFClient::UI::Label->escape ($desc) |
|
|
2678 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
2679 | connect_button_down => sub { |
|
|
2680 | my ($self, $ev, $x, $y) = @_; |
|
|
2681 | |
|
|
2682 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
2683 | if ($ev->{button} == 1) { |
|
|
2684 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
|
|
2685 | } elsif ($ev->{button} == 2) { |
|
|
2686 | $::CONN->send ("apply $item->{tag}"); |
|
|
2687 | } elsif ($ev->{button} == 3) { |
|
|
2688 | CFClient::UI::Menu->new ( |
|
|
2689 | items => [ |
|
|
2690 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
|
|
2691 | [ |
|
|
2692 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
|
|
2693 | sub { $::CONN->send ("lock $item->{tag}") }, |
|
|
2694 | ], |
|
|
2695 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
|
|
2696 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2697 | ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }], |
|
|
2698 | ], |
|
|
2699 | )->popup ($ev); |
|
|
2700 | } |
|
|
2701 | |
|
|
2702 | 1 |
|
|
2703 | }, |
|
|
2704 | %args |
|
|
2705 | ); |
|
|
2706 | $self->add(new CFClient::UI::Face |
|
|
2707 | can_events => 0, |
|
|
2708 | face => $item->{face}, |
|
|
2709 | anim => $item->{anim}, |
|
|
2710 | animspeed => $item->{animspeed}); |
|
|
2711 | $self->add(new CFClient::UI::Label |
|
|
2712 | can_events => 0, |
|
|
2713 | text => $desc); |
|
|
2714 | |
|
|
2715 | $self |
|
|
2716 | } |
|
|
2717 | |
|
|
2718 | ############################################################################# |
|
|
2719 | |
2639 | package CFClient::UI::Inventory; |
2720 | package CFClient::UI::Inventory; |
2640 | |
2721 | |
2641 | our @ISA = CFClient::UI::ScrolledWindow::; |
2722 | our @ISA = CFClient::UI::ScrolledWindow::; |
2642 | |
2723 | |
2643 | sub new { |
2724 | sub new { |
… | |
… | |
2664 | for my $item (@items) { |
2745 | for my $item (@items) { |
2665 | my $desc = $item->{nrof} < 2 |
2746 | my $desc = $item->{nrof} < 2 |
2666 | ? $item->{name} |
2747 | ? $item->{name} |
2667 | : "$item->{nrof} $item->{name_pl}"; |
2748 | : "$item->{nrof} $item->{name_pl}"; |
2668 | |
2749 | |
2669 | my $hb = new CFClient::UI::HBox; |
2750 | $self->{scrolled}->add (new CFClient::UI::InventoryItem item => $item); |
2670 | |
|
|
2671 | $hb->add (my $f = new CFClient::UI::Face |
|
|
2672 | can_events => 0, |
|
|
2673 | face => $item->{face}, |
|
|
2674 | anim => $item->{anim}, |
|
|
2675 | animspeed => $item->{animspeed}, |
|
|
2676 | expand => 1, |
|
|
2677 | ); |
|
|
2678 | $hb->add (new CFClient::UI::Label text => $desc, expand => 1); |
|
|
2679 | $self->{scrolled}->add ($hb); |
|
|
2680 | } |
2751 | } |
2681 | |
2752 | |
2682 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2753 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2683 | } |
2754 | } |
2684 | |
2755 | |
2685 | sub size_request { |
2756 | sub size_request { |
2686 | my ($self) = @_; |
2757 | my ($self) = @_; |
2687 | (100, 200) |
2758 | ($self->{req_w}, $self->{req_h}); |
2688 | } |
2759 | } |
2689 | |
2760 | |
2690 | ############################################################################# |
2761 | ############################################################################# |
2691 | |
2762 | |
2692 | package CFClient::UI; |
2763 | package CFClient::UI; |