… | |
… | |
233 | delete $self->{visible}; |
233 | delete $self->{visible}; |
234 | |
234 | |
235 | undef $GRAB if $GRAB == $self; |
235 | undef $GRAB if $GRAB == $self; |
236 | undef $HOVER if $HOVER == $self; |
236 | undef $HOVER if $HOVER == $self; |
237 | |
237 | |
|
|
238 | CFClient::UI::check_tooltip |
|
|
239 | if $CFClient::UI::TOOLTIP->{owner} == $self; |
|
|
240 | |
238 | $self->focus_out; |
241 | $self->focus_out; |
239 | } |
242 | } |
240 | |
243 | |
241 | sub hide { |
244 | sub hide { |
242 | my ($self) = @_; |
245 | my ($self) = @_; |
… | |
… | |
318 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
321 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
319 | } |
322 | } |
320 | |
323 | |
321 | sub set_tooltip { |
324 | sub set_tooltip { |
322 | my ($self, $tooltip) = @_; |
325 | my ($self, $tooltip) = @_; |
|
|
326 | |
|
|
327 | $tooltip =~ s/^\s+//; |
|
|
328 | $tooltip =~ s/\s+$//; |
|
|
329 | |
|
|
330 | return if $self->{tooltip} eq $tooltip; |
323 | |
331 | |
324 | $self->{tooltip} = $tooltip; |
332 | $self->{tooltip} = $tooltip; |
325 | |
333 | |
326 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
334 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
327 | delete $CFClient::UI::TOOLTIP->{owner}; |
335 | delete $CFClient::UI::TOOLTIP->{owner}; |
… | |
… | |
417 | if ($ENV{PCLIENT_DEBUG}) { |
425 | if ($ENV{PCLIENT_DEBUG}) { |
418 | glPushMatrix; |
426 | glPushMatrix; |
419 | glColor 1, 1, 0, 1; |
427 | glColor 1, 1, 0, 1; |
420 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
428 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
421 | glBegin GL_LINE_LOOP; |
429 | glBegin GL_LINE_LOOP; |
422 | glVertex 0 , 0; |
430 | glVertex 0 , 0; |
423 | glVertex $self->{w}, 0; |
431 | glVertex $self->{w} - 1, 0; |
424 | glVertex $self->{w}, $self->{h}; |
432 | glVertex $self->{w} - 1, $self->{h} - 1; |
425 | glVertex 0 , $self->{h}; |
433 | glVertex 0 , $self->{h} - 1; |
426 | glEnd; |
434 | glEnd; |
427 | glPopMatrix; |
435 | glPopMatrix; |
428 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
436 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
429 | } |
437 | } |
430 | } |
438 | } |
… | |
… | |
760 | |
768 | |
761 | package CFClient::UI::ViewPort; |
769 | package CFClient::UI::ViewPort; |
762 | |
770 | |
763 | our @ISA = CFClient::UI::Window::; |
771 | our @ISA = CFClient::UI::Window::; |
764 | |
772 | |
|
|
773 | sub new { |
|
|
774 | my $class = shift; |
|
|
775 | |
|
|
776 | $class->SUPER::new ( |
|
|
777 | scroll_x => 0, |
|
|
778 | scroll_y => 1, |
|
|
779 | @_, |
|
|
780 | ) |
|
|
781 | } |
|
|
782 | |
765 | sub size_request { |
783 | sub size_request { |
766 | my ($self) = @_; |
784 | my ($self) = @_; |
767 | |
785 | |
768 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
786 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
769 | |
787 | |
… | |
… | |
771 | } |
789 | } |
772 | |
790 | |
773 | sub size_allocate { |
791 | sub size_allocate { |
774 | my ($self, $w, $h) = @_; |
792 | my ($self, $w, $h) = @_; |
775 | |
793 | |
776 | my ($cw, $ch) = @$self{qw(child_w child_h)}; |
794 | $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; |
777 | # $w = $self->{w}; |
795 | $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; |
|
|
796 | |
778 | $self->child->configure (0, 0, $cw, $ch); |
797 | $self->child->configure (0, 0, $w, $h); |
779 | $self->update; |
798 | $self->update; |
780 | } |
799 | } |
781 | |
800 | |
782 | sub set_offset { |
801 | sub set_offset { |
783 | my ($self, $x, $y) = @_; |
802 | my ($self, $x, $y) = @_; |
… | |
… | |
1078 | sub new { |
1097 | sub new { |
1079 | my $class = shift; |
1098 | my $class = shift; |
1080 | |
1099 | |
1081 | $class->SUPER::new ( |
1100 | $class->SUPER::new ( |
1082 | col_expand => [], |
1101 | col_expand => [], |
1083 | @_ |
1102 | @_, |
1084 | ) |
1103 | ) |
1085 | } |
1104 | } |
1086 | |
1105 | |
1087 | sub add { |
1106 | sub add { |
1088 | my ($self, $x, $y, $child) = @_; |
1107 | my ($self, $x, $y, $child) = @_; |
… | |
… | |
1562 | my ($self) = @_; |
1581 | my ($self) = @_; |
1563 | |
1582 | |
1564 | my ($w, $h) = $self->SUPER::size_request; |
1583 | my ($w, $h) = $self->SUPER::size_request; |
1565 | |
1584 | |
1566 | ($w + 1, $h) # add 1 for cursor |
1585 | ($w + 1, $h) # add 1 for cursor |
1567 | } |
|
|
1568 | |
|
|
1569 | sub size_allocate { |
|
|
1570 | my ($self, $w, $h) = @_; |
|
|
1571 | |
|
|
1572 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
|
|
1573 | } |
1586 | } |
1574 | |
1587 | |
1575 | sub key_down { |
1588 | sub key_down { |
1576 | my ($self, $ev) = @_; |
1589 | my ($self, $ev) = @_; |
1577 | |
1590 | |
… | |
… | |
2626 | |
2639 | |
2627 | sub new { |
2640 | sub new { |
2628 | my $class = shift; |
2641 | my $class = shift; |
2629 | |
2642 | |
2630 | my $self = $class->SUPER::new ( |
2643 | my $self = $class->SUPER::new ( |
2631 | aspect => 1, |
2644 | aspect => 1, |
|
|
2645 | can_events => 0, |
2632 | @_, |
2646 | @_, |
2633 | ); |
2647 | ); |
2634 | |
2648 | |
2635 | if ($self->{anim} && $self->{animspeed}) { |
2649 | if ($self->{anim} && $self->{animspeed}) { |
2636 | Scalar::Util::weaken (my $widget = $self); |
2650 | Scalar::Util::weaken (my $widget = $self); |
… | |
… | |
2695 | $self->SUPER::DESTROY; |
2709 | $self->SUPER::DESTROY; |
2696 | } |
2710 | } |
2697 | |
2711 | |
2698 | ############################################################################# |
2712 | ############################################################################# |
2699 | |
2713 | |
2700 | package CFClient::UI::InventoryItem; |
2714 | package CFClient::UI::Inventory; |
2701 | |
2715 | |
2702 | our @ISA = CFClient::UI::HBox::; |
2716 | our @ISA = CFClient::UI::ScrolledWindow::; |
2703 | |
|
|
2704 | sub _item_to_desc { |
|
|
2705 | my ($item) = @_; |
|
|
2706 | |
|
|
2707 | my $desc = |
|
|
2708 | $item->{nrof} < 2 |
|
|
2709 | ? $item->{name} |
|
|
2710 | : "$item->{nrof} × $item->{name_pl}"; |
|
|
2711 | |
|
|
2712 | $item->{flags} & Crossfire::Protocol::F_OPEN |
|
|
2713 | and $desc .= " (open)"; |
|
|
2714 | $item->{flags} & Crossfire::Protocol::F_APPLIED |
|
|
2715 | and $desc .= " (applied)"; |
|
|
2716 | $item->{flags} & Crossfire::Protocol::F_UNPAID |
|
|
2717 | and $desc .= " (unpaid)"; |
|
|
2718 | $item->{flags} & Crossfire::Protocol::F_MAGIC |
|
|
2719 | and $desc .= " (magic)"; |
|
|
2720 | $item->{flags} & Crossfire::Protocol::F_CURSED |
|
|
2721 | and $desc .= " (cursed)"; |
|
|
2722 | $item->{flags} & Crossfire::Protocol::F_DAMNED |
|
|
2723 | and $desc .= " (damned)"; |
|
|
2724 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2725 | and $desc .= " *"; |
|
|
2726 | |
|
|
2727 | $desc |
|
|
2728 | } |
|
|
2729 | |
2717 | |
2730 | sub new { |
2718 | sub new { |
2731 | my $class = shift; |
2719 | my $class = shift; |
2732 | |
2720 | |
2733 | my %args = @_; |
|
|
2734 | |
|
|
2735 | my $item = delete $args{item}; |
|
|
2736 | |
|
|
2737 | my $desc = _item_to_desc ($item); |
|
|
2738 | |
|
|
2739 | my $self = $class->SUPER::new ( |
2721 | my $self = $class->SUPER::new ( |
2740 | can_hover => 1, |
|
|
2741 | can_events => 1, |
|
|
2742 | tooltip => ((CFClient::UI::Label::escape $desc) |
|
|
2743 | . "\n<small>leftclick - examine\nshift+leftclick - move/pickup/drop\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
2744 | connect_button_down => sub { |
|
|
2745 | my ($self, $ev, $x, $y) = @_; |
|
|
2746 | |
|
|
2747 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
2748 | if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { |
|
|
2749 | my $targ = $::CONN->{player}{tag}; |
|
|
2750 | |
|
|
2751 | if ($item->{container} == $::CONN->{player}{tag}) { |
|
|
2752 | $targ = $main::OPENCONT; |
|
|
2753 | } |
|
|
2754 | |
|
|
2755 | $::CONN->send ("move $targ $item->{tag} 0"); |
|
|
2756 | } elsif ($ev->{button} == 1) { |
|
|
2757 | $::CONN->send ("examine $item->{tag}"); |
|
|
2758 | } elsif ($ev->{button} == 2) { |
|
|
2759 | $::CONN->send ("apply $item->{tag}"); |
|
|
2760 | } elsif ($ev->{button} == 3) { |
|
|
2761 | my @menu_items = ( |
|
|
2762 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
|
|
2763 | ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }], |
|
|
2764 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2765 | ( |
|
|
2766 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2767 | ? ( |
|
|
2768 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }], |
|
|
2769 | ) |
|
|
2770 | : ( |
|
|
2771 | ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }], |
|
|
2772 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
|
|
2773 | ) |
|
|
2774 | ), |
|
|
2775 | ); |
|
|
2776 | |
|
|
2777 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
|
|
2778 | } |
|
|
2779 | |
|
|
2780 | 1 |
|
|
2781 | }, |
|
|
2782 | %args |
|
|
2783 | ); |
|
|
2784 | |
|
|
2785 | |
|
|
2786 | $self->add (new CFClient::UI::Face |
|
|
2787 | can_events => 0, |
|
|
2788 | face => $item->{face}, |
|
|
2789 | anim => $item->{anim}, |
|
|
2790 | animspeed => $item->{animspeed}, |
|
|
2791 | ); |
|
|
2792 | |
|
|
2793 | $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0); |
|
|
2794 | |
|
|
2795 | $self->{item} = $item; |
|
|
2796 | |
|
|
2797 | $self->update_item; |
|
|
2798 | |
|
|
2799 | $self |
|
|
2800 | } |
|
|
2801 | |
|
|
2802 | sub update_item { |
|
|
2803 | my ($self) = @_; |
|
|
2804 | |
|
|
2805 | my $desc = _item_to_desc ($self->{item}); |
|
|
2806 | |
|
|
2807 | $self->{name_lbl}->set_text ($desc); |
|
|
2808 | } |
|
|
2809 | |
|
|
2810 | ############################################################################# |
|
|
2811 | |
|
|
2812 | package CFClient::UI::Inventory; |
|
|
2813 | |
|
|
2814 | our @ISA = CFClient::UI::ScrolledWindow::; |
|
|
2815 | |
|
|
2816 | sub new { |
|
|
2817 | my $class = shift; |
|
|
2818 | |
|
|
2819 | my $self = $class->SUPER::new ( |
|
|
2820 | scrolled => (new CFClient::UI::Table), |
2722 | scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
2821 | @_, |
2723 | @_, |
2822 | ); |
2724 | ); |
2823 | |
2725 | |
2824 | $self |
2726 | $self |
2825 | } |
2727 | } |
… | |
… | |
2835 | or ($a->{name} cmp $b->{name}) |
2737 | or ($a->{name} cmp $b->{name}) |
2836 | } @$items; |
2738 | } @$items; |
2837 | |
2739 | |
2838 | $self->{real_items} = \@items; |
2740 | $self->{real_items} = \@items; |
2839 | |
2741 | |
|
|
2742 | my $row = 0; |
2840 | for my $item (@items) { |
2743 | for my $item (@items) { |
2841 | $item->{item} = $item; |
2744 | CFClient::Item::update_widgets $item; |
2842 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
|
|
2843 | $item->update_item (); |
|
|
2844 | } |
|
|
2845 | |
2745 | |
2846 | my $i = 0; |
2746 | $self->{scrolled}->add (0, $row, $item->{face_widget}); |
2847 | for (@items) { |
2747 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
2848 | $self->{scrolled}->add (0, $i, $_); |
2748 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
2849 | my $nrof = $_->{item}->{nrof} || 1; |
2749 | |
2850 | $self->{scrolled}->add (1, $i++, new CFClient::UI::Label text => ($_->{item}->{weight} * $nrof) / 1000); |
2750 | $row++; |
2851 | } |
2751 | } |
2852 | |
2752 | |
2853 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2753 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2854 | } |
2754 | } |
2855 | |
2755 | |
… | |
… | |
2995 | sub add { |
2895 | sub add { |
2996 | my ($self, $text, %arg) = @_; |
2896 | my ($self, $text, %arg) = @_; |
2997 | |
2897 | |
2998 | $text =~ s/^\s+//; |
2898 | $text =~ s/^\s+//; |
2999 | $text =~ s/\s+$//; |
2899 | $text =~ s/\s+$//; |
|
|
2900 | |
|
|
2901 | return unless $text; |
3000 | |
2902 | |
3001 | my $timeout = time + ((delete $arg{timeout}) || 60); |
2903 | my $timeout = time + ((delete $arg{timeout}) || 60); |
3002 | |
2904 | |
3003 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
2905 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
3004 | |
2906 | |