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.284 by root, Mon Jun 5 03:06:04 2006 UTC vs.
Revision 1.290 by root, Mon Jun 5 22:30:35 2006 UTC

18our $BUTTON_STATE; 18our $BUTTON_STATE;
19 19
20our %WIDGET; # all widgets, weak-referenced 20our %WIDGET; # all widgets, weak-referenced
21 21
22our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { 22our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub {
23 return if $ENV{CFPLUS_DEBUG} & 8;
24
25 if (!$GRAB) { 23 if (!$GRAB) {
26 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 24 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
27 if (length $widget->{tooltip}) { 25 if (length $widget->{tooltip}) {
28 if ($TOOLTIP->{owner} != $widget) { 26 if ($TOOLTIP->{owner} != $widget) {
29 $TOOLTIP->hide; 27 $TOOLTIP->hide;
30 28
31 $TOOLTIP->{owner} = $widget; 29 $TOOLTIP->{owner} = $widget;
30
31 return if $ENV{CFPLUS_DEBUG} & 8;
32 32
33 my $tip = $widget->{tooltip}; 33 my $tip = $widget->{tooltip};
34 34
35 $tip = $tip->($widget) if CODE:: eq ref $tip; 35 $tip = $tip->($widget) if CODE:: eq ref $tip;
36 36
1554 return if $self->{text} eq "T$text"; 1554 return if $self->{text} eq "T$text";
1555 $self->{text} = "T$text"; 1555 $self->{text} = "T$text";
1556 1556
1557 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; 1557 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba;
1558 $self->{layout}->set_text ($text); 1558 $self->{layout}->set_text ($text);
1559
1559 delete $self->{req_h}; 1560 delete $self->{size_req};
1560
1561 $self->realloc; 1561 $self->realloc;
1562 $self->update; 1562 $self->update;
1563} 1563}
1564 1564
1565sub set_markup { 1565sub set_markup {
1570 1570
1571 my $rgba = $markup =~ /span.*(?:foreground|background)/; 1571 my $rgba = $markup =~ /span.*(?:foreground|background)/;
1572 1572
1573 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; 1573 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba;
1574 $self->{layout}->set_markup ($markup); 1574 $self->{layout}->set_markup ($markup);
1575
1575 delete $self->{req_h}; 1576 delete $self->{size_req};
1576
1577 $self->realloc; 1577 $self->realloc;
1578 $self->update; 1578 $self->update;
1579} 1579}
1580 1580
1581sub size_request { 1581sub size_request {
1582 my ($self) = @_; 1582 my ($self) = @_;
1583 1583
1584 if (exists $self->{req_h}) { 1584 $self->{size_req} ||= do {
1585 @$self{qw(req_w req_h)}
1586 } else {
1587 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1585 $self->{layout}->set_font ($self->{font}) if $self->{font};
1588 $self->{layout}->set_width ($self->{max_w} || -1); 1586 $self->{layout}->set_width ($self->{max_w} || -1);
1589 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1587 $self->{layout}->set_ellipsise ($self->{ellipsise});
1590 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1588 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1591 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1589 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1600 1598
1601 $w = List::Util::max $w, $w2; 1599 $w = List::Util::max $w, $w2;
1602 $h = List::Util::max $h, $h2; 1600 $h = List::Util::max $h, $h2;
1603 } 1601 }
1604 1602
1605 ($w, $h) 1603 [$w, $h]
1606 } 1604 };
1605
1606 @{ $self->{size_req} }
1607} 1607}
1608 1608
1609sub size_allocate { 1609sub size_allocate {
1610 my ($self, $w, $h) = @_; 1610 my ($self, $w, $h) = @_;
1611 1611
1620 1620
1621 $self->{fontsize} = $fontsize; 1621 $self->{fontsize} = $fontsize;
1622 delete $self->{texture}; 1622 delete $self->{texture};
1623 1623
1624 $self->realloc; 1624 $self->realloc;
1625}
1626
1627sub reconfigure {
1628 my ($self) = @_;
1629
1630 delete $self->{size_req};
1631
1632 $self->SUPER::reconfigure;
1625} 1633}
1626 1634
1627sub _draw { 1635sub _draw {
1628 my ($self) = @_; 1636 my ($self) = @_;
1629 1637
1649 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} 1657 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y}
1650 : ($self->{h} - $tex->{h}) * 0.5); 1658 : ($self->{h} - $tex->{h}) * 0.5);
1651 }; 1659 };
1652 1660
1653 glEnable GL_TEXTURE_2D; 1661 glEnable GL_TEXTURE_2D;
1662
1663 if ($tex->{format} == GL_ALPHA) {
1664 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1665 glColor @{$self->{fg}};
1666 $tex->draw_quad_alpha ($self->{ox}, $self->{oy});
1667 } else {
1654 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1668 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1655
1656 glColor_premultiply @{$self->{fg}}
1657 if $tex->{format} == GL_ALPHA;
1658
1659 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); 1669 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy});
1670 }
1660 1671
1661 glDisable GL_TEXTURE_2D; 1672 glDisable GL_TEXTURE_2D;
1662} 1673}
1663 1674
1664############################################################################# 1675#############################################################################
1696 $self->{last_activity} = $::NOW; 1707 $self->{last_activity} = $::NOW;
1697 $self->{text} = $text; 1708 $self->{text} = $text;
1698 1709
1699 $text =~ s/./*/g if $self->{hidden}; 1710 $text =~ s/./*/g if $self->{hidden};
1700 $self->{layout}->set_text ("$text "); 1711 $self->{layout}->set_text ("$text ");
1701 delete $self->{req_h}; 1712 delete $self->{size_req};
1702 1713
1703 $self->_emit (changed => $self->{text}); 1714 $self->_emit (changed => $self->{text});
1704 1715
1705 $self->realloc; 1716 $self->realloc;
1706 $self->update; 1717 $self->update;
3473 commands => [], 3484 commands => [],
3474 @_, 3485 @_,
3475 ) 3486 )
3476} 3487}
3477 3488
3478# XXX: Do sorting? Argl... 3489my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3490 "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.");
3491my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3492 "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.");
3493my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3494 "<b>Damage</b>. The amount of damage the spell deals when it hits.");
3495
3496sub rebuild_spell_list {
3497 my ($self) = @_;
3498
3499 $CFClient::UI::ROOT->on_refresh ($self => sub {
3500 $self->clear;
3501
3502 $self->add (1, 0, new CFClient::UI::Label text => "Spell Name");
3503 $self->add (2, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL);
3504 $self->add (3, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP);
3505 $self->add (4, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG);
3506
3507 my $row = 0;
3508
3509 for (sort { $a cmp $b } keys %{ $self->{spell} }) {
3510 my $spell = $self->{spell}{$_};
3511
3512 $row++;
3513
3514 $self->add (0, $row, new CFClient::UI::Face
3515 face => $spell->{face},
3516 can_hover => 1,
3517 can_events => 1,
3518 tooltip => $spell->{message},
3519 );
3520
3521 $self->add (1, $row, new CFClient::UI::Label
3522 expand => 1,
3523 text => $spell->{name},
3524 can_hover => 1,
3525 can_events => 1,
3526 tooltip => $spell->{message},
3527 );
3528
3529 $self->add (2, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL);
3530 $self->add (3, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP);
3531 $self->add (4, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG);
3532
3533 # TODO: should be done via popup
3534 $self->add (5, $row, new CFClient::UI::Button
3535 text => "bind",
3536 tooltip => "bind spell readying (cast command) to key",
3537 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) },
3538 );
3539 }
3540 });
3541}
3542
3479sub add_spell { 3543sub add_spell {
3480 my ($self, $spell) = @_; 3544 my ($self, $spell) = @_;
3545
3481 $self->{spells}->{$spell->{name}} = $spell; 3546 $self->{spell}->{$spell->{name}} = $spell;
3482 3547 $self->rebuild_spell_list;
3483 $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face
3484 face => $spell->{face},
3485 can_hover => 1,
3486 can_events => 1,
3487 tooltip => $spell->{message});
3488
3489 $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label
3490 text => $spell->{name},
3491 can_hover => 1,
3492 can_events => 1,
3493 tooltip => $spell->{message},
3494 expand => 1);
3495
3496 $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label
3497 text => (sprintf "lvl: %2d sp: %2d dmg: %2d",
3498 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}),
3499 expand => 1);
3500
3501 $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button
3502 text => "bind to key",
3503 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) });
3504}
3505
3506sub rebuild_spell_list {
3507 my ($self) = @_;
3508 $self->{tbl_idx} = 0;
3509 $self->add_spell ($_) for values %{$self->{spells}};
3510} 3548}
3511 3549
3512sub remove_spell { 3550sub remove_spell {
3513 my ($self, $spell) = @_; 3551 my ($self, $spell) = @_;
3552
3514 delete $self->{spells}->{$spell->{name}}; 3553 delete $self->{spell}->{$spell->{name}};
3515 $self->rebuild_spell_list; 3554 $self->rebuild_spell_list;
3516} 3555}
3517 3556
3518############################################################################# 3557#############################################################################
3519 3558

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines