ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.351 by root, Sun Oct 1 12:08:58 2006 UTC vs.
Revision 1.367 by root, Fri Apr 27 00:59:14 2007 UTC

1package CFPlus::UI; 1package CFPlus::UI;
2 2
3use utf8; 3use utf8;
4use strict; 4use strict;
5 5
6use Scalar::Util ();
7use List::Util (); 6use List::Util ();
8use Event; 7use Event;
9 8
10use CFPlus; 9use CFPlus;
11use CFPlus::Pod; 10use CFPlus::Pod;
23our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { 22our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub {
24 if (!$GRAB) { 23 if (!$GRAB) {
25 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 24 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
26 if (length $widget->{tooltip}) { 25 if (length $widget->{tooltip}) {
27 if ($TOOLTIP->{owner} != $widget) { 26 if ($TOOLTIP->{owner} != $widget) {
27 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
28 $TOOLTIP->hide; 28 $TOOLTIP->hide;
29 29
30 $TOOLTIP->{owner} = $widget; 30 $TOOLTIP->{owner} = $widget;
31 $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner};
31 32
32 return if $ENV{CFPLUS_DEBUG} & 8; 33 return if $ENV{CFPLUS_DEBUG} & 8;
33 34
34 my $tip = $widget->{tooltip}; 35 my $tip = $widget->{tooltip};
35 36
43 } 44 }
44 } 45 }
45 } 46 }
46 47
47 $TOOLTIP->hide; 48 $TOOLTIP->hide;
49 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
48 delete $TOOLTIP->{owner}; 50 delete $TOOLTIP->{owner};
49}); 51});
50 52
51sub get_layout { 53sub get_layout {
52 my $layout; 54 my $layout;
235 h => undef, 237 h => undef,
236 can_events => 1, 238 can_events => 1,
237 @_ 239 @_
238 }, $class; 240 }, $class;
239 241
240 Scalar::Util::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); 242 CFPlus::weaken ($CFPlus::UI::WIDGET{$self+0} = $self);
241 243
242 for (keys %$self) { 244 for (keys %$self) {
243 if (/^on_(.*)$/) { 245 if (/^on_(.*)$/) {
244 $self->connect ($1 => delete $self->{$_}); 246 $self->connect ($1 => delete $self->{$_});
245 } 247 }
262 264
263sub destroy { 265sub destroy {
264 my ($self) = @_; 266 my ($self) = @_;
265 267
266 $self->hide; 268 $self->hide;
269 $self->emit ("destroy");
267 %$self = (); 270 %$self = ();
268} 271}
269 272
270sub show { 273sub show {
271 my ($self) = @_; 274 my ($self) = @_;
502 505
503 defined wantarray and CFPlus::guard { 506 defined wantarray and CFPlus::guard {
504 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, 507 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb,
505 @{ $self->{signal_cb}{$signal} }; 508 @{ $self->{signal_cb}{$signal} };
506 } 509 }
510}
511
512sub disconnect_all {
513 my ($self, $signal) = @_;
514
515 delete $self->{signal_cb}{$signal};
507} 516}
508 517
509my %has_coords = ( 518my %has_coords = (
510 button_down => 1, 519 button_down => 1,
511 button_up => 1, 520 button_up => 1,
514); 523);
515 524
516sub emit { 525sub emit {
517 my ($self, $signal, @args) = @_; 526 my ($self, $signal, @args) = @_;
518 527
519 # I do not really like this solution, but I dislike duplication 528 # I do not really like this solution, but I do not like duplication
520 # and needlessly verbose code, too. 529 # and needlessly verbose code, either.
521 my @append 530 my @append
522 = $has_coords{$signal} 531 = $has_coords{$signal}
523 ? $args[0]->xy ($self) 532 ? $args[0]->xy ($self)
524 : (); 533 : ();
525 534
526 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# 535 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d#
527 536
528 #d##TODO# stop propagating at first true, do not use sum 537 for my $cb (
529 (List::Util::sum map $_->($self, @args, @append), @{$self->{signal_cb}{$signal} || []}) # before 538 @{$self->{signal_cb}{$signal} || []}, # before
530 || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args, @append) # closure 539 ($self->can ("invoke_$signal") || sub { 1 }), # closure
540 ) {
541 return $cb->($self, @args, @append) || next;
542 }
543
544 # parent
531 || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent 545 $self->{parent} && $self->{parent}->emit ($signal, @args)
532} 546}
533 547
534sub find_widget { 548sub find_widget {
535 my ($self, $x, $y) = @_; 549 my ($self, $x, $y) = @_;
536 550
544} 558}
545 559
546sub set_parent { 560sub set_parent {
547 my ($self, $parent) = @_; 561 my ($self, $parent) = @_;
548 562
549 Scalar::Util::weaken ($self->{parent} = $parent); 563 CFPlus::weaken ($self->{parent} = $parent);
550 $self->set_visible if $parent->{visible}; 564 $self->set_visible if $parent->{visible};
551} 565}
552 566
553sub realloc { 567sub realloc {
554 my ($self) = @_; 568 my ($self) = @_;
633 my ($self) = @_; 647 my ($self) = @_;
634 648
635 warn "no draw defined for $self\n"; 649 warn "no draw defined for $self\n";
636} 650}
637 651
652my $cntx;#d#
638sub DESTROY { 653sub DESTROY {
639 my ($self) = @_; 654 my ($self) = @_;
640 655
641 return if CFPlus::in_destruct; 656 return if CFPlus::in_destruct;
642
643 delete $WIDGET{$self+0};
644 657
645 eval { $self->destroy }; 658 eval { $self->destroy };
646 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; 659 warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/;
660
661 delete $WIDGET{$self+0};
647} 662}
648 663
649############################################################################# 664#############################################################################
650 665
651package CFPlus::UI::DrawBG; 666package CFPlus::UI::DrawBG;
900 { 915 {
901 package CFPlus::UI::Base; 916 package CFPlus::UI::Base;
902 917
903 local ($draw_x, $draw_y, $draw_w, $draw_h) = 918 local ($draw_x, $draw_y, $draw_w, $draw_h) =
904 (0, 0, $self->{w}, $self->{h}); 919 (0, 0, $self->{w}, $self->{h});
920
921 $self->_render;
905 } 922 }
906
907 $self->_render;
908 }; 923 };
909} 924}
910 925
911sub _draw { 926sub _draw {
912 my ($self) = @_; 927 my ($self) = @_;
1900 active_fg => [0, 0, 0], 1915 active_fg => [0, 0, 0],
1901 can_hover => 1, 1916 can_hover => 1,
1902 can_focus => 1, 1917 can_focus => 1,
1903 valign => 0, 1918 valign => 0,
1904 can_events => 1, 1919 can_events => 1,
1920 ellipsise => 0,
1905 #text => ... 1921 #text => ...
1906 #hidden => "*", 1922 #hidden => "*",
1907 @_ 1923 @_
1908 ) 1924 )
1909} 1925}
1953 my $mod = $ev->{mod}; 1969 my $mod = $ev->{mod};
1954 my $sym = $ev->{sym}; 1970 my $sym = $ev->{sym};
1955 my $uni = $ev->{unicode}; 1971 my $uni = $ev->{unicode};
1956 1972
1957 my $text = $self->get_text; 1973 my $text = $self->get_text;
1974
1975 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text;
1958 1976
1959 if ($uni == 8) { 1977 if ($uni == 8) {
1960 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1978 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1961 } elsif ($uni == 127) { 1979 } elsif ($uni == 127) {
1962 substr $text, $self->{cursor}, 1, ""; 1980 substr $text, $self->{cursor}, 1, "";
1963 } elsif ($sym == CFPlus::SDLK_LEFT) { 1981 } elsif ($sym == CFPlus::SDLK_LEFT) {
1964 --$self->{cursor} if $self->{cursor}; 1982 --$self->{cursor} if $self->{cursor};
1965 } elsif ($sym == CFPlus::SDLK_RIGHT) { 1983 } elsif ($sym == CFPlus::SDLK_RIGHT) {
1966 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1984 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1967 } elsif ($sym == CFPlus::SDLK_HOME) { 1985 } elsif ($sym == CFPlus::SDLK_HOME) {
1986 # what a hack
1968 $self->{cursor} = 0; 1987 $self->{cursor} =
1988 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/
1989 ? length $1
1990 : 0;
1969 } elsif ($sym == CFPlus::SDLK_END) { 1991 } elsif ($sym == CFPlus::SDLK_END) {
1992 # uh, again
1993 $self->{cursor} =
1994 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/
1970 $self->{cursor} = length $text; 1995 ? $self->{cursor} + length $1
1996 : length $self->{text};
1971 } elsif ($uni == 21) { # ctrl-u 1997 } elsif ($uni == 21) { # ctrl-u
1972 $text = ""; 1998 $text = "";
1973 $self->{cursor} = 0; 1999 $self->{cursor} = 0;
1974 } elsif ($uni == 27) { 2000 } elsif ($uni == 27) {
1975 $self->emit ('escape'); 2001 $self->emit ('escape');
1976 } elsif ($uni) { 2002 } elsif ($uni == 0x0d) {
2003 substr $text, $self->{cursor}++, 0, "\012";
2004 } elsif ($uni >= 0x20) {
1977 substr $text, $self->{cursor}++, 0, chr $uni; 2005 substr $text, $self->{cursor}++, 0, chr $uni;
1978 } else { 2006 } else {
1979 return 0; 2007 return 0;
1980 } 2008 }
1981 2009
1982 $self->_set_text ($text); 2010 $self->_set_text ($text);
1983 2011
1984 $self->realloc; 2012 $self->realloc;
2013 $self->update;
1985 2014
1986 1 2015 1
1987} 2016}
1988 2017
1989sub invoke_focus_in { 2018sub invoke_focus_in {
2058 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; 2087 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
2059 glEnd; 2088 glEnd;
2060 } 2089 }
2061} 2090}
2062 2091
2092#############################################################################
2093
2063package CFPlus::UI::Entry; 2094package CFPlus::UI::Entry;
2064 2095
2065our @ISA = CFPlus::UI::EntryBase::; 2096our @ISA = CFPlus::UI::EntryBase::;
2066 2097
2067use CFPlus::OpenGL; 2098use CFPlus::OpenGL;
2069sub invoke_key_down { 2100sub invoke_key_down {
2070 my ($self, $ev) = @_; 2101 my ($self, $ev) = @_;
2071 2102
2072 my $sym = $ev->{sym}; 2103 my $sym = $ev->{sym};
2073 2104
2074 if ($sym == 13) { 2105 if ($ev->{uni} == 0x0d || $sym == 13) {
2075 unshift @{$self->{history}}, 2106 unshift @{$self->{history}},
2076 my $txt = $self->get_text; 2107 my $txt = $self->get_text;
2077 2108
2078 $self->{history_pointer} = -1; 2109 $self->{history_pointer} = -1;
2079 $self->{history_saveback} = ''; 2110 $self->{history_saveback} = '';
2109 1 2140 1
2110} 2141}
2111 2142
2112############################################################################# 2143#############################################################################
2113 2144
2145package CFPlus::UI::TextEdit;
2146
2147our @ISA = CFPlus::UI::EntryBase::;
2148
2149use CFPlus::OpenGL;
2150
2151sub move_cursor_ver {
2152 my ($self, $dy) = @_;
2153
2154 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2155
2156 $y += $dy;
2157
2158 if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) {
2159 $self->{cursor} = $index;
2160 delete $self->{cur_h};
2161 $self->update;
2162 return;
2163 }
2164}
2165
2166sub invoke_key_down {
2167 my ($self, $ev) = @_;
2168
2169 my $sym = $ev->{sym};
2170
2171 if ($sym == CFPlus::SDLK_UP) {
2172 $self->move_cursor_ver (-1);
2173 } elsif ($sym == CFPlus::SDLK_DOWN) {
2174 $self->move_cursor_ver (+1);
2175 } else {
2176 return $self->SUPER::invoke_key_down ($ev)
2177 }
2178
2179 1
2180}
2181
2182#############################################################################
2183
2114package CFPlus::UI::Button; 2184package CFPlus::UI::Button;
2115 2185
2116our @ISA = CFPlus::UI::Label::; 2186our @ISA = CFPlus::UI::Label::;
2117 2187
2118use CFPlus::OpenGL; 2188use CFPlus::OpenGL;
2260 or Carp::croak "'path' or 'tex' attributes required"; 2330 or Carp::croak "'path' or 'tex' attributes required";
2261 2331
2262 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2332 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2263 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; 2333 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1;
2264 2334
2265 Scalar::Util::weaken $texture_cache{$self->{path}}; 2335 CFPlus::weaken $texture_cache{$self->{path}};
2266 2336
2267 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2337 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2268 2338
2269 $self 2339 $self
2270} 2340}
2643sub invoke_mouse_wheel { 2713sub invoke_mouse_wheel {
2644 my ($self, $ev) = @_; 2714 my ($self, $ev) = @_;
2645 2715
2646 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 2716 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
2647 2717
2718 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2;
2719
2648 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.2); 2720 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
2649 2721
2650 ! ! $delta 2722 ! ! $delta
2651} 2723}
2652 2724
2653sub update { 2725sub update {
2763 #font => default_font 2835 #font => default_font
2764 @_, 2836 @_,
2765 2837
2766 layout => (new CFPlus::Layout), 2838 layout => (new CFPlus::Layout),
2767 par => [], 2839 par => [],
2840 max_par => 0,
2768 height => 0, 2841 height => 0,
2769 children => [ 2842 children => [
2770 (new CFPlus::UI::Empty expand => 1), 2843 (new CFPlus::UI::Empty expand => 1),
2771 (new CFPlus::UI::Slider vertical => 1), 2844 (new CFPlus::UI::Slider vertical => 1),
2772 ], 2845 ],
2897 2970
2898 $self->add (@{ $para->{widget} }) if @{ $para->{widget} }; 2971 $self->add (@{ $para->{widget} }) if @{ $para->{widget} };
2899 push @{$self->{par}}, $para; 2972 push @{$self->{par}}, $para;
2900 } 2973 }
2901 2974
2975 if (my $max = $self->{max_par}) {
2976 shift @{$self->{par}} while @{$self->{par}} > $max;
2977 }
2978
2902 $self->{need_reflow}++; 2979 $self->{need_reflow}++;
2903 $self->update; 2980 $self->update;
2904} 2981}
2905 2982
2906sub scroll_to_bottom { 2983sub scroll_to_bottom {
2959 3036
2960 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { 3037 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub {
2961 glClearColor 0, 0, 0, 0; 3038 glClearColor 0, 0, 0, 0;
2962 glClear GL_COLOR_BUFFER_BIT; 3039 glClear GL_COLOR_BUFFER_BIT;
2963 3040
2964 {
2965 package CFPlus::UI::Base; 3041 package CFPlus::UI::Base;
2966
2967 local ($draw_x, $draw_y, $draw_w, $draw_h) = 3042 local ($draw_x, $draw_y, $draw_w, $draw_h) =
2968 (0, 0, $self->{w}, $self->{h}); 3043 (0, 0, $self->{w}, $self->{h});
2969 }
2970 3044
2971 my $top = int $self->{children}[1]{range}[0]; 3045 my $top = int $self->{children}[1]{range}[0];
2972 3046
2973 my $paridx = 0; 3047 my $paridx = 0;
2974 my $top_paragraph; 3048 my $top_paragraph;
3221 can_events => 0, 3295 can_events => 0,
3222 @_, 3296 @_,
3223 ); 3297 );
3224 3298
3225 if ($self->{anim} && $self->{animspeed}) { 3299 if ($self->{anim} && $self->{animspeed}) {
3226 Scalar::Util::weaken (my $widget = $self); 3300 CFPlus::weaken (my $widget = $self);
3227 3301
3228 $self->{timer} = Event->timer ( 3302 $self->{timer} = Event->timer (
3229 at => $self->{animspeed} * int $::NOW / $self->{animspeed}, 3303 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3230 hard => 1, 3304 hard => 1,
3231 interval => $self->{animspeed}, 3305 interval => $self->{animspeed},
3291 3365
3292package CFPlus::UI::Buttonbar; 3366package CFPlus::UI::Buttonbar;
3293 3367
3294our @ISA = CFPlus::UI::HBox::; 3368our @ISA = CFPlus::UI::HBox::;
3295 3369
3296# TODO: should actualyl wrap buttons and other goodies. 3370# TODO: should actually wrap buttons and other goodies.
3297 3371
3298############################################################################# 3372#############################################################################
3299 3373
3300package CFPlus::UI::Menu; 3374package CFPlus::UI::Menu;
3301 3375
3485} 3559}
3486 3560
3487sub add { 3561sub add {
3488 my ($self, $title, $widget, $tooltip) = @_; 3562 my ($self, $title, $widget, $tooltip) = @_;
3489 3563
3490 Scalar::Util::weaken $self; 3564 CFPlus::weaken $self;
3491 3565
3492 $self->{buttonbar}->add (new CFPlus::UI::Button 3566 $self->{buttonbar}->add (new CFPlus::UI::Button
3493 markup => $title, 3567 markup => $title,
3494 tooltip => $tooltip, 3568 tooltip => $tooltip,
3495 on_activate => sub { $self->set_current_page ($widget) }, 3569 on_activate => sub { $self->set_current_page ($widget) },
3579 my $self = $class->SUPER::new ( 3653 my $self = $class->SUPER::new (
3580 fontsize => 0.8, 3654 fontsize => 0.8,
3581 @_, 3655 @_,
3582 ); 3656 );
3583 3657
3584 Scalar::Util::weaken (my $this = $self); 3658 CFPlus::weaken (my $this = $self);
3585 3659
3586 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); 3660 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder });
3587 3661
3588 $self 3662 $self
3589} 3663}
3712 $self->SUPER::destroy; 3786 $self->SUPER::destroy;
3713} 3787}
3714 3788
3715############################################################################# 3789#############################################################################
3716 3790
3717package CFPlus::UI::Inventory;
3718
3719our @ISA = CFPlus::UI::Table::;
3720
3721sub new {
3722 my $class = shift;
3723
3724 my $self = $class->SUPER::new (
3725 col_expand => [0, 1, 0],
3726 items => [],
3727 @_,
3728 );
3729
3730 $self->set_sort_order (undef);
3731
3732 $self
3733}
3734
3735sub update_items {
3736 my ($self) = @_;
3737
3738 $self->clear;
3739
3740 my @item = $self->{sort}->(@{ $self->{items} });
3741
3742 my @adds;
3743 my $row = 0;
3744 for my $item ($self->{sort}->(@{ $self->{items} })) {
3745 CFPlus::Item::update_widgets $item;
3746
3747 push @adds, 0, $row, $item->{face_widget};
3748 push @adds, 1, $row, $item->{desc_widget};
3749 push @adds, 2, $row, $item->{weight_widget};
3750
3751 $row++;
3752 }
3753
3754 $self->add (@adds);
3755}
3756
3757sub set_sort_order {
3758 my ($self, $order) = @_;
3759
3760 $self->{sort} = $order ||= sub {
3761 sort {
3762 $a->{type} <=> $b->{type}
3763 or $a->{name} cmp $b->{name}
3764 } @_
3765 };
3766
3767 $self->update_items;
3768}
3769
3770sub set_items {
3771 my ($self, $items) = @_;
3772
3773 $self->{items} = [$items ? values %$items : ()];
3774 $self->update_items;
3775}
3776
3777#############################################################################
3778
3779package CFPlus::UI::SpellList;
3780
3781our @ISA = CFPlus::UI::Table::;
3782
3783sub new {
3784 my $class = shift;
3785
3786 my $self = $class->SUPER::new (
3787 binding => [],
3788 commands => [],
3789 @_,
3790 )
3791}
3792
3793my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>";
3794
3795my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip =>
3796 "<b>Name</b>. The name of the spell.$TOOLTIP_ALL");
3797my @TOOLTIP_SKILL = (align => -1, can_events => 1, can_hover => 1, tooltip =>
3798 "<b>Skill</b>. The skill (or magic school) required to be able to attempt casting this spell.$TOOLTIP_ALL");
3799my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3800 "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL");
3801my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3802 "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL");
3803my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3804 "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL");
3805
3806sub rebuild_spell_list {
3807 my ($self) = @_;
3808
3809 $CFPlus::UI::ROOT->on_refresh ($self => sub {
3810 $self->clear;
3811
3812 return unless $::CONN;
3813
3814 $self->add (1, 0, new CFPlus::UI::Label text => "Spell Name", @TOOLTIP_NAME);
3815 $self->add (2, 0, new CFPlus::UI::Label text => "Skill", @TOOLTIP_SKILL);
3816 $self->add (3, 0, new CFPlus::UI::Label text => "Lvl" , @TOOLTIP_LVL);
3817 $self->add (4, 0, new CFPlus::UI::Label text => "Sp/Gp", @TOOLTIP_SP);
3818 $self->add (5, 0, new CFPlus::UI::Label text => "Dmg" , @TOOLTIP_DMG);
3819
3820 my $row = 0;
3821
3822 for (sort { $a cmp $b } keys %{ $self->{spell} }) {
3823 my $spell = $self->{spell}{$_};
3824
3825 $row++;
3826
3827 my $spell_cb = sub {
3828 my ($widget, $ev) = @_;
3829
3830 if ($ev->{button} == 1) {
3831 $::CONN->user_send ("cast $spell->{name}");
3832 } elsif ($ev->{button} == 2) {
3833 $::CONN->user_send ("invoke $spell->{name}");
3834 } elsif ($ev->{button} == 3) {
3835 (new CFPlus::UI::Menu
3836 items => [
3837 ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }],
3838 ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }],
3839 ],
3840 )->popup ($ev);
3841 } else {
3842 return 0;
3843 }
3844
3845 1
3846 };
3847
3848 my $tooltip = (CFPlus::asxml $spell->{message}) . $TOOLTIP_ALL;
3849
3850 #TODO: add path info to tooltip
3851 #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path});
3852
3853 $self->add (0, $row, new CFPlus::UI::Face
3854 face => $spell->{face},
3855 can_hover => 1,
3856 can_events => 1,
3857 tooltip => $tooltip,
3858 on_button_down => $spell_cb,
3859 );
3860
3861 $self->add (1, $row, new CFPlus::UI::Label
3862 expand => 1,
3863 text => $spell->{name},
3864 can_hover => 1,
3865 can_events => 1,
3866 tooltip => $tooltip,
3867 on_button_down => $spell_cb,
3868 );
3869
3870 $self->add (2, $row, new CFPlus::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL);
3871 $self->add (3, $row, new CFPlus::UI::Label text => $spell->{level}, @TOOLTIP_LVL);
3872 $self->add (4, $row, new CFPlus::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP);
3873 $self->add (5, $row, new CFPlus::UI::Label text => $spell->{damage}, @TOOLTIP_DMG);
3874 }
3875 });
3876}
3877
3878sub add_spell {
3879 my ($self, $spell) = @_;
3880
3881 $self->{spell}->{$spell->{name}} = $spell;
3882 $self->rebuild_spell_list;
3883}
3884
3885sub remove_spell {
3886 my ($self, $spell) = @_;
3887
3888 delete $self->{spell}->{$spell->{name}};
3889 $self->rebuild_spell_list;
3890}
3891
3892sub clear_spells {
3893 my ($self) = @_;
3894
3895 $self->{spell} = {};
3896 $self->rebuild_spell_list;
3897}
3898
3899#############################################################################
3900
3901package CFPlus::UI::Root; 3791package CFPlus::UI::Root;
3902 3792
3903our @ISA = CFPlus::UI::Container::; 3793our @ISA = CFPlus::UI::Container::;
3904 3794
3905use List::Util qw(min max); 3795use List::Util qw(min max);
3912 my $self = $class->SUPER::new ( 3802 my $self = $class->SUPER::new (
3913 visible => 1, 3803 visible => 1,
3914 @_, 3804 @_,
3915 ); 3805 );
3916 3806
3917 Scalar::Util::weaken ($self->{root} = $self); 3807 CFPlus::weaken ($self->{root} = $self);
3918 3808
3919 $self 3809 $self
3920} 3810}
3921 3811
3922sub size_request { 3812sub size_request {
4133 { 4023 {
4134 package CFPlus::UI::Base; 4024 package CFPlus::UI::Base;
4135 4025
4136 local ($draw_x, $draw_y, $draw_w, $draw_h) = 4026 local ($draw_x, $draw_y, $draw_w, $draw_h) =
4137 (0, 0, $self->{w}, $self->{h}); 4027 (0, 0, $self->{w}, $self->{h});
4138 }
4139 4028
4140 $self->_draw; 4029 $self->_draw;
4030 }
4141} 4031}
4142 4032
4143############################################################################# 4033#############################################################################
4144 4034
4145package CFPlus::UI; 4035package CFPlus::UI;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines