… | |
… | |
280 | sub set_max_size { |
280 | sub set_max_size { |
281 | my ($self, $w, $h) = @_; |
281 | my ($self, $w, $h) = @_; |
282 | |
282 | |
283 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
283 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
284 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
284 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
|
|
285 | } |
|
|
286 | |
|
|
287 | sub set_tooltip { |
|
|
288 | my ($self, $tooltip) = @_; |
|
|
289 | |
|
|
290 | $self->{tooltip} = $tooltip; |
|
|
291 | |
|
|
292 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
|
|
293 | delete $CFClient::UI::TOOLTIP->{owner}; |
|
|
294 | CFClient::UI::check_tooltip; |
|
|
295 | } |
285 | } |
296 | } |
286 | |
297 | |
287 | # translate global coordinates to local coordinate system |
298 | # translate global coordinates to local coordinate system |
288 | sub coord2local { |
299 | sub coord2local { |
289 | my ($self, $x, $y) = @_; |
300 | my ($self, $x, $y) = @_; |
… | |
… | |
455 | my $class = shift; |
466 | my $class = shift; |
456 | |
467 | |
457 | # range [value, low, high, page] |
468 | # range [value, low, high, page] |
458 | |
469 | |
459 | $class->SUPER::new ( |
470 | $class->SUPER::new ( |
460 | bg => [0, 0, 0, 0.2], |
471 | #bg => [0, 0, 0, 0.2], |
461 | active_bg => [1, 1, 1, 0.5], |
472 | #active_bg => [1, 1, 1, 0.5], |
462 | @_ |
473 | @_ |
463 | ) |
474 | ) |
464 | } |
475 | } |
465 | |
476 | |
466 | sub _draw { |
477 | sub _draw { |
467 | my ($self) = @_; |
478 | my ($self) = @_; |
468 | |
479 | |
|
|
480 | my $color = $FOCUS == $self && $self->{active_bg} |
|
|
481 | ? $self->{active_bg} |
|
|
482 | : $self->{bg}; |
|
|
483 | |
|
|
484 | if ($color && (@$color < 4 || $color->[3])) { |
469 | my ($w, $h) = @$self{qw(w h)}; |
485 | my ($w, $h) = @$self{qw(w h)}; |
470 | |
486 | |
471 | glEnable GL_BLEND; |
487 | glEnable GL_BLEND; |
472 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
488 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
473 | glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; |
489 | glColor @$color; |
474 | |
490 | |
475 | glBegin GL_QUADS; |
491 | glBegin GL_QUADS; |
476 | glVertex 0 , 0; |
492 | glVertex 0 , 0; |
477 | glVertex 0 , $h; |
493 | glVertex 0 , $h; |
478 | glVertex $w, $h; |
494 | glVertex $w, $h; |
479 | glVertex $w, 0; |
495 | glVertex $w, 0; |
480 | glEnd; |
496 | glEnd; |
481 | |
497 | |
482 | glDisable GL_BLEND; |
498 | glDisable GL_BLEND; |
|
|
499 | } |
483 | } |
500 | } |
484 | |
501 | |
485 | ############################################################################# |
502 | ############################################################################# |
486 | |
503 | |
487 | package CFClient::UI::Empty; |
504 | package CFClient::UI::Empty; |
… | |
… | |
1266 | |
1283 | |
1267 | ############################################################################# |
1284 | ############################################################################# |
1268 | |
1285 | |
1269 | package CFClient::UI::Label; |
1286 | package CFClient::UI::Label; |
1270 | |
1287 | |
1271 | our @ISA = CFClient::UI::Base::; |
1288 | our @ISA = CFClient::UI::DrawBG::; |
1272 | |
1289 | |
1273 | use CFClient::OpenGL; |
1290 | use CFClient::OpenGL; |
1274 | |
1291 | |
1275 | sub new { |
1292 | sub new { |
1276 | my ($class, %arg) = @_; |
1293 | my ($class, %arg) = @_; |
1277 | |
1294 | |
1278 | my $self = $class->SUPER::new ( |
1295 | my $self = $class->SUPER::new ( |
1279 | fg => [1, 1, 1], |
1296 | fg => [1, 1, 1], |
|
|
1297 | #bg => none |
|
|
1298 | #active_bg => none |
1280 | #font => default_font |
1299 | #font => default_font |
1281 | #text => initial text |
1300 | #text => initial text |
1282 | #markup => initial narkup |
1301 | #markup => initial narkup |
1283 | layout => (new CFClient::Layout), |
1302 | layout => (new CFClient::Layout), |
1284 | fontsize => 1, |
1303 | fontsize => 1, |
… | |
… | |
1302 | } |
1321 | } |
1303 | |
1322 | |
1304 | $self |
1323 | $self |
1305 | } |
1324 | } |
1306 | |
1325 | |
1307 | sub escape { |
1326 | sub escape($) { |
1308 | local $_ = $_[1]; |
1327 | local $_ = $_[0]; |
1309 | |
1328 | |
1310 | s/&/&/g; |
1329 | s/&/&/g; |
1311 | s/>/>/g; |
1330 | s/>/>/g; |
1312 | s/</</g; |
1331 | s/</</g; |
1313 | |
1332 | |
1314 | $_[1] |
1333 | $_ |
1315 | } |
1334 | } |
1316 | |
1335 | |
1317 | sub update { |
1336 | sub update { |
1318 | my ($self) = @_; |
1337 | my ($self) = @_; |
1319 | |
1338 | |
… | |
… | |
1390 | $self->check_size; |
1409 | $self->check_size; |
1391 | } |
1410 | } |
1392 | |
1411 | |
1393 | sub _draw { |
1412 | sub _draw { |
1394 | my ($self) = @_; |
1413 | my ($self) = @_; |
|
|
1414 | |
|
|
1415 | $self->SUPER::_draw; # draw background, if applicable |
1395 | |
1416 | |
1396 | my $tex = $self->{texture} ||= do { |
1417 | my $tex = $self->{texture} ||= do { |
1397 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1418 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1398 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1419 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1399 | $self->{layout}->set_width ($self->{w}); |
1420 | $self->{layout}->set_width ($self->{w}); |
… | |
… | |
1660 | my $class = shift; |
1681 | my $class = shift; |
1661 | |
1682 | |
1662 | $class->SUPER::new ( |
1683 | $class->SUPER::new ( |
1663 | padding => 4, |
1684 | padding => 4, |
1664 | fg => [1, 1, 1], |
1685 | fg => [1, 1, 1], |
1665 | bg => [1, 1, 1, 0.2], |
|
|
1666 | active_fg => [0, 0, 1], |
1686 | active_fg => [0, 0, 1], |
1667 | can_hover => 1, |
1687 | can_hover => 1, |
1668 | align => 0, |
1688 | align => 0, |
1669 | valign => 0, |
1689 | valign => 0, |
1670 | can_events => 1, |
1690 | can_events => 1, |
… | |
… | |
1718 | |
1738 | |
1719 | $class->SUPER::new ( |
1739 | $class->SUPER::new ( |
1720 | padding => 2, |
1740 | padding => 2, |
1721 | fg => [1, 1, 1], |
1741 | fg => [1, 1, 1], |
1722 | active_fg => [1, 1, 0], |
1742 | active_fg => [1, 1, 0], |
|
|
1743 | bg => [0, 0, 0, 0.2], |
|
|
1744 | active_bg => [1, 1, 1, 0.5], |
1723 | state => 0, |
1745 | state => 0, |
1724 | can_hover => 1, |
1746 | can_hover => 1, |
1725 | @_ |
1747 | @_ |
1726 | ) |
1748 | ) |
1727 | } |
1749 | } |
… | |
… | |
2019 | # TODO: req_w/h are wrong with vertical |
2041 | # TODO: req_w/h are wrong with vertical |
2020 | # TODO: calculations are off |
2042 | # TODO: calculations are off |
2021 | my $self = $class->SUPER::new ( |
2043 | my $self = $class->SUPER::new ( |
2022 | fg => [1, 1, 1], |
2044 | fg => [1, 1, 1], |
2023 | active_fg => [0, 0, 0], |
2045 | active_fg => [0, 0, 0], |
|
|
2046 | bg => [0, 0, 0, 0.2], |
|
|
2047 | active_bg => [1, 1, 1, 0.5], |
2024 | range => [0, 0, 100, 10], |
2048 | range => [0, 0, 100, 10], |
2025 | req_w => $::WIDTH / 80, |
2049 | req_w => $::WIDTH / 80, |
2026 | req_h => $::WIDTH / 80, |
2050 | req_h => $::WIDTH / 80, |
2027 | vertical => 0, |
2051 | vertical => 0, |
2028 | can_hover => 1, |
2052 | can_hover => 1, |
… | |
… | |
2523 | and $desc .= " *"; |
2547 | and $desc .= " *"; |
2524 | |
2548 | |
2525 | my $self = $class->SUPER::new ( |
2549 | my $self = $class->SUPER::new ( |
2526 | can_hover => 1, |
2550 | can_hover => 1, |
2527 | can_events => 1, |
2551 | can_events => 1, |
2528 | tooltip => (CFClient::UI::Label->escape ($desc) |
2552 | tooltip => ((CFClient::UI::Label::escape $desc) |
2529 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2553 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2530 | connect_button_down => sub { |
2554 | connect_button_down => sub { |
2531 | my ($self, $ev, $x, $y) = @_; |
2555 | my ($self, $ev, $x, $y) = @_; |
2532 | |
2556 | |
2533 | # todo: maybe put examine on 1? but should just be a tooltip :( |
2557 | # todo: maybe put examine on 1? but should just be a tooltip :( |
2534 | if ($ev->{button} == 1) { |
2558 | if ($ev->{button} == 1) { |
|
|
2559 | my $targ = $::CONN->{player}{tag}; |
|
|
2560 | |
|
|
2561 | if ($item->{container} == $::CONN->{player}{tag}) { |
|
|
2562 | $targ = $main::OPENCONT; |
|
|
2563 | } |
|
|
2564 | |
2535 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
2565 | $::CONN->send ("move $targ $item->{tag} 0"); |
2536 | } elsif ($ev->{button} == 2) { |
2566 | } elsif ($ev->{button} == 2) { |
2537 | $::CONN->send ("apply $item->{tag}"); |
2567 | $::CONN->send ("apply $item->{tag}"); |
2538 | } elsif ($ev->{button} == 3) { |
2568 | } elsif ($ev->{button} == 3) { |
2539 | my @menu_items = ( |
2569 | my @menu_items = ( |
2540 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2570 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2541 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
2571 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
2542 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
2572 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
2543 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
2573 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
2544 | [ |
2574 | [ |
2545 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
2575 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
2546 | sub { $::CONN->send ("lock ". () ."$item->{tag}") }, |
2576 | sub { $::CONN->send ("lock $item->{tag}") }, |
2547 | ], |
2577 | ], |
2548 | ); |
2578 | ); |
2549 | |
2579 | |
2550 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2580 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2551 | } |
2581 | } |
… | |
… | |
2694 | |
2724 | |
2695 | package CFClient::UI::Statusbox; |
2725 | package CFClient::UI::Statusbox; |
2696 | |
2726 | |
2697 | our @ISA = CFClient::UI::VBox::; |
2727 | our @ISA = CFClient::UI::VBox::; |
2698 | |
2728 | |
|
|
2729 | sub new { |
|
|
2730 | my $class = shift; |
|
|
2731 | |
|
|
2732 | $class->SUPER::new ( |
|
|
2733 | fontsize => 0.8, |
|
|
2734 | @_, |
|
|
2735 | ) |
|
|
2736 | } |
|
|
2737 | |
2699 | sub reorder { |
2738 | sub reorder { |
2700 | my ($self) = @_; |
2739 | my ($self) = @_; |
2701 | my $NOW = time; |
2740 | my $NOW = time; |
2702 | |
2741 | |
2703 | while (my ($k, $v) = each %{ $self->{item} }) { |
2742 | while (my ($k, $v) = each %{ $self->{item} }) { |
… | |
… | |
2719 | # TODO: doesn't handle markup well (read as: at all) |
2758 | # TODO: doesn't handle markup well (read as: at all) |
2720 | my $short = $item->{count} > 1 |
2759 | my $short = $item->{count} > 1 |
2721 | ? "<b>$item->{count} ×</b> $item->{text}" |
2760 | ? "<b>$item->{count} ×</b> $item->{text}" |
2722 | : $item->{text}; |
2761 | : $item->{text}; |
2723 | |
2762 | |
|
|
2763 | my $fontsize = $item->{fontsize} || $self->{fontsize}; |
|
|
2764 | |
2724 | for ($short) { |
2765 | for ($short) { |
2725 | s/^\s+//; |
2766 | s/^\s+//; |
2726 | s/\s+/ /g; |
2767 | s/\s+/ /g; |
2727 | my $len = int 40 / $item->{fontsize}; |
2768 | my $len = int 40 / $fontsize; |
2728 | substr $_, $len, length, "…" if $len < length; |
2769 | substr $_, $len, length, "…" if $len < length; |
2729 | } |
2770 | } |
2730 | |
2771 | |
2731 | new CFClient::UI::Label |
2772 | new CFClient::UI::Label |
2732 | markup => $short, |
2773 | markup => $short, |
2733 | tooltip => $item->{tooltip}, |
2774 | tooltip => $item->{tooltip}, |
2734 | tooltip_font => $::FONT_PROP, |
2775 | tooltip_font => $::FONT_PROP, |
2735 | tooltip_width => 0.67, |
2776 | tooltip_width => 0.67, |
2736 | fontsize => $item->{fontsize}, |
2777 | fontsize => $fontsize, |
2737 | fg => $item->{fg}, |
2778 | fg => $item->{fg}, |
2738 | can_events => 1, |
2779 | can_events => 1, |
2739 | can_hover => 1 |
2780 | can_hover => 1 |
2740 | }; |
2781 | }; |
2741 | } |
2782 | } |
… | |
… | |
2768 | $self->{item}{$group} = { |
2809 | $self->{item}{$group} = { |
2769 | id => ++$self->{id}, |
2810 | id => ++$self->{id}, |
2770 | text => $text, |
2811 | text => $text, |
2771 | timeout => $timeout, |
2812 | timeout => $timeout, |
2772 | tooltip => $text, |
2813 | tooltip => $text, |
2773 | fontsize => 0.8, |
|
|
2774 | fg => [0.8, 0.8, 0.8, 0.8], |
2814 | fg => [0.8, 0.8, 0.8, 0.8], |
2775 | pri => 0, |
2815 | pri => 0, |
2776 | count => 1, |
2816 | count => 1, |
2777 | %arg, |
2817 | %arg, |
2778 | }; |
2818 | }; |