… | |
… | |
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 | |
1565 | sub set_markup { |
1565 | sub 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 | |
1581 | sub size_request { |
1581 | sub 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 | |
1609 | sub size_allocate { |
1609 | sub 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 | |
|
|
1627 | sub reconfigure { |
|
|
1628 | my ($self) = @_; |
|
|
1629 | |
|
|
1630 | delete $self->{size_req}; |
|
|
1631 | |
|
|
1632 | $self->SUPER::reconfigure; |
1625 | } |
1633 | } |
1626 | |
1634 | |
1627 | sub _draw { |
1635 | sub _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; |
1654 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1655 | |
1662 | |
1656 | if ($tex->{format} == GL_ALPHA) { |
1663 | if ($tex->{format} == GL_ALPHA) { |
|
|
1664 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1657 | glColor @{$self->{fg}}; |
1665 | glColor @{$self->{fg}}; |
1658 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
1666 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
1659 | } else { |
1667 | } else { |
|
|
1668 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1660 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1669 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1661 | } |
1670 | } |
1662 | |
1671 | |
1663 | glDisable GL_TEXTURE_2D; |
1672 | glDisable GL_TEXTURE_2D; |
1664 | } |
1673 | } |
… | |
… | |
1682 | can_hover => 1, |
1691 | can_hover => 1, |
1683 | can_focus => 1, |
1692 | can_focus => 1, |
1684 | valign => 0, |
1693 | valign => 0, |
1685 | can_events => 1, |
1694 | can_events => 1, |
1686 | #text => ... |
1695 | #text => ... |
|
|
1696 | #hidden => "*", |
1687 | @_ |
1697 | @_ |
1688 | ) |
1698 | ) |
1689 | } |
1699 | } |
1690 | |
1700 | |
1691 | sub _set_text { |
1701 | sub _set_text { |
… | |
… | |
1698 | $self->{last_activity} = $::NOW; |
1708 | $self->{last_activity} = $::NOW; |
1699 | $self->{text} = $text; |
1709 | $self->{text} = $text; |
1700 | |
1710 | |
1701 | $text =~ s/./*/g if $self->{hidden}; |
1711 | $text =~ s/./*/g if $self->{hidden}; |
1702 | $self->{layout}->set_text ("$text "); |
1712 | $self->{layout}->set_text ("$text "); |
1703 | delete $self->{req_h}; |
1713 | delete $self->{size_req}; |
1704 | |
1714 | |
1705 | $self->_emit (changed => $self->{text}); |
1715 | $self->_emit (changed => $self->{text}); |
1706 | |
1716 | |
1707 | $self->realloc; |
1717 | $self->realloc; |
1708 | $self->update; |
1718 | $self->update; |
… | |
… | |
2911 | ); |
2921 | ); |
2912 | |
2922 | |
2913 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
2923 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
2914 | |
2924 | |
2915 | for my $item (@{ $self->{items} }) { |
2925 | for my $item (@{ $self->{items} }) { |
2916 | my ($widget, $cb) = @$item; |
2926 | my ($widget, $cb, $tooltip) = @$item; |
2917 | |
2927 | |
2918 | # handle various types of items, only text for now |
2928 | # handle various types of items, only text for now |
2919 | if (!ref $widget) { |
2929 | if (!ref $widget) { |
2920 | $widget = new CFClient::UI::Label |
2930 | $widget = new CFClient::UI::Label |
2921 | can_hover => 1, |
2931 | can_hover => 1, |
2922 | can_events => 1, |
2932 | can_events => 1, |
2923 | text => $widget; |
2933 | text => $widget, |
|
|
2934 | tooltip => $tooltip |
2924 | } |
2935 | } |
2925 | |
2936 | |
2926 | $self->{item}{$widget} = $item; |
2937 | $self->{item}{$widget} = $item; |
2927 | |
2938 | |
2928 | $self->{vbox}->add ($widget); |
2939 | $self->{vbox}->add ($widget); |
… | |
… | |
3075 | sub set_current_page { |
3086 | sub set_current_page { |
3076 | my ($self, $page) = @_; |
3087 | my ($self, $page) = @_; |
3077 | |
3088 | |
3078 | $self->{multiplexer}->set_current_page ($page); |
3089 | $self->{multiplexer}->set_current_page ($page); |
3079 | $self->_emit (page_changed => $self->{multiplexer}{current}); |
3090 | $self->_emit (page_changed => $self->{multiplexer}{current}); |
|
|
3091 | } |
|
|
3092 | |
|
|
3093 | ############################################################################# |
|
|
3094 | |
|
|
3095 | package CFClient::UI::Combobox; |
|
|
3096 | |
|
|
3097 | use utf8; |
|
|
3098 | |
|
|
3099 | our @ISA = CFClient::UI::Button::; |
|
|
3100 | |
|
|
3101 | sub new { |
|
|
3102 | my $class = shift; |
|
|
3103 | |
|
|
3104 | my $self = $class->SUPER::new ( |
|
|
3105 | options => [], # [title, value, tooltip], ... |
|
|
3106 | value => undef, |
|
|
3107 | @_, |
|
|
3108 | ); |
|
|
3109 | |
|
|
3110 | $self->_set_value ($self->{value}); |
|
|
3111 | |
|
|
3112 | $self |
|
|
3113 | } |
|
|
3114 | |
|
|
3115 | sub button_down { |
|
|
3116 | my ($self, $ev) = @_; |
|
|
3117 | |
|
|
3118 | my @menu_items; |
|
|
3119 | |
|
|
3120 | for (@{ $self->{options} }) { |
|
|
3121 | my ($title, $value, $tooltip) = @$_; |
|
|
3122 | |
|
|
3123 | push @menu_items, [$tooltip, sub { $self->set_value ($value) }]; |
|
|
3124 | } |
|
|
3125 | |
|
|
3126 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
|
|
3127 | } |
|
|
3128 | |
|
|
3129 | sub _set_value { |
|
|
3130 | my ($self, $value) = @_; |
|
|
3131 | |
|
|
3132 | my ($item) = grep $_->[1] eq $value, @{ $self->{options} } |
|
|
3133 | or return; |
|
|
3134 | |
|
|
3135 | $self->{value} = $item->[1]; |
|
|
3136 | $self->set_markup ("$item->[0] ⇓"); |
|
|
3137 | $self->set_tooltip ($item->[2]); |
|
|
3138 | } |
|
|
3139 | |
|
|
3140 | sub set_value { |
|
|
3141 | my ($self, $value) = @_; |
|
|
3142 | |
|
|
3143 | return unless $self->{value} ne $value; |
|
|
3144 | |
|
|
3145 | $self->_set_value ($value); |
|
|
3146 | $self->_emit (changed => $value); |
3080 | } |
3147 | } |
3081 | |
3148 | |
3082 | ############################################################################# |
3149 | ############################################################################# |
3083 | |
3150 | |
3084 | package CFClient::UI::Statusbox; |
3151 | package CFClient::UI::Statusbox; |
… | |
… | |
3475 | commands => [], |
3542 | commands => [], |
3476 | @_, |
3543 | @_, |
3477 | ) |
3544 | ) |
3478 | } |
3545 | } |
3479 | |
3546 | |
3480 | # XXX: Do sorting? Argl... |
3547 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3548 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell."); |
|
|
3549 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3550 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation."); |
|
|
3551 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3552 | "<b>Damage</b>. The amount of damage the spell deals when it hits."); |
|
|
3553 | |
|
|
3554 | sub rebuild_spell_list { |
|
|
3555 | my ($self) = @_; |
|
|
3556 | |
|
|
3557 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
|
|
3558 | $self->clear; |
|
|
3559 | |
|
|
3560 | $self->add (1, 0, new CFClient::UI::Label text => "Spell Name"); |
|
|
3561 | $self->add (2, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
|
|
3562 | $self->add (3, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
|
|
3563 | $self->add (4, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
|
|
3564 | |
|
|
3565 | my $row = 0; |
|
|
3566 | |
|
|
3567 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
|
|
3568 | my $spell = $self->{spell}{$_}; |
|
|
3569 | |
|
|
3570 | $row++; |
|
|
3571 | |
|
|
3572 | $self->add (0, $row, new CFClient::UI::Face |
|
|
3573 | face => $spell->{face}, |
|
|
3574 | can_hover => 1, |
|
|
3575 | can_events => 1, |
|
|
3576 | tooltip => $spell->{message}, |
|
|
3577 | ); |
|
|
3578 | |
|
|
3579 | $self->add (1, $row, new CFClient::UI::Label |
|
|
3580 | expand => 1, |
|
|
3581 | text => $spell->{name}, |
|
|
3582 | can_hover => 1, |
|
|
3583 | can_events => 1, |
|
|
3584 | tooltip => $spell->{message}, |
|
|
3585 | ); |
|
|
3586 | |
|
|
3587 | $self->add (2, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
|
|
3588 | $self->add (3, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
|
|
3589 | $self->add (4, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
|
|
3590 | |
|
|
3591 | # TODO: should be done via popup |
|
|
3592 | $self->add (5, $row, new CFClient::UI::Button |
|
|
3593 | text => "bind", |
|
|
3594 | tooltip => "bind spell readying (cast command) to key", |
|
|
3595 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }, |
|
|
3596 | ); |
|
|
3597 | } |
|
|
3598 | }); |
|
|
3599 | } |
|
|
3600 | |
3481 | sub add_spell { |
3601 | sub add_spell { |
3482 | my ($self, $spell) = @_; |
3602 | my ($self, $spell) = @_; |
|
|
3603 | |
3483 | $self->{spells}->{$spell->{name}} = $spell; |
3604 | $self->{spell}->{$spell->{name}} = $spell; |
3484 | |
3605 | $self->rebuild_spell_list; |
3485 | $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
|
|
3486 | face => $spell->{face}, |
|
|
3487 | can_hover => 1, |
|
|
3488 | can_events => 1, |
|
|
3489 | tooltip => $spell->{message}); |
|
|
3490 | |
|
|
3491 | $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
|
|
3492 | text => $spell->{name}, |
|
|
3493 | can_hover => 1, |
|
|
3494 | can_events => 1, |
|
|
3495 | tooltip => $spell->{message}, |
|
|
3496 | expand => 1); |
|
|
3497 | |
|
|
3498 | $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
|
|
3499 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
|
|
3500 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
|
|
3501 | expand => 1); |
|
|
3502 | |
|
|
3503 | $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
|
|
3504 | text => "bind to key", |
|
|
3505 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
|
|
3506 | } |
|
|
3507 | |
|
|
3508 | sub rebuild_spell_list { |
|
|
3509 | my ($self) = @_; |
|
|
3510 | $self->{tbl_idx} = 0; |
|
|
3511 | $self->add_spell ($_) for values %{$self->{spells}}; |
|
|
3512 | } |
3606 | } |
3513 | |
3607 | |
3514 | sub remove_spell { |
3608 | sub remove_spell { |
3515 | my ($self, $spell) = @_; |
3609 | my ($self, $spell) = @_; |
|
|
3610 | |
3516 | delete $self->{spells}->{$spell->{name}}; |
3611 | delete $self->{spell}->{$spell->{name}}; |
3517 | $self->rebuild_spell_list; |
3612 | $self->rebuild_spell_list; |
3518 | } |
3613 | } |
3519 | |
3614 | |
3520 | ############################################################################# |
3615 | ############################################################################# |
3521 | |
3616 | |