… | |
… | |
272 | |
272 | |
273 | return unless $self->{visible}; |
273 | return unless $self->{visible}; |
274 | |
274 | |
275 | $_->set_invisible for $self->children; |
275 | $_->set_invisible for $self->children; |
276 | |
276 | |
|
|
277 | delete $self->{visible}; |
277 | delete $self->{root}; |
278 | delete $self->{root}; |
278 | delete $self->{visible}; |
|
|
279 | |
279 | |
280 | undef $GRAB if $GRAB == $self; |
280 | undef $GRAB if $GRAB == $self; |
281 | undef $HOVER if $HOVER == $self; |
281 | undef $HOVER if $HOVER == $self; |
282 | |
282 | |
283 | $CFClient::UI::TOOLTIP_WATCHER->cb->() |
283 | $CFClient::UI::TOOLTIP_WATCHER->cb->() |
… | |
… | |
593 | |
593 | |
594 | sub DESTROY { |
594 | sub DESTROY { |
595 | my ($self) = @_; |
595 | my ($self) = @_; |
596 | |
596 | |
597 | delete $WIDGET{$self+0}; |
597 | delete $WIDGET{$self+0}; |
598 | #$self->deactivate; |
598 | |
|
|
599 | eval { $self->destroy }; |
|
|
600 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
599 | } |
601 | } |
600 | |
602 | |
601 | ############################################################################# |
603 | ############################################################################# |
602 | |
604 | |
603 | package CFClient::UI::DrawBG; |
605 | package CFClient::UI::DrawBG; |
… | |
… | |
768 | } |
770 | } |
769 | |
771 | |
770 | sub add { |
772 | sub add { |
771 | my ($self, $child) = @_; |
773 | my ($self, $child) = @_; |
772 | |
774 | |
773 | $self->{children} = []; |
775 | $self->SUPER::remove ($_) for @{ $self->{children} }; |
774 | |
|
|
775 | $self->SUPER::add ($child); |
776 | $self->SUPER::add ($child); |
776 | } |
777 | } |
777 | |
778 | |
778 | sub remove { |
779 | sub remove { |
779 | my ($self, $widget) = @_; |
780 | my ($self, $widget) = @_; |
… | |
… | |
1071 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1072 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1072 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1073 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1073 | |
1074 | |
1074 | sub new { |
1075 | sub new { |
1075 | my ($class, %arg) = @_; |
1076 | my ($class, %arg) = @_; |
1076 | |
|
|
1077 | my $title = delete $arg{title}; |
|
|
1078 | |
1077 | |
1079 | my $self = $class->SUPER::new ( |
1078 | my $self = $class->SUPER::new ( |
1080 | bg => [1, 1, 1, 1], |
1079 | bg => [1, 1, 1, 1], |
1081 | border_bg => [1, 1, 1, 1], |
1080 | border_bg => [1, 1, 1, 1], |
1082 | border => 0.6, |
1081 | border => 0.6, |
… | |
… | |
1084 | min_w => 16, |
1083 | min_w => 16, |
1085 | min_h => 16, |
1084 | min_h => 16, |
1086 | %arg, |
1085 | %arg, |
1087 | ); |
1086 | ); |
1088 | |
1087 | |
1089 | $self->{title} = new CFClient::UI::Label |
1088 | $self->{title_widget} = new CFClient::UI::Label |
1090 | align => 0, |
1089 | align => 0, |
1091 | valign => 1, |
1090 | valign => 1, |
1092 | text => $title, |
1091 | text => $self->{title}, |
1093 | fontsize => $self->{border} |
1092 | fontsize => $self->{border}, |
1094 | if defined $title; |
1093 | if exists $self->{title}; |
|
|
1094 | |
|
|
1095 | unless ($self->{no_close_button}) { |
|
|
1096 | $self->{close_btn} = |
|
|
1097 | new CFClient::UI::ImageButton |
|
|
1098 | image => 'x1_close.png', |
|
|
1099 | on_activate => sub { $self->hide }; |
|
|
1100 | |
|
|
1101 | $self->CFClient::UI::Container::add ($self->{close_btn}); |
|
|
1102 | } |
1095 | |
1103 | |
1096 | $self |
1104 | $self |
1097 | } |
1105 | } |
1098 | |
1106 | |
1099 | sub add { |
1107 | sub add { |
1100 | my ($self, @widgets) = @_; |
1108 | my ($self, @widgets) = @_; |
1101 | |
1109 | |
1102 | $self->SUPER::add (@widgets); |
1110 | $self->SUPER::add (@widgets); |
|
|
1111 | $self->CFClient::UI::Container::add ($self->{close_btn}) if $self->{close_btn}; |
1103 | $self->CFClient::UI::Container::add ($self->{title}) if $self->{title}; |
1112 | $self->CFClient::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1104 | } |
1113 | } |
1105 | |
1114 | |
1106 | sub border { |
1115 | sub border { |
1107 | int $_[0]{border} * $::FONTSIZE |
1116 | int $_[0]{border} * $::FONTSIZE |
1108 | } |
1117 | } |
1109 | |
1118 | |
1110 | sub size_request { |
1119 | sub size_request { |
1111 | my ($self) = @_; |
1120 | my ($self) = @_; |
1112 | |
1121 | |
1113 | $self->{title}->size_request |
1122 | $self->{title_widget}->size_request |
1114 | if $self->{title}; |
1123 | if $self->{title_widget}; |
|
|
1124 | |
|
|
1125 | $self->{close_btn}->size_request |
|
|
1126 | if $self->{close_btn}; |
1115 | |
1127 | |
1116 | my ($w, $h) = $self->SUPER::size_request; |
1128 | my ($w, $h) = $self->SUPER::size_request; |
1117 | |
1129 | |
1118 | ( |
1130 | ( |
1119 | $w + $self->border * 2, |
1131 | $w + $self->border * 2, |
… | |
… | |
1122 | } |
1134 | } |
1123 | |
1135 | |
1124 | sub size_allocate { |
1136 | sub size_allocate { |
1125 | my ($self, $w, $h) = @_; |
1137 | my ($self, $w, $h) = @_; |
1126 | |
1138 | |
1127 | if ($self->{title}) { |
1139 | if ($self->{title_widget}) { |
1128 | $self->{title}{w} = $w; |
1140 | $self->{title_widget}{w} = $w; |
1129 | $self->{title}{h} = $h; |
1141 | $self->{title_widget}{h} = $h; |
1130 | $self->{title}->size_allocate ($w, $h); |
1142 | $self->{title_widget}->size_allocate ($w, $h); |
1131 | } |
1143 | } |
1132 | |
1144 | |
1133 | my $border = $self->border; |
1145 | my $border = $self->border; |
1134 | |
1146 | |
1135 | $h -= List::Util::max 0, $border * 2; |
1147 | $h -= List::Util::max 0, $border * 2; |
1136 | $w -= List::Util::max 0, $border * 2; |
1148 | $w -= List::Util::max 0, $border * 2; |
1137 | |
1149 | |
1138 | $self->child->configure ($border, $border, $w, $h); |
1150 | $self->child->configure ($border, $border, $w, $h); |
|
|
1151 | |
|
|
1152 | $self->{close_btn}->configure ($self->{w} - (2 * $border), 0, $border, $border) |
|
|
1153 | if $self->{close_btn}; |
1139 | } |
1154 | } |
1140 | |
1155 | |
1141 | sub button_down { |
1156 | sub button_down { |
1142 | my ($self, $ev, $x, $y) = @_; |
1157 | my ($self, $ev, $x, $y) = @_; |
1143 | |
1158 | |
… | |
… | |
1189 | } |
1204 | } |
1190 | |
1205 | |
1191 | sub button_up { |
1206 | sub button_up { |
1192 | my ($self, $ev, $x, $y) = @_; |
1207 | my ($self, $ev, $x, $y) = @_; |
1193 | |
1208 | |
|
|
1209 | $self->{close_btn}->button_up ($ev, $x, $y) |
|
|
1210 | if $self->{close_btn}; |
|
|
1211 | |
1194 | !!delete $self->{motion} |
1212 | !!delete $self->{motion} |
1195 | } |
1213 | } |
1196 | |
1214 | |
1197 | sub mouse_motion { |
1215 | sub mouse_motion { |
1198 | my ($self, $ev, $x, $y) = @_; |
1216 | my ($self, $ev, $x, $y) = @_; |
… | |
… | |
1233 | |
1251 | |
1234 | glDisable GL_TEXTURE_2D; |
1252 | glDisable GL_TEXTURE_2D; |
1235 | |
1253 | |
1236 | $child->draw; |
1254 | $child->draw; |
1237 | |
1255 | |
1238 | if ($self->{title}) { |
1256 | if ($self->{title_widget}) { |
1239 | glTranslate 0, $border - $self->{h}; |
1257 | glTranslate 0, $border - $self->{h}; |
1240 | $self->{title}->_draw; |
1258 | $self->{title_widget}->_draw; |
|
|
1259 | |
|
|
1260 | glTranslate 0, - ($border - $self->{h}); |
1241 | } |
1261 | } |
|
|
1262 | |
|
|
1263 | $self->{close_btn}->draw |
|
|
1264 | if $self->{close_btn}; |
1242 | } |
1265 | } |
1243 | |
1266 | |
1244 | ############################################################################# |
1267 | ############################################################################# |
1245 | |
1268 | |
1246 | package CFClient::UI::Table; |
1269 | package CFClient::UI::Table; |
… | |
… | |
1269 | |
1292 | |
1270 | $child->set_parent ($self); |
1293 | $child->set_parent ($self); |
1271 | $self->{children}[$y][$x] = $child; |
1294 | $self->{children}[$y][$x] = $child; |
1272 | |
1295 | |
1273 | $self->realloc; |
1296 | $self->realloc; |
|
|
1297 | } |
|
|
1298 | |
|
|
1299 | sub remove { |
|
|
1300 | my ($self, $child) = @_; |
|
|
1301 | |
|
|
1302 | # TODO: not yet implemented |
1274 | } |
1303 | } |
1275 | |
1304 | |
1276 | # TODO: move to container class maybe? send children a signal on removal? |
1305 | # TODO: move to container class maybe? send children a signal on removal? |
1277 | sub clear { |
1306 | sub clear { |
1278 | my ($self) = @_; |
1307 | my ($self) = @_; |
… | |
… | |
1955 | $self->SUPER::_draw; |
1984 | $self->SUPER::_draw; |
1956 | } |
1985 | } |
1957 | |
1986 | |
1958 | ############################################################################# |
1987 | ############################################################################# |
1959 | |
1988 | |
|
|
1989 | package CFClient::UI::ImageButton; |
|
|
1990 | |
|
|
1991 | our @ISA = CFClient::UI::Image::; |
|
|
1992 | |
|
|
1993 | use CFClient::OpenGL; |
|
|
1994 | |
|
|
1995 | my %textures; |
|
|
1996 | |
|
|
1997 | sub new { |
|
|
1998 | my $class = shift; |
|
|
1999 | |
|
|
2000 | my $self = $class->SUPER::new ( |
|
|
2001 | padding_x => 4, |
|
|
2002 | padding_y => 4, |
|
|
2003 | fg => [1, 1, 1], |
|
|
2004 | active_fg => [0, 0, 1], |
|
|
2005 | can_hover => 1, |
|
|
2006 | align => 0, |
|
|
2007 | valign => 0, |
|
|
2008 | can_events => 1, |
|
|
2009 | @_ |
|
|
2010 | ); |
|
|
2011 | } |
|
|
2012 | |
|
|
2013 | sub activate { } |
|
|
2014 | |
|
|
2015 | sub button_up { |
|
|
2016 | my ($self, $ev, $x, $y) = @_; |
|
|
2017 | |
|
|
2018 | $self->emit ("activate") |
|
|
2019 | if $x >= 0 && $x < $self->{w} |
|
|
2020 | && $y >= 0 && $y < $self->{h}; |
|
|
2021 | |
|
|
2022 | 1 |
|
|
2023 | } |
|
|
2024 | |
|
|
2025 | ############################################################################# |
|
|
2026 | |
1960 | package CFClient::UI::CheckBox; |
2027 | package CFClient::UI::CheckBox; |
1961 | |
2028 | |
1962 | our @ISA = CFClient::UI::DrawBG::; |
2029 | our @ISA = CFClient::UI::DrawBG::; |
1963 | |
2030 | |
1964 | my @tex = |
2031 | my @tex = |
… | |
… | |
2467 | sub set_range { shift->{slider}->set_range (@_) } |
2534 | sub set_range { shift->{slider}->set_range (@_) } |
2468 | sub set_value { shift->{slider}->set_value (@_) } |
2535 | sub set_value { shift->{slider}->set_value (@_) } |
2469 | |
2536 | |
2470 | ############################################################################# |
2537 | ############################################################################# |
2471 | |
2538 | |
2472 | package CFClient::UI::TextView; |
2539 | package CFClient::UI::TextScroller; |
2473 | |
2540 | |
2474 | our @ISA = CFClient::UI::HBox::; |
2541 | our @ISA = CFClient::UI::HBox::; |
2475 | |
2542 | |
2476 | use CFClient::OpenGL; |
2543 | use CFClient::OpenGL; |
2477 | |
2544 | |
… | |
… | |
2752 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2819 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2753 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2820 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2754 | . "req $widget->{req_w} $widget->{req_h}\n" |
2821 | . "req $widget->{req_w} $widget->{req_h}\n" |
2755 | . "visible $widget->{visible}"; |
2822 | . "visible $widget->{visible}"; |
2756 | } |
2823 | } |
|
|
2824 | |
|
|
2825 | $tooltip =~ s/^\n+//; |
|
|
2826 | $tooltip =~ s/\n+$//; |
2757 | |
2827 | |
2758 | $self->add (new CFClient::UI::Label |
2828 | $self->add (new CFClient::UI::Label |
2759 | markup => $tooltip, |
2829 | markup => $tooltip, |
2760 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2830 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2761 | fontsize => 0.8, |
2831 | fontsize => 0.8, |
… | |
… | |
2894 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2964 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2895 | glDisable GL_TEXTURE_2D; |
2965 | glDisable GL_TEXTURE_2D; |
2896 | } |
2966 | } |
2897 | } |
2967 | } |
2898 | |
2968 | |
2899 | sub DESTROY { |
2969 | sub destroy { |
2900 | my ($self) = @_; |
2970 | my ($self) = @_; |
2901 | |
2971 | |
2902 | $self->{timer}->cancel |
2972 | $self->{timer}->cancel |
2903 | if $self->{timer}; |
2973 | if $self->{timer}; |
2904 | |
2974 | |
2905 | $self->SUPER::DESTROY; |
2975 | $self->SUPER::destroy; |
2906 | } |
2976 | } |
2907 | |
2977 | |
2908 | ############################################################################# |
2978 | ############################################################################# |
2909 | |
2979 | |
2910 | package CFClient::UI::Buttonbar; |
2980 | package CFClient::UI::Buttonbar; |
… | |
… | |
2938 | # handle various types of items, only text for now |
3008 | # handle various types of items, only text for now |
2939 | if (!ref $widget) { |
3009 | if (!ref $widget) { |
2940 | $widget = new CFClient::UI::Label |
3010 | $widget = new CFClient::UI::Label |
2941 | can_hover => 1, |
3011 | can_hover => 1, |
2942 | can_events => 1, |
3012 | can_events => 1, |
2943 | text => $widget, |
3013 | markup => $widget, |
2944 | tooltip => $tooltip |
3014 | tooltip => $tooltip |
2945 | } |
3015 | } |
2946 | |
3016 | |
2947 | $self->{item}{$widget} = $item; |
3017 | $self->{item}{$widget} = $item; |
2948 | |
3018 | |
… | |
… | |
3110 | |
3180 | |
3111 | sub new { |
3181 | sub new { |
3112 | my $class = shift; |
3182 | my $class = shift; |
3113 | |
3183 | |
3114 | my $self = $class->SUPER::new ( |
3184 | my $self = $class->SUPER::new ( |
3115 | options => [], # [title, value, tooltip], ... |
3185 | options => [], # [value, title, longdesc], ... |
3116 | value => undef, |
3186 | value => undef, |
3117 | @_, |
3187 | @_, |
3118 | ); |
3188 | ); |
3119 | |
3189 | |
3120 | $self->_set_value ($self->{value}); |
3190 | $self->_set_value ($self->{value}); |
… | |
… | |
3126 | my ($self, $ev) = @_; |
3196 | my ($self, $ev) = @_; |
3127 | |
3197 | |
3128 | my @menu_items; |
3198 | my @menu_items; |
3129 | |
3199 | |
3130 | for (@{ $self->{options} }) { |
3200 | for (@{ $self->{options} }) { |
3131 | my ($title, $value, $tooltip) = @$_; |
3201 | my ($value, $title, $tooltip) = @$_; |
3132 | |
3202 | |
3133 | push @menu_items, [$tooltip, sub { $self->set_value ($value) }]; |
3203 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
3134 | } |
3204 | } |
3135 | |
3205 | |
3136 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3206 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3137 | } |
3207 | } |
3138 | |
3208 | |
3139 | sub _set_value { |
3209 | sub _set_value { |
3140 | my ($self, $value) = @_; |
3210 | my ($self, $value) = @_; |
3141 | |
3211 | |
3142 | my ($item) = grep $_->[1] eq $value, @{ $self->{options} } |
3212 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} } |
3143 | or return; |
3213 | or return; |
3144 | |
3214 | |
3145 | $self->{value} = $item->[1]; |
3215 | $self->{value} = $item->[0]; |
3146 | $self->set_markup ("$item->[0] ⇓"); |
3216 | $self->set_markup ("$item->[1] ⇓"); |
3147 | $self->set_tooltip ($item->[2]); |
3217 | $self->set_tooltip ($item->[2]); |
3148 | } |
3218 | } |
3149 | |
3219 | |
3150 | sub set_value { |
3220 | sub set_value { |
3151 | my ($self, $value) = @_; |
3221 | my ($self, $value) = @_; |
… | |
… | |
3260 | $item->{count}++; |
3330 | $item->{count}++; |
3261 | } else { |
3331 | } else { |
3262 | $item->{count} = 1; |
3332 | $item->{count} = 1; |
3263 | $item->{text} = $item->{tooltip} = $text; |
3333 | $item->{text} = $item->{tooltip} = $text; |
3264 | } |
3334 | } |
3265 | $item->{id} = ++$self->{id}; |
3335 | $item->{id} += 0.2;#d# |
3266 | $item->{timeout} = $timeout; |
3336 | $item->{timeout} = $timeout; |
3267 | delete $item->{label}; |
3337 | delete $item->{label}; |
3268 | } else { |
3338 | } else { |
3269 | $self->{item}{$group} = { |
3339 | $self->{item}{$group} = { |
3270 | id => ++$self->{id}, |
3340 | id => ++$self->{id}, |
… | |
… | |
3289 | |
3359 | |
3290 | $self->reorder; |
3360 | $self->reorder; |
3291 | $self->SUPER::reconfigure; |
3361 | $self->SUPER::reconfigure; |
3292 | } |
3362 | } |
3293 | |
3363 | |
3294 | sub DESTROY { |
3364 | sub destroy { |
3295 | my ($self) = @_; |
3365 | my ($self) = @_; |
3296 | |
3366 | |
3297 | $self->{timer}->cancel; |
3367 | $self->{timer}->cancel; |
3298 | |
3368 | |
3299 | $self->SUPER::DESTROY; |
3369 | $self->SUPER::destroy; |
3300 | } |
3370 | } |
3301 | |
3371 | |
3302 | ############################################################################# |
3372 | ############################################################################# |
3303 | |
3373 | |
3304 | package CFClient::UI::Inventory; |
3374 | package CFClient::UI::Inventory; |
… | |
… | |
3448 | my ($self) = @_; |
3518 | my ($self) = @_; |
3449 | $self->ask_for_bind (1); |
3519 | $self->ask_for_bind (1); |
3450 | } |
3520 | } |
3451 | |
3521 | |
3452 | sub ask_for_bind { |
3522 | sub ask_for_bind { |
3453 | my ($self, $commit) = @_; |
3523 | my ($self, $commit, $end_cb) = @_; |
3454 | |
3524 | |
3455 | CFClient::Binder::open_binding_dialog (sub { |
3525 | CFClient::Binder::open_binding_dialog (sub { |
3456 | my ($mod, $sym) = @_; |
3526 | my ($mod, $sym) = @_; |
3457 | $self->{binding} = [$mod, $sym]; # XXX: how to stop that memleak? |
3527 | $self->{binding} = [$mod, $sym]; # XXX: how to stop that memleak? |
3458 | $self->update_binding_widgets; |
3528 | $self->update_binding_widgets; |
3459 | $self->commit if $commit; |
3529 | $self->commit if $commit; |
|
|
3530 | $end_cb->() if $end_cb; |
3460 | }); |
3531 | }); |
3461 | } |
3532 | } |
3462 | |
3533 | |
3463 | # $mod and $sym are the modifiers and key symbol |
3534 | # $mod and $sym are the modifiers and key symbol |
3464 | # $cmds is a array ref of strings (the commands) |
3535 | # $cmds is a array ref of strings (the commands) |
… | |
… | |
3482 | } |
3553 | } |
3483 | |
3554 | |
3484 | # this is a shortcut method that asks for a binding |
3555 | # this is a shortcut method that asks for a binding |
3485 | # and then just binds it. |
3556 | # and then just binds it. |
3486 | sub do_quick_binding { |
3557 | sub do_quick_binding { |
3487 | my ($self, $cmds) = @_; |
3558 | my ($self, $cmds, $end_cb) = @_; |
3488 | $self->set_binding (undef, undef, $cmds, sub { |
3559 | $self->set_binding (undef, undef, $cmds, sub { |
3489 | $::CFG->{bindings}->{$_[0]}->{$_[1]} = $_[2]; |
3560 | $::CFG->{bindings}->{$_[0]}->{$_[1]} = $_[2]; |
3490 | }); |
3561 | }); |
3491 | $self->ask_for_bind (1); |
3562 | $self->ask_for_bind (1, $end_cb); |
3492 | } |
3563 | } |
3493 | |
3564 | |
3494 | sub update_binding_widgets { |
3565 | sub update_binding_widgets { |
3495 | my ($self) = @_; |
3566 | my ($self) = @_; |
3496 | my ($mod, $sym, $cmds) = $self->get_binding; |
3567 | my ($mod, $sym, $cmds) = $self->get_binding; |
… | |
… | |
3552 | commands => [], |
3623 | commands => [], |
3553 | @_, |
3624 | @_, |
3554 | ) |
3625 | ) |
3555 | } |
3626 | } |
3556 | |
3627 | |
|
|
3628 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>"; |
|
|
3629 | |
|
|
3630 | my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3631 | "<b>Name</b>. The name of the spell.$TOOLTIP_ALL"); |
|
|
3632 | my @TOOLTIP_SKILL = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3633 | "<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 => |
3634 | 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."); |
3635 | "<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 => |
3636 | 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."); |
3637 | "<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 => |
3638 | 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."); |
3639 | "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL"); |
3563 | |
3640 | |
3564 | sub rebuild_spell_list { |
3641 | sub rebuild_spell_list { |
3565 | my ($self) = @_; |
3642 | my ($self) = @_; |
3566 | |
3643 | |
3567 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
3644 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
3568 | $self->clear; |
3645 | $self->clear; |
3569 | |
3646 | |
|
|
3647 | return unless $::CONN; |
|
|
3648 | |
3570 | $self->add (1, 0, new CFClient::UI::Label text => "Spell Name"); |
3649 | $self->add (1, 0, new CFClient::UI::Label text => "Spell Name", @TOOLTIP_NAME); |
|
|
3650 | $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); |
3651 | $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); |
3652 | $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); |
3653 | $self->add (5, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
3574 | |
3654 | |
3575 | my $row = 0; |
3655 | my $row = 0; |
3576 | |
3656 | |
3577 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
3657 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
3578 | my $spell = $self->{spell}{$_}; |
3658 | my $spell = $self->{spell}{$_}; |
3579 | |
3659 | |
3580 | $row++; |
3660 | $row++; |
|
|
3661 | |
|
|
3662 | my $spell_cb = sub { |
|
|
3663 | my ($widget, $ev) = @_; |
|
|
3664 | |
|
|
3665 | if ($ev->{button} == 1) { |
|
|
3666 | $::CONN->user_send ("cast $spell->{name}"); |
|
|
3667 | } elsif ($ev->{button} == 2) { |
|
|
3668 | $::CONN->user_send ("invoke $spell->{name}"); |
|
|
3669 | } elsif ($ev->{button} == 3) { |
|
|
3670 | (new CFClient::UI::Menu |
|
|
3671 | items => [ |
|
|
3672 | ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], |
|
|
3673 | ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], |
|
|
3674 | ], |
|
|
3675 | )->popup ($ev); |
|
|
3676 | } else { |
|
|
3677 | return 0; |
|
|
3678 | } |
|
|
3679 | |
|
|
3680 | 1 |
|
|
3681 | }; |
|
|
3682 | |
|
|
3683 | my $tooltip = "$spell->{message}$TOOLTIP_ALL"; |
|
|
3684 | |
|
|
3685 | #TODO: add path info to tooltip |
|
|
3686 | #$self->add (6, $row, new CFClient::UI::Label text => $spell->{path}); |
3581 | |
3687 | |
3582 | $self->add (0, $row, new CFClient::UI::Face |
3688 | $self->add (0, $row, new CFClient::UI::Face |
3583 | face => $spell->{face}, |
3689 | face => $spell->{face}, |
3584 | can_hover => 1, |
3690 | can_hover => 1, |
3585 | can_events => 1, |
3691 | can_events => 1, |
3586 | tooltip => $spell->{message}, |
3692 | tooltip => $tooltip, |
|
|
3693 | on_button_down => $spell_cb, |
3587 | ); |
3694 | ); |
3588 | |
3695 | |
3589 | $self->add (1, $row, new CFClient::UI::Label |
3696 | $self->add (1, $row, new CFClient::UI::Label |
3590 | expand => 1, |
3697 | expand => 1, |
3591 | text => $spell->{name}, |
3698 | text => $spell->{name}, |
3592 | can_hover => 1, |
3699 | can_hover => 1, |
3593 | can_events => 1, |
3700 | can_events => 1, |
3594 | tooltip => $spell->{message}, |
3701 | tooltip => $tooltip, |
|
|
3702 | on_button_down => $spell_cb, |
3595 | ); |
3703 | ); |
3596 | |
3704 | |
|
|
3705 | $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); |
3706 | $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); |
3707 | $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); |
3708 | $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 | } |
3709 | } |
3608 | }); |
3710 | }); |
3609 | } |
3711 | } |
3610 | |
3712 | |
3611 | sub add_spell { |
3713 | sub add_spell { |
… | |
… | |
3617 | |
3719 | |
3618 | sub remove_spell { |
3720 | sub remove_spell { |
3619 | my ($self, $spell) = @_; |
3721 | my ($self, $spell) = @_; |
3620 | |
3722 | |
3621 | delete $self->{spell}->{$spell->{name}}; |
3723 | delete $self->{spell}->{$spell->{name}}; |
|
|
3724 | $self->rebuild_spell_list; |
|
|
3725 | } |
|
|
3726 | |
|
|
3727 | sub clear_spells { |
|
|
3728 | my ($self) = @_; |
|
|
3729 | |
|
|
3730 | $self->{spell} = {}; |
3622 | $self->rebuild_spell_list; |
3731 | $self->rebuild_spell_list; |
3623 | } |
3732 | } |
3624 | |
3733 | |
3625 | ############################################################################# |
3734 | ############################################################################# |
3626 | |
3735 | |