ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.232 by root, Thu May 25 02:23:14 2006 UTC vs.
Revision 1.235 by root, Thu May 25 16:35:42 2006 UTC

322} 322}
323 323
324sub set_tooltip { 324sub 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}
763 768
764package CFClient::UI::ViewPort; 769package CFClient::UI::ViewPort;
765 770
766our @ISA = CFClient::UI::Window::; 771our @ISA = CFClient::UI::Window::;
767 772
773sub new {
774 my $class = shift;
775
776 $class->SUPER::new (
777 scroll_x => 0,
778 scroll_y => 1,
779 @_,
780 )
781}
782
768sub size_request { 783sub 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
776sub size_allocate { 791sub 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
785sub set_offset { 801sub set_offset {
786 my ($self, $x, $y) = @_; 802 my ($self, $x, $y) = @_;
1081sub new { 1097sub 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 )
1088} 1104}
1089 1105
1090sub add { 1106sub add {
1091 my ($self, $x, $y, $child) = @_; 1107 my ($self, $x, $y, $child) = @_;
2623 2639
2624sub new { 2640sub new {
2625 my $class = shift; 2641 my $class = shift;
2626 2642
2627 my $self = $class->SUPER::new ( 2643 my $self = $class->SUPER::new (
2628 aspect => 1, 2644 aspect => 1,
2645 can_events => 0,
2629 @_, 2646 @_,
2630 ); 2647 );
2631 2648
2632 if ($self->{anim} && $self->{animspeed}) { 2649 if ($self->{anim} && $self->{animspeed}) {
2633 Scalar::Util::weaken (my $widget = $self); 2650 Scalar::Util::weaken (my $widget = $self);
2692 $self->SUPER::DESTROY; 2709 $self->SUPER::DESTROY;
2693} 2710}
2694 2711
2695############################################################################# 2712#############################################################################
2696 2713
2697package CFClient::UI::InventoryItem; 2714package CFClient::UI::Inventory;
2698 2715
2699our @ISA = CFClient::UI::HBox::; 2716our @ISA = CFClient::UI::ScrolledWindow::;
2700
2701sub _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 2717
2727sub new { 2718sub new {
2728 my $class = shift; 2719 my $class = shift;
2729 2720
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 ( 2721 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
2799sub 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
2809package CFClient::UI::Inventory;
2810
2811our @ISA = CFClient::UI::ScrolledWindow::;
2812
2813sub new {
2814 my $class = shift;
2815
2816 my $self = $class->SUPER::new (
2817 scrolled => (new CFClient::UI::Table), 2722 scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]),
2818 @_, 2723 @_,
2819 ); 2724 );
2820 2725
2821 $self 2726 $self
2822} 2727}
2832 or ($a->{name} cmp $b->{name}) 2737 or ($a->{name} cmp $b->{name})
2833 } @$items; 2738 } @$items;
2834 2739
2835 $self->{real_items} = \@items; 2740 $self->{real_items} = \@items;
2836 2741
2742 my $row = 0;
2837 for my $item (@items) { 2743 for my $item (@items) {
2838 $item->{item} = $item; 2744 CFClient::Item::update_widgets $item;
2839 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2840 $item->update_item ();
2841 }
2842 2745
2843 my $i = 0; 2746 $self->{scrolled}->add (0, $row, $item->{face_widget});
2844 for (@items) { 2747 $self->{scrolled}->add (1, $row, $item->{desc_widget});
2845 $self->{scrolled}->add (0, $i, $_); 2748 $self->{scrolled}->add (2, $row, $item->{weight_widget});
2846 my $nrof = $_->{item}->{nrof} || 1; 2749
2847 $self->{scrolled}->add (1, $i++, new CFClient::UI::Label text => ($_->{item}->{weight} * $nrof) / 1000); 2750 $row++;
2848 } 2751 }
2849 2752
2850# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2753# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2851} 2754}
2852 2755
2992sub add { 2895sub add {
2993 my ($self, $text, %arg) = @_; 2896 my ($self, $text, %arg) = @_;
2994 2897
2995 $text =~ s/^\s+//; 2898 $text =~ s/^\s+//;
2996 $text =~ s/\s+$//; 2899 $text =~ s/\s+$//;
2900
2901 return unless $text;
2997 2902
2998 my $timeout = time + ((delete $arg{timeout}) || 60); 2903 my $timeout = time + ((delete $arg{timeout}) || 60);
2999 2904
3000 my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; 2905 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
3001 2906

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines