… | |
… | |
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 | |
… | |
… | |
1522 | } |
1523 | } |
1523 | |
1524 | |
1524 | sub size_allocate { |
1525 | sub size_allocate { |
1525 | my ($self, $w, $h) = @_; |
1526 | my ($self, $w, $h) = @_; |
1526 | |
1527 | |
1527 | delete $self->{texture}; |
1528 | delete $self->{texture} |
|
|
1529 | unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; |
1528 | } |
1530 | } |
1529 | |
1531 | |
1530 | sub set_fontsize { |
1532 | sub set_fontsize { |
1531 | my ($self, $fontsize) = @_; |
1533 | my ($self, $fontsize) = @_; |
1532 | |
1534 | |
… | |
… | |
2776 | |
2778 | |
2777 | $self->{timer}->cancel |
2779 | $self->{timer}->cancel |
2778 | if $self->{timer}; |
2780 | if $self->{timer}; |
2779 | |
2781 | |
2780 | $self->SUPER::DESTROY; |
2782 | $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 | } |
2783 | } |
2824 | |
2784 | |
2825 | ############################################################################# |
2785 | ############################################################################# |
2826 | |
2786 | |
2827 | package CFClient::UI::Menu; |
2787 | package CFClient::UI::Menu; |
… | |
… | |
3004 | $self->SUPER::reconfigure; |
2964 | $self->SUPER::reconfigure; |
3005 | } |
2965 | } |
3006 | |
2966 | |
3007 | ############################################################################# |
2967 | ############################################################################# |
3008 | |
2968 | |
|
|
2969 | package CFClient::UI::Inventory; |
|
|
2970 | |
|
|
2971 | our @ISA = CFClient::UI::ScrolledWindow::; |
|
|
2972 | |
|
|
2973 | sub new { |
|
|
2974 | my $class = shift; |
|
|
2975 | |
|
|
2976 | my $self = $class->SUPER::new ( |
|
|
2977 | scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
|
|
2978 | @_, |
|
|
2979 | ); |
|
|
2980 | |
|
|
2981 | $self |
|
|
2982 | } |
|
|
2983 | |
|
|
2984 | sub set_items { |
|
|
2985 | my ($self, $items) = @_; |
|
|
2986 | |
|
|
2987 | $self->{scrolled}->clear; |
|
|
2988 | return unless $items; |
|
|
2989 | |
|
|
2990 | my @items = sort { |
|
|
2991 | ($a->{type} <=> $b->{type}) |
|
|
2992 | or ($a->{name} cmp $b->{name}) |
|
|
2993 | } @$items; |
|
|
2994 | |
|
|
2995 | $self->{real_items} = \@items; |
|
|
2996 | |
|
|
2997 | my $row = 0; |
|
|
2998 | for my $item (@items) { |
|
|
2999 | CFClient::Item::update_widgets $item; |
|
|
3000 | |
|
|
3001 | $self->{scrolled}->add (0, $row, $item->{face_widget}); |
|
|
3002 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
|
|
3003 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
|
|
3004 | |
|
|
3005 | $row++; |
|
|
3006 | } |
|
|
3007 | } |
|
|
3008 | |
|
|
3009 | ############################################################################# |
|
|
3010 | |
|
|
3011 | package CFClient::UI::BindEditor; |
|
|
3012 | |
|
|
3013 | our @ISA = CFClient::UI::FancyFrame::; |
|
|
3014 | |
|
|
3015 | sub new { |
|
|
3016 | my $class = shift; |
|
|
3017 | |
|
|
3018 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
|
|
3019 | |
|
|
3020 | $self->add (my $vb = new CFClient::UI::VBox); |
|
|
3021 | |
|
|
3022 | |
|
|
3023 | $vb->add ($self->{rec_btn} = new CFClient::UI::Button |
|
|
3024 | text => "start recording", |
|
|
3025 | tooltip => "Start/Stops recording of actions." |
|
|
3026 | ."All subsequent actions after the recording started will be captured." |
|
|
3027 | ."The actions are displayed after the record was stopped." |
|
|
3028 | ."To bind the action you have to click on the 'Bind' button", |
|
|
3029 | on_activate => sub { |
|
|
3030 | unless ($self->{recording}) { |
|
|
3031 | $self->start; |
|
|
3032 | } else { |
|
|
3033 | $self->stop; |
|
|
3034 | } |
|
|
3035 | }); |
|
|
3036 | |
|
|
3037 | $vb->add (new CFClient::UI::Label text => "Actions:"); |
|
|
3038 | $vb->add ($self->{cmdbox} = new CFClient::UI::VBox); |
|
|
3039 | |
|
|
3040 | $vb->add (new CFClient::UI::Label text => "Bound to: "); |
|
|
3041 | $vb->add (my $hb = new CFClient::UI::HBox); |
|
|
3042 | $hb->add ($self->{keylbl} = new CFClient::UI::Label expand => 1); |
|
|
3043 | $hb->add (new CFClient::UI::Button |
|
|
3044 | text => "bind", |
|
|
3045 | tooltip => "This opens a query where you have to press the key combination to bind the recorded actions", |
|
|
3046 | on_activate => sub { |
|
|
3047 | $self->ask_for_bind; |
|
|
3048 | }); |
|
|
3049 | |
|
|
3050 | $vb->add (my $hb = new CFClient::UI::HBox); |
|
|
3051 | $hb->add (new CFClient::UI::Button |
|
|
3052 | text => "ok", |
|
|
3053 | expand => 1, |
|
|
3054 | tooltip => "This closes the binding editor and saves the binding", |
|
|
3055 | on_activate => sub { |
|
|
3056 | $self->hide; |
|
|
3057 | $self->commit; |
|
|
3058 | }); |
|
|
3059 | |
|
|
3060 | $hb->add (new CFClient::UI::Button |
|
|
3061 | text => "cancel", |
|
|
3062 | expand => 1, |
|
|
3063 | tooltip => "This closes the binding editor without saving", |
|
|
3064 | on_activate => sub { |
|
|
3065 | $self->hide; |
|
|
3066 | $self->{binding_cancel}->() |
|
|
3067 | if $self->{binding_cancel}; |
|
|
3068 | }); |
|
|
3069 | |
|
|
3070 | $self->update_binding_widgets; |
|
|
3071 | |
|
|
3072 | $self |
|
|
3073 | } |
|
|
3074 | |
|
|
3075 | sub commit { |
|
|
3076 | my ($self) = @_; |
|
|
3077 | my ($mod, $sym, $cmds) = $self->get_binding; |
|
|
3078 | if ($sym != 0 && @$cmds > 0) { |
|
|
3079 | $::STATUSBOX->add ("Bound actions to '".CFClient::Binder::keycombo_to_name ($mod, $sym) |
|
|
3080 | ."'. Don't forget 'Save Config'!"); |
|
|
3081 | $self->{binding_change}->($mod, $sym, $cmds) |
|
|
3082 | if $self->{binding_change}; |
|
|
3083 | } else { |
|
|
3084 | $::STATUSBOX->add ("No action bound, no key or action specified!"); |
|
|
3085 | $self->{binding_cancel}->() |
|
|
3086 | if $self->{binding_cancel}; |
|
|
3087 | } |
|
|
3088 | } |
|
|
3089 | |
|
|
3090 | sub start { |
|
|
3091 | my ($self) = @_; |
|
|
3092 | |
|
|
3093 | $self->{rec_btn}->set_text ("stop recording"); |
|
|
3094 | $self->{recording} = 1; |
|
|
3095 | $self->clear_command_list; |
|
|
3096 | $::CONN->start_record if $::CONN; |
|
|
3097 | } |
|
|
3098 | |
|
|
3099 | sub stop { |
|
|
3100 | my ($self) = @_; |
|
|
3101 | |
|
|
3102 | $self->{rec_btn}->set_text ("start recording"); |
|
|
3103 | $self->{recording} = 0; |
|
|
3104 | |
|
|
3105 | my $rec; |
|
|
3106 | $rec = $::CONN->stop_record if $::CONN; |
|
|
3107 | return unless ref $rec eq 'ARRAY'; |
|
|
3108 | $self->set_command_list ($rec); |
|
|
3109 | } |
|
|
3110 | |
|
|
3111 | # if $commit is true, the binding will be set after the user entered a key combo |
|
|
3112 | sub ask_for_bind { |
|
|
3113 | my ($self, $commit) = @_; |
|
|
3114 | |
|
|
3115 | CFClient::Binder::open_binding_dialog (sub { |
|
|
3116 | my ($mod, $sym) = @_; |
|
|
3117 | $self->{binding} = [$mod, $sym]; # XXX: how to stop that memleak? |
|
|
3118 | $self->update_binding_widgets; |
|
|
3119 | $self->commit if $commit; |
|
|
3120 | }); |
|
|
3121 | } |
|
|
3122 | |
|
|
3123 | # $mod and $sym are the modifiers and key symbol |
|
|
3124 | # $cmds is a array ref of strings (the commands) |
|
|
3125 | # $cb is the callback that is executed on OK |
|
|
3126 | # $ccb is the callback that is executed on CANCEL and |
|
|
3127 | # when the binding was unsuccessful on OK |
|
|
3128 | sub set_binding { |
|
|
3129 | my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_; |
|
|
3130 | |
|
|
3131 | $self->clear_command_list; |
|
|
3132 | $self->{recording} = 0; |
|
|
3133 | $self->{rec_btn}->set_text ("start recording"); |
|
|
3134 | |
|
|
3135 | $self->{binding} = [$mod, $sym]; |
|
|
3136 | $self->{commands} = $cmds; |
|
|
3137 | |
|
|
3138 | $self->{binding_change} = $cb; |
|
|
3139 | $self->{binding_cancel} = $ccb; |
|
|
3140 | |
|
|
3141 | $self->update_binding_widgets; |
|
|
3142 | } |
|
|
3143 | |
|
|
3144 | # this is a shortcut method that asks for a binding |
|
|
3145 | # and then just binds it. |
|
|
3146 | sub do_quick_binding { |
|
|
3147 | my ($self, $cmds) = @_; |
|
|
3148 | $self->set_binding (undef, undef, $cmds, sub { |
|
|
3149 | $::CFG->{bindings}->{$_[0]}->{$_[1]} = $_[2]; |
|
|
3150 | }); |
|
|
3151 | $self->ask_for_bind (1); |
|
|
3152 | } |
|
|
3153 | |
|
|
3154 | sub update_binding_widgets { |
|
|
3155 | my ($self) = @_; |
|
|
3156 | my ($mod, $sym, $cmds) = $self->get_binding; |
|
|
3157 | $self->{keylbl}->set_text (CFClient::Binder::keycombo_to_name ($mod, $sym)); |
|
|
3158 | $self->set_command_list ($cmds); |
|
|
3159 | } |
|
|
3160 | |
|
|
3161 | sub get_binding { |
|
|
3162 | my ($self) = @_; |
|
|
3163 | return ( |
|
|
3164 | $self->{binding}->[0], |
|
|
3165 | $self->{binding}->[1], |
|
|
3166 | [ grep { defined $_ } @{$self->{commands}} ] |
|
|
3167 | ); |
|
|
3168 | } |
|
|
3169 | |
|
|
3170 | sub clear_command_list { |
|
|
3171 | my ($self) = @_; |
|
|
3172 | $self->{cmdbox}->clear (); |
|
|
3173 | } |
|
|
3174 | |
|
|
3175 | sub set_command_list { |
|
|
3176 | my ($self, $cmds) = @_; |
|
|
3177 | |
|
|
3178 | $self->{cmdbox}->clear (); |
|
|
3179 | $self->{commands} = $cmds; |
|
|
3180 | |
|
|
3181 | my $idx = 0; |
|
|
3182 | |
|
|
3183 | for (@$cmds) { |
|
|
3184 | $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox); |
|
|
3185 | |
|
|
3186 | my $i = $idx; |
|
|
3187 | $hb->add (new CFClient::UI::Label text => $_); |
|
|
3188 | $hb->add (new CFClient::UI::Button |
|
|
3189 | text => "delete", |
|
|
3190 | tooltip => "Deletes the action from the record", |
|
|
3191 | on_activate => sub { |
|
|
3192 | $self->{cmdbox}->remove ($hb); |
|
|
3193 | $cmds->[$i] = undef; |
|
|
3194 | }); |
|
|
3195 | |
|
|
3196 | |
|
|
3197 | $idx++ |
|
|
3198 | } |
|
|
3199 | } |
|
|
3200 | |
|
|
3201 | ############################################################################# |
|
|
3202 | |
|
|
3203 | package CFClient::UI::SpellList; |
|
|
3204 | |
|
|
3205 | our @ISA = CFClient::UI::FancyFrame::; |
|
|
3206 | |
|
|
3207 | sub new { |
|
|
3208 | my $class = shift; |
|
|
3209 | |
|
|
3210 | my $self = $class->SUPER::new (binding => [], commands => [], @_); |
|
|
3211 | |
|
|
3212 | $self->add (new CFClient::UI::ScrolledWindow |
|
|
3213 | scrolled => $self->{spellbox} = new CFClient::UI::Table); |
|
|
3214 | |
|
|
3215 | $self; |
|
|
3216 | } |
|
|
3217 | |
|
|
3218 | # XXX: Do sorting? Argl... |
|
|
3219 | sub add_spell { |
|
|
3220 | my ($self, $spell) = @_; |
|
|
3221 | $self->{spells}->{$spell->{name}} = $spell; |
|
|
3222 | |
|
|
3223 | $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face |
|
|
3224 | face => $spell->{face}, |
|
|
3225 | can_hover => 1, |
|
|
3226 | can_events => 1, |
|
|
3227 | tooltip => $spell->{message}); |
|
|
3228 | |
|
|
3229 | $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label |
|
|
3230 | text => $spell->{name}, |
|
|
3231 | can_hover => 1, |
|
|
3232 | can_events => 1, |
|
|
3233 | tooltip => $spell->{message}, |
|
|
3234 | expand => 1); |
|
|
3235 | |
|
|
3236 | $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label |
|
|
3237 | text => (sprintf "lvl: %2d sp: %2d dmg: %2d", |
|
|
3238 | $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), |
|
|
3239 | expand => 1); |
|
|
3240 | |
|
|
3241 | $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button |
|
|
3242 | text => "bind to key", |
|
|
3243 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); |
|
|
3244 | } |
|
|
3245 | |
|
|
3246 | sub rebuild_spell_list { |
|
|
3247 | my ($self) = @_; |
|
|
3248 | $self->{tbl_idx} = 0; |
|
|
3249 | $self->add_spell ($_) for values %{$self->{spells}}; |
|
|
3250 | } |
|
|
3251 | |
|
|
3252 | sub remove_spell { |
|
|
3253 | my ($self, $spell) = @_; |
|
|
3254 | delete $self->{spells}->{$spell->{name}}; |
|
|
3255 | $self->rebuild_spell_list; |
|
|
3256 | } |
|
|
3257 | |
|
|
3258 | ############################################################################# |
|
|
3259 | |
3009 | package CFClient::UI::Root; |
3260 | package CFClient::UI::Root; |
3010 | |
3261 | |
3011 | our @ISA = CFClient::UI::Container::; |
3262 | our @ISA = CFClient::UI::Container::; |
3012 | |
3263 | |
3013 | use CFClient::OpenGL; |
3264 | use CFClient::OpenGL; |
… | |
… | |
3122 | $_->() |
3373 | $_->() |
3123 | for values %{delete $self->{refresh_hook}}; |
3374 | for values %{delete $self->{refresh_hook}}; |
3124 | } |
3375 | } |
3125 | |
3376 | |
3126 | if ($self->{realloc}) { |
3377 | if ($self->{realloc}) { |
|
|
3378 | my %queue; |
3127 | my @queue; |
3379 | my @queue; |
|
|
3380 | my $widget; |
3128 | |
3381 | |
|
|
3382 | outer: |
3129 | while () { |
3383 | while () { |
3130 | if ($self->{realloc}) { |
3384 | if (my $realloc = delete $self->{realloc}) { |
3131 | #TODO use array-of-depth approach |
3385 | for $widget (values %$realloc) { |
|
|
3386 | $widget->{visible} or next; # do not resize invisible widgets |
3132 | |
3387 | |
3133 | use sort 'stable'; |
3388 | $queue{$widget+0}++ and next; # duplicates are common |
3134 | |
3389 | |
3135 | @queue = sort { $a->{visible} <=> $b->{visible} } |
3390 | push @{ $queue[$widget->{visible}] }, $widget; |
3136 | @queue, values %{delete $self->{realloc}}; |
3391 | } |
3137 | } |
3392 | } |
3138 | |
3393 | |
|
|
3394 | while () { |
|
|
3395 | @queue or last outer; |
|
|
3396 | |
3139 | my $widget = pop @queue || last; |
3397 | $widget = pop @{ $queue[-1] || [] } |
|
|
3398 | and last; |
|
|
3399 | |
|
|
3400 | pop @queue; |
|
|
3401 | } |
3140 | |
3402 | |
3141 | $widget->{visible} or last; # do not resize invisible widgets |
3403 | delete $queue{$widget+0}; |
3142 | |
3404 | |
3143 | my ($w, $h) = $widget->size_request; |
3405 | my ($w, $h) = $widget->size_request; |
3144 | |
3406 | |
3145 | $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; |
3407 | $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; |
3408 | $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; |
… | |
… | |
3154 | $widget->{req_h} = $h; |
3416 | $widget->{req_h} = $h; |
3155 | |
3417 | |
3156 | $self->{size_alloc}{$widget+0} = $widget; |
3418 | $self->{size_alloc}{$widget+0} = $widget; |
3157 | |
3419 | |
3158 | if (my $parent = $widget->{parent}) { |
3420 | if (my $parent = $widget->{parent}) { |
3159 | $self->{realloc}{$parent+0} = $parent; |
3421 | $self->{realloc}{$parent+0} = $parent |
3160 | #unshift @queue, $parent; |
3422 | unless $queue{$parent+0}; |
|
|
3423 | |
3161 | $parent->{force_size_alloc} = 1; |
3424 | $parent->{force_size_alloc} = 1; |
3162 | $self->{size_alloc}{$parent+0} = $parent; |
3425 | $self->{size_alloc}{$parent+0} = $parent; |
3163 | } |
3426 | } |
3164 | } |
3427 | } |
3165 | |
3428 | |
… | |
… | |
3181 | |
3444 | |
3182 | $w = int $w + 0.5; |
3445 | $w = int $w + 0.5; |
3183 | $h = int $h + 0.5; |
3446 | $h = int $h + 0.5; |
3184 | |
3447 | |
3185 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
3448 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
|
|
3449 | $widget->{old_w} = $widget->{w}; |
|
|
3450 | $widget->{old_h} = $widget->{h}; |
|
|
3451 | |
3186 | $widget->{w} = $w; |
3452 | $widget->{w} = $w; |
3187 | $widget->{h} = $h; |
3453 | $widget->{h} = $h; |
3188 | |
3454 | |
3189 | $widget->emit (size_allocate => $w, $h); |
3455 | $widget->emit (size_allocate => $w, $h); |
3190 | } |
3456 | } |