--- deliantra/Deliantra-Client/DC/UI.pm 2006/05/17 10:14:52 1.210 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/05/19 03:49:48 1.215 @@ -142,7 +142,10 @@ sub rescale_widgets { my ($sx, $sy) = @_; - for my $widget (values %WIDGET) { + # make a copy, otherwise for complains about freed values. + my @widgets = values %WIDGET; + + for my $widget (@widgets) { if ($widget->{toplevel}) { $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; @@ -686,17 +689,10 @@ my ($self) = @_; $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { - glClearColor 0, 0, 0, 0; + glClearColor 0.5, 0.5, 0.5, 1; glClear GL_COLOR_BUFFER_BIT; $self->_render; -# glColorMask 1, 1, 1, 0; -# glEnable GL_BLEND; -# glBlendFunc GL_SRC_ALPHA, GL_ZERO; -# glRasterPos 0, 0; -# glCopyPixels 0, 0, $self->{w}, $self->{h}; -# glDisable GL_BLEND; -# glColorMask 1, 1, 1, 1; }; } @@ -710,7 +706,7 @@ glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - glColor 0, 0, 0, 1; + glColor 1, 1, 1, 1; $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); @@ -1299,6 +1295,8 @@ #font => default_font #text => initial text #markup => initial narkup + #max_w => maximum pixel width + ellipsise => 3, # end layout => (new CFClient::Layout), fontsize => 1, align => -1, @@ -1373,6 +1371,8 @@ $self->{layout}->set_font ($self->{font}) if $self->{font}; $self->{layout}->set_width ($self->{max_w} || -1); + $self->{layout}->set_ellipsise ($self->{ellipsise}); + $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); my ($w, $h) = $self->{layout}->size; @@ -1418,7 +1418,9 @@ $self->{layout}->set_foreground (@{$self->{fg}}); $self->{layout}->set_font ($self->{font}) if $self->{font}; $self->{layout}->set_width ($self->{w}); - $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); + $self->{layout}->set_ellipsise ($self->{ellipsise}); + $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); + $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); my $tex = new_from_layout CFClient::Texture $self->{layout}; @@ -2150,8 +2152,8 @@ if ($self->{vertical}) { # draw a vertical slider like a rotated horizontal slider + glTranslate 1, 0, 0; glRotate 90, 0, 0, 1; - glTranslate 0, 1, 0; } my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; @@ -2277,7 +2279,7 @@ } $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { - glClearColor 0, 0, 0, 0; + glClearColor 0.5, 0.5, 0.5, 0; glClear GL_COLOR_BUFFER_BIT; glEnable GL_TEXTURE_2D; @@ -2428,11 +2430,12 @@ my ($self, $widget) = @_; $self->add (new CFClient::UI::Label - markup => $widget->{tooltip}, - max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, - fontsize => 0.8, - fg => [0, 0, 0, 1], - font => ($widget->{tooltip_font} || $::FONT_PROP), + markup => $widget->{tooltip}, + max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, + fontsize => 0.8, + fg => [0, 0, 0, 1], + ellipsise => 0, + font => ($widget->{tooltip_font} || $::FONT_PROP), ); } @@ -2520,16 +2523,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)"; @@ -2546,6 +2546,18 @@ $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, @@ -2556,7 +2568,13 @@ # 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) { @@ -2567,7 +2585,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}") }, ], ); @@ -2579,6 +2597,7 @@ %args ); + $self->add (new CFClient::UI::Face can_events => 0, face => $item->{face}, @@ -2586,14 +2605,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; @@ -2625,11 +2653,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); @@ -2754,13 +2779,9 @@ ? "$item->{count} × $item->{text}" : $item->{text}; - my $fontsize = $item->{fontsize} || $self->{fontsize}; - for ($short) { s/^\s+//; s/\s+/ /g; - my $len = int 40 / $fontsize; - substr $_, $len, length, "…" if $len < length; } new CFClient::UI::Label @@ -2768,7 +2789,8 @@ tooltip => $item->{tooltip}, tooltip_font => $::FONT_PROP, tooltip_width => 0.67, - fontsize => $fontsize, + fontsize => $item->{fontsize} || $self->{fontsize}, + max_w => $::WIDTH * 0.44, fg => $item->{fg}, can_events => 1, can_hover => 1 @@ -2815,6 +2837,16 @@ $self->reorder; } +sub reconfigure { + my ($self) = @_; + + delete $_->{label} + for values %{ $self->{item} || {} }; + + $self->reorder; + $self->SUPER::reconfigure; +} + ############################################################################# package CFClient::UI::Root; @@ -2997,7 +3029,7 @@ package CFClient::UI; $ROOT = new CFClient::UI::Root; -$TOOLTIP = new CFClient::UI::Tooltip; +$TOOLTIP = new CFClient::UI::Tooltip z => 900; 1