… | |
… | |
40 | |
40 | |
41 | $LAYOUT = $layout; |
41 | $LAYOUT = $layout; |
42 | } |
42 | } |
43 | |
43 | |
44 | sub check_tooltip { |
44 | sub check_tooltip { |
|
|
45 | return if $ENV{CFPLUS_DEBUG} & 8; |
|
|
46 | |
45 | if (!$GRAB) { |
47 | if (!$GRAB) { |
46 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
48 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
47 | if (length $widget->{tooltip}) { |
49 | if (length $widget->{tooltip}) { |
48 | |
|
|
49 | if ($TOOLTIP->{owner} != $widget) { |
50 | if ($TOOLTIP->{owner} != $widget) { |
50 | $TOOLTIP->hide; |
51 | $TOOLTIP->hide; |
51 | |
52 | |
52 | $TOOLTIP->{owner} = $widget; |
53 | $TOOLTIP->{owner} = $widget; |
53 | |
54 | |
… | |
… | |
170 | sub rescale_widgets { |
171 | sub rescale_widgets { |
171 | my ($sx, $sy) = @_; |
172 | my ($sx, $sy) = @_; |
172 | |
173 | |
173 | for my $widget (values %WIDGET) { |
174 | for my $widget (values %WIDGET) { |
174 | if ($widget->{is_toplevel}) { |
175 | if ($widget->{is_toplevel}) { |
175 | $widget->{x} += $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
176 | $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
176 | $widget->{y} += $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
177 | $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
177 | |
178 | |
178 | $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; |
179 | $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; |
179 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
180 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
180 | $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w}; |
181 | $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w}; |
181 | $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/; |
182 | $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/; |
182 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
183 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
183 | $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h}; |
184 | $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h}; |
184 | |
185 | |
185 | $widget->{x} -= $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
186 | $widget->{x} -= int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
186 | $widget->{y} -= $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
187 | $widget->{y} -= int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
187 | |
188 | |
188 | } |
189 | } |
189 | } |
190 | } |
190 | |
191 | |
191 | reconfigure_widgets; |
192 | reconfigure_widgets; |
… | |
… | |
449 | my ($self, $ev, $x, $y) = @_; |
450 | my ($self, $ev, $x, $y) = @_; |
450 | |
451 | |
451 | $self->focus_in; |
452 | $self->focus_in; |
452 | } |
453 | } |
453 | |
454 | |
454 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
|
|
455 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
|
|
456 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
|
|
457 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
|
|
458 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
|
|
459 | |
|
|
460 | sub find_widget { |
455 | sub find_widget { |
461 | my ($self, $x, $y) = @_; |
456 | my ($self, $x, $y) = @_; |
462 | |
457 | |
463 | return () unless $self->{can_events}; |
458 | return () unless $self->{can_events}; |
464 | |
459 | |
… | |
… | |
525 | |
520 | |
526 | $self->realloc; |
521 | $self->realloc; |
527 | $self->update; |
522 | $self->update; |
528 | } |
523 | } |
529 | |
524 | |
|
|
525 | # using global variables seems a bit hacky, but passing through all drawing |
|
|
526 | # functions seems pointless. |
|
|
527 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
|
|
528 | |
530 | sub draw { |
529 | sub draw { |
531 | my ($self) = @_; |
530 | my ($self) = @_; |
532 | |
531 | |
533 | return unless $self->{h} && $self->{w}; |
532 | return unless $self->{h} && $self->{w}; |
|
|
533 | |
|
|
534 | # update screen rectangle |
|
|
535 | local $draw_x = $draw_x + $self->{x}; |
|
|
536 | local $draw_y = $draw_y + $self->{y}; |
|
|
537 | local $draw_w = $draw_x + $self->{w}; |
|
|
538 | local $draw_h = $draw_y + $self->{h}; |
|
|
539 | |
|
|
540 | # skip widgets that are entirely outside the drawing area |
|
|
541 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
|
|
542 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
534 | |
543 | |
535 | glPushMatrix; |
544 | glPushMatrix; |
536 | glTranslate $self->{x}, $self->{y}, 0; |
545 | glTranslate $self->{x}, $self->{y}, 0; |
537 | $self->_draw; |
546 | $self->_draw; |
538 | glPopMatrix; |
547 | glPopMatrix; |
… | |
… | |
803 | $self->SUPER::size_allocate ($w, $h); |
812 | $self->SUPER::size_allocate ($w, $h); |
804 | $self->update; |
813 | $self->update; |
805 | } |
814 | } |
806 | |
815 | |
807 | sub _render { |
816 | sub _render { |
|
|
817 | my ($self) = @_; |
|
|
818 | |
808 | $_[0]{children}[0]->draw; |
819 | $self->{children}[0]->draw; |
809 | } |
820 | } |
810 | |
821 | |
811 | sub render_child { |
822 | sub render_child { |
812 | my ($self) = @_; |
823 | my ($self) = @_; |
813 | |
824 | |
814 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
825 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
815 | glClearColor 0, 0, 0, 0; |
826 | glClearColor 0, 0, 0, 0; |
816 | glClear GL_COLOR_BUFFER_BIT; |
827 | glClear GL_COLOR_BUFFER_BIT; |
817 | |
828 | |
|
|
829 | { |
|
|
830 | package CFClient::UI::Base; |
|
|
831 | |
|
|
832 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
|
|
833 | (0, 0, $self->{w}, $self->{h}); |
|
|
834 | } |
|
|
835 | |
818 | $self->_render; |
836 | $self->_render; |
819 | }; |
837 | }; |
820 | } |
838 | } |
821 | |
839 | |
822 | sub _draw { |
840 | sub _draw { |
823 | my ($self) = @_; |
841 | my ($self) = @_; |
824 | |
842 | |
825 | my ($w, $h) = ($self->w, $self->h); |
843 | my ($w, $h) = @$self{qw(w h)}; |
826 | |
844 | |
827 | my $tex = $self->{texture} |
845 | my $tex = $self->{texture} |
828 | or return; |
846 | or return; |
829 | |
847 | |
830 | glEnable GL_TEXTURE_2D; |
848 | glEnable GL_TEXTURE_2D; |
… | |
… | |
912 | } |
930 | } |
913 | } |
931 | } |
914 | |
932 | |
915 | sub _render { |
933 | sub _render { |
916 | my ($self) = @_; |
934 | my ($self) = @_; |
|
|
935 | |
|
|
936 | local $CFClient::UI::Base::draw_x = $CFClient::UI::Base::draw_x - $self->{view_x}; |
|
|
937 | local $CFClient::UI::Base::draw_y = $CFClient::UI::Base::draw_y - $self->{view_y}; |
917 | |
938 | |
918 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
939 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
919 | |
940 | |
920 | $self->SUPER::_render; |
941 | $self->SUPER::_render; |
921 | } |
942 | } |
… | |
… | |
1522 | } |
1543 | } |
1523 | |
1544 | |
1524 | sub size_allocate { |
1545 | sub size_allocate { |
1525 | my ($self, $w, $h) = @_; |
1546 | my ($self, $w, $h) = @_; |
1526 | |
1547 | |
1527 | delete $self->{texture}; |
1548 | delete $self->{texture} |
|
|
1549 | unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; |
1528 | } |
1550 | } |
1529 | |
1551 | |
1530 | sub set_fontsize { |
1552 | sub set_fontsize { |
1531 | my ($self, $fontsize) = @_; |
1553 | my ($self, $fontsize) = @_; |
1532 | |
1554 | |
… | |
… | |
2776 | |
2798 | |
2777 | $self->{timer}->cancel |
2799 | $self->{timer}->cancel |
2778 | if $self->{timer}; |
2800 | if $self->{timer}; |
2779 | |
2801 | |
2780 | $self->SUPER::DESTROY; |
2802 | $self->SUPER::DESTROY; |
2781 | } |
|
|
2782 | |
|
|
2783 | ############################################################################# |
|
|
2784 | |
|
|
2785 | package CFClient::UI::Inventory; |
|
|
2786 | |
|
|
2787 | our @ISA = CFClient::UI::ScrolledWindow::; |
|
|
2788 | |
|
|
2789 | sub new { |
|
|
2790 | my $class = shift; |
|
|
2791 | |
|
|
2792 | my $self = $class->SUPER::new ( |
|
|
2793 | scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
|
|
2794 | @_, |
|
|
2795 | ); |
|
|
2796 | |
|
|
2797 | $self |
|
|
2798 | } |
|
|
2799 | |
|
|
2800 | sub set_items { |
|
|
2801 | my ($self, $items) = @_; |
|
|
2802 | |
|
|
2803 | $self->{scrolled}->clear; |
|
|
2804 | return unless $items; |
|
|
2805 | |
|
|
2806 | my @items = sort { |
|
|
2807 | ($a->{type} <=> $b->{type}) |
|
|
2808 | or ($a->{name} cmp $b->{name}) |
|
|
2809 | } @$items; |
|
|
2810 | |
|
|
2811 | $self->{real_items} = \@items; |
|
|
2812 | |
|
|
2813 | my $row = 0; |
|
|
2814 | for my $item (@items) { |
|
|
2815 | CFClient::Item::update_widgets $item; |
|
|
2816 | |
|
|
2817 | $self->{scrolled}->add (0, $row, $item->{face_widget}); |
|
|
2818 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
|
|
2819 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
|
|
2820 | |
|
|
2821 | $row++; |
|
|
2822 | } |
|
|
2823 | } |
2803 | } |
2824 | |
2804 | |
2825 | ############################################################################# |
2805 | ############################################################################# |
2826 | |
2806 | |
2827 | package CFClient::UI::Menu; |
2807 | package CFClient::UI::Menu; |
… | |
… | |
3004 | $self->SUPER::reconfigure; |
2984 | $self->SUPER::reconfigure; |
3005 | } |
2985 | } |
3006 | |
2986 | |
3007 | ############################################################################# |
2987 | ############################################################################# |
3008 | |
2988 | |
|
|
2989 | package CFClient::UI::Inventory; |
|
|
2990 | |
|
|
2991 | our @ISA = CFClient::UI::ScrolledWindow::; |
|
|
2992 | |
|
|
2993 | sub new { |
|
|
2994 | my $class = shift; |
|
|
2995 | |
|
|
2996 | my $self = $class->SUPER::new ( |
|
|
2997 | scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
|
|
2998 | @_, |
|
|
2999 | ); |
|
|
3000 | |
|
|
3001 | $self |
|
|
3002 | } |
|
|
3003 | |
|
|
3004 | sub set_items { |
|
|
3005 | my ($self, $items) = @_; |
|
|
3006 | |
|
|
3007 | $self->{scrolled}->clear; |
|
|
3008 | return unless $items; |
|
|
3009 | |
|
|
3010 | my @items = sort { |
|
|
3011 | ($a->{type} <=> $b->{type}) |
|
|
3012 | or ($a->{name} cmp $b->{name}) |
|
|
3013 | } @$items; |
|
|
3014 | |
|
|
3015 | $self->{real_items} = \@items; |
|
|
3016 | |
|
|
3017 | my $row = 0; |
|
|
3018 | for my $item (@items) { |
|
|
3019 | CFClient::Item::update_widgets $item; |
|
|
3020 | |
|
|
3021 | $self->{scrolled}->add (0, $row, $item->{face_widget}); |
|
|
3022 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
|
|
3023 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
|
|
3024 | |
|
|
3025 | $row++; |
|
|
3026 | } |
|
|
3027 | } |
|
|
3028 | |
|
|
3029 | ############################################################################# |
|
|
3030 | |
|
|
3031 | package CFClient::UI::BindEditor; |
|
|
3032 | |
|
|
3033 | our @ISA = CFClient::UI::FancyFrame::; |
|
|
3034 | |
|
|
3035 | sub new { |
|
|
3036 | my $class = shift; |
|
|
3037 | |
|
|
3038 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
|
|
3039 | |
|
|
3040 | $self->add (my $vb = new CFClient::UI::VBox); |
|
|
3041 | |
|
|
3042 | |
|
|
3043 | $vb->add ($self->{rec_btn} = new CFClient::UI::Button |
|
|
3044 | text => "start recording", |
|
|
3045 | tooltip => "Start/Stops recording of actions." |
|
|
3046 | ."All subsequent actions after the recording started will be captured." |
|
|
3047 | ."The actions are displayed after the record was stopped." |
|
|
3048 | ."To bind the action you have to click on the 'Bind' button", |
|
|
3049 | on_activate => sub { |
|
|
3050 | unless ($self->{recording}) { |
|
|
3051 | $self->start; |
|
|
3052 | } else { |
|
|
3053 | $self->stop; |
|
|
3054 | } |
|
|
3055 | }); |
|
|
3056 | |
|
|
3057 | $vb->add (new CFClient::UI::Label text => "Actions:"); |
|
|
3058 | $vb->add ($self->{cmdbox} = new CFClient::UI::VBox); |
|
|
3059 | |
|
|
3060 | $vb->add (new CFClient::UI::Label text => "Bound to: "); |
|
|
3061 | $vb->add (my $hb = new CFClient::UI::HBox); |
|
|
3062 | $hb->add ($self->{keylbl} = new CFClient::UI::Label expand => 1); |
|
|
3063 | $hb->add (new CFClient::UI::Button |
|
|
3064 | text => "bind", |
|
|
3065 | tooltip => "This opens a query where you have to press the key combination to bind the recorded actions", |
|
|
3066 | on_activate => sub { |
|
|
3067 | $self->ask_for_bind; |
|
|
3068 | }); |
|
|
3069 | |
|
|
3070 | $vb->add (my $hb = new CFClient::UI::HBox); |
|
|
3071 | $hb->add (new CFClient::UI::Button |
|
|
3072 | text => "ok", |
|
|
3073 | expand => 1, |
|
|
3074 | tooltip => "This closes the binding editor and saves the binding", |
|
|
3075 | on_activate => sub { |
|
|
3076 | $self->hide; |
|
|
3077 | $self->commit; |
|
|
3078 | }); |
|
|
3079 | |
|
|
3080 | $hb->add (new CFClient::UI::Button |
|
|
3081 | text => "cancel", |
|
|
3082 | expand => 1, |
|
|
3083 | tooltip => "This closes the binding editor without saving", |
|
|
3084 | on_activate => sub { |
|
|
3085 | $self->hide; |
|
|
3086 | $self->{binding_cancel}->() |
|
|
3087 | if $self->{binding_cancel}; |
|
|
3088 | }); |
|
|
3089 | |
|
|
3090 | $self->update_binding_widgets; |
|
|
3091 | |
|
|
3092 | $self |
|
|
3093 | } |
|
|
3094 | |
|
|
3095 | sub commit { |
|
|
3096 | my ($self) = @_; |
|
|
3097 | my ($mod, $sym, $cmds) = $self->get_binding; |
|
|
3098 | if ($sym != 0 && @$cmds > 0) { |
|
|
3099 | $::STATUSBOX->add ("Bound actions to '".CFClient::Binder::keycombo_to_name ($mod, $sym) |
|
|
3100 | ."'. Don't forget 'Save Config'!"); |
|
|
3101 | $self->{binding_change}->($mod, $sym, $cmds) |
|
|
3102 | if $self->{binding_change}; |
|
|
3103 | } else { |
|
|
3104 | $::STATUSBOX->add ("No action bound, no key or action specified!"); |
|
|
3105 | $self->{binding_cancel}->() |
|
|
3106 | if $self->{binding_cancel}; |
|
|
3107 | } |
|
|
3108 | } |
|
|
3109 | |
|
|
3110 | sub start { |
|
|
3111 | my ($self) = @_; |
|
|
3112 | |
|
|
3113 | $self->{rec_btn}->set_text ("stop recording"); |
|
|
3114 | $self->{recording} = 1; |
|
|
3115 | $self->clear_command_list; |
|
|
3116 | $::CONN->start_record if $::CONN; |
|
|
3117 | } |
|
|
3118 | |
|
|
3119 | sub stop { |
|
|
3120 | my ($self) = @_; |
|
|
3121 | |
|
|
3122 | $self->{rec_btn}->set_text ("start recording"); |
|
|
3123 | $self->{recording} = 0; |
|
|
3124 | |
|
|
3125 | my $rec; |
|
|
3126 | $rec = $::CONN->stop_record if $::CONN; |
|
|
3127 | return unless ref $rec eq 'ARRAY'; |
|
|
3128 | $self->set_command_list ($rec); |
|
|
3129 | } |
|
|
3130 | |
|
|
3131 | # if $commit is true, the binding will be set after the user entered a key combo |
|
|
3132 | sub ask_for_bind { |
|
|
3133 | my ($self, $commit) = @_; |
|
|
3134 | |
|
|
3135 | CFClient::Binder::open_binding_dialog (sub { |
|
|
3136 | my ($mod, $sym) = @_; |
|
|
3137 | $self->{binding} = [$mod, $sym]; # XXX: how to stop that memleak? |
|
|
3138 | $self->update_binding_widgets; |
|
|
3139 | $self->commit if $commit; |
|
|
3140 | }); |
|
|
3141 | } |
|
|
3142 | |
|
|
3143 | # $mod and $sym are the modifiers and key symbol |
|
|
3144 | # $cmds is a array ref of strings (the commands) |
|
|
3145 | # $cb is the callback that is executed on OK |
|
|
3146 | # $ccb is the callback that is executed on CANCEL and |
|
|
3147 | # when the binding was unsuccessful on OK |
|
|
3148 | sub set_binding { |
|
|
3149 | my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_; |
|
|
3150 | |
|
|
3151 | $self->clear_command_list; |
|
|
3152 | $self->{recording} = 0; |
|
|
3153 | $self->{rec_btn}->set_text ("start recording"); |
|
|
3154 | |
|
|
3155 | $self->{binding} = [$mod, $sym]; |
|
|
3156 | $self->{commands} = $cmds; |
|
|
3157 | |
|
|
3158 | $self->{binding_change} = $cb; |
|
|
3159 | $self->{binding_cancel} = $ccb; |
|
|
3160 | |
|
|
3161 | $self->update_binding_widgets; |
|
|
3162 | } |
|
|
3163 | |
|
|
3164 | # this is a shortcut method that asks for a binding |
|
|
3165 | # and then just binds it. |
|
|
3166 | sub do_quick_binding { |
|
|
3167 | my ($self, $cmds) = @_; |
|
|
3168 | $self->set_binding (undef, undef, $cmds, sub { |
|
|
3169 | $::CFG->{bindings}->{$_[0]}->{$_[1]} = $_[2]; |
|
|
3170 | }); |
|
|
3171 | $self->ask_for_bind (1); |
|
|
3172 | } |
|
|
3173 | |
|
|
3174 | sub update_binding_widgets { |
|
|
3175 | my ($self) = @_; |
|
|
3176 | my ($mod, $sym, $cmds) = $self->get_binding; |
|
|
3177 | $self->{keylbl}->set_text (CFClient::Binder::keycombo_to_name ($mod, $sym)); |
|
|
3178 | $self->set_command_list ($cmds); |
|
|
3179 | } |
|
|
3180 | |
|
|
3181 | sub get_binding { |
|
|
3182 | my ($self) = @_; |
|
|
3183 | return ( |
|
|
3184 | $self->{binding}->[0], |
|
|
3185 | $self->{binding}->[1], |
|
|
3186 | [ grep { defined $_ } @{$self->{commands}} ] |
|
|
3187 | ); |
|
|
3188 | } |
|
|
3189 | |
|
|
3190 | sub clear_command_list { |
|
|
3191 | my ($self) = @_; |
|
|
3192 | $self->{cmdbox}->clear (); |
|
|
3193 | } |
|
|
3194 | |
|
|
3195 | sub set_command_list { |
|
|
3196 | my ($self, $cmds) = @_; |
|
|
3197 | |
|
|
3198 | $self->{cmdbox}->clear (); |
|
|
3199 | $self->{commands} = $cmds; |
|
|
3200 | |
|
|
3201 | my $idx = 0; |
|
|
3202 | |
|
|
3203 | for (@$cmds) { |
|
|
3204 | $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox); |
|
|
3205 | |
|
|
3206 | my $i = $idx; |
|
|
3207 | $hb->add (new CFClient::UI::Label text => $_); |
|
|
3208 | $hb->add (new CFClient::UI::Button |
|
|
3209 | text => "delete", |
|
|
3210 | tooltip => "Deletes the action from the record", |
|
|
3211 | on_activate => sub { |
|
|
3212 | $self->{cmdbox}->remove ($hb); |
|
|
3213 | $cmds->[$i] = undef; |
|
|
3214 | }); |
|
|
3215 | |
|
|
3216 | |
|
|
3217 | $idx++ |
|
|
3218 | } |
|
|
3219 | } |
|
|
3220 | |
|
|
3221 | ############################################################################# |
|
|
3222 | |
|
|
3223 | package CFClient::UI::SpellList; |
|
|
3224 | |
|
|
3225 | our @ISA = CFClient::UI::FancyFrame::; |
|
|
3226 | |
|
|
3227 | sub new { |
|
|
3228 | my $class = shift; |
|
|
3229 | |
|
|
3230 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
|
|
3231 | |
|
|
3232 | $self->add (new CFClient::UI::ScrolledWindow |
|
|
3233 | scrolled => $self->{spellbox} = new CFClient::UI::Table); |
|
|
3234 | |
|
|
3235 | $self; |
|
|
3236 | } |
|
|
3237 | |
|
|
3238 | # XXX: Do sorting? Argl... |
|
|
3239 | sub add_spell { |
|
|
3240 | my ($self, $spell) = @_; |
|
|
3241 | $self->{spells}->{$spell->{name}} = $spell; |
|
|
3242 | |
|
|
3243 | $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
|
|
3244 | face => $spell->{face}, |
|
|
3245 | can_hover => 1, |
|
|
3246 | can_events => 1, |
|
|
3247 | tooltip => $spell->{message}); |
|
|
3248 | |
|
|
3249 | $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
|
|
3250 | text => $spell->{name}, |
|
|
3251 | can_hover => 1, |
|
|
3252 | can_events => 1, |
|
|
3253 | tooltip => $spell->{message}, |
|
|
3254 | expand => 1); |
|
|
3255 | |
|
|
3256 | $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
|
|
3257 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
|
|
3258 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
|
|
3259 | expand => 1); |
|
|
3260 | |
|
|
3261 | $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
|
|
3262 | text => "bind to key", |
|
|
3263 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
|
|
3264 | } |
|
|
3265 | |
|
|
3266 | sub rebuild_spell_list { |
|
|
3267 | my ($self) = @_; |
|
|
3268 | $self->{tbl_idx} = 0; |
|
|
3269 | $self->add_spell ($_) for values %{$self->{spells}}; |
|
|
3270 | } |
|
|
3271 | |
|
|
3272 | sub remove_spell { |
|
|
3273 | my ($self, $spell) = @_; |
|
|
3274 | delete $self->{spells}->{$spell->{name}}; |
|
|
3275 | $self->rebuild_spell_list; |
|
|
3276 | } |
|
|
3277 | |
|
|
3278 | ############################################################################# |
|
|
3279 | |
3009 | package CFClient::UI::Root; |
3280 | package CFClient::UI::Root; |
3010 | |
3281 | |
3011 | our @ISA = CFClient::UI::Container::; |
3282 | our @ISA = CFClient::UI::Container::; |
3012 | |
3283 | |
3013 | use CFClient::OpenGL; |
3284 | use CFClient::OpenGL; |
… | |
… | |
3122 | $_->() |
3393 | $_->() |
3123 | for values %{delete $self->{refresh_hook}}; |
3394 | for values %{delete $self->{refresh_hook}}; |
3124 | } |
3395 | } |
3125 | |
3396 | |
3126 | if ($self->{realloc}) { |
3397 | if ($self->{realloc}) { |
|
|
3398 | my %queue; |
3127 | my @queue; |
3399 | my @queue; |
|
|
3400 | my $widget; |
3128 | |
3401 | |
|
|
3402 | outer: |
3129 | while () { |
3403 | while () { |
3130 | if ($self->{realloc}) { |
3404 | if (my $realloc = delete $self->{realloc}) { |
3131 | #TODO use array-of-depth approach |
3405 | for $widget (values %$realloc) { |
|
|
3406 | $widget->{visible} or next; # do not resize invisible widgets |
3132 | |
3407 | |
3133 | use sort 'stable'; |
3408 | $queue{$widget+0}++ and next; # duplicates are common |
3134 | |
3409 | |
3135 | @queue = sort { $a->{visible} <=> $b->{visible} } |
3410 | push @{ $queue[$widget->{visible}] }, $widget; |
3136 | @queue, values %{delete $self->{realloc}}; |
3411 | } |
3137 | } |
3412 | } |
3138 | |
3413 | |
|
|
3414 | while () { |
|
|
3415 | @queue or last outer; |
|
|
3416 | |
3139 | my $widget = pop @queue || last; |
3417 | $widget = pop @{ $queue[-1] || [] } |
|
|
3418 | and last; |
|
|
3419 | |
|
|
3420 | pop @queue; |
|
|
3421 | } |
3140 | |
3422 | |
3141 | $widget->{visible} or last; # do not resize invisible widgets |
3423 | delete $queue{$widget+0}; |
3142 | |
3424 | |
3143 | my ($w, $h) = $widget->size_request; |
3425 | my ($w, $h) = $widget->size_request; |
3144 | |
3426 | |
3145 | $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
3427 | $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
3146 | $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; |
3428 | $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; |
… | |
… | |
3154 | $widget->{req_h} = $h; |
3436 | $widget->{req_h} = $h; |
3155 | |
3437 | |
3156 | $self->{size_alloc}{$widget+0} = $widget; |
3438 | $self->{size_alloc}{$widget+0} = $widget; |
3157 | |
3439 | |
3158 | if (my $parent = $widget->{parent}) { |
3440 | if (my $parent = $widget->{parent}) { |
3159 | $self->{realloc}{$parent+0} = $parent; |
3441 | $self->{realloc}{$parent+0} = $parent |
3160 | #unshift @queue, $parent; |
3442 | unless $queue{$parent+0}; |
|
|
3443 | |
3161 | $parent->{force_size_alloc} = 1; |
3444 | $parent->{force_size_alloc} = 1; |
3162 | $self->{size_alloc}{$parent+0} = $parent; |
3445 | $self->{size_alloc}{$parent+0} = $parent; |
3163 | } |
3446 | } |
3164 | } |
3447 | } |
3165 | |
3448 | |
… | |
… | |
3181 | |
3464 | |
3182 | $w = int $w + 0.5; |
3465 | $w = int $w + 0.5; |
3183 | $h = int $h + 0.5; |
3466 | $h = int $h + 0.5; |
3184 | |
3467 | |
3185 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
3468 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
|
|
3469 | $widget->{old_w} = $widget->{w}; |
|
|
3470 | $widget->{old_h} = $widget->{h}; |
|
|
3471 | |
3186 | $widget->{w} = $w; |
3472 | $widget->{w} = $w; |
3187 | $widget->{h} = $h; |
3473 | $widget->{h} = $h; |
3188 | |
3474 | |
3189 | $widget->emit (size_allocate => $w, $h); |
3475 | $widget->emit (size_allocate => $w, $h); |
3190 | } |
3476 | } |
… | |
… | |
3205 | glLoadIdentity; |
3491 | glLoadIdentity; |
3206 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
3492 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
3207 | glMatrixMode GL_MODELVIEW; |
3493 | glMatrixMode GL_MODELVIEW; |
3208 | glLoadIdentity; |
3494 | glLoadIdentity; |
3209 | |
3495 | |
|
|
3496 | { |
|
|
3497 | package CFClient::UI::Base; |
|
|
3498 | |
|
|
3499 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
|
|
3500 | (0, 0, $self->{w}, $self->{h}); |
|
|
3501 | } |
|
|
3502 | |
3210 | $self->_draw; |
3503 | $self->_draw; |
3211 | } |
3504 | } |
3212 | |
3505 | |
3213 | ############################################################################# |
3506 | ############################################################################# |
3214 | |
3507 | |