… | |
… | |
2467 | sub set_range { shift->{slider}->set_range (@_) } |
2467 | sub set_range { shift->{slider}->set_range (@_) } |
2468 | sub set_value { shift->{slider}->set_value (@_) } |
2468 | sub set_value { shift->{slider}->set_value (@_) } |
2469 | |
2469 | |
2470 | ############################################################################# |
2470 | ############################################################################# |
2471 | |
2471 | |
2472 | package CFClient::UI::TextView; |
2472 | package CFClient::UI::TextScroller; |
2473 | |
2473 | |
2474 | our @ISA = CFClient::UI::HBox::; |
2474 | our @ISA = CFClient::UI::HBox::; |
2475 | |
2475 | |
2476 | use CFClient::OpenGL; |
2476 | use CFClient::OpenGL; |
2477 | |
2477 | |
… | |
… | |
2752 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2752 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2753 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2753 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2754 | . "req $widget->{req_w} $widget->{req_h}\n" |
2754 | . "req $widget->{req_w} $widget->{req_h}\n" |
2755 | . "visible $widget->{visible}"; |
2755 | . "visible $widget->{visible}"; |
2756 | } |
2756 | } |
|
|
2757 | |
|
|
2758 | $tooltip =~ s/^\n+//; |
|
|
2759 | $tooltip =~ s/\n+$//; |
2757 | |
2760 | |
2758 | $self->add (new CFClient::UI::Label |
2761 | $self->add (new CFClient::UI::Label |
2759 | markup => $tooltip, |
2762 | markup => $tooltip, |
2760 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2763 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2761 | fontsize => 0.8, |
2764 | fontsize => 0.8, |
… | |
… | |
2938 | # handle various types of items, only text for now |
2941 | # handle various types of items, only text for now |
2939 | if (!ref $widget) { |
2942 | if (!ref $widget) { |
2940 | $widget = new CFClient::UI::Label |
2943 | $widget = new CFClient::UI::Label |
2941 | can_hover => 1, |
2944 | can_hover => 1, |
2942 | can_events => 1, |
2945 | can_events => 1, |
2943 | text => $widget, |
2946 | markup => $widget, |
2944 | tooltip => $tooltip |
2947 | tooltip => $tooltip |
2945 | } |
2948 | } |
2946 | |
2949 | |
2947 | $self->{item}{$widget} = $item; |
2950 | $self->{item}{$widget} = $item; |
2948 | |
2951 | |
… | |
… | |
3110 | |
3113 | |
3111 | sub new { |
3114 | sub new { |
3112 | my $class = shift; |
3115 | my $class = shift; |
3113 | |
3116 | |
3114 | my $self = $class->SUPER::new ( |
3117 | my $self = $class->SUPER::new ( |
3115 | options => [], # [title, value, tooltip], ... |
3118 | options => [], # [value, title, longdesc], ... |
3116 | value => undef, |
3119 | value => undef, |
3117 | @_, |
3120 | @_, |
3118 | ); |
3121 | ); |
3119 | |
3122 | |
3120 | $self->_set_value ($self->{value}); |
3123 | $self->_set_value ($self->{value}); |
… | |
… | |
3126 | my ($self, $ev) = @_; |
3129 | my ($self, $ev) = @_; |
3127 | |
3130 | |
3128 | my @menu_items; |
3131 | my @menu_items; |
3129 | |
3132 | |
3130 | for (@{ $self->{options} }) { |
3133 | for (@{ $self->{options} }) { |
3131 | my ($title, $value, $tooltip) = @$_; |
3134 | my ($value, $title, $tooltip) = @$_; |
3132 | |
3135 | |
3133 | push @menu_items, [$tooltip, sub { $self->set_value ($value) }]; |
3136 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
3134 | } |
3137 | } |
3135 | |
3138 | |
3136 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3139 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3137 | } |
3140 | } |
3138 | |
3141 | |
3139 | sub _set_value { |
3142 | sub _set_value { |
3140 | my ($self, $value) = @_; |
3143 | my ($self, $value) = @_; |
3141 | |
3144 | |
3142 | my ($item) = grep $_->[1] eq $value, @{ $self->{options} } |
3145 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} } |
3143 | or return; |
3146 | or return; |
3144 | |
3147 | |
3145 | $self->{value} = $item->[1]; |
3148 | $self->{value} = $item->[0]; |
3146 | $self->set_markup ("$item->[0] ⇓"); |
3149 | $self->set_markup ("$item->[1] ⇓"); |
3147 | $self->set_tooltip ($item->[2]); |
3150 | $self->set_tooltip ($item->[2]); |
3148 | } |
3151 | } |
3149 | |
3152 | |
3150 | sub set_value { |
3153 | sub set_value { |
3151 | my ($self, $value) = @_; |
3154 | my ($self, $value) = @_; |
… | |
… | |
3260 | $item->{count}++; |
3263 | $item->{count}++; |
3261 | } else { |
3264 | } else { |
3262 | $item->{count} = 1; |
3265 | $item->{count} = 1; |
3263 | $item->{text} = $item->{tooltip} = $text; |
3266 | $item->{text} = $item->{tooltip} = $text; |
3264 | } |
3267 | } |
3265 | $item->{id} = ++$self->{id}; |
3268 | $item->{id} += 0.2;#d# |
3266 | $item->{timeout} = $timeout; |
3269 | $item->{timeout} = $timeout; |
3267 | delete $item->{label}; |
3270 | delete $item->{label}; |
3268 | } else { |
3271 | } else { |
3269 | $self->{item}{$group} = { |
3272 | $self->{item}{$group} = { |
3270 | id => ++$self->{id}, |
3273 | id => ++$self->{id}, |
… | |
… | |
3552 | commands => [], |
3555 | commands => [], |
3553 | @_, |
3556 | @_, |
3554 | ) |
3557 | ) |
3555 | } |
3558 | } |
3556 | |
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"); |
3557 | 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 => |
3558 | "<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"); |
3559 | 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 => |
3560 | "<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"); |
3561 | 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 => |
3562 | "<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"); |
3563 | |
3572 | |
3564 | sub rebuild_spell_list { |
3573 | sub rebuild_spell_list { |
3565 | my ($self) = @_; |
3574 | my ($self) = @_; |
3566 | |
3575 | |
3567 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
3576 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
3568 | $self->clear; |
3577 | $self->clear; |
3569 | |
3578 | |
3570 | $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); |
3571 | $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); |
3572 | $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); |
3573 | $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); |
3574 | |
3584 | |
3575 | my $row = 0; |
3585 | my $row = 0; |
3576 | |
3586 | |
3577 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
3587 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
3578 | my $spell = $self->{spell}{$_}; |
3588 | my $spell = $self->{spell}{$_}; |
3579 | |
3589 | |
3580 | $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}); |
3581 | |
3617 | |
3582 | $self->add (0, $row, new CFClient::UI::Face |
3618 | $self->add (0, $row, new CFClient::UI::Face |
3583 | face => $spell->{face}, |
3619 | face => $spell->{face}, |
3584 | can_hover => 1, |
3620 | can_hover => 1, |
3585 | can_events => 1, |
3621 | can_events => 1, |
3586 | tooltip => $spell->{message}, |
3622 | tooltip => $tooltip, |
|
|
3623 | on_button_down => $spell_cb, |
3587 | ); |
3624 | ); |
3588 | |
3625 | |
3589 | $self->add (1, $row, new CFClient::UI::Label |
3626 | $self->add (1, $row, new CFClient::UI::Label |
3590 | expand => 1, |
3627 | expand => 1, |
3591 | text => $spell->{name}, |
3628 | text => $spell->{name}, |
3592 | can_hover => 1, |
3629 | can_hover => 1, |
3593 | can_events => 1, |
3630 | can_events => 1, |
3594 | tooltip => $spell->{message}, |
3631 | tooltip => $tooltip, |
|
|
3632 | on_button_down => $spell_cb, |
3595 | ); |
3633 | ); |
3596 | |
3634 | |
|
|
3635 | $self->add (2, $row, new CFClient::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL); |
3597 | $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); |
3598 | $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); |
3599 | $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); |
3600 | |
|
|
3601 | # TODO: should be done via popup |
|
|
3602 | $self->add (5, $row, new CFClient::UI::Button |
|
|
3603 | text => "bind", |
|
|
3604 | tooltip => "bind spell readying (cast command) to key", |
|
|
3605 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }, |
|
|
3606 | ); |
|
|
3607 | } |
3639 | } |
3608 | }); |
3640 | }); |
3609 | } |
3641 | } |
3610 | |
3642 | |
3611 | sub add_spell { |
3643 | sub add_spell { |
… | |
… | |
3617 | |
3649 | |
3618 | sub remove_spell { |
3650 | sub remove_spell { |
3619 | my ($self, $spell) = @_; |
3651 | my ($self, $spell) = @_; |
3620 | |
3652 | |
3621 | 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} = {}; |
3622 | $self->rebuild_spell_list; |
3661 | $self->rebuild_spell_list; |
3623 | } |
3662 | } |
3624 | |
3663 | |
3625 | ############################################################################# |
3664 | ############################################################################# |
3626 | |
3665 | |