… | |
… | |
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 | |
… | |
… | |
2307 | sub set_range { |
2307 | sub set_range { |
2308 | my ($self, $range) = @_; |
2308 | my ($self, $range) = @_; |
2309 | |
2309 | |
2310 | ($range, $self->{range}) = ($self->{range}, $range); |
2310 | ($range, $self->{range}) = ($self->{range}, $range); |
2311 | |
2311 | |
2312 | $self->update |
|
|
2313 | if "@$range" ne "@{$self->{range}}"; |
2312 | if ("@$range" ne "@{$self->{range}}") { |
|
|
2313 | $self->update; |
|
|
2314 | $self->set_value ($self->{range}[0]); |
|
|
2315 | } |
2314 | } |
2316 | } |
2315 | |
2317 | |
2316 | sub set_value { |
2318 | sub set_value { |
2317 | my ($self, $value) = @_; |
2319 | my ($self, $value) = @_; |
2318 | |
2320 | |
… | |
… | |
2465 | sub set_range { shift->{slider}->set_range (@_) } |
2467 | sub set_range { shift->{slider}->set_range (@_) } |
2466 | sub set_value { shift->{slider}->set_value (@_) } |
2468 | sub set_value { shift->{slider}->set_value (@_) } |
2467 | |
2469 | |
2468 | ############################################################################# |
2470 | ############################################################################# |
2469 | |
2471 | |
2470 | package CFClient::UI::TextView; |
2472 | package CFClient::UI::TextScroller; |
2471 | |
2473 | |
2472 | our @ISA = CFClient::UI::HBox::; |
2474 | our @ISA = CFClient::UI::HBox::; |
2473 | |
2475 | |
2474 | use CFClient::OpenGL; |
2476 | use CFClient::OpenGL; |
2475 | |
2477 | |
… | |
… | |
2571 | |
2573 | |
2572 | return unless $self->{h} > 0; |
2574 | return unless $self->{h} > 0; |
2573 | |
2575 | |
2574 | delete $self->{texture}; |
2576 | delete $self->{texture}; |
2575 | |
2577 | |
2576 | $ROOT->on_post_alloc ($self, sub { |
2578 | $ROOT->on_post_alloc ($self => sub { |
2577 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2579 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2578 | |
2580 | |
2579 | if (delete $self->{need_reflow}) { |
2581 | if (delete $self->{need_reflow}) { |
2580 | my $height = 0; |
2582 | my $height = 0; |
2581 | |
2583 | |
… | |
… | |
2597 | } |
2599 | } |
2598 | |
2600 | |
2599 | $self->{height} = $height; |
2601 | $self->{height} = $height; |
2600 | |
2602 | |
2601 | $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); |
2603 | $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); |
2602 | |
2604 | |
2603 | delete $self->{texture}; |
2605 | delete $self->{texture}; |
2604 | } |
2606 | } |
2605 | |
2607 | |
2606 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2608 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2607 | glClearColor 0, 0, 0, 0; |
2609 | glClearColor 0, 0, 0, 0; |
… | |
… | |
2750 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2752 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2751 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2753 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2752 | . "req $widget->{req_w} $widget->{req_h}\n" |
2754 | . "req $widget->{req_w} $widget->{req_h}\n" |
2753 | . "visible $widget->{visible}"; |
2755 | . "visible $widget->{visible}"; |
2754 | } |
2756 | } |
|
|
2757 | |
|
|
2758 | $tooltip =~ s/^\n+//; |
|
|
2759 | $tooltip =~ s/\n+$//; |
2755 | |
2760 | |
2756 | $self->add (new CFClient::UI::Label |
2761 | $self->add (new CFClient::UI::Label |
2757 | markup => $tooltip, |
2762 | markup => $tooltip, |
2758 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2763 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2759 | fontsize => 0.8, |
2764 | fontsize => 0.8, |
… | |
… | |
2787 | or return; |
2792 | or return; |
2788 | |
2793 | |
2789 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
2794 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
2790 | |
2795 | |
2791 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
2796 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
2792 | if $x + $self->{w} > $::WIDTH; |
2797 | if $x + $self->{w} > $self->{root}{w}; |
2793 | |
2798 | |
2794 | $self->move_abs ($x, $y); |
2799 | $self->move_abs ($x, $y); |
2795 | }); |
2800 | }); |
2796 | } |
2801 | } |
2797 | |
2802 | |
… | |
… | |
2936 | # handle various types of items, only text for now |
2941 | # handle various types of items, only text for now |
2937 | if (!ref $widget) { |
2942 | if (!ref $widget) { |
2938 | $widget = new CFClient::UI::Label |
2943 | $widget = new CFClient::UI::Label |
2939 | can_hover => 1, |
2944 | can_hover => 1, |
2940 | can_events => 1, |
2945 | can_events => 1, |
2941 | text => $widget, |
2946 | markup => $widget, |
2942 | tooltip => $tooltip |
2947 | tooltip => $tooltip |
2943 | } |
2948 | } |
2944 | |
2949 | |
2945 | $self->{item}{$widget} = $item; |
2950 | $self->{item}{$widget} = $item; |
2946 | |
2951 | |
… | |
… | |
3108 | |
3113 | |
3109 | sub new { |
3114 | sub new { |
3110 | my $class = shift; |
3115 | my $class = shift; |
3111 | |
3116 | |
3112 | my $self = $class->SUPER::new ( |
3117 | my $self = $class->SUPER::new ( |
3113 | options => [], # [title, value, tooltip], ... |
3118 | options => [], # [value, title, longdesc], ... |
3114 | value => undef, |
3119 | value => undef, |
3115 | @_, |
3120 | @_, |
3116 | ); |
3121 | ); |
3117 | |
3122 | |
3118 | $self->_set_value ($self->{value}); |
3123 | $self->_set_value ($self->{value}); |
… | |
… | |
3124 | my ($self, $ev) = @_; |
3129 | my ($self, $ev) = @_; |
3125 | |
3130 | |
3126 | my @menu_items; |
3131 | my @menu_items; |
3127 | |
3132 | |
3128 | for (@{ $self->{options} }) { |
3133 | for (@{ $self->{options} }) { |
3129 | my ($title, $value, $tooltip) = @$_; |
3134 | my ($value, $title, $tooltip) = @$_; |
3130 | |
3135 | |
3131 | push @menu_items, [$tooltip, sub { $self->set_value ($value) }]; |
3136 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
3132 | } |
3137 | } |
3133 | |
3138 | |
3134 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3139 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3135 | } |
3140 | } |
3136 | |
3141 | |
3137 | sub _set_value { |
3142 | sub _set_value { |
3138 | my ($self, $value) = @_; |
3143 | my ($self, $value) = @_; |
3139 | |
3144 | |
3140 | my ($item) = grep $_->[1] eq $value, @{ $self->{options} } |
3145 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} } |
3141 | or return; |
3146 | or return; |
3142 | |
3147 | |
3143 | $self->{value} = $item->[1]; |
3148 | $self->{value} = $item->[0]; |
3144 | $self->set_markup ("$item->[0] ⇓"); |
3149 | $self->set_markup ("$item->[1] ⇓"); |
3145 | $self->set_tooltip ($item->[2]); |
3150 | $self->set_tooltip ($item->[2]); |
3146 | } |
3151 | } |
3147 | |
3152 | |
3148 | sub set_value { |
3153 | sub set_value { |
3149 | my ($self, $value) = @_; |
3154 | my ($self, $value) = @_; |
… | |
… | |
3550 | commands => [], |
3555 | commands => [], |
3551 | @_, |
3556 | @_, |
3552 | ) |
3557 | ) |
3553 | } |
3558 | } |
3554 | |
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 => 0, can_events => 1, can_hover => 1, tooltip => |
|
|
3563 | "<b>Name</b>. The name of the spell.$TOOLTIP_ALL"); |
3555 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3564 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3556 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell."); |
3565 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL"); |
3557 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3566 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3558 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation."); |
3567 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL"); |
3559 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3568 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3560 | "<b>Damage</b>. The amount of damage the spell deals when it hits."); |
3569 | "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL"); |
3561 | |
3570 | |
3562 | sub rebuild_spell_list { |
3571 | sub rebuild_spell_list { |
3563 | my ($self) = @_; |
3572 | my ($self) = @_; |
3564 | |
3573 | |
3565 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
3574 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
3566 | $self->clear; |
3575 | $self->clear; |
3567 | |
3576 | |
3568 | $self->add (1, 0, new CFClient::UI::Label text => "Spell Name"); |
3577 | $self->add (1, 0, new CFClient::UI::Label text => "Spell Name", @TOOLTIP_NAME); |
3569 | $self->add (2, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
3578 | $self->add (2, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
3570 | $self->add (3, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
3579 | $self->add (3, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
3571 | $self->add (4, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
3580 | $self->add (4, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
3572 | |
3581 | |
3573 | my $row = 0; |
3582 | my $row = 0; |
3574 | |
3583 | |
3575 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
3584 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
3576 | my $spell = $self->{spell}{$_}; |
3585 | my $spell = $self->{spell}{$_}; |
3577 | |
3586 | |
3578 | $row++; |
3587 | $row++; |
|
|
3588 | |
|
|
3589 | my $spell_cb = sub { |
|
|
3590 | my ($widget, $ev) = @_; |
|
|
3591 | |
|
|
3592 | if ($ev->{button} == 1) { |
|
|
3593 | $::CONN->user_send ("cast $spell->{name}"); |
|
|
3594 | } elsif ($ev->{button} == 2) { |
|
|
3595 | $::CONN->user_send ("invoke $spell->{name}"); |
|
|
3596 | } elsif ($ev->{button} == 3) { |
|
|
3597 | (new CFClient::UI::Menu |
|
|
3598 | items => [ |
|
|
3599 | ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], |
|
|
3600 | ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], |
|
|
3601 | ], |
|
|
3602 | )->popup ($ev); |
|
|
3603 | } else { |
|
|
3604 | return 0; |
|
|
3605 | } |
|
|
3606 | |
|
|
3607 | 1 |
|
|
3608 | }; |
3579 | |
3609 | |
3580 | $self->add (0, $row, new CFClient::UI::Face |
3610 | $self->add (0, $row, new CFClient::UI::Face |
3581 | face => $spell->{face}, |
3611 | face => $spell->{face}, |
3582 | can_hover => 1, |
3612 | can_hover => 1, |
3583 | can_events => 1, |
3613 | can_events => 1, |
3584 | tooltip => $spell->{message}, |
3614 | tooltip => $spell->{message}, |
|
|
3615 | on_button_down => $spell_cb, |
3585 | ); |
3616 | ); |
3586 | |
3617 | |
3587 | $self->add (1, $row, new CFClient::UI::Label |
3618 | $self->add (1, $row, new CFClient::UI::Label |
3588 | expand => 1, |
3619 | expand => 1, |
3589 | text => $spell->{name}, |
3620 | text => $spell->{name}, |
3590 | can_hover => 1, |
3621 | can_hover => 1, |
3591 | can_events => 1, |
3622 | can_events => 1, |
3592 | tooltip => $spell->{message}, |
3623 | tooltip => "$spell->{message}$TOOLTIP_ALL", |
|
|
3624 | on_button_down => $spell_cb, |
3593 | ); |
3625 | ); |
3594 | |
3626 | |
3595 | $self->add (2, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
3627 | $self->add (2, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
3596 | $self->add (3, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
3628 | $self->add (3, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
3597 | $self->add (4, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
3629 | $self->add (4, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
3598 | |
|
|
3599 | # TODO: should be done via popup |
|
|
3600 | $self->add (5, $row, new CFClient::UI::Button |
|
|
3601 | text => "bind", |
|
|
3602 | tooltip => "bind spell readying (cast command) to key", |
|
|
3603 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }, |
|
|
3604 | ); |
|
|
3605 | } |
3630 | } |
3606 | }); |
3631 | }); |
3607 | } |
3632 | } |
3608 | |
3633 | |
3609 | sub add_spell { |
3634 | sub add_spell { |