… | |
… | |
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->() |
… | |
… | |
315 | } |
315 | } |
316 | |
316 | |
317 | sub move_abs { |
317 | sub move_abs { |
318 | my ($self, $x, $y, $z) = @_; |
318 | my ($self, $x, $y, $z) = @_; |
319 | |
319 | |
320 | $self->{x} = List::Util::max 0, int $x; |
320 | $self->{x} = List::Util::max 0, List::Util::min $self->{root}{w} - $self->{w}, int $x; |
321 | $self->{y} = List::Util::max 0, int $y; |
321 | $self->{y} = List::Util::max 0, List::Util::min $self->{root}{h} - $self->{h}, int $y; |
322 | $self->{z} = $z if defined $z; |
322 | $self->{z} = $z if defined $z; |
323 | |
323 | |
324 | $self->update; |
324 | $self->update; |
325 | } |
325 | } |
326 | |
326 | |
… | |
… | |
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}; |
1095 | |
1094 | |
1096 | $self |
1095 | $self |
1097 | } |
1096 | } |
1098 | |
1097 | |
1099 | sub add { |
1098 | sub add { |
1100 | my ($self, @widgets) = @_; |
1099 | my ($self, @widgets) = @_; |
1101 | |
1100 | |
1102 | $self->SUPER::add (@widgets); |
1101 | $self->SUPER::add (@widgets); |
1103 | $self->CFClient::UI::Container::add ($self->{title}) if $self->{title}; |
1102 | $self->CFClient::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1104 | } |
1103 | } |
1105 | |
1104 | |
1106 | sub border { |
1105 | sub border { |
1107 | int $_[0]{border} * $::FONTSIZE |
1106 | int $_[0]{border} * $::FONTSIZE |
1108 | } |
1107 | } |
1109 | |
1108 | |
1110 | sub size_request { |
1109 | sub size_request { |
1111 | my ($self) = @_; |
1110 | my ($self) = @_; |
1112 | |
1111 | |
1113 | $self->{title}->size_request |
1112 | $self->{title_widget}->size_request |
1114 | if $self->{title}; |
1113 | if $self->{title_widget}; |
1115 | |
1114 | |
1116 | my ($w, $h) = $self->SUPER::size_request; |
1115 | my ($w, $h) = $self->SUPER::size_request; |
1117 | |
1116 | |
1118 | ( |
1117 | ( |
1119 | $w + $self->border * 2, |
1118 | $w + $self->border * 2, |
… | |
… | |
1122 | } |
1121 | } |
1123 | |
1122 | |
1124 | sub size_allocate { |
1123 | sub size_allocate { |
1125 | my ($self, $w, $h) = @_; |
1124 | my ($self, $w, $h) = @_; |
1126 | |
1125 | |
1127 | if ($self->{title}) { |
1126 | if ($self->{title_widget}) { |
1128 | $self->{title}{w} = $w; |
1127 | $self->{title_widget}{w} = $w; |
1129 | $self->{title}{h} = $h; |
1128 | $self->{title_widget}{h} = $h; |
1130 | $self->{title}->size_allocate ($w, $h); |
1129 | $self->{title_widget}->size_allocate ($w, $h); |
1131 | } |
1130 | } |
1132 | |
1131 | |
1133 | my $border = $self->border; |
1132 | my $border = $self->border; |
1134 | |
1133 | |
1135 | $h -= List::Util::max 0, $border * 2; |
1134 | $h -= List::Util::max 0, $border * 2; |
… | |
… | |
1233 | |
1232 | |
1234 | glDisable GL_TEXTURE_2D; |
1233 | glDisable GL_TEXTURE_2D; |
1235 | |
1234 | |
1236 | $child->draw; |
1235 | $child->draw; |
1237 | |
1236 | |
1238 | if ($self->{title}) { |
1237 | if ($self->{title_widget}) { |
1239 | glTranslate 0, $border - $self->{h}; |
1238 | glTranslate 0, $border - $self->{h}; |
1240 | $self->{title}->_draw; |
1239 | $self->{title_widget}->_draw; |
1241 | } |
1240 | } |
1242 | } |
1241 | } |
1243 | |
1242 | |
1244 | ############################################################################# |
1243 | ############################################################################# |
1245 | |
1244 | |
… | |
… | |
1269 | |
1268 | |
1270 | $child->set_parent ($self); |
1269 | $child->set_parent ($self); |
1271 | $self->{children}[$y][$x] = $child; |
1270 | $self->{children}[$y][$x] = $child; |
1272 | |
1271 | |
1273 | $self->realloc; |
1272 | $self->realloc; |
|
|
1273 | } |
|
|
1274 | |
|
|
1275 | sub remove { |
|
|
1276 | my ($self, $child) = @_; |
|
|
1277 | |
|
|
1278 | # TODO: not yet implemented |
1274 | } |
1279 | } |
1275 | |
1280 | |
1276 | # TODO: move to container class maybe? send children a signal on removal? |
1281 | # TODO: move to container class maybe? send children a signal on removal? |
1277 | sub clear { |
1282 | sub clear { |
1278 | my ($self) = @_; |
1283 | my ($self) = @_; |
… | |
… | |
1658 | : ($self->{h} - $tex->{h}) * 0.5); |
1663 | : ($self->{h} - $tex->{h}) * 0.5); |
1659 | }; |
1664 | }; |
1660 | |
1665 | |
1661 | glEnable GL_TEXTURE_2D; |
1666 | glEnable GL_TEXTURE_2D; |
1662 | |
1667 | |
|
|
1668 | my $w = List::Util::min $self->{w} + 4, $tex->{w}; |
|
|
1669 | my $h = List::Util::min $self->{h} + 2, $tex->{h}; |
|
|
1670 | |
1663 | if ($tex->{format} == GL_ALPHA) { |
1671 | if ($tex->{format} == GL_ALPHA) { |
1664 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1672 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1665 | glColor @{$self->{fg}}; |
1673 | glColor @{$self->{fg}}; |
1666 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
1674 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}, $w, $h); |
1667 | } else { |
1675 | } else { |
1668 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1676 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1669 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
1677 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}, $w, $h); |
1670 | } |
1678 | } |
1671 | |
1679 | |
1672 | glDisable GL_TEXTURE_2D; |
1680 | glDisable GL_TEXTURE_2D; |
1673 | } |
1681 | } |
1674 | |
1682 | |
… | |
… | |
2304 | sub set_range { |
2312 | sub set_range { |
2305 | my ($self, $range) = @_; |
2313 | my ($self, $range) = @_; |
2306 | |
2314 | |
2307 | ($range, $self->{range}) = ($self->{range}, $range); |
2315 | ($range, $self->{range}) = ($self->{range}, $range); |
2308 | |
2316 | |
2309 | $self->update |
|
|
2310 | if "@$range" ne "@{$self->{range}}"; |
2317 | if ("@$range" ne "@{$self->{range}}") { |
|
|
2318 | $self->update; |
|
|
2319 | $self->set_value ($self->{range}[0]); |
|
|
2320 | } |
2311 | } |
2321 | } |
2312 | |
2322 | |
2313 | sub set_value { |
2323 | sub set_value { |
2314 | my ($self, $value) = @_; |
2324 | my ($self, $value) = @_; |
2315 | |
2325 | |
… | |
… | |
2462 | sub set_range { shift->{slider}->set_range (@_) } |
2472 | sub set_range { shift->{slider}->set_range (@_) } |
2463 | sub set_value { shift->{slider}->set_value (@_) } |
2473 | sub set_value { shift->{slider}->set_value (@_) } |
2464 | |
2474 | |
2465 | ############################################################################# |
2475 | ############################################################################# |
2466 | |
2476 | |
2467 | package CFClient::UI::TextView; |
2477 | package CFClient::UI::TextScroller; |
2468 | |
2478 | |
2469 | our @ISA = CFClient::UI::HBox::; |
2479 | our @ISA = CFClient::UI::HBox::; |
2470 | |
2480 | |
2471 | use CFClient::OpenGL; |
2481 | use CFClient::OpenGL; |
2472 | |
2482 | |
… | |
… | |
2474 | my $class = shift; |
2484 | my $class = shift; |
2475 | |
2485 | |
2476 | my $self = $class->SUPER::new ( |
2486 | my $self = $class->SUPER::new ( |
2477 | fontsize => 1, |
2487 | fontsize => 1, |
2478 | can_events => 0, |
2488 | can_events => 0, |
|
|
2489 | indent => 0, |
2479 | #font => default_font |
2490 | #font => default_font |
2480 | @_, |
2491 | @_, |
2481 | |
2492 | |
2482 | layout => (new CFClient::Layout 1), |
2493 | layout => (new CFClient::Layout 1), |
2483 | par => [], |
2494 | par => [], |
… | |
… | |
2506 | $self->SUPER::size_allocate ($w, $h); |
2517 | $self->SUPER::size_allocate ($w, $h); |
2507 | |
2518 | |
2508 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
2519 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
2509 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2520 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2510 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2521 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2511 | $self->{layout}->set_indent (-$self->{fontsize} * $::FONTSIZE * 4); |
2522 | $self->{layout}->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
2512 | |
2523 | |
2513 | $self->reflow; |
2524 | $self->reflow; |
2514 | } |
2525 | } |
2515 | |
2526 | |
2516 | sub text_size { |
2527 | sub text_size { |
… | |
… | |
2518 | |
2529 | |
2519 | my $layout = $self->{layout}; |
2530 | my $layout = $self->{layout}; |
2520 | |
2531 | |
2521 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2532 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2522 | $layout->set_width ($self->{children}[0]{w} - $indent); |
2533 | $layout->set_width ($self->{children}[0]{w} - $indent); |
2523 | $layout->set_indent (-$self->{fontsize} * $::FONTSIZE * 4); |
2534 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
2524 | $layout->set_markup ($text); |
2535 | $layout->set_markup ($text); |
2525 | |
2536 | |
2526 | $layout->size |
2537 | $layout->size |
2527 | } |
2538 | } |
2528 | |
2539 | |
… | |
… | |
2567 | |
2578 | |
2568 | return unless $self->{h} > 0; |
2579 | return unless $self->{h} > 0; |
2569 | |
2580 | |
2570 | delete $self->{texture}; |
2581 | delete $self->{texture}; |
2571 | |
2582 | |
2572 | $ROOT->on_post_alloc ($self, sub { |
2583 | $ROOT->on_post_alloc ($self => sub { |
2573 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2584 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2574 | |
2585 | |
2575 | if (delete $self->{need_reflow}) { |
2586 | if (delete $self->{need_reflow}) { |
2576 | my $height = 0; |
2587 | my $height = 0; |
2577 | |
2588 | |
… | |
… | |
2580 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2591 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2581 | |
2592 | |
2582 | for (@{$self->{par}}) { |
2593 | for (@{$self->{par}}) { |
2583 | if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support |
2594 | if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support |
2584 | $layout->set_width ($W - $_->[3]); |
2595 | $layout->set_width ($W - $_->[3]); |
2585 | $layout->set_indent (-$self->{fontsize} * $::FONTSIZE * 4); |
2596 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
2586 | $layout->set_markup ($_->[4]); |
2597 | $layout->set_markup ($_->[4]); |
2587 | my ($w, $h) = $layout->size; |
2598 | my ($w, $h) = $layout->size; |
2588 | $_->[0] = $w + $_->[3]; |
2599 | $_->[0] = $w + $_->[3]; |
2589 | $_->[1] = $h; |
2600 | $_->[1] = $h; |
2590 | } |
2601 | } |
… | |
… | |
2593 | } |
2604 | } |
2594 | |
2605 | |
2595 | $self->{height} = $height; |
2606 | $self->{height} = $height; |
2596 | |
2607 | |
2597 | $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); |
2608 | $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); |
2598 | |
2609 | |
2599 | delete $self->{texture}; |
2610 | delete $self->{texture}; |
2600 | } |
2611 | } |
2601 | |
2612 | |
2602 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2613 | $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { |
2603 | glClearColor 0, 0, 0, 0; |
2614 | glClearColor 0, 0, 0, 0; |
… | |
… | |
2622 | my $h = $par->[1]; |
2633 | my $h = $par->[1]; |
2623 | |
2634 | |
2624 | if ($y0 < $y + $h && $y < $y1) { |
2635 | if ($y0 < $y + $h && $y < $y1) { |
2625 | $layout->set_foreground (@{ $par->[2] }); |
2636 | $layout->set_foreground (@{ $par->[2] }); |
2626 | $layout->set_width ($W - $par->[3]); |
2637 | $layout->set_width ($W - $par->[3]); |
2627 | $layout->set_indent (-$self->{fontsize} * $::FONTSIZE * 4); |
2638 | $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); |
2628 | $layout->set_markup ($par->[4]); |
2639 | $layout->set_markup ($par->[4]); |
2629 | |
2640 | |
2630 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
2641 | my ($w, $h, $data, $format, $internalformat) = $layout->render; |
2631 | |
2642 | |
2632 | glRasterPos $par->[3], $y - $y0; |
2643 | glRasterPos $par->[3], $y - $y0; |
… | |
… | |
2746 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2757 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
2747 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2758 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
2748 | . "req $widget->{req_w} $widget->{req_h}\n" |
2759 | . "req $widget->{req_w} $widget->{req_h}\n" |
2749 | . "visible $widget->{visible}"; |
2760 | . "visible $widget->{visible}"; |
2750 | } |
2761 | } |
|
|
2762 | |
|
|
2763 | $tooltip =~ s/^\n+//; |
|
|
2764 | $tooltip =~ s/\n+$//; |
2751 | |
2765 | |
2752 | $self->add (new CFClient::UI::Label |
2766 | $self->add (new CFClient::UI::Label |
2753 | markup => $tooltip, |
2767 | markup => $tooltip, |
2754 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2768 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2755 | fontsize => 0.8, |
2769 | fontsize => 0.8, |
… | |
… | |
2783 | or return; |
2797 | or return; |
2784 | |
2798 | |
2785 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
2799 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
2786 | |
2800 | |
2787 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
2801 | ($x, $y) = $widget->coord2global (-$self->{w}, 0) |
2788 | if $x + $self->{w} > $::WIDTH; |
2802 | if $x + $self->{w} > $self->{root}{w}; |
2789 | |
2803 | |
2790 | $self->move_abs ($x, $y); |
2804 | $self->move_abs ($x, $y); |
2791 | }); |
2805 | }); |
2792 | } |
2806 | } |
2793 | |
2807 | |
… | |
… | |
2888 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2902 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2889 | glDisable GL_TEXTURE_2D; |
2903 | glDisable GL_TEXTURE_2D; |
2890 | } |
2904 | } |
2891 | } |
2905 | } |
2892 | |
2906 | |
2893 | sub DESTROY { |
2907 | sub destroy { |
2894 | my ($self) = @_; |
2908 | my ($self) = @_; |
2895 | |
2909 | |
2896 | $self->{timer}->cancel |
2910 | $self->{timer}->cancel |
2897 | if $self->{timer}; |
2911 | if $self->{timer}; |
2898 | |
2912 | |
2899 | $self->SUPER::DESTROY; |
2913 | $self->SUPER::destroy; |
2900 | } |
2914 | } |
2901 | |
2915 | |
2902 | ############################################################################# |
2916 | ############################################################################# |
2903 | |
2917 | |
2904 | package CFClient::UI::Buttonbar; |
2918 | package CFClient::UI::Buttonbar; |
… | |
… | |
2932 | # handle various types of items, only text for now |
2946 | # handle various types of items, only text for now |
2933 | if (!ref $widget) { |
2947 | if (!ref $widget) { |
2934 | $widget = new CFClient::UI::Label |
2948 | $widget = new CFClient::UI::Label |
2935 | can_hover => 1, |
2949 | can_hover => 1, |
2936 | can_events => 1, |
2950 | can_events => 1, |
2937 | text => $widget, |
2951 | markup => $widget, |
2938 | tooltip => $tooltip |
2952 | tooltip => $tooltip |
2939 | } |
2953 | } |
2940 | |
2954 | |
2941 | $self->{item}{$widget} = $item; |
2955 | $self->{item}{$widget} = $item; |
2942 | |
2956 | |
… | |
… | |
3104 | |
3118 | |
3105 | sub new { |
3119 | sub new { |
3106 | my $class = shift; |
3120 | my $class = shift; |
3107 | |
3121 | |
3108 | my $self = $class->SUPER::new ( |
3122 | my $self = $class->SUPER::new ( |
3109 | options => [], # [title, value, tooltip], ... |
3123 | options => [], # [value, title, longdesc], ... |
3110 | value => undef, |
3124 | value => undef, |
3111 | @_, |
3125 | @_, |
3112 | ); |
3126 | ); |
3113 | |
3127 | |
3114 | $self->_set_value ($self->{value}); |
3128 | $self->_set_value ($self->{value}); |
… | |
… | |
3120 | my ($self, $ev) = @_; |
3134 | my ($self, $ev) = @_; |
3121 | |
3135 | |
3122 | my @menu_items; |
3136 | my @menu_items; |
3123 | |
3137 | |
3124 | for (@{ $self->{options} }) { |
3138 | for (@{ $self->{options} }) { |
3125 | my ($title, $value, $tooltip) = @$_; |
3139 | my ($value, $title, $tooltip) = @$_; |
3126 | |
3140 | |
3127 | push @menu_items, [$tooltip, sub { $self->set_value ($value) }]; |
3141 | push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }]; |
3128 | } |
3142 | } |
3129 | |
3143 | |
3130 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3144 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
3131 | } |
3145 | } |
3132 | |
3146 | |
3133 | sub _set_value { |
3147 | sub _set_value { |
3134 | my ($self, $value) = @_; |
3148 | my ($self, $value) = @_; |
3135 | |
3149 | |
3136 | my ($item) = grep $_->[1] eq $value, @{ $self->{options} } |
3150 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} } |
3137 | or return; |
3151 | or return; |
3138 | |
3152 | |
3139 | $self->{value} = $item->[1]; |
3153 | $self->{value} = $item->[0]; |
3140 | $self->set_markup ("$item->[0] ⇓"); |
3154 | $self->set_markup ("$item->[1] ⇓"); |
3141 | $self->set_tooltip ($item->[2]); |
3155 | $self->set_tooltip ($item->[2]); |
3142 | } |
3156 | } |
3143 | |
3157 | |
3144 | sub set_value { |
3158 | sub set_value { |
3145 | my ($self, $value) = @_; |
3159 | my ($self, $value) = @_; |
… | |
… | |
3254 | $item->{count}++; |
3268 | $item->{count}++; |
3255 | } else { |
3269 | } else { |
3256 | $item->{count} = 1; |
3270 | $item->{count} = 1; |
3257 | $item->{text} = $item->{tooltip} = $text; |
3271 | $item->{text} = $item->{tooltip} = $text; |
3258 | } |
3272 | } |
3259 | $item->{id} = ++$self->{id}; |
3273 | $item->{id} += 0.2;#d# |
3260 | $item->{timeout} = $timeout; |
3274 | $item->{timeout} = $timeout; |
3261 | delete $item->{label}; |
3275 | delete $item->{label}; |
3262 | } else { |
3276 | } else { |
3263 | $self->{item}{$group} = { |
3277 | $self->{item}{$group} = { |
3264 | id => ++$self->{id}, |
3278 | id => ++$self->{id}, |
… | |
… | |
3283 | |
3297 | |
3284 | $self->reorder; |
3298 | $self->reorder; |
3285 | $self->SUPER::reconfigure; |
3299 | $self->SUPER::reconfigure; |
3286 | } |
3300 | } |
3287 | |
3301 | |
3288 | sub DESTROY { |
3302 | sub destroy { |
3289 | my ($self) = @_; |
3303 | my ($self) = @_; |
3290 | |
3304 | |
3291 | $self->{timer}->cancel; |
3305 | $self->{timer}->cancel; |
3292 | |
3306 | |
3293 | $self->SUPER::DESTROY; |
3307 | $self->SUPER::destroy; |
3294 | } |
3308 | } |
3295 | |
3309 | |
3296 | ############################################################################# |
3310 | ############################################################################# |
3297 | |
3311 | |
3298 | package CFClient::UI::Inventory; |
3312 | package CFClient::UI::Inventory; |
… | |
… | |
3546 | commands => [], |
3560 | commands => [], |
3547 | @_, |
3561 | @_, |
3548 | ) |
3562 | ) |
3549 | } |
3563 | } |
3550 | |
3564 | |
|
|
3565 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>"; |
|
|
3566 | |
|
|
3567 | my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3568 | "<b>Name</b>. The name of the spell.$TOOLTIP_ALL"); |
|
|
3569 | my @TOOLTIP_SKILL = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3570 | "<b>Skill</b>. The skill (or magic school) required to be able to attempt casting this spell.$TOOLTIP_ALL"); |
3551 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3571 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3552 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell."); |
3572 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL"); |
3553 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3573 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3554 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation."); |
3574 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL"); |
3555 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3575 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3556 | "<b>Damage</b>. The amount of damage the spell deals when it hits."); |
3576 | "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL"); |
3557 | |
3577 | |
3558 | sub rebuild_spell_list { |
3578 | sub rebuild_spell_list { |
3559 | my ($self) = @_; |
3579 | my ($self) = @_; |
3560 | |
3580 | |
3561 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
3581 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
3562 | $self->clear; |
3582 | $self->clear; |
3563 | |
3583 | |
|
|
3584 | return unless $::CONN; |
|
|
3585 | |
3564 | $self->add (1, 0, new CFClient::UI::Label text => "Spell Name"); |
3586 | $self->add (1, 0, new CFClient::UI::Label text => "Spell Name", @TOOLTIP_NAME); |
|
|
3587 | $self->add (2, 0, new CFClient::UI::Label text => "Skill", @TOOLTIP_SKILL); |
3565 | $self->add (2, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
3588 | $self->add (3, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
3566 | $self->add (3, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
3589 | $self->add (4, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
3567 | $self->add (4, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
3590 | $self->add (5, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
3568 | |
3591 | |
3569 | my $row = 0; |
3592 | my $row = 0; |
3570 | |
3593 | |
3571 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
3594 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
3572 | my $spell = $self->{spell}{$_}; |
3595 | my $spell = $self->{spell}{$_}; |
3573 | |
3596 | |
3574 | $row++; |
3597 | $row++; |
|
|
3598 | |
|
|
3599 | my $spell_cb = sub { |
|
|
3600 | my ($widget, $ev) = @_; |
|
|
3601 | |
|
|
3602 | if ($ev->{button} == 1) { |
|
|
3603 | $::CONN->user_send ("cast $spell->{name}"); |
|
|
3604 | } elsif ($ev->{button} == 2) { |
|
|
3605 | $::CONN->user_send ("invoke $spell->{name}"); |
|
|
3606 | } elsif ($ev->{button} == 3) { |
|
|
3607 | (new CFClient::UI::Menu |
|
|
3608 | items => [ |
|
|
3609 | ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }], |
|
|
3610 | ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }], |
|
|
3611 | ], |
|
|
3612 | )->popup ($ev); |
|
|
3613 | } else { |
|
|
3614 | return 0; |
|
|
3615 | } |
|
|
3616 | |
|
|
3617 | 1 |
|
|
3618 | }; |
|
|
3619 | |
|
|
3620 | my $tooltip = "$spell->{message}$TOOLTIP_ALL"; |
|
|
3621 | |
|
|
3622 | #TODO: add path info to tooltip |
|
|
3623 | #$self->add (6, $row, new CFClient::UI::Label text => $spell->{path}); |
3575 | |
3624 | |
3576 | $self->add (0, $row, new CFClient::UI::Face |
3625 | $self->add (0, $row, new CFClient::UI::Face |
3577 | face => $spell->{face}, |
3626 | face => $spell->{face}, |
3578 | can_hover => 1, |
3627 | can_hover => 1, |
3579 | can_events => 1, |
3628 | can_events => 1, |
3580 | tooltip => $spell->{message}, |
3629 | tooltip => $tooltip, |
|
|
3630 | on_button_down => $spell_cb, |
3581 | ); |
3631 | ); |
3582 | |
3632 | |
3583 | $self->add (1, $row, new CFClient::UI::Label |
3633 | $self->add (1, $row, new CFClient::UI::Label |
3584 | expand => 1, |
3634 | expand => 1, |
3585 | text => $spell->{name}, |
3635 | text => $spell->{name}, |
3586 | can_hover => 1, |
3636 | can_hover => 1, |
3587 | can_events => 1, |
3637 | can_events => 1, |
3588 | tooltip => $spell->{message}, |
3638 | tooltip => $tooltip, |
|
|
3639 | on_button_down => $spell_cb, |
3589 | ); |
3640 | ); |
3590 | |
3641 | |
|
|
3642 | $self->add (2, $row, new CFClient::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL); |
3591 | $self->add (2, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
3643 | $self->add (3, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
3592 | $self->add (3, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
3644 | $self->add (4, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
3593 | $self->add (4, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
3645 | $self->add (5, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
3594 | |
|
|
3595 | # TODO: should be done via popup |
|
|
3596 | $self->add (5, $row, new CFClient::UI::Button |
|
|
3597 | text => "bind", |
|
|
3598 | tooltip => "bind spell readying (cast command) to key", |
|
|
3599 | on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }, |
|
|
3600 | ); |
|
|
3601 | } |
3646 | } |
3602 | }); |
3647 | }); |
3603 | } |
3648 | } |
3604 | |
3649 | |
3605 | sub add_spell { |
3650 | sub add_spell { |
… | |
… | |
3611 | |
3656 | |
3612 | sub remove_spell { |
3657 | sub remove_spell { |
3613 | my ($self, $spell) = @_; |
3658 | my ($self, $spell) = @_; |
3614 | |
3659 | |
3615 | delete $self->{spell}->{$spell->{name}}; |
3660 | delete $self->{spell}->{$spell->{name}}; |
|
|
3661 | $self->rebuild_spell_list; |
|
|
3662 | } |
|
|
3663 | |
|
|
3664 | sub clear_spells { |
|
|
3665 | my ($self) = @_; |
|
|
3666 | |
|
|
3667 | $self->{spell} = {}; |
3616 | $self->rebuild_spell_list; |
3668 | $self->rebuild_spell_list; |
3617 | } |
3669 | } |
3618 | |
3670 | |
3619 | ############################################################################# |
3671 | ############################################################################# |
3620 | |
3672 | |