… | |
… | |
322 | } |
322 | } |
323 | |
323 | |
324 | sub set_tooltip { |
324 | sub set_tooltip { |
325 | my ($self, $tooltip) = @_; |
325 | my ($self, $tooltip) = @_; |
326 | |
326 | |
|
|
327 | $tooltip =~ s/^\s+//; |
|
|
328 | $tooltip =~ s/\s+$//; |
|
|
329 | |
|
|
330 | return if $self->{tooltip} eq $tooltip; |
|
|
331 | |
327 | $self->{tooltip} = $tooltip; |
332 | $self->{tooltip} = $tooltip; |
328 | |
333 | |
329 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
334 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
330 | delete $CFClient::UI::TOOLTIP->{owner}; |
335 | delete $CFClient::UI::TOOLTIP->{owner}; |
331 | CFClient::UI::check_tooltip; |
336 | CFClient::UI::check_tooltip; |
… | |
… | |
420 | if ($ENV{PCLIENT_DEBUG}) { |
425 | if ($ENV{PCLIENT_DEBUG}) { |
421 | glPushMatrix; |
426 | glPushMatrix; |
422 | glColor 1, 1, 0, 1; |
427 | glColor 1, 1, 0, 1; |
423 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
428 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
424 | glBegin GL_LINE_LOOP; |
429 | glBegin GL_LINE_LOOP; |
425 | glVertex 0 , 0; |
430 | glVertex 0 , 0; |
426 | glVertex $self->{w}, 0; |
431 | glVertex $self->{w} - 1, 0; |
427 | glVertex $self->{w}, $self->{h}; |
432 | glVertex $self->{w} - 1, $self->{h} - 1; |
428 | glVertex 0 , $self->{h}; |
433 | glVertex 0 , $self->{h} - 1; |
429 | glEnd; |
434 | glEnd; |
430 | glPopMatrix; |
435 | glPopMatrix; |
431 | #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; |
432 | } |
437 | } |
433 | } |
438 | } |
… | |
… | |
613 | delete $child->{parent}; |
618 | delete $child->{parent}; |
614 | $child->hide; |
619 | $child->hide; |
615 | |
620 | |
616 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
621 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
617 | |
622 | |
618 | $self->check_size; |
623 | $self->check_size (1); |
619 | $self->update; |
624 | $self->update; |
620 | } |
625 | } |
621 | |
626 | |
622 | sub clear { |
627 | sub clear { |
623 | my ($self) = @_; |
628 | my ($self) = @_; |
… | |
… | |
763 | |
768 | |
764 | package CFClient::UI::ViewPort; |
769 | package CFClient::UI::ViewPort; |
765 | |
770 | |
766 | our @ISA = CFClient::UI::Window::; |
771 | our @ISA = CFClient::UI::Window::; |
767 | |
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 | |
768 | sub size_request { |
783 | sub size_request { |
769 | my ($self) = @_; |
784 | my ($self) = @_; |
770 | |
785 | |
771 | @$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)}; |
772 | |
787 | |
… | |
… | |
774 | } |
789 | } |
775 | |
790 | |
776 | sub size_allocate { |
791 | sub size_allocate { |
777 | my ($self, $w, $h) = @_; |
792 | my ($self, $w, $h) = @_; |
778 | |
793 | |
779 | my ($cw, $ch) = @$self{qw(child_w child_h)}; |
794 | $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; |
780 | # $w = $self->{w}; |
795 | $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; |
|
|
796 | |
781 | $self->child->configure (0, 0, $cw, $ch); |
797 | $self->child->configure (0, 0, $w, $h); |
782 | $self->update; |
798 | $self->update; |
783 | } |
799 | } |
784 | |
800 | |
785 | sub set_offset { |
801 | sub set_offset { |
786 | my ($self, $x, $y) = @_; |
802 | my ($self, $x, $y) = @_; |
… | |
… | |
1081 | sub new { |
1097 | sub new { |
1082 | my $class = shift; |
1098 | my $class = shift; |
1083 | |
1099 | |
1084 | $class->SUPER::new ( |
1100 | $class->SUPER::new ( |
1085 | col_expand => [], |
1101 | col_expand => [], |
1086 | @_ |
1102 | @_, |
1087 | ) |
1103 | ) |
|
|
1104 | } |
|
|
1105 | |
|
|
1106 | sub children { |
|
|
1107 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
1088 | } |
1108 | } |
1089 | |
1109 | |
1090 | sub add { |
1110 | sub add { |
1091 | my ($self, $x, $y, $child) = @_; |
1111 | my ($self, $x, $y, $child) = @_; |
1092 | |
1112 | |
1093 | $child->set_parent ($self); |
1113 | $child->set_parent ($self); |
1094 | $self->{children}[$y][$x] = $child; |
1114 | $self->{children}[$y][$x] = $child; |
1095 | |
1115 | |
1096 | $child->check_size; |
1116 | $self->check_size (1); |
1097 | } |
1117 | } |
1098 | |
1118 | |
1099 | sub children { |
|
|
1100 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
1101 | } |
|
|
1102 | |
|
|
1103 | # TODO: move to container class maybe? send childs a signal on removal? |
1119 | # TODO: move to container class maybe? send children a signal on removal? |
1104 | sub clear { |
1120 | sub clear { |
1105 | my ($self) = @_; |
1121 | my ($self) = @_; |
1106 | |
1122 | |
1107 | my @children = $self->children; |
1123 | my @children = $self->children; |
1108 | delete $self->{children}; |
1124 | delete $self->{children}; |
… | |
… | |
1110 | for (@children) { |
1126 | for (@children) { |
1111 | delete $_->{parent}; |
1127 | delete $_->{parent}; |
1112 | $_->hide; |
1128 | $_->hide; |
1113 | } |
1129 | } |
1114 | |
1130 | |
|
|
1131 | $self->check_size (1); |
1115 | $self->update; |
1132 | $self->update; |
1116 | } |
1133 | } |
1117 | |
1134 | |
1118 | sub get_wh { |
1135 | sub get_wh { |
1119 | my ($self) = @_; |
1136 | my ($self) = @_; |
… | |
… | |
2623 | |
2640 | |
2624 | sub new { |
2641 | sub new { |
2625 | my $class = shift; |
2642 | my $class = shift; |
2626 | |
2643 | |
2627 | my $self = $class->SUPER::new ( |
2644 | my $self = $class->SUPER::new ( |
2628 | aspect => 1, |
2645 | aspect => 1, |
|
|
2646 | can_events => 0, |
2629 | @_, |
2647 | @_, |
2630 | ); |
2648 | ); |
2631 | |
2649 | |
2632 | if ($self->{anim} && $self->{animspeed}) { |
2650 | if ($self->{anim} && $self->{animspeed}) { |
2633 | Scalar::Util::weaken (my $widget = $self); |
2651 | Scalar::Util::weaken (my $widget = $self); |
… | |
… | |
2692 | $self->SUPER::DESTROY; |
2710 | $self->SUPER::DESTROY; |
2693 | } |
2711 | } |
2694 | |
2712 | |
2695 | ############################################################################# |
2713 | ############################################################################# |
2696 | |
2714 | |
2697 | package CFClient::UI::InventoryItem; |
2715 | package CFClient::UI::Inventory; |
2698 | |
2716 | |
2699 | our @ISA = CFClient::UI::HBox::; |
2717 | our @ISA = CFClient::UI::ScrolledWindow::; |
2700 | |
|
|
2701 | sub _item_to_desc { |
|
|
2702 | my ($item) = @_; |
|
|
2703 | |
|
|
2704 | my $desc = |
|
|
2705 | $item->{nrof} < 2 |
|
|
2706 | ? $item->{name} |
|
|
2707 | : "$item->{nrof} × $item->{name_pl}"; |
|
|
2708 | |
|
|
2709 | $item->{flags} & Crossfire::Protocol::F_OPEN |
|
|
2710 | and $desc .= " (open)"; |
|
|
2711 | $item->{flags} & Crossfire::Protocol::F_APPLIED |
|
|
2712 | and $desc .= " (applied)"; |
|
|
2713 | $item->{flags} & Crossfire::Protocol::F_UNPAID |
|
|
2714 | and $desc .= " (unpaid)"; |
|
|
2715 | $item->{flags} & Crossfire::Protocol::F_MAGIC |
|
|
2716 | and $desc .= " (magic)"; |
|
|
2717 | $item->{flags} & Crossfire::Protocol::F_CURSED |
|
|
2718 | and $desc .= " (cursed)"; |
|
|
2719 | $item->{flags} & Crossfire::Protocol::F_DAMNED |
|
|
2720 | and $desc .= " (damned)"; |
|
|
2721 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2722 | and $desc .= " *"; |
|
|
2723 | |
|
|
2724 | $desc |
|
|
2725 | } |
|
|
2726 | |
2718 | |
2727 | sub new { |
2719 | sub new { |
2728 | my $class = shift; |
2720 | my $class = shift; |
2729 | |
2721 | |
2730 | my %args = @_; |
|
|
2731 | |
|
|
2732 | my $item = delete $args{item}; |
|
|
2733 | |
|
|
2734 | my $desc = _item_to_desc ($item); |
|
|
2735 | |
|
|
2736 | my $self = $class->SUPER::new ( |
2722 | my $self = $class->SUPER::new ( |
2737 | can_hover => 1, |
|
|
2738 | can_events => 1, |
|
|
2739 | tooltip => ((CFClient::UI::Label::escape $desc) |
|
|
2740 | . "\n<small>leftclick - examine\nshift+leftclick - move/pickup/drop\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
2741 | connect_button_down => sub { |
|
|
2742 | my ($self, $ev, $x, $y) = @_; |
|
|
2743 | |
|
|
2744 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
2745 | if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { |
|
|
2746 | my $targ = $::CONN->{player}{tag}; |
|
|
2747 | |
|
|
2748 | if ($item->{container} == $::CONN->{player}{tag}) { |
|
|
2749 | $targ = $main::OPENCONT; |
|
|
2750 | } |
|
|
2751 | |
|
|
2752 | $::CONN->send ("move $targ $item->{tag} 0"); |
|
|
2753 | } elsif ($ev->{button} == 1) { |
|
|
2754 | $::CONN->send ("examine $item->{tag}"); |
|
|
2755 | } elsif ($ev->{button} == 2) { |
|
|
2756 | $::CONN->send ("apply $item->{tag}"); |
|
|
2757 | } elsif ($ev->{button} == 3) { |
|
|
2758 | my @menu_items = ( |
|
|
2759 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
|
|
2760 | ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }], |
|
|
2761 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2762 | ( |
|
|
2763 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2764 | ? ( |
|
|
2765 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }], |
|
|
2766 | ) |
|
|
2767 | : ( |
|
|
2768 | ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }], |
|
|
2769 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
|
|
2770 | ) |
|
|
2771 | ), |
|
|
2772 | ); |
|
|
2773 | |
|
|
2774 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
|
|
2775 | } |
|
|
2776 | |
|
|
2777 | 1 |
|
|
2778 | }, |
|
|
2779 | %args |
|
|
2780 | ); |
|
|
2781 | |
|
|
2782 | |
|
|
2783 | $self->add (new CFClient::UI::Face |
|
|
2784 | can_events => 0, |
|
|
2785 | face => $item->{face}, |
|
|
2786 | anim => $item->{anim}, |
|
|
2787 | animspeed => $item->{animspeed}, |
|
|
2788 | ); |
|
|
2789 | |
|
|
2790 | $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0); |
|
|
2791 | |
|
|
2792 | $self->{item} = $item; |
|
|
2793 | |
|
|
2794 | $self->update_item; |
|
|
2795 | |
|
|
2796 | $self |
|
|
2797 | } |
|
|
2798 | |
|
|
2799 | sub update_item { |
|
|
2800 | my ($self) = @_; |
|
|
2801 | |
|
|
2802 | my $desc = _item_to_desc ($self->{item}); |
|
|
2803 | |
|
|
2804 | $self->{name_lbl}->set_text ($desc); |
|
|
2805 | } |
|
|
2806 | |
|
|
2807 | ############################################################################# |
|
|
2808 | |
|
|
2809 | package CFClient::UI::Inventory; |
|
|
2810 | |
|
|
2811 | our @ISA = CFClient::UI::ScrolledWindow::; |
|
|
2812 | |
|
|
2813 | sub new { |
|
|
2814 | my $class = shift; |
|
|
2815 | |
|
|
2816 | my $self = $class->SUPER::new ( |
|
|
2817 | scrolled => (new CFClient::UI::Table), |
2723 | scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
2818 | @_, |
2724 | @_, |
2819 | ); |
2725 | ); |
2820 | |
2726 | |
2821 | $self |
2727 | $self |
2822 | } |
2728 | } |
… | |
… | |
2832 | or ($a->{name} cmp $b->{name}) |
2738 | or ($a->{name} cmp $b->{name}) |
2833 | } @$items; |
2739 | } @$items; |
2834 | |
2740 | |
2835 | $self->{real_items} = \@items; |
2741 | $self->{real_items} = \@items; |
2836 | |
2742 | |
|
|
2743 | my $row = 0; |
2837 | for my $item (@items) { |
2744 | for my $item (@items) { |
2838 | $item->{item} = $item; |
2745 | CFClient::Item::update_widgets $item; |
2839 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
|
|
2840 | $item->update_item (); |
|
|
2841 | } |
|
|
2842 | |
2746 | |
2843 | my $i = 0; |
2747 | $self->{scrolled}->add (0, $row, $item->{face_widget}); |
2844 | for (@items) { |
2748 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
2845 | $self->{scrolled}->add (0, $i, $_); |
2749 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
2846 | my $nrof = $_->{item}->{nrof} || 1; |
2750 | |
2847 | $self->{scrolled}->add (1, $i++, new CFClient::UI::Label text => ($_->{item}->{weight} * $nrof) / 1000); |
2751 | $row++; |
2848 | } |
2752 | } |
2849 | |
2753 | |
2850 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2754 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2851 | } |
2755 | } |
2852 | |
2756 | |
… | |
… | |
2992 | sub add { |
2896 | sub add { |
2993 | my ($self, $text, %arg) = @_; |
2897 | my ($self, $text, %arg) = @_; |
2994 | |
2898 | |
2995 | $text =~ s/^\s+//; |
2899 | $text =~ s/^\s+//; |
2996 | $text =~ s/\s+$//; |
2900 | $text =~ s/\s+$//; |
|
|
2901 | |
|
|
2902 | return unless $text; |
2997 | |
2903 | |
2998 | my $timeout = time + ((delete $arg{timeout}) || 60); |
2904 | my $timeout = time + ((delete $arg{timeout}) || 60); |
2999 | |
2905 | |
3000 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
2906 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
3001 | |
2907 | |