… | |
… | |
315 | } |
315 | } |
316 | |
316 | |
317 | sub move_abs { |
317 | sub move_abs { |
318 | my ($self, $x, $y, $z) = @_; |
318 | my ($self, $x, $y, $z) = @_; |
319 | |
319 | |
320 | $self->{x} = List::Util::max 0, int $x; |
320 | $self->{x} = List::Util::max 0, List::Util::min $self->{root}{w} - $self->{w}, int $x; |
321 | $self->{y} = List::Util::max 0, int $y; |
321 | $self->{y} = List::Util::max 0, List::Util::min $self->{root}{h} - $self->{h}, int $y; |
322 | $self->{z} = $z if defined $z; |
322 | $self->{z} = $z if defined $z; |
323 | |
323 | |
324 | $self->update; |
324 | $self->update; |
325 | } |
325 | } |
326 | |
326 | |
… | |
… | |
1658 | : ($self->{h} - $tex->{h}) * 0.5); |
1658 | : ($self->{h} - $tex->{h}) * 0.5); |
1659 | }; |
1659 | }; |
1660 | |
1660 | |
1661 | glEnable GL_TEXTURE_2D; |
1661 | glEnable GL_TEXTURE_2D; |
1662 | |
1662 | |
|
|
1663 | my $w = List::Util::min $self->{w} + 4, $tex->{w}; |
|
|
1664 | my $h = List::Util::min $self->{h} + 2, $tex->{h}; |
|
|
1665 | |
1663 | if ($tex->{format} == GL_ALPHA) { |
1666 | if ($tex->{format} == GL_ALPHA) { |
1664 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1667 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1665 | glColor @{$self->{fg}}; |
1668 | glColor @{$self->{fg}}; |
1666 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
1669 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}, $w, $h); |
1667 | } else { |
1670 | } else { |
1668 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1671 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1669 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1672 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}, $w, $h); |
1670 | } |
1673 | } |
1671 | |
1674 | |
1672 | glDisable GL_TEXTURE_2D; |
1675 | glDisable GL_TEXTURE_2D; |
1673 | } |
1676 | } |
1674 | |
1677 | |
… | |
… | |
2304 | sub set_range { |
2307 | sub set_range { |
2305 | my ($self, $range) = @_; |
2308 | my ($self, $range) = @_; |
2306 | |
2309 | |
2307 | ($range, $self->{range}) = ($self->{range}, $range); |
2310 | ($range, $self->{range}) = ($self->{range}, $range); |
2308 | |
2311 | |
2309 | $self->update |
|
|
2310 | if "@$range" ne "@{$self->{range}}"; |
2312 | if ("@$range" ne "@{$self->{range}}") { |
|
|
2313 | $self->update; |
|
|
2314 | $self->set_value ($self->{range}[0]); |
|
|
2315 | } |
2311 | } |
2316 | } |
2312 | |
2317 | |
2313 | sub set_value { |
2318 | sub set_value { |
2314 | my ($self, $value) = @_; |
2319 | my ($self, $value) = @_; |
2315 | |
2320 | |
… | |
… | |
2462 | sub set_range { shift->{slider}->set_range (@_) } |
2467 | sub set_range { shift->{slider}->set_range (@_) } |
2463 | sub set_value { shift->{slider}->set_value (@_) } |
2468 | sub set_value { shift->{slider}->set_value (@_) } |
2464 | |
2469 | |
2465 | ############################################################################# |
2470 | ############################################################################# |
2466 | |
2471 | |
2467 | package CFClient::UI::TextView; |
2472 | package CFClient::UI::TextScroller; |
2468 | |
2473 | |
2469 | our @ISA = CFClient::UI::HBox::; |
2474 | our @ISA = CFClient::UI::HBox::; |
2470 | |
2475 | |
2471 | use CFClient::OpenGL; |
2476 | use CFClient::OpenGL; |
2472 | |
2477 | |
… | |
… | |
2568 | |
2573 | |
2569 | return unless $self->{h} > 0; |
2574 | return unless $self->{h} > 0; |
2570 | |
2575 | |
2571 | delete $self->{texture}; |
2576 | delete $self->{texture}; |
2572 | |
2577 | |
2573 | $ROOT->on_post_alloc ($self, sub { |
2578 | $ROOT->on_post_alloc ($self => sub { |
2574 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2579 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2575 | |
2580 | |
2576 | if (delete $self->{need_reflow}) { |
2581 | if (delete $self->{need_reflow}) { |
2577 | my $height = 0; |
2582 | my $height = 0; |
2578 | |
2583 | |
… | |
… | |
2594 | } |
2599 | } |
2595 | |
2600 | |
2596 | $self->{height} = $height; |
2601 | $self->{height} = $height; |
2597 | |
2602 | |
2598 | $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); |
2603 | $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); |
2599 | |
2604 | |
2600 | delete $self->{texture}; |
2605 | delete $self->{texture}; |
2601 | } |
2606 | } |
2602 | |
2607 | |
2603 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2608 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2604 | glClearColor 0, 0, 0, 0; |
2609 | glClearColor 0, 0, 0, 0; |
… | |
… | |
2747 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2752 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2748 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2753 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2749 | . "req $widget->{req_w} $widget->{req_h}\n" |
2754 | . "req $widget->{req_w} $widget->{req_h}\n" |
2750 | . "visible $widget->{visible}"; |
2755 | . "visible $widget->{visible}"; |
2751 | } |
2756 | } |
|
|
2757 | |
|
|
2758 | $tooltip =~ s/^\n+//; |
|
|
2759 | $tooltip =~ s/\n+$//; |
2752 | |
2760 | |
2753 | $self->add (new CFClient::UI::Label |
2761 | $self->add (new CFClient::UI::Label |
2754 | markup => $tooltip, |
2762 | markup => $tooltip, |
2755 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2763 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2756 | fontsize => 0.8, |
2764 | fontsize => 0.8, |
… | |
… | |
2784 | or return; |
2792 | or return; |
2785 | |
2793 | |
2786 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
2794 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
2787 | |
2795 | |
2788 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
2796 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
2789 | if $x + $self->{w} > $::WIDTH; |
2797 | if $x + $self->{w} > $self->{root}{w}; |
2790 | |
2798 | |
2791 | $self->move_abs ($x, $y); |
2799 | $self->move_abs ($x, $y); |
2792 | }); |
2800 | }); |
2793 | } |
2801 | } |
2794 | |
2802 | |
… | |
… | |
2933 | # handle various types of items, only text for now |
2941 | # handle various types of items, only text for now |
2934 | if (!ref $widget) { |
2942 | if (!ref $widget) { |
2935 | $widget = new CFClient::UI::Label |
2943 | $widget = new CFClient::UI::Label |
2936 | can_hover => 1, |
2944 | can_hover => 1, |
2937 | can_events => 1, |
2945 | can_events => 1, |
2938 | text => $widget, |
2946 | markup => $widget, |
2939 | tooltip => $tooltip |
2947 | tooltip => $tooltip |
2940 | } |
2948 | } |
2941 | |
2949 | |
2942 | $self->{item}{$widget} = $item; |
2950 | $self->{item}{$widget} = $item; |
2943 | |
2951 | |
… | |
… | |
3105 | |
3113 | |
3106 | sub new { |
3114 | sub new { |
3107 | my $class = shift; |
3115 | my $class = shift; |
3108 | |
3116 | |
3109 | my $self = $class->SUPER::new ( |
3117 | my $self = $class->SUPER::new ( |
3110 | options => [], # [title, value, tooltip], ... |
3118 | options => [], # [value, title, longdesc], ... |
3111 | value => undef, |
3119 | value => undef, |
3112 | @_, |
3120 | @_, |
3113 | ); |
3121 | ); |
3114 | |
3122 | |
3115 | $self->_set_value ($self->{value}); |
3123 | $self->_set_value ($self->{value}); |
… | |
… | |
3121 | my ($self, $ev) = @_; |
3129 | my ($self, $ev) = @_; |
3122 | |
3130 | |
3123 | my @menu_items; |
3131 | my @menu_items; |
3124 | |
3132 | |
3125 | for (@{ $self->{options} }) { |
3133 | for (@{ $self->{options} }) { |
3126 | my ($title, $value, $tooltip) = @$_; |
3134 | my ($value, $title, $tooltip) = @$_; |
3127 | |
3135 | |
3128 | push @menu_items, [$tooltip, sub { $self->set_value ($value) }]; |
3136 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
3129 | } |
3137 | } |
3130 | |
3138 | |
3131 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3139 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3132 | } |
3140 | } |
3133 | |
3141 | |
3134 | sub _set_value { |
3142 | sub _set_value { |
3135 | my ($self, $value) = @_; |
3143 | my ($self, $value) = @_; |
3136 | |
3144 | |
3137 | my ($item) = grep $_->[1] eq $value, @{ $self->{options} } |
3145 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} } |
3138 | or return; |
3146 | or return; |
3139 | |
3147 | |
3140 | $self->{value} = $item->[1]; |
3148 | $self->{value} = $item->[0]; |
3141 | $self->set_markup ("$item->[0] ⇓"); |
3149 | $self->set_markup ("$item->[1] ⇓"); |
3142 | $self->set_tooltip ($item->[2]); |
3150 | $self->set_tooltip ($item->[2]); |
3143 | } |
3151 | } |
3144 | |
3152 | |
3145 | sub set_value { |
3153 | sub set_value { |
3146 | my ($self, $value) = @_; |
3154 | my ($self, $value) = @_; |
… | |
… | |
3255 | $item->{count}++; |
3263 | $item->{count}++; |
3256 | } else { |
3264 | } else { |
3257 | $item->{count} = 1; |
3265 | $item->{count} = 1; |
3258 | $item->{text} = $item->{tooltip} = $text; |
3266 | $item->{text} = $item->{tooltip} = $text; |
3259 | } |
3267 | } |
3260 | $item->{id} = ++$self->{id}; |
3268 | $item->{id} += 0.2;#d# |
3261 | $item->{timeout} = $timeout; |
3269 | $item->{timeout} = $timeout; |
3262 | delete $item->{label}; |
3270 | delete $item->{label}; |
3263 | } else { |
3271 | } else { |
3264 | $self->{item}{$group} = { |
3272 | $self->{item}{$group} = { |
3265 | id => ++$self->{id}, |
3273 | id => ++$self->{id}, |
… | |
… | |
3547 | commands => [], |
3555 | commands => [], |
3548 | @_, |
3556 | @_, |
3549 | ) |
3557 | ) |
3550 | } |
3558 | } |
3551 | |
3559 | |
|
|
3560 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>"; |
|
|
3561 | |
|
|
3562 | my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3563 | "<b>Name</b>. The name of the spell.$TOOLTIP_ALL"); |
|
|
3564 | my @TOOLTIP_SKILL = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3565 | "<b>Skill</b>. The skill (or magic school) required to be able to attempt casting this spell.$TOOLTIP_ALL"); |
3552 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3566 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3553 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell."); |
3567 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL"); |
3554 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3568 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3555 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation."); |
3569 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL"); |
3556 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3570 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3557 | "<b>Damage</b>. The amount of damage the spell deals when it hits."); |
3571 | "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL"); |
3558 | |
3572 | |
3559 | sub rebuild_spell_list { |
3573 | sub rebuild_spell_list { |
3560 | my ($self) = @_; |
3574 | my ($self) = @_; |
3561 | |
3575 | |
3562 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
3576 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
3563 | $self->clear; |
3577 | $self->clear; |
3564 | |
3578 | |
3565 | $self->add (1, 0, new CFClient::UI::Label text => "Spell Name"); |
3579 | $self->add (1, 0, new CFClient::UI::Label text => "Spell Name", @TOOLTIP_NAME); |
|
|
3580 | $self->add (2, 0, new CFClient::UI::Label text => "Skill", @TOOLTIP_SKILL); |
3566 | $self->add (2, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
3581 | $self->add (3, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
3567 | $self->add (3, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
3582 | $self->add (4, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
3568 | $self->add (4, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
3583 | $self->add (5, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
3569 | |
3584 | |
3570 | my $row = 0; |
3585 | my $row = 0; |
3571 | |
3586 | |
3572 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
3587 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
3573 | my $spell = $self->{spell}{$_}; |
3588 | my $spell = $self->{spell}{$_}; |
3574 | |
3589 | |
3575 | $row++; |
3590 | $row++; |
|
|
3591 | |
|
|
3592 | my $spell_cb = sub { |
|
|
3593 | my ($widget, $ev) = @_; |
|
|
3594 | |
|
|
3595 | if ($ev->{button} == 1) { |
|
|
3596 | $::CONN->user_send ("cast $spell->{name}"); |
|
|
3597 | } elsif ($ev->{button} == 2) { |
|
|
3598 | $::CONN->user_send ("invoke $spell->{name}"); |
|
|
3599 | } elsif ($ev->{button} == 3) { |
|
|
3600 | (new CFClient::UI::Menu |
|
|
3601 | items => [ |
|
|
3602 | ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], |
|
|
3603 | ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], |
|
|
3604 | ], |
|
|
3605 | )->popup ($ev); |
|
|
3606 | } else { |
|
|
3607 | return 0; |
|
|
3608 | } |
|
|
3609 | |
|
|
3610 | 1 |
|
|
3611 | }; |
|
|
3612 | |
|
|
3613 | my $tooltip = "$spell->{message}$TOOLTIP_ALL"; |
|
|
3614 | |
|
|
3615 | #TODO: add path info to tooltip |
|
|
3616 | #$self->add (6, $row, new CFClient::UI::Label text => $spell->{path}); |
3576 | |
3617 | |
3577 | $self->add (0, $row, new CFClient::UI::Face |
3618 | $self->add (0, $row, new CFClient::UI::Face |
3578 | face => $spell->{face}, |
3619 | face => $spell->{face}, |
3579 | can_hover => 1, |
3620 | can_hover => 1, |
3580 | can_events => 1, |
3621 | can_events => 1, |
3581 | tooltip => $spell->{message}, |
3622 | tooltip => $tooltip, |
|
|
3623 | on_button_down => $spell_cb, |
3582 | ); |
3624 | ); |
3583 | |
3625 | |
3584 | $self->add (1, $row, new CFClient::UI::Label |
3626 | $self->add (1, $row, new CFClient::UI::Label |
3585 | expand => 1, |
3627 | expand => 1, |
3586 | text => $spell->{name}, |
3628 | text => $spell->{name}, |
3587 | can_hover => 1, |
3629 | can_hover => 1, |
3588 | can_events => 1, |
3630 | can_events => 1, |
3589 | tooltip => $spell->{message}, |
3631 | tooltip => $tooltip, |
|
|
3632 | on_button_down => $spell_cb, |
3590 | ); |
3633 | ); |
3591 | |
3634 | |
|
|
3635 | $self->add (2, $row, new CFClient::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL); |
3592 | $self->add (2, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
3636 | $self->add (3, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
3593 | $self->add (3, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
3637 | $self->add (4, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
3594 | $self->add (4, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
3638 | $self->add (5, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
3595 | |
|
|
3596 | # TODO: should be done via popup |
|
|
3597 | $self->add (5, $row, new CFClient::UI::Button |
|
|
3598 | text => "bind", |
|
|
3599 | tooltip => "bind spell readying (cast command) to key", |
|
|
3600 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }, |
|
|
3601 | ); |
|
|
3602 | } |
3639 | } |
3603 | }); |
3640 | }); |
3604 | } |
3641 | } |
3605 | |
3642 | |
3606 | sub add_spell { |
3643 | sub add_spell { |
… | |
… | |
3612 | |
3649 | |
3613 | sub remove_spell { |
3650 | sub remove_spell { |
3614 | my ($self, $spell) = @_; |
3651 | my ($self, $spell) = @_; |
3615 | |
3652 | |
3616 | delete $self->{spell}->{$spell->{name}}; |
3653 | delete $self->{spell}->{$spell->{name}}; |
|
|
3654 | $self->rebuild_spell_list; |
|
|
3655 | } |
|
|
3656 | |
|
|
3657 | sub clear_spells { |
|
|
3658 | my ($self) = @_; |
|
|
3659 | |
|
|
3660 | $self->{spell} = {}; |
3617 | $self->rebuild_spell_list; |
3661 | $self->rebuild_spell_list; |
3618 | } |
3662 | } |
3619 | |
3663 | |
3620 | ############################################################################# |
3664 | ############################################################################# |
3621 | |
3665 | |