--- deliantra/Deliantra-Client/DC/UI.pm 2006/06/05 02:28:30 1.283 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/06/05 22:30:35 1.290 @@ -5,6 +5,7 @@ use Scalar::Util (); use List::Util (); +use Event; use CFClient; use CFClient::Texture; @@ -18,32 +19,7 @@ our %WIDGET; # all widgets, weak-referenced -sub get_layout { - my $layout; - - for (grep { $_->{name} } values %WIDGET) { - my $win = $layout->{$_->{name}} = { }; - - $win->{x} = ($_->{x} + $_->{w} * 0.5) / $::WIDTH if $_->{x} =~ /^[0-9.]+$/; - $win->{y} = ($_->{y} + $_->{h} * 0.5) / $::HEIGHT if $_->{y} =~ /^[0-9.]+$/; - $win->{w} = $_->{w} / $::WIDTH if defined $_->{w}; - $win->{h} = $_->{h} / $::HEIGHT if defined $_->{h}; - - $win->{show} = $_->{visible} && $_->{is_toplevel}; - } - - $layout -} - -sub set_layout { - my ($layout) = @_; - - $LAYOUT = $layout; -} - -sub check_tooltip { - return if $ENV{CFPLUS_DEBUG} & 8; - +our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { if (!$GRAB) { for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { if (length $widget->{tooltip}) { @@ -52,6 +28,8 @@ $TOOLTIP->{owner} = $widget; + return if $ENV{CFPLUS_DEBUG} & 8; + my $tip = $widget->{tooltip}; $tip = $tip->($widget) if CODE:: eq ref $tip; @@ -67,6 +45,29 @@ $TOOLTIP->hide; delete $TOOLTIP->{owner}; +}); + +sub get_layout { + my $layout; + + for (grep { $_->{name} } values %WIDGET) { + my $win = $layout->{$_->{name}} = { }; + + $win->{x} = ($_->{x} + $_->{w} * 0.5) / $::WIDTH if $_->{x} =~ /^[0-9.]+$/; + $win->{y} = ($_->{y} + $_->{h} * 0.5) / $::HEIGHT if $_->{y} =~ /^[0-9.]+$/; + $win->{w} = $_->{w} / $::WIDTH if defined $_->{w}; + $win->{h} = $_->{h} / $::HEIGHT if defined $_->{h}; + + $win->{show} = $_->{visible} && $_->{is_toplevel}; + } + + $layout +} + +sub set_layout { + my ($layout) = @_; + + $LAYOUT = $layout; } # class methods for events @@ -90,7 +91,7 @@ $GRAB = $widget; $GRAB->update if $GRAB; - check_tooltip; + $TOOLTIP_WATCHER->cb->(); } $BUTTON_STATE |= 1 << ($ev->{button} - 1); @@ -115,7 +116,7 @@ $grab->update if $grab; $GRAB->update if $GRAB; - check_tooltip; + $TOOLTIP_WATCHER->cb->(); } } @@ -131,7 +132,7 @@ $hover->update if $hover && $hover->{can_hover}; $HOVER->update if $HOVER && $HOVER->{can_hover}; - check_tooltip; + $TOOLTIP_WATCHER->start; } $HOVER->emit (mouse_motion => $ev, $HOVER->coord2local ($x, $y)) @@ -279,7 +280,7 @@ undef $GRAB if $GRAB == $self; undef $HOVER if $HOVER == $self; - CFClient::UI::check_tooltip + $CFClient::UI::TOOLTIP_WATCHER->cb->() if $TOOLTIP->{owner} == $self; $self->focus_out; @@ -401,7 +402,7 @@ if ($CFClient::UI::TOOLTIP->{owner} == $self) { delete $CFClient::UI::TOOLTIP->{owner}; - CFClient::UI::check_tooltip; + $CFClient::UI::TOOLTIP_WATCHER->cb->(); } } @@ -1555,8 +1556,8 @@ $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; $self->{layout}->set_text ($text); - delete $self->{req_h}; + delete $self->{size_req}; $self->realloc; $self->update; } @@ -1571,8 +1572,8 @@ $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; $self->{layout}->set_markup ($markup); - delete $self->{req_h}; + delete $self->{size_req}; $self->realloc; $self->update; } @@ -1580,9 +1581,7 @@ sub size_request { my ($self) = @_; - if (exists $self->{req_h}) { - @$self{qw(req_w req_h)} - } else { + $self->{size_req} ||= do { $self->{layout}->set_font ($self->{font}) if $self->{font}; $self->{layout}->set_width ($self->{max_w} || -1); $self->{layout}->set_ellipsise ($self->{ellipsise}); @@ -1601,8 +1600,10 @@ $h = List::Util::max $h, $h2; } - ($w, $h) - } + [$w, $h] + }; + + @{ $self->{size_req} } } sub size_allocate { @@ -1623,6 +1624,14 @@ $self->realloc; } +sub reconfigure { + my ($self) = @_; + + delete $self->{size_req}; + + $self->SUPER::reconfigure; +} + sub _draw { my ($self) = @_; @@ -1650,12 +1659,15 @@ }; glEnable GL_TEXTURE_2D; - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - - glColor_premultiply @{$self->{fg}} - if $tex->{format} == GL_ALPHA; - $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); + if ($tex->{format} == GL_ALPHA) { + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; + glColor @{$self->{fg}}; + $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); + } else { + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; + $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); + } glDisable GL_TEXTURE_2D; } @@ -1697,7 +1709,7 @@ $text =~ s/./*/g if $self->{hidden}; $self->{layout}->set_text ("$text "); - delete $self->{req_h}; + delete $self->{size_req}; $self->_emit (changed => $self->{text}); @@ -3474,43 +3486,71 @@ ) } -# XXX: Do sorting? Argl... -sub add_spell { - my ($self, $spell) = @_; - $self->{spells}->{$spell->{name}} = $spell; +my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => + "Level. Minimum level the caster needs in the associated skill to be able to attempt casting this spell."); +my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => + "Spell points / Grace points. Amount of spell or grace points used by each invocation."); +my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => + "Damage. The amount of damage the spell deals when it hits."); - $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face - face => $spell->{face}, - can_hover => 1, - can_events => 1, - tooltip => $spell->{message}); +sub rebuild_spell_list { + my ($self) = @_; - $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label - text => $spell->{name}, - can_hover => 1, - can_events => 1, - tooltip => $spell->{message}, - expand => 1); + $CFClient::UI::ROOT->on_refresh ($self => sub { + $self->clear; + + $self->add (1, 0, new CFClient::UI::Label text => "Spell Name"); + $self->add (2, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); + $self->add (3, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); + $self->add (4, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); + + my $row = 0; + + for (sort { $a cmp $b } keys %{ $self->{spell} }) { + my $spell = $self->{spell}{$_}; + + $row++; + + $self->add (0, $row, new CFClient::UI::Face + face => $spell->{face}, + can_hover => 1, + can_events => 1, + tooltip => $spell->{message}, + ); + + $self->add (1, $row, new CFClient::UI::Label + expand => 1, + text => $spell->{name}, + can_hover => 1, + can_events => 1, + tooltip => $spell->{message}, + ); - $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label - text => (sprintf "lvl: %2d sp: %2d dmg: %2d", - $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), - expand => 1); - - $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button - text => "bind to key", - on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); + $self->add (2, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); + $self->add (3, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); + $self->add (4, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); + + # TODO: should be done via popup + $self->add (5, $row, new CFClient::UI::Button + text => "bind", + tooltip => "bind spell readying (cast command) to key", + on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }, + ); + } + }); } -sub rebuild_spell_list { - my ($self) = @_; - $self->{tbl_idx} = 0; - $self->add_spell ($_) for values %{$self->{spells}}; +sub add_spell { + my ($self, $spell) = @_; + + $self->{spell}->{$spell->{name}} = $spell; + $self->rebuild_spell_list; } sub remove_spell { my ($self, $spell) = @_; - delete $self->{spells}->{$spell->{name}}; + + delete $self->{spell}->{$spell->{name}}; $self->rebuild_spell_list; }