1 | package CFPlus::UI; |
1 | package CFPlus::UI; |
2 | |
2 | |
3 | use utf8; |
3 | use utf8; |
4 | use strict; |
4 | use strict; |
5 | |
5 | |
6 | use Scalar::Util (); |
|
|
7 | use List::Util (); |
6 | use List::Util (); |
8 | use Event; |
7 | use Event; |
9 | |
8 | |
10 | use CFPlus; |
9 | use CFPlus; |
11 | use CFPlus::Pod; |
10 | use CFPlus::Pod; |
… | |
… | |
235 | h => undef, |
234 | h => undef, |
236 | can_events => 1, |
235 | can_events => 1, |
237 | @_ |
236 | @_ |
238 | }, $class; |
237 | }, $class; |
239 | |
238 | |
240 | Scalar::Util::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); |
239 | CFPlus::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); |
241 | |
240 | |
242 | for (keys %$self) { |
241 | for (keys %$self) { |
243 | if (/^on_(.*)$/) { |
242 | if (/^on_(.*)$/) { |
244 | $self->connect ($1 => delete $self->{$_}); |
243 | $self->connect ($1 => delete $self->{$_}); |
245 | } |
244 | } |
… | |
… | |
262 | |
261 | |
263 | sub destroy { |
262 | sub destroy { |
264 | my ($self) = @_; |
263 | my ($self) = @_; |
265 | |
264 | |
266 | $self->hide; |
265 | $self->hide; |
|
|
266 | $self->emit ("destroy"); |
267 | %$self = (); |
267 | %$self = (); |
268 | } |
268 | } |
269 | |
269 | |
270 | sub show { |
270 | sub show { |
271 | my ($self) = @_; |
271 | my ($self) = @_; |
… | |
… | |
502 | |
502 | |
503 | defined wantarray and CFPlus::guard { |
503 | defined wantarray and CFPlus::guard { |
504 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
504 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
505 | @{ $self->{signal_cb}{$signal} }; |
505 | @{ $self->{signal_cb}{$signal} }; |
506 | } |
506 | } |
|
|
507 | } |
|
|
508 | |
|
|
509 | sub disconnect_all { |
|
|
510 | my ($self, $signal) = @_; |
|
|
511 | |
|
|
512 | delete $self->{signal_cb}{$signal}; |
507 | } |
513 | } |
508 | |
514 | |
509 | my %has_coords = ( |
515 | my %has_coords = ( |
510 | button_down => 1, |
516 | button_down => 1, |
511 | button_up => 1, |
517 | button_up => 1, |
… | |
… | |
523 | ? $args[0]->xy ($self) |
529 | ? $args[0]->xy ($self) |
524 | : (); |
530 | : (); |
525 | |
531 | |
526 | #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# |
532 | #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# |
527 | |
533 | |
528 | if ($self->{tooltip} =~ /Apply.*audio/) { |
534 | for my $cb ( |
529 | warn "2 ", join ":", @{ $self->{signal_cb}{$signal} || []}, "\n";#d# |
535 | @{$self->{signal_cb}{$signal} || []}, # before |
530 | warn "3 $self->{parent}\n";#d# |
536 | ($self->can ("invoke_$signal") || sub { 1 }), # closure |
|
|
537 | ) { |
|
|
538 | return $cb->($self, @args, @append) || next; |
531 | } |
539 | } |
532 | |
540 | |
533 | #d##TODO# stop propagating at first true, do not use sum |
541 | # parent |
534 | my $res = |
|
|
535 | (List::Util::sum map $_->($self, @args, @append), @{$self->{signal_cb}{$signal} || []}) # before |
|
|
536 | || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args, @append) # closure |
|
|
537 | || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent |
542 | $self->{parent} && $self->{parent}->emit ($signal, @args) |
538 | ; |
|
|
539 | if ($self->{tooltip} =~ /Apply.*audio/) { |
|
|
540 | warn "4 ", join ":", @{ $self->{signal_cb}{$signal} || []}, "\n";#d# |
|
|
541 | warn "5 $self->{parent}\n";#d# |
|
|
542 | } |
|
|
543 | |
|
|
544 | $res |
|
|
545 | } |
543 | } |
546 | |
544 | |
547 | sub find_widget { |
545 | sub find_widget { |
548 | my ($self, $x, $y) = @_; |
546 | my ($self, $x, $y) = @_; |
549 | |
547 | |
… | |
… | |
557 | } |
555 | } |
558 | |
556 | |
559 | sub set_parent { |
557 | sub set_parent { |
560 | my ($self, $parent) = @_; |
558 | my ($self, $parent) = @_; |
561 | |
559 | |
562 | Scalar::Util::weaken ($self->{parent} = $parent); |
560 | CFPlus::weaken ($self->{parent} = $parent); |
563 | $self->set_visible if $parent->{visible}; |
561 | $self->set_visible if $parent->{visible}; |
564 | } |
562 | } |
565 | |
563 | |
566 | sub realloc { |
564 | sub realloc { |
567 | my ($self) = @_; |
565 | my ($self) = @_; |
… | |
… | |
646 | my ($self) = @_; |
644 | my ($self) = @_; |
647 | |
645 | |
648 | warn "no draw defined for $self\n"; |
646 | warn "no draw defined for $self\n"; |
649 | } |
647 | } |
650 | |
648 | |
|
|
649 | my $cntx;#d# |
651 | sub DESTROY { |
650 | sub DESTROY { |
652 | my ($self) = @_; |
651 | my ($self) = @_; |
653 | |
652 | |
654 | return if CFPlus::in_destruct; |
653 | return if CFPlus::in_destruct; |
655 | |
|
|
656 | delete $WIDGET{$self+0}; |
|
|
657 | |
654 | |
658 | eval { $self->destroy }; |
655 | eval { $self->destroy }; |
659 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
656 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
|
|
657 | |
|
|
658 | delete $WIDGET{$self+0}; |
660 | } |
659 | } |
661 | |
660 | |
662 | ############################################################################# |
661 | ############################################################################# |
663 | |
662 | |
664 | package CFPlus::UI::DrawBG; |
663 | package CFPlus::UI::DrawBG; |
… | |
… | |
1913 | active_fg => [0, 0, 0], |
1912 | active_fg => [0, 0, 0], |
1914 | can_hover => 1, |
1913 | can_hover => 1, |
1915 | can_focus => 1, |
1914 | can_focus => 1, |
1916 | valign => 0, |
1915 | valign => 0, |
1917 | can_events => 1, |
1916 | can_events => 1, |
|
|
1917 | ellipsise => 0, |
1918 | #text => ... |
1918 | #text => ... |
1919 | #hidden => "*", |
1919 | #hidden => "*", |
1920 | @_ |
1920 | @_ |
1921 | ) |
1921 | ) |
1922 | } |
1922 | } |
… | |
… | |
1976 | } elsif ($sym == CFPlus::SDLK_LEFT) { |
1976 | } elsif ($sym == CFPlus::SDLK_LEFT) { |
1977 | --$self->{cursor} if $self->{cursor}; |
1977 | --$self->{cursor} if $self->{cursor}; |
1978 | } elsif ($sym == CFPlus::SDLK_RIGHT) { |
1978 | } elsif ($sym == CFPlus::SDLK_RIGHT) { |
1979 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1979 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1980 | } elsif ($sym == CFPlus::SDLK_HOME) { |
1980 | } elsif ($sym == CFPlus::SDLK_HOME) { |
|
|
1981 | # what a hack |
1981 | $self->{cursor} = 0; |
1982 | $self->{cursor} = |
|
|
1983 | (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/ |
|
|
1984 | ? length $1 |
|
|
1985 | : 0; |
1982 | } elsif ($sym == CFPlus::SDLK_END) { |
1986 | } elsif ($sym == CFPlus::SDLK_END) { |
|
|
1987 | # uh, again |
|
|
1988 | $self->{cursor} = |
|
|
1989 | (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/ |
1983 | $self->{cursor} = length $text; |
1990 | ? $self->{cursor} + length $1 |
|
|
1991 | : length $self->{text}; |
1984 | } elsif ($uni == 21) { # ctrl-u |
1992 | } elsif ($uni == 21) { # ctrl-u |
1985 | $text = ""; |
1993 | $text = ""; |
1986 | $self->{cursor} = 0; |
1994 | $self->{cursor} = 0; |
1987 | } elsif ($uni == 27) { |
1995 | } elsif ($uni == 27) { |
1988 | $self->emit ('escape'); |
1996 | $self->emit ('escape'); |
1989 | } elsif ($uni) { |
1997 | } elsif ($uni == 0x0d) { |
|
|
1998 | substr $text, $self->{cursor}++, 0, "\012"; |
|
|
1999 | } elsif ($uni >= 0x20) { |
1990 | substr $text, $self->{cursor}++, 0, chr $uni; |
2000 | substr $text, $self->{cursor}++, 0, chr $uni; |
1991 | } else { |
2001 | } else { |
1992 | return 0; |
2002 | return 0; |
1993 | } |
2003 | } |
1994 | |
2004 | |
1995 | $self->_set_text ($text); |
2005 | $self->_set_text ($text); |
1996 | |
2006 | |
1997 | $self->realloc; |
2007 | $self->realloc; |
|
|
2008 | $self->update; |
1998 | |
2009 | |
1999 | 1 |
2010 | 1 |
2000 | } |
2011 | } |
2001 | |
2012 | |
2002 | sub invoke_focus_in { |
2013 | sub invoke_focus_in { |
… | |
… | |
2071 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2082 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2072 | glEnd; |
2083 | glEnd; |
2073 | } |
2084 | } |
2074 | } |
2085 | } |
2075 | |
2086 | |
|
|
2087 | ############################################################################# |
|
|
2088 | |
2076 | package CFPlus::UI::Entry; |
2089 | package CFPlus::UI::Entry; |
2077 | |
2090 | |
2078 | our @ISA = CFPlus::UI::EntryBase::; |
2091 | our @ISA = CFPlus::UI::EntryBase::; |
2079 | |
2092 | |
2080 | use CFPlus::OpenGL; |
2093 | use CFPlus::OpenGL; |
… | |
… | |
2082 | sub invoke_key_down { |
2095 | sub invoke_key_down { |
2083 | my ($self, $ev) = @_; |
2096 | my ($self, $ev) = @_; |
2084 | |
2097 | |
2085 | my $sym = $ev->{sym}; |
2098 | my $sym = $ev->{sym}; |
2086 | |
2099 | |
2087 | if ($sym == 13) { |
2100 | if ($ev->{uni} == 0x0d || $sym == 13) { |
2088 | unshift @{$self->{history}}, |
2101 | unshift @{$self->{history}}, |
2089 | my $txt = $self->get_text; |
2102 | my $txt = $self->get_text; |
2090 | |
2103 | |
2091 | $self->{history_pointer} = -1; |
2104 | $self->{history_pointer} = -1; |
2092 | $self->{history_saveback} = ''; |
2105 | $self->{history_saveback} = ''; |
… | |
… | |
2122 | 1 |
2135 | 1 |
2123 | } |
2136 | } |
2124 | |
2137 | |
2125 | ############################################################################# |
2138 | ############################################################################# |
2126 | |
2139 | |
|
|
2140 | package CFPlus::UI::TextEdit; |
|
|
2141 | |
|
|
2142 | our @ISA = CFPlus::UI::EntryBase::; |
|
|
2143 | |
|
|
2144 | use CFPlus::OpenGL; |
|
|
2145 | |
|
|
2146 | sub move_cursor_ver { |
|
|
2147 | my ($self, $dy) = @_; |
|
|
2148 | |
|
|
2149 | my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); |
|
|
2150 | |
|
|
2151 | $y += $dy; |
|
|
2152 | |
|
|
2153 | if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { |
|
|
2154 | $self->{cursor} = $index; |
|
|
2155 | delete $self->{cur_h}; |
|
|
2156 | $self->update; |
|
|
2157 | return; |
|
|
2158 | } |
|
|
2159 | } |
|
|
2160 | |
|
|
2161 | sub invoke_key_down { |
|
|
2162 | my ($self, $ev) = @_; |
|
|
2163 | |
|
|
2164 | my $sym = $ev->{sym}; |
|
|
2165 | |
|
|
2166 | if ($sym == CFPlus::SDLK_UP) { |
|
|
2167 | $self->move_cursor_ver (-1); |
|
|
2168 | } elsif ($sym == CFPlus::SDLK_DOWN) { |
|
|
2169 | $self->move_cursor_ver (+1); |
|
|
2170 | } else { |
|
|
2171 | return $self->SUPER::invoke_key_down ($ev) |
|
|
2172 | } |
|
|
2173 | |
|
|
2174 | 1 |
|
|
2175 | } |
|
|
2176 | |
|
|
2177 | ############################################################################# |
|
|
2178 | |
2127 | package CFPlus::UI::Button; |
2179 | package CFPlus::UI::Button; |
2128 | |
2180 | |
2129 | our @ISA = CFPlus::UI::Label::; |
2181 | our @ISA = CFPlus::UI::Label::; |
2130 | |
2182 | |
2131 | use CFPlus::OpenGL; |
2183 | use CFPlus::OpenGL; |
… | |
… | |
2273 | or Carp::croak "'path' or 'tex' attributes required"; |
2325 | or Carp::croak "'path' or 'tex' attributes required"; |
2274 | |
2326 | |
2275 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
2327 | $self->{tex} ||= $texture_cache{$self->{path}} ||= |
2276 | new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; |
2328 | new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; |
2277 | |
2329 | |
2278 | Scalar::Util::weaken $texture_cache{$self->{path}}; |
2330 | CFPlus::weaken $texture_cache{$self->{path}}; |
2279 | |
2331 | |
2280 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
2332 | $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; |
2281 | |
2333 | |
2282 | $self |
2334 | $self |
2283 | } |
2335 | } |
… | |
… | |
2656 | sub invoke_mouse_wheel { |
2708 | sub invoke_mouse_wheel { |
2657 | my ($self, $ev) = @_; |
2709 | my ($self, $ev) = @_; |
2658 | |
2710 | |
2659 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
2711 | my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; |
2660 | |
2712 | |
|
|
2713 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
|
|
2714 | |
2661 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.2); |
2715 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2662 | |
2716 | |
2663 | ! ! $delta |
2717 | ! ! $delta |
2664 | } |
2718 | } |
2665 | |
2719 | |
2666 | sub update { |
2720 | sub update { |
… | |
… | |
2776 | #font => default_font |
2830 | #font => default_font |
2777 | @_, |
2831 | @_, |
2778 | |
2832 | |
2779 | layout => (new CFPlus::Layout), |
2833 | layout => (new CFPlus::Layout), |
2780 | par => [], |
2834 | par => [], |
|
|
2835 | max_par => 0, |
2781 | height => 0, |
2836 | height => 0, |
2782 | children => [ |
2837 | children => [ |
2783 | (new CFPlus::UI::Empty expand => 1), |
2838 | (new CFPlus::UI::Empty expand => 1), |
2784 | (new CFPlus::UI::Slider vertical => 1), |
2839 | (new CFPlus::UI::Slider vertical => 1), |
2785 | ], |
2840 | ], |
… | |
… | |
2908 | wrapped => 1, |
2963 | wrapped => 1, |
2909 | }; |
2964 | }; |
2910 | |
2965 | |
2911 | $self->add (@{ $para->{widget} }) if @{ $para->{widget} }; |
2966 | $self->add (@{ $para->{widget} }) if @{ $para->{widget} }; |
2912 | push @{$self->{par}}, $para; |
2967 | push @{$self->{par}}, $para; |
|
|
2968 | } |
|
|
2969 | |
|
|
2970 | if (my $max = $self->{max_par}) { |
|
|
2971 | shift @{$self->{par}} while @{$self->{par}} > $max; |
2913 | } |
2972 | } |
2914 | |
2973 | |
2915 | $self->{need_reflow}++; |
2974 | $self->{need_reflow}++; |
2916 | $self->update; |
2975 | $self->update; |
2917 | } |
2976 | } |
… | |
… | |
3231 | can_events => 0, |
3290 | can_events => 0, |
3232 | @_, |
3291 | @_, |
3233 | ); |
3292 | ); |
3234 | |
3293 | |
3235 | if ($self->{anim} && $self->{animspeed}) { |
3294 | if ($self->{anim} && $self->{animspeed}) { |
3236 | Scalar::Util::weaken (my $widget = $self); |
3295 | CFPlus::weaken (my $widget = $self); |
3237 | |
3296 | |
3238 | $self->{timer} = Event->timer ( |
3297 | $self->{timer} = Event->timer ( |
3239 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
3298 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
3240 | hard => 1, |
3299 | hard => 1, |
3241 | interval => $self->{animspeed}, |
3300 | interval => $self->{animspeed}, |
… | |
… | |
3495 | } |
3554 | } |
3496 | |
3555 | |
3497 | sub add { |
3556 | sub add { |
3498 | my ($self, $title, $widget, $tooltip) = @_; |
3557 | my ($self, $title, $widget, $tooltip) = @_; |
3499 | |
3558 | |
3500 | Scalar::Util::weaken $self; |
3559 | CFPlus::weaken $self; |
3501 | |
3560 | |
3502 | $self->{buttonbar}->add (new CFPlus::UI::Button |
3561 | $self->{buttonbar}->add (new CFPlus::UI::Button |
3503 | markup => $title, |
3562 | markup => $title, |
3504 | tooltip => $tooltip, |
3563 | tooltip => $tooltip, |
3505 | on_activate => sub { $self->set_current_page ($widget) }, |
3564 | on_activate => sub { $self->set_current_page ($widget) }, |
… | |
… | |
3589 | my $self = $class->SUPER::new ( |
3648 | my $self = $class->SUPER::new ( |
3590 | fontsize => 0.8, |
3649 | fontsize => 0.8, |
3591 | @_, |
3650 | @_, |
3592 | ); |
3651 | ); |
3593 | |
3652 | |
3594 | Scalar::Util::weaken (my $this = $self); |
3653 | CFPlus::weaken (my $this = $self); |
3595 | |
3654 | |
3596 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
3655 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
3597 | |
3656 | |
3598 | $self |
3657 | $self |
3599 | } |
3658 | } |
… | |
… | |
3722 | $self->SUPER::destroy; |
3781 | $self->SUPER::destroy; |
3723 | } |
3782 | } |
3724 | |
3783 | |
3725 | ############################################################################# |
3784 | ############################################################################# |
3726 | |
3785 | |
3727 | package CFPlus::UI::Inventory; |
|
|
3728 | |
|
|
3729 | our @ISA = CFPlus::UI::Table::; |
|
|
3730 | |
|
|
3731 | sub new { |
|
|
3732 | my $class = shift; |
|
|
3733 | |
|
|
3734 | my $self = $class->SUPER::new ( |
|
|
3735 | col_expand => [0, 1, 0], |
|
|
3736 | items => [], |
|
|
3737 | @_, |
|
|
3738 | ); |
|
|
3739 | |
|
|
3740 | $self->set_sort_order (undef); |
|
|
3741 | |
|
|
3742 | $self |
|
|
3743 | } |
|
|
3744 | |
|
|
3745 | sub update_items { |
|
|
3746 | my ($self) = @_; |
|
|
3747 | |
|
|
3748 | $self->clear; |
|
|
3749 | |
|
|
3750 | my @item = $self->{sort}->(@{ $self->{items} }); |
|
|
3751 | |
|
|
3752 | my @adds; |
|
|
3753 | my $row = 0; |
|
|
3754 | for my $item ($self->{sort}->(@{ $self->{items} })) { |
|
|
3755 | CFPlus::Item::update_widgets $item; |
|
|
3756 | |
|
|
3757 | push @adds, 0, $row, $item->{face_widget}; |
|
|
3758 | push @adds, 1, $row, $item->{desc_widget}; |
|
|
3759 | push @adds, 2, $row, $item->{weight_widget}; |
|
|
3760 | |
|
|
3761 | $row++; |
|
|
3762 | } |
|
|
3763 | |
|
|
3764 | $self->add (@adds); |
|
|
3765 | } |
|
|
3766 | |
|
|
3767 | sub set_sort_order { |
|
|
3768 | my ($self, $order) = @_; |
|
|
3769 | |
|
|
3770 | $self->{sort} = $order ||= sub { |
|
|
3771 | sort { |
|
|
3772 | $a->{type} <=> $b->{type} |
|
|
3773 | or $a->{name} cmp $b->{name} |
|
|
3774 | } @_ |
|
|
3775 | }; |
|
|
3776 | |
|
|
3777 | $self->update_items; |
|
|
3778 | } |
|
|
3779 | |
|
|
3780 | sub set_items { |
|
|
3781 | my ($self, $items) = @_; |
|
|
3782 | |
|
|
3783 | $self->{items} = [$items ? values %$items : ()]; |
|
|
3784 | $self->update_items; |
|
|
3785 | } |
|
|
3786 | |
|
|
3787 | ############################################################################# |
|
|
3788 | |
|
|
3789 | package CFPlus::UI::SpellList; |
|
|
3790 | |
|
|
3791 | our @ISA = CFPlus::UI::Table::; |
|
|
3792 | |
|
|
3793 | sub new { |
|
|
3794 | my $class = shift; |
|
|
3795 | |
|
|
3796 | my $self = $class->SUPER::new ( |
|
|
3797 | binding => [], |
|
|
3798 | commands => [], |
|
|
3799 | @_, |
|
|
3800 | ) |
|
|
3801 | } |
|
|
3802 | |
|
|
3803 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>"; |
|
|
3804 | |
|
|
3805 | my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3806 | "<b>Name</b>. The name of the spell.$TOOLTIP_ALL"); |
|
|
3807 | my @TOOLTIP_SKILL = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3808 | "<b>Skill</b>. The skill (or magic school) required to be able to attempt casting this spell.$TOOLTIP_ALL"); |
|
|
3809 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3810 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL"); |
|
|
3811 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3812 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL"); |
|
|
3813 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
|
|
3814 | "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL"); |
|
|
3815 | |
|
|
3816 | sub rebuild_spell_list { |
|
|
3817 | my ($self) = @_; |
|
|
3818 | |
|
|
3819 | $CFPlus::UI::ROOT->on_refresh ($self => sub { |
|
|
3820 | $self->clear; |
|
|
3821 | |
|
|
3822 | return unless $::CONN; |
|
|
3823 | |
|
|
3824 | $self->add (1, 0, new CFPlus::UI::Label text => "Spell Name", @TOOLTIP_NAME); |
|
|
3825 | $self->add (2, 0, new CFPlus::UI::Label text => "Skill", @TOOLTIP_SKILL); |
|
|
3826 | $self->add (3, 0, new CFPlus::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
|
|
3827 | $self->add (4, 0, new CFPlus::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
|
|
3828 | $self->add (5, 0, new CFPlus::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
|
|
3829 | |
|
|
3830 | my $row = 0; |
|
|
3831 | |
|
|
3832 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
|
|
3833 | my $spell = $self->{spell}{$_}; |
|
|
3834 | |
|
|
3835 | $row++; |
|
|
3836 | |
|
|
3837 | my $spell_cb = sub { |
|
|
3838 | my ($widget, $ev) = @_; |
|
|
3839 | |
|
|
3840 | if ($ev->{button} == 1) { |
|
|
3841 | $::CONN->user_send ("cast $spell->{name}"); |
|
|
3842 | } elsif ($ev->{button} == 2) { |
|
|
3843 | $::CONN->user_send ("invoke $spell->{name}"); |
|
|
3844 | } elsif ($ev->{button} == 3) { |
|
|
3845 | (new CFPlus::UI::Menu |
|
|
3846 | items => [ |
|
|
3847 | ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], |
|
|
3848 | ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], |
|
|
3849 | ], |
|
|
3850 | )->popup ($ev); |
|
|
3851 | } else { |
|
|
3852 | return 0; |
|
|
3853 | } |
|
|
3854 | |
|
|
3855 | 1 |
|
|
3856 | }; |
|
|
3857 | |
|
|
3858 | my $tooltip = (CFPlus::asxml $spell->{message}) . $TOOLTIP_ALL; |
|
|
3859 | |
|
|
3860 | #TODO: add path info to tooltip |
|
|
3861 | #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path}); |
|
|
3862 | |
|
|
3863 | $self->add (0, $row, new CFPlus::UI::Face |
|
|
3864 | face => $spell->{face}, |
|
|
3865 | can_hover => 1, |
|
|
3866 | can_events => 1, |
|
|
3867 | tooltip => $tooltip, |
|
|
3868 | on_button_down => $spell_cb, |
|
|
3869 | ); |
|
|
3870 | |
|
|
3871 | $self->add (1, $row, new CFPlus::UI::Label |
|
|
3872 | expand => 1, |
|
|
3873 | text => $spell->{name}, |
|
|
3874 | can_hover => 1, |
|
|
3875 | can_events => 1, |
|
|
3876 | tooltip => $tooltip, |
|
|
3877 | on_button_down => $spell_cb, |
|
|
3878 | ); |
|
|
3879 | |
|
|
3880 | $self->add (2, $row, new CFPlus::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL); |
|
|
3881 | $self->add (3, $row, new CFPlus::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
|
|
3882 | $self->add (4, $row, new CFPlus::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
|
|
3883 | $self->add (5, $row, new CFPlus::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
|
|
3884 | } |
|
|
3885 | }); |
|
|
3886 | } |
|
|
3887 | |
|
|
3888 | sub add_spell { |
|
|
3889 | my ($self, $spell) = @_; |
|
|
3890 | |
|
|
3891 | $self->{spell}->{$spell->{name}} = $spell; |
|
|
3892 | $self->rebuild_spell_list; |
|
|
3893 | } |
|
|
3894 | |
|
|
3895 | sub remove_spell { |
|
|
3896 | my ($self, $spell) = @_; |
|
|
3897 | |
|
|
3898 | delete $self->{spell}->{$spell->{name}}; |
|
|
3899 | $self->rebuild_spell_list; |
|
|
3900 | } |
|
|
3901 | |
|
|
3902 | sub clear_spells { |
|
|
3903 | my ($self) = @_; |
|
|
3904 | |
|
|
3905 | $self->{spell} = {}; |
|
|
3906 | $self->rebuild_spell_list; |
|
|
3907 | } |
|
|
3908 | |
|
|
3909 | ############################################################################# |
|
|
3910 | |
|
|
3911 | package CFPlus::UI::Root; |
3786 | package CFPlus::UI::Root; |
3912 | |
3787 | |
3913 | our @ISA = CFPlus::UI::Container::; |
3788 | our @ISA = CFPlus::UI::Container::; |
3914 | |
3789 | |
3915 | use List::Util qw(min max); |
3790 | use List::Util qw(min max); |
… | |
… | |
3922 | my $self = $class->SUPER::new ( |
3797 | my $self = $class->SUPER::new ( |
3923 | visible => 1, |
3798 | visible => 1, |
3924 | @_, |
3799 | @_, |
3925 | ); |
3800 | ); |
3926 | |
3801 | |
3927 | Scalar::Util::weaken ($self->{root} = $self); |
3802 | CFPlus::weaken ($self->{root} = $self); |
3928 | |
3803 | |
3929 | $self |
3804 | $self |
3930 | } |
3805 | } |
3931 | |
3806 | |
3932 | sub size_request { |
3807 | sub size_request { |