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

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.285 by root, Mon Jun 5 03:07:01 2006 UTC vs.
Revision 1.302 by root, Mon Jun 12 13:26:14 2006 UTC

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
317sub move_abs { 317sub 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
594sub DESTROY { 594sub 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
603package CFClient::UI::DrawBG; 605package CFClient::UI::DrawBG;
768} 770}
769 771
770sub add { 772sub 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
778sub remove { 779sub 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
1074sub new { 1075sub 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
1099sub add { 1098sub 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
1106sub border { 1105sub border {
1107 int $_[0]{border} * $::FONTSIZE 1106 int $_[0]{border} * $::FONTSIZE
1108} 1107}
1109 1108
1110sub size_request { 1109sub 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
1124sub size_allocate { 1123sub 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
1275sub 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?
1277sub clear { 1282sub clear {
1278 my ($self) = @_; 1283 my ($self) = @_;
1554 return if $self->{text} eq "T$text"; 1559 return if $self->{text} eq "T$text";
1555 $self->{text} = "T$text"; 1560 $self->{text} = "T$text";
1556 1561
1557 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; 1562 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba;
1558 $self->{layout}->set_text ($text); 1563 $self->{layout}->set_text ($text);
1564
1559 delete $self->{req_h}; 1565 delete $self->{size_req};
1560
1561 $self->realloc; 1566 $self->realloc;
1562 $self->update; 1567 $self->update;
1563} 1568}
1564 1569
1565sub set_markup { 1570sub set_markup {
1570 1575
1571 my $rgba = $markup =~ /span.*(?:foreground|background)/; 1576 my $rgba = $markup =~ /span.*(?:foreground|background)/;
1572 1577
1573 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; 1578 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba;
1574 $self->{layout}->set_markup ($markup); 1579 $self->{layout}->set_markup ($markup);
1580
1575 delete $self->{req_h}; 1581 delete $self->{size_req};
1576
1577 $self->realloc; 1582 $self->realloc;
1578 $self->update; 1583 $self->update;
1579} 1584}
1580 1585
1581sub size_request { 1586sub size_request {
1582 my ($self) = @_; 1587 my ($self) = @_;
1583 1588
1584 if (exists $self->{req_h}) { 1589 $self->{size_req} ||= do {
1585 @$self{qw(req_w req_h)}
1586 } else {
1587 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1590 $self->{layout}->set_font ($self->{font}) if $self->{font};
1588 $self->{layout}->set_width ($self->{max_w} || -1); 1591 $self->{layout}->set_width ($self->{max_w} || -1);
1589 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1592 $self->{layout}->set_ellipsise ($self->{ellipsise});
1590 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1593 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1591 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1594 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1600 1603
1601 $w = List::Util::max $w, $w2; 1604 $w = List::Util::max $w, $w2;
1602 $h = List::Util::max $h, $h2; 1605 $h = List::Util::max $h, $h2;
1603 } 1606 }
1604 1607
1605 ($w, $h) 1608 [$w, $h]
1606 } 1609 };
1610
1611 @{ $self->{size_req} }
1607} 1612}
1608 1613
1609sub size_allocate { 1614sub size_allocate {
1610 my ($self, $w, $h) = @_; 1615 my ($self, $w, $h) = @_;
1611 1616
1620 1625
1621 $self->{fontsize} = $fontsize; 1626 $self->{fontsize} = $fontsize;
1622 delete $self->{texture}; 1627 delete $self->{texture};
1623 1628
1624 $self->realloc; 1629 $self->realloc;
1630}
1631
1632sub reconfigure {
1633 my ($self) = @_;
1634
1635 delete $self->{size_req};
1636
1637 $self->SUPER::reconfigure;
1625} 1638}
1626 1639
1627sub _draw { 1640sub _draw {
1628 my ($self) = @_; 1641 my ($self) = @_;
1629 1642
1649 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} 1662 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y}
1650 : ($self->{h} - $tex->{h}) * 0.5); 1663 : ($self->{h} - $tex->{h}) * 0.5);
1651 }; 1664 };
1652 1665
1653 glEnable GL_TEXTURE_2D; 1666 glEnable GL_TEXTURE_2D;
1667
1668 my $w = List::Util::min $self->{w} + 4, $tex->{w};
1669 my $h = List::Util::min $self->{h} + 2, $tex->{h};
1670
1671 if ($tex->{format} == GL_ALPHA) {
1672 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1673 glColor @{$self->{fg}};
1674 $tex->draw_quad_alpha ($self->{ox}, $self->{oy}, $w, $h);
1675 } else {
1654 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1676 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1655
1656 glColor_premultiply @{$self->{fg}}
1657 if $tex->{format} == GL_ALPHA;
1658
1659 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); 1677 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}, $w, $h);
1678 }
1660 1679
1661 glDisable GL_TEXTURE_2D; 1680 glDisable GL_TEXTURE_2D;
1662} 1681}
1663 1682
1664############################################################################# 1683#############################################################################
1680 can_hover => 1, 1699 can_hover => 1,
1681 can_focus => 1, 1700 can_focus => 1,
1682 valign => 0, 1701 valign => 0,
1683 can_events => 1, 1702 can_events => 1,
1684 #text => ... 1703 #text => ...
1704 #hidden => "*",
1685 @_ 1705 @_
1686 ) 1706 )
1687} 1707}
1688 1708
1689sub _set_text { 1709sub _set_text {
1696 $self->{last_activity} = $::NOW; 1716 $self->{last_activity} = $::NOW;
1697 $self->{text} = $text; 1717 $self->{text} = $text;
1698 1718
1699 $text =~ s/./*/g if $self->{hidden}; 1719 $text =~ s/./*/g if $self->{hidden};
1700 $self->{layout}->set_text ("$text "); 1720 $self->{layout}->set_text ("$text ");
1701 delete $self->{req_h}; 1721 delete $self->{size_req};
1702 1722
1703 $self->_emit (changed => $self->{text}); 1723 $self->_emit (changed => $self->{text});
1704 1724
1705 $self->realloc; 1725 $self->realloc;
1706 $self->update; 1726 $self->update;
2292sub set_range { 2312sub set_range {
2293 my ($self, $range) = @_; 2313 my ($self, $range) = @_;
2294 2314
2295 ($range, $self->{range}) = ($self->{range}, $range); 2315 ($range, $self->{range}) = ($self->{range}, $range);
2296 2316
2297 $self->update
2298 if "@$range" ne "@{$self->{range}}"; 2317 if ("@$range" ne "@{$self->{range}}") {
2318 $self->update;
2319 $self->set_value ($self->{range}[0]);
2320 }
2299} 2321}
2300 2322
2301sub set_value { 2323sub set_value {
2302 my ($self, $value) = @_; 2324 my ($self, $value) = @_;
2303 2325
2450sub set_range { shift->{slider}->set_range (@_) } 2472sub set_range { shift->{slider}->set_range (@_) }
2451sub set_value { shift->{slider}->set_value (@_) } 2473sub set_value { shift->{slider}->set_value (@_) }
2452 2474
2453############################################################################# 2475#############################################################################
2454 2476
2455package CFClient::UI::TextView; 2477package CFClient::UI::TextScroller;
2456 2478
2457our @ISA = CFClient::UI::HBox::; 2479our @ISA = CFClient::UI::HBox::;
2458 2480
2459use CFClient::OpenGL; 2481use CFClient::OpenGL;
2460 2482
2462 my $class = shift; 2484 my $class = shift;
2463 2485
2464 my $self = $class->SUPER::new ( 2486 my $self = $class->SUPER::new (
2465 fontsize => 1, 2487 fontsize => 1,
2466 can_events => 0, 2488 can_events => 0,
2489 indent => 0,
2467 #font => default_font 2490 #font => default_font
2468 @_, 2491 @_,
2469 2492
2470 layout => (new CFClient::Layout 1), 2493 layout => (new CFClient::Layout 1),
2471 par => [], 2494 par => [],
2494 $self->SUPER::size_allocate ($w, $h); 2517 $self->SUPER::size_allocate ($w, $h);
2495 2518
2496 $self->{layout}->set_font ($self->{font}) if $self->{font}; 2519 $self->{layout}->set_font ($self->{font}) if $self->{font};
2497 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 2520 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2498 $self->{layout}->set_width ($self->{children}[0]{w}); 2521 $self->{layout}->set_width ($self->{children}[0]{w});
2522 $self->{layout}->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
2499 2523
2500 $self->reflow; 2524 $self->reflow;
2501} 2525}
2502 2526
2503sub text_size { 2527sub text_size {
2505 2529
2506 my $layout = $self->{layout}; 2530 my $layout = $self->{layout};
2507 2531
2508 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2532 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2509 $layout->set_width ($self->{children}[0]{w} - $indent); 2533 $layout->set_width ($self->{children}[0]{w} - $indent);
2534 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
2510 $layout->set_markup ($text); 2535 $layout->set_markup ($text);
2511 2536
2512 $layout->size 2537 $layout->size
2513} 2538}
2514 2539
2553 2578
2554 return unless $self->{h} > 0; 2579 return unless $self->{h} > 0;
2555 2580
2556 delete $self->{texture}; 2581 delete $self->{texture};
2557 2582
2558 $ROOT->on_post_alloc ($self, sub { 2583 $ROOT->on_post_alloc ($self => sub {
2559 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 2584 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2560 2585
2561 if (delete $self->{need_reflow}) { 2586 if (delete $self->{need_reflow}) {
2562 my $height = 0; 2587 my $height = 0;
2563 2588
2566 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2591 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2567 2592
2568 for (@{$self->{par}}) { 2593 for (@{$self->{par}}) {
2569 if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support 2594 if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support
2570 $layout->set_width ($W - $_->[3]); 2595 $layout->set_width ($W - $_->[3]);
2596 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
2571 $layout->set_markup ($_->[4]); 2597 $layout->set_markup ($_->[4]);
2572 my ($w, $h) = $layout->size; 2598 my ($w, $h) = $layout->size;
2573 $_->[0] = $w + $_->[3]; 2599 $_->[0] = $w + $_->[3];
2574 $_->[1] = $h; 2600 $_->[1] = $h;
2575 } 2601 }
2578 } 2604 }
2579 2605
2580 $self->{height} = $height; 2606 $self->{height} = $height;
2581 2607
2582 $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); 2608 $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]);
2583 2609
2584 delete $self->{texture}; 2610 delete $self->{texture};
2585 } 2611 }
2586 2612
2587 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { 2613 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub {
2588 glClearColor 0, 0, 0, 0; 2614 glClearColor 0, 0, 0, 0;
2607 my $h = $par->[1]; 2633 my $h = $par->[1];
2608 2634
2609 if ($y0 < $y + $h && $y < $y1) { 2635 if ($y0 < $y + $h && $y < $y1) {
2610 $layout->set_foreground (@{ $par->[2] }); 2636 $layout->set_foreground (@{ $par->[2] });
2611 $layout->set_width ($W - $par->[3]); 2637 $layout->set_width ($W - $par->[3]);
2638 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
2612 $layout->set_markup ($par->[4]); 2639 $layout->set_markup ($par->[4]);
2613 2640
2614 my ($w, $h, $data, $format, $internalformat) = $layout->render; 2641 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2615 2642
2616 glRasterPos $par->[3], $y - $y0; 2643 glRasterPos $par->[3], $y - $y0;
2730 $tooltip .= "\n\n" . (ref $widget) . "\n" 2757 $tooltip .= "\n\n" . (ref $widget) . "\n"
2731 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 2758 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
2732 . "req $widget->{req_w} $widget->{req_h}\n" 2759 . "req $widget->{req_w} $widget->{req_h}\n"
2733 . "visible $widget->{visible}"; 2760 . "visible $widget->{visible}";
2734 } 2761 }
2762
2763 $tooltip =~ s/^\n+//;
2764 $tooltip =~ s/\n+$//;
2735 2765
2736 $self->add (new CFClient::UI::Label 2766 $self->add (new CFClient::UI::Label
2737 markup => $tooltip, 2767 markup => $tooltip,
2738 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2768 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2739 fontsize => 0.8, 2769 fontsize => 0.8,
2767 or return; 2797 or return;
2768 2798
2769 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 2799 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2770 2800
2771 ($x, $y) = $widget->coord2global (-$self->{w}, 0) 2801 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2772 if $x + $self->{w} > $::WIDTH; 2802 if $x + $self->{w} > $self->{root}{w};
2773 2803
2774 $self->move_abs ($x, $y); 2804 $self->move_abs ($x, $y);
2775 }); 2805 });
2776} 2806}
2777 2807
2872 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2902 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2873 glDisable GL_TEXTURE_2D; 2903 glDisable GL_TEXTURE_2D;
2874 } 2904 }
2875} 2905}
2876 2906
2877sub DESTROY { 2907sub destroy {
2878 my ($self) = @_; 2908 my ($self) = @_;
2879 2909
2880 $self->{timer}->cancel 2910 $self->{timer}->cancel
2881 if $self->{timer}; 2911 if $self->{timer};
2882 2912
2883 $self->SUPER::DESTROY; 2913 $self->SUPER::destroy;
2884} 2914}
2885 2915
2886############################################################################# 2916#############################################################################
2887 2917
2888package CFClient::UI::Buttonbar; 2918package CFClient::UI::Buttonbar;
2909 ); 2939 );
2910 2940
2911 $self->add ($self->{vbox} = new CFClient::UI::VBox); 2941 $self->add ($self->{vbox} = new CFClient::UI::VBox);
2912 2942
2913 for my $item (@{ $self->{items} }) { 2943 for my $item (@{ $self->{items} }) {
2914 my ($widget, $cb) = @$item; 2944 my ($widget, $cb, $tooltip) = @$item;
2915 2945
2916 # handle various types of items, only text for now 2946 # handle various types of items, only text for now
2917 if (!ref $widget) { 2947 if (!ref $widget) {
2918 $widget = new CFClient::UI::Label 2948 $widget = new CFClient::UI::Label
2919 can_hover => 1, 2949 can_hover => 1,
2920 can_events => 1, 2950 can_events => 1,
2921 text => $widget; 2951 markup => $widget,
2952 tooltip => $tooltip
2922 } 2953 }
2923 2954
2924 $self->{item}{$widget} = $item; 2955 $self->{item}{$widget} = $item;
2925 2956
2926 $self->{vbox}->add ($widget); 2957 $self->{vbox}->add ($widget);
3073sub set_current_page { 3104sub set_current_page {
3074 my ($self, $page) = @_; 3105 my ($self, $page) = @_;
3075 3106
3076 $self->{multiplexer}->set_current_page ($page); 3107 $self->{multiplexer}->set_current_page ($page);
3077 $self->_emit (page_changed => $self->{multiplexer}{current}); 3108 $self->_emit (page_changed => $self->{multiplexer}{current});
3109}
3110
3111#############################################################################
3112
3113package CFClient::UI::Combobox;
3114
3115use utf8;
3116
3117our @ISA = CFClient::UI::Button::;
3118
3119sub new {
3120 my $class = shift;
3121
3122 my $self = $class->SUPER::new (
3123 options => [], # [value, title, longdesc], ...
3124 value => undef,
3125 @_,
3126 );
3127
3128 $self->_set_value ($self->{value});
3129
3130 $self
3131}
3132
3133sub button_down {
3134 my ($self, $ev) = @_;
3135
3136 my @menu_items;
3137
3138 for (@{ $self->{options} }) {
3139 my ($value, $title, $tooltip) = @$_;
3140
3141 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
3142 }
3143
3144 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
3145}
3146
3147sub _set_value {
3148 my ($self, $value) = @_;
3149
3150 my ($item) = grep $_->[0] eq $value, @{ $self->{options} }
3151 or return;
3152
3153 $self->{value} = $item->[0];
3154 $self->set_markup ("$item->[1] ⇓");
3155 $self->set_tooltip ($item->[2]);
3156}
3157
3158sub set_value {
3159 my ($self, $value) = @_;
3160
3161 return unless $self->{value} ne $value;
3162
3163 $self->_set_value ($value);
3164 $self->_emit (changed => $value);
3078} 3165}
3079 3166
3080############################################################################# 3167#############################################################################
3081 3168
3082package CFClient::UI::Statusbox; 3169package CFClient::UI::Statusbox;
3181 $item->{count}++; 3268 $item->{count}++;
3182 } else { 3269 } else {
3183 $item->{count} = 1; 3270 $item->{count} = 1;
3184 $item->{text} = $item->{tooltip} = $text; 3271 $item->{text} = $item->{tooltip} = $text;
3185 } 3272 }
3186 $item->{id} = ++$self->{id}; 3273 $item->{id} += 0.2;#d#
3187 $item->{timeout} = $timeout; 3274 $item->{timeout} = $timeout;
3188 delete $item->{label}; 3275 delete $item->{label};
3189 } else { 3276 } else {
3190 $self->{item}{$group} = { 3277 $self->{item}{$group} = {
3191 id => ++$self->{id}, 3278 id => ++$self->{id},
3210 3297
3211 $self->reorder; 3298 $self->reorder;
3212 $self->SUPER::reconfigure; 3299 $self->SUPER::reconfigure;
3213} 3300}
3214 3301
3215sub DESTROY { 3302sub destroy {
3216 my ($self) = @_; 3303 my ($self) = @_;
3217 3304
3218 $self->{timer}->cancel; 3305 $self->{timer}->cancel;
3219 3306
3220 $self->SUPER::DESTROY; 3307 $self->SUPER::destroy;
3221} 3308}
3222 3309
3223############################################################################# 3310#############################################################################
3224 3311
3225package CFClient::UI::Inventory; 3312package CFClient::UI::Inventory;
3473 commands => [], 3560 commands => [],
3474 @_, 3561 @_,
3475 ) 3562 )
3476} 3563}
3477 3564
3478# XXX: Do sorting? Argl... 3565my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>";
3566
3567my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip =>
3568 "<b>Name</b>. The name of the spell.$TOOLTIP_ALL");
3569my @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");
3571my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3572 "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL");
3573my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3574 "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL");
3575my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3576 "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL");
3577
3578sub rebuild_spell_list {
3579 my ($self) = @_;
3580
3581 $CFClient::UI::ROOT->on_refresh ($self => sub {
3582 $self->clear;
3583
3584 return unless $::CONN;
3585
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);
3588 $self->add (3, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL);
3589 $self->add (4, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP);
3590 $self->add (5, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG);
3591
3592 my $row = 0;
3593
3594 for (sort { $a cmp $b } keys %{ $self->{spell} }) {
3595 my $spell = $self->{spell}{$_};
3596
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});
3624
3625 $self->add (0, $row, new CFClient::UI::Face
3626 face => $spell->{face},
3627 can_hover => 1,
3628 can_events => 1,
3629 tooltip => $tooltip,
3630 on_button_down => $spell_cb,
3631 );
3632
3633 $self->add (1, $row, new CFClient::UI::Label
3634 expand => 1,
3635 text => $spell->{name},
3636 can_hover => 1,
3637 can_events => 1,
3638 tooltip => $tooltip,
3639 on_button_down => $spell_cb,
3640 );
3641
3642 $self->add (2, $row, new CFClient::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL);
3643 $self->add (3, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL);
3644 $self->add (4, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP);
3645 $self->add (5, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG);
3646 }
3647 });
3648}
3649
3479sub add_spell { 3650sub add_spell {
3480 my ($self, $spell) = @_; 3651 my ($self, $spell) = @_;
3652
3481 $self->{spells}->{$spell->{name}} = $spell; 3653 $self->{spell}->{$spell->{name}} = $spell;
3482 3654 $self->rebuild_spell_list;
3483 $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face
3484 face => $spell->{face},
3485 can_hover => 1,
3486 can_events => 1,
3487 tooltip => $spell->{message});
3488
3489 $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label
3490 text => $spell->{name},
3491 can_hover => 1,
3492 can_events => 1,
3493 tooltip => $spell->{message},
3494 expand => 1);
3495
3496 $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label
3497 text => (sprintf "lvl: %2d sp: %2d dmg: %2d",
3498 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}),
3499 expand => 1);
3500
3501 $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button
3502 text => "bind to key",
3503 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) });
3504}
3505
3506sub rebuild_spell_list {
3507 my ($self) = @_;
3508 $self->{tbl_idx} = 0;
3509 $self->add_spell ($_) for values %{$self->{spells}};
3510} 3655}
3511 3656
3512sub remove_spell { 3657sub remove_spell {
3513 my ($self, $spell) = @_; 3658 my ($self, $spell) = @_;
3659
3514 delete $self->{spells}->{$spell->{name}}; 3660 delete $self->{spell}->{$spell->{name}};
3661 $self->rebuild_spell_list;
3662}
3663
3664sub clear_spells {
3665 my ($self) = @_;
3666
3667 $self->{spell} = {};
3515 $self->rebuild_spell_list; 3668 $self->rebuild_spell_list;
3516} 3669}
3517 3670
3518############################################################################# 3671#############################################################################
3519 3672

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines