--- deliantra/Deliantra-Client/DC/UI.pm 2006/05/25 00:26:19 1.231 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/05/25 16:35:42 1.235 @@ -235,6 +235,9 @@ undef $GRAB if $GRAB == $self; undef $HOVER if $HOVER == $self; + CFClient::UI::check_tooltip + if $CFClient::UI::TOOLTIP->{owner} == $self; + $self->focus_out; } @@ -321,6 +324,11 @@ sub set_tooltip { my ($self, $tooltip) = @_; + $tooltip =~ s/^\s+//; + $tooltip =~ s/\s+$//; + + return if $self->{tooltip} eq $tooltip; + $self->{tooltip} = $tooltip; if ($CFClient::UI::TOOLTIP->{owner} == $self) { @@ -419,10 +427,10 @@ glColor 1, 1, 0, 1; glTranslate $self->{x} + 0.375, $self->{y} + 0.375; glBegin GL_LINE_LOOP; - glVertex 0 , 0; - glVertex $self->{w}, 0; - glVertex $self->{w}, $self->{h}; - glVertex 0 , $self->{h}; + glVertex 0 , 0; + glVertex $self->{w} - 1, 0; + glVertex $self->{w} - 1, $self->{h} - 1; + glVertex 0 , $self->{h} - 1; glEnd; glPopMatrix; #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; @@ -762,6 +770,16 @@ our @ISA = CFClient::UI::Window::; +sub new { + my $class = shift; + + $class->SUPER::new ( + scroll_x => 0, + scroll_y => 1, + @_, + ) +} + sub size_request { my ($self) = @_; @@ -773,9 +791,10 @@ sub size_allocate { my ($self, $w, $h) = @_; - my ($cw, $ch) = @$self{qw(child_w child_h)}; -# $w = $self->{w}; - $self->child->configure (0, 0, $cw, $ch); + $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; + $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; + + $self->child->configure (0, 0, $w, $h); $self->update; } @@ -1080,7 +1099,7 @@ $class->SUPER::new ( col_expand => [], - @_ + @_, ) } @@ -1566,12 +1585,6 @@ ($w + 1, $h) # add 1 for cursor } -sub size_allocate { - my ($self, $w, $h) = @_; - - $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text -} - sub key_down { my ($self, $ev) = @_; @@ -2628,7 +2641,8 @@ my $class = shift; my $self = $class->SUPER::new ( - aspect => 1, + aspect => 1, + can_events => 0, @_, ); @@ -2697,118 +2711,6 @@ ############################################################################# -package CFClient::UI::InventoryItem; - -our @ISA = CFClient::UI::HBox::; - -sub _item_to_desc { - my ($item) = @_; - - my $desc = - $item->{nrof} < 2 - ? $item->{name} - : "$item->{nrof} × $item->{name_pl}"; - - $item->{flags} & Crossfire::Protocol::F_OPEN - and $desc .= " (open)"; - $item->{flags} & Crossfire::Protocol::F_APPLIED - and $desc .= " (applied)"; - $item->{flags} & Crossfire::Protocol::F_UNPAID - and $desc .= " (unpaid)"; - $item->{flags} & Crossfire::Protocol::F_MAGIC - and $desc .= " (magic)"; - $item->{flags} & Crossfire::Protocol::F_CURSED - and $desc .= " (cursed)"; - $item->{flags} & Crossfire::Protocol::F_DAMNED - and $desc .= " (damned)"; - $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) - . "\nleftclick - examine\nshift+leftclick - move/pickup/drop\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->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { - my $targ = $::CONN->{player}{tag}; - - if ($item->{container} == $::CONN->{player}{tag}) { - $targ = $main::OPENCONT; - } - - $::CONN->send ("move $targ $item->{tag} 0"); - } elsif ($ev->{button} == 1) { - $::CONN->send ("examine $item->{tag}"); - } elsif ($ev->{button} == 2) { - $::CONN->send ("apply $item->{tag}"); - } elsif ($ev->{button} == 3) { - my @menu_items = ( - ["examine", sub { $::CONN->send ("examine $item->{tag}") }], - ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }], - ["apply", sub { $::CONN->send ("apply $item->{tag}") }], - ( - $item->{flags} & Crossfire::Protocol::F_LOCKED - ? ( - ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }], - ) - : ( - ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }], - ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], - ) - ), - ); - - CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); - } - - 1 - }, - %args - ); - - - $self->add (new CFClient::UI::Face - can_events => 0, - face => $item->{face}, - anim => $item->{anim}, - animspeed => $item->{animspeed}, - ); - - $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; our @ISA = CFClient::UI::ScrolledWindow::; @@ -2817,7 +2719,7 @@ my $class = shift; my $self = $class->SUPER::new ( - scrolled => (new CFClient::UI::Table), + scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), @_, ); @@ -2837,17 +2739,15 @@ $self->{real_items} = \@items; + my $row = 0; for my $item (@items) { - $item->{item} = $item; - $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; - $item->update_item (); - } + CFClient::Item::update_widgets $item; - my $i = 0; - for (@items) { - $self->{scrolled}->add (0, $i, $_); - my $nrof = $_->{item}->{nrof} || 1; - $self->{scrolled}->add (1, $i++, new CFClient::UI::Label text => ($_->{item}->{weight} * $nrof) / 1000); + $self->{scrolled}->add (0, $row, $item->{face_widget}); + $self->{scrolled}->add (1, $row, $item->{desc_widget}); + $self->{scrolled}->add (2, $row, $item->{weight_widget}); + + $row++; } # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; @@ -2998,6 +2898,8 @@ $text =~ s/^\s+//; $text =~ s/\s+$//; + return unless $text; + my $timeout = time + ((delete $arg{timeout}) || 60); my $group = exists $arg{group} ? $arg{group} : ++$self->{id};