--- deliantra/Deliantra-Client/DC/UI.pm 2006/05/15 22:52:17 1.208 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/05/17 14:55:14 1.212 @@ -284,6 +284,17 @@ delete $self->{max_h}; $self->{max_h} = $h if $h; } +sub set_tooltip { + my ($self, $tooltip) = @_; + + $self->{tooltip} = $tooltip; + + if ($CFClient::UI::TOOLTIP->{owner} == $self) { + delete $CFClient::UI::TOOLTIP->{owner}; + CFClient::UI::check_tooltip; + } +} + # translate global coordinates to local coordinate system sub coord2local { my ($self, $x, $y) = @_; @@ -457,8 +468,8 @@ # range [value, low, high, page] $class->SUPER::new ( - bg => [0, 0, 0, 0.2], - active_bg => [1, 1, 1, 0.5], + #bg => [0, 0, 0, 0.2], + #active_bg => [1, 1, 1, 0.5], @_ ) } @@ -466,20 +477,26 @@ sub _draw { my ($self) = @_; - my ($w, $h) = @$self{qw(w h)}; + my $color = $FOCUS == $self && $self->{active_bg} + ? $self->{active_bg} + : $self->{bg}; - glEnable GL_BLEND; - glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; - glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; + if ($color && (@$color < 4 || $color->[3])) { + my ($w, $h) = @$self{qw(w h)}; - glBegin GL_QUADS; - glVertex 0 , 0; - glVertex 0 , $h; - glVertex $w, $h; - glVertex $w, 0; - glEnd; + glEnable GL_BLEND; + glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; + glColor @$color; - glDisable GL_BLEND; + glBegin GL_QUADS; + glVertex 0 , 0; + glVertex 0 , $h; + glVertex $w, $h; + glVertex $w, 0; + glEnd; + + glDisable GL_BLEND; + } } ############################################################################# @@ -1268,7 +1285,7 @@ package CFClient::UI::Label; -our @ISA = CFClient::UI::Base::; +our @ISA = CFClient::UI::DrawBG::; use CFClient::OpenGL; @@ -1277,6 +1294,8 @@ my $self = $class->SUPER::new ( fg => [1, 1, 1], + #bg => none + #active_bg => none #font => default_font #text => initial text #markup => initial narkup @@ -1304,14 +1323,14 @@ $self } -sub escape { - local $_ = $_[1]; +sub escape($) { + local $_ = $_[0]; s/&/&/g; s/>/>/g; s/SUPER::_draw; # draw background, if applicable + my $tex = $self->{texture} ||= do { $self->{layout}->set_foreground (@{$self->{fg}}); $self->{layout}->set_font ($self->{font}) if $self->{font}; @@ -1662,7 +1683,6 @@ $class->SUPER::new ( padding => 4, fg => [1, 1, 1], - bg => [1, 1, 1, 0.2], active_fg => [0, 0, 1], can_hover => 1, align => 0, @@ -1720,6 +1740,8 @@ padding => 2, fg => [1, 1, 1], active_fg => [1, 1, 0], + bg => [0, 0, 0, 0.2], + active_bg => [1, 1, 1, 0.5], state => 0, can_hover => 1, @_ @@ -2021,6 +2043,8 @@ my $self = $class->SUPER::new ( fg => [1, 1, 1], active_fg => [0, 0, 0], + bg => [0, 0, 0, 0.2], + active_bg => [1, 1, 1, 0.5], range => [0, 0, 100, 10], req_w => $::WIDTH / 80, req_h => $::WIDTH / 80, @@ -2496,16 +2520,13 @@ our @ISA = CFClient::UI::HBox::; -sub new { - my $class = shift; +sub _item_to_desc { + my ($item) = @_; - my %args = @_; - - my $item = delete $args{item}; - - my $desc = $item->{nrof} < 2 - ? $item->{name} - : "$item->{nrof} $item->{name_pl}"; + my $desc = + $item->{nrof} < 2 + ? $item->{name} + : "$item->{nrof} $item->{name_pl}"; $item->{flags} & Crossfire::Protocol::F_OPEN and $desc .= " (open)"; @@ -2522,17 +2543,35 @@ $item->{flags} & Crossfire::Protocol::F_LOCKED and $desc .= " *"; + $desc +} + +sub new { + my $class = shift; + + my %args = @_; + + my $item = delete $args{item}; + + my $desc = _item_to_desc ($item); + my $self = $class->SUPER::new ( can_hover => 1, can_events => 1, - tooltip => (CFClient::UI::Label->escape ($desc) + tooltip => ((CFClient::UI::Label::escape $desc) . "\nleftclick - pick up\nmiddle click - apply\nrightclick - menu"), connect_button_down => sub { my ($self, $ev, $x, $y) = @_; # todo: maybe put examine on 1? but should just be a tooltip :( if ($ev->{button} == 1) { - $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); + my $targ = $::CONN->{player}{tag}; + + if ($item->{container} == $::CONN->{player}{tag}) { + $targ = $main::OPENCONT; + } + + $::CONN->send ("move $targ $item->{tag} 0"); } elsif ($ev->{button} == 2) { $::CONN->send ("apply $item->{tag}"); } elsif ($ev->{button} == 3) { @@ -2543,7 +2582,7 @@ ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], [ $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", - sub { $::CONN->send ("lock ". () ."$item->{tag}") }, + sub { $::CONN->send ("lock $item->{tag}") }, ], ); @@ -2555,6 +2594,7 @@ %args ); + $self->add (new CFClient::UI::Face can_events => 0, face => $item->{face}, @@ -2562,14 +2602,23 @@ animspeed => $item->{animspeed}, ); - $self->add (new CFClient::UI::Label - can_events => 0, - text => $desc, - ); + $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0); + + $self->{item} = $item; + + $self->update_item; $self } +sub update_item { + my ($self) = @_; + + my $desc = _item_to_desc ($self->{item}); + + $self->{name_lbl}->set_text ($desc); +} + ############################################################################# package CFClient::UI::Inventory; @@ -2601,11 +2650,8 @@ $self->{real_items} = \@items; for my $item (@items) { - my $desc = $item->{nrof} < 2 - ? $item->{name} - : "$item->{nrof} $item->{name_pl}"; - $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; + $item->update_item (); } $self->{scrolled}->add (@items); @@ -2696,6 +2742,15 @@ our @ISA = CFClient::UI::VBox::; +sub new { + my $class = shift; + + $class->SUPER::new ( + fontsize => 0.8, + @_, + ) +} + sub reorder { my ($self) = @_; my $NOW = time; @@ -2721,10 +2776,12 @@ ? "$item->{count} × $item->{text}" : $item->{text}; + my $fontsize = $item->{fontsize} || $self->{fontsize}; + for ($short) { s/^\s+//; s/\s+/ /g; - my $len = int 40 / $item->{fontsize}; + my $len = int 40 / $fontsize; substr $_, $len, length, "…" if $len < length; } @@ -2733,7 +2790,7 @@ tooltip => $item->{tooltip}, tooltip_font => $::FONT_PROP, tooltip_width => 0.67, - fontsize => $item->{fontsize}, + fontsize => $fontsize, fg => $item->{fg}, can_events => 1, can_hover => 1 @@ -2770,7 +2827,6 @@ text => $text, timeout => $timeout, tooltip => $text, - fontsize => 0.8, fg => [0.8, 0.8, 0.8, 0.8], pri => 0, count => 1,