… | |
… | |
255 | my ($self) = @_; |
255 | my ($self) = @_; |
256 | |
256 | |
257 | $_->reconfigure |
257 | $_->reconfigure |
258 | for $self->children; |
258 | for $self->children; |
259 | |
259 | |
260 | $_->check_size; |
260 | $self->check_size; |
|
|
261 | $self->size_allocate ($self->{w}, $self->{h}); |
|
|
262 | $self->update; |
261 | } |
263 | } |
262 | |
264 | |
263 | sub set_max_size { |
265 | sub set_max_size { |
264 | my ($self, $w, $h) = @_; |
266 | my ($self, $w, $h) = @_; |
265 | |
267 | |
… | |
… | |
739 | $self->{view_y} = int $y; |
741 | $self->{view_y} = int $y; |
740 | |
742 | |
741 | $self->update; |
743 | $self->update; |
742 | } |
744 | } |
743 | |
745 | |
|
|
746 | # hmm, this does not work for topleft of $self... but we should not aks for that |
|
|
747 | sub _topleft { |
|
|
748 | my ($self, $x, $y) = @_; |
|
|
749 | |
|
|
750 | $self->SUPER::_topleft ($x - $self->{view_x}, $y - $self->{view_y}) |
|
|
751 | } |
|
|
752 | |
|
|
753 | sub find_widget { |
|
|
754 | my ($self, $x, $y) = @_; |
|
|
755 | |
|
|
756 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
757 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
|
|
758 | ) { |
|
|
759 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
|
|
760 | } else { |
|
|
761 | $self->CFClient::UI::Base::find_widget ($x, $y) |
|
|
762 | } |
|
|
763 | } |
|
|
764 | |
744 | sub _render { |
765 | sub _render { |
745 | my ($self) = @_; |
766 | my ($self) = @_; |
746 | |
767 | |
747 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
768 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
748 | |
769 | |
… | |
… | |
1303 | |
1324 | |
1304 | delete $self->{texture}; |
1325 | delete $self->{texture}; |
1305 | $self->SUPER::update; |
1326 | $self->SUPER::update; |
1306 | } |
1327 | } |
1307 | |
1328 | |
1308 | sub reconfigure { |
|
|
1309 | my ($self) = @_; |
|
|
1310 | |
|
|
1311 | delete $self->{texture}; |
|
|
1312 | } |
|
|
1313 | |
|
|
1314 | sub set_text { |
1329 | sub set_text { |
1315 | my ($self, $text) = @_; |
1330 | my ($self, $text) = @_; |
1316 | |
1331 | |
1317 | return if $self->{text} eq "T$text"; |
1332 | return if $self->{text} eq "T$text"; |
1318 | $self->{text} = "T$text"; |
1333 | $self->{text} = "T$text"; |
… | |
… | |
1371 | sub set_fontsize { |
1386 | sub set_fontsize { |
1372 | my ($self, $fontsize) = @_; |
1387 | my ($self, $fontsize) = @_; |
1373 | |
1388 | |
1374 | $self->{fontsize} = $fontsize; |
1389 | $self->{fontsize} = $fontsize; |
1375 | delete $self->{texture}; |
1390 | delete $self->{texture}; |
|
|
1391 | |
|
|
1392 | $self->update; |
1376 | $self->check_size; |
1393 | $self->check_size; |
1377 | $self->update; |
|
|
1378 | } |
1394 | } |
1379 | |
1395 | |
1380 | sub _draw { |
1396 | sub _draw { |
1381 | my ($self) = @_; |
1397 | my ($self) = @_; |
1382 | |
1398 | |
… | |
… | |
2464 | } |
2480 | } |
2465 | |
2481 | |
2466 | sub _draw { |
2482 | sub _draw { |
2467 | my ($self) = @_; |
2483 | my ($self) = @_; |
2468 | |
2484 | |
|
|
2485 | return unless $::CONN;#d# manage and cache textures differently |
2469 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2486 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2470 | |
2487 | |
2471 | # TODO animation |
2488 | # TODO animation |
2472 | if ($tex) { |
2489 | if ($tex) { |
2473 | glEnable GL_BLEND; |
2490 | glEnable GL_BLEND; |
… | |
… | |
2481 | } |
2498 | } |
2482 | } |
2499 | } |
2483 | |
2500 | |
2484 | ############################################################################# |
2501 | ############################################################################# |
2485 | |
2502 | |
|
|
2503 | package CFClient::UI::InventoryItem; |
|
|
2504 | |
|
|
2505 | our @ISA = CFClient::UI::HBox::; |
|
|
2506 | |
|
|
2507 | sub new { |
|
|
2508 | my $class = shift; |
|
|
2509 | |
|
|
2510 | my %args = @_; |
|
|
2511 | |
|
|
2512 | my $item = $args{item}; |
|
|
2513 | |
|
|
2514 | my $desc = $item->{nrof} < 2 |
|
|
2515 | ? $item->{name} |
|
|
2516 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2517 | |
|
|
2518 | |
|
|
2519 | my $self = $class->SUPER::new ( |
|
|
2520 | can_hover => 1, |
|
|
2521 | can_events => 1, |
|
|
2522 | tooltip => (CFClient::UI::Label->escape ($desc) |
|
|
2523 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
2524 | connect_button_down => sub { |
|
|
2525 | my ($self, $ev, $x, $y) = @_; |
|
|
2526 | |
|
|
2527 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
2528 | if ($ev->{button} == 1) { |
|
|
2529 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
|
|
2530 | } elsif ($ev->{button} == 2) { |
|
|
2531 | $::CONN->send ("apply $item->{tag}"); |
|
|
2532 | } elsif ($ev->{button} == 3) { |
|
|
2533 | CFClient::UI::Menu->new ( |
|
|
2534 | items => [ |
|
|
2535 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
|
|
2536 | [ |
|
|
2537 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
|
|
2538 | sub { $::CONN->send ("lock $item->{tag}") }, |
|
|
2539 | ], |
|
|
2540 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
|
|
2541 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2542 | ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }], |
|
|
2543 | ], |
|
|
2544 | )->popup ($ev); |
|
|
2545 | } |
|
|
2546 | |
|
|
2547 | 1 |
|
|
2548 | }, |
|
|
2549 | %args |
|
|
2550 | ); |
|
|
2551 | $self->add(new CFClient::UI::Face |
|
|
2552 | can_events => 0, |
|
|
2553 | face => $item->{face}, |
|
|
2554 | anim => $item->{anim}, |
|
|
2555 | animspeed => $item->{animspeed}); |
|
|
2556 | $self->add(new CFClient::UI::Label |
|
|
2557 | can_events => 0, |
|
|
2558 | text => $desc); |
|
|
2559 | |
|
|
2560 | $self |
|
|
2561 | } |
|
|
2562 | |
|
|
2563 | ############################################################################# |
|
|
2564 | |
|
|
2565 | package CFClient::UI::Inventory; |
|
|
2566 | |
|
|
2567 | our @ISA = CFClient::UI::ScrolledWindow::; |
|
|
2568 | |
|
|
2569 | sub new { |
|
|
2570 | my $class = shift; |
|
|
2571 | |
|
|
2572 | my $self = $class->SUPER::new ( |
|
|
2573 | scrolled => (new CFClient::UI::VBox), |
|
|
2574 | @_, |
|
|
2575 | ); |
|
|
2576 | |
|
|
2577 | $self |
|
|
2578 | } |
|
|
2579 | |
|
|
2580 | sub set_items { |
|
|
2581 | my ($self, $items) = @_; |
|
|
2582 | |
|
|
2583 | $self->{scrolled}->clear; |
|
|
2584 | return unless $items; |
|
|
2585 | |
|
|
2586 | my @items = sort { $a->{type} <=> $b->{type} } @$items; |
|
|
2587 | |
|
|
2588 | $self->{real_items} = \@items; |
|
|
2589 | |
|
|
2590 | for my $item (@items) { |
|
|
2591 | my $desc = $item->{nrof} < 2 |
|
|
2592 | ? $item->{name} |
|
|
2593 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2594 | |
|
|
2595 | $self->{scrolled}->add (new CFClient::UI::InventoryItem item => $item); |
|
|
2596 | } |
|
|
2597 | |
|
|
2598 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
|
|
2599 | } |
|
|
2600 | |
|
|
2601 | sub size_request { |
|
|
2602 | my ($self) = @_; |
|
|
2603 | ($self->{req_w}, $self->{req_h}); |
|
|
2604 | } |
|
|
2605 | |
|
|
2606 | ############################################################################# |
|
|
2607 | |
2486 | package CFClient::UI::Menu; |
2608 | package CFClient::UI::Menu; |
2487 | |
2609 | |
2488 | our @ISA = CFClient::UI::FancyFrame::; |
2610 | our @ISA = CFClient::UI::FancyFrame::; |
2489 | |
2611 | |
2490 | use CFClient::OpenGL; |
2612 | use CFClient::OpenGL; |
… | |
… | |
2562 | use CFClient::OpenGL; |
2684 | use CFClient::OpenGL; |
2563 | |
2685 | |
2564 | sub check_size { |
2686 | sub check_size { |
2565 | my ($self) = @_; |
2687 | my ($self) = @_; |
2566 | |
2688 | |
2567 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
2689 | $self->configure (0, 0, $self->{w}, $self->{h}); |
2568 | } |
2690 | } |
2569 | |
2691 | |
2570 | sub size_request { |
2692 | sub size_request { |
2571 | ($::WIDTH, $::HEIGHT) |
2693 | my ($self) = @_; |
|
|
2694 | |
|
|
2695 | ($self->{w}, $self->{h}) |
|
|
2696 | } |
|
|
2697 | |
|
|
2698 | sub size_allocate { |
|
|
2699 | my ($self, $w, $h) = @_; |
|
|
2700 | |
|
|
2701 | my $old_w = $self->{old_w}; |
|
|
2702 | my $old_h = $self->{old_h}; |
|
|
2703 | |
|
|
2704 | if ($old_w && $old_h) { |
|
|
2705 | for my $child ($self->children) { |
|
|
2706 | $child->{x} = int 0.5 + $child->{x} * $w / $old_w; |
|
|
2707 | $child->{w} = int 0.5 + $child->{req_w} * $w / $old_w; |
|
|
2708 | $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w}; |
|
|
2709 | $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w}; |
|
|
2710 | $child->{y} = int 0.5 + $child->{y} * $h / $old_h; |
|
|
2711 | $child->{h} = int 0.5 + $child->{h} * $h / $old_h; |
|
|
2712 | $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h}; |
|
|
2713 | $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h}; |
|
|
2714 | } |
|
|
2715 | } |
|
|
2716 | |
|
|
2717 | $self->{old_w} = $w; |
|
|
2718 | $self->{old_h} = $h; |
2572 | } |
2719 | } |
2573 | |
2720 | |
2574 | sub configure { |
2721 | sub configure { |
2575 | my ($self, $x, $y, $w, $h) = @_; |
2722 | my ($self, $x, $y, $w, $h) = @_; |
2576 | |
2723 | |
2577 | $self->SUPER::configure ($x, $y, $w, $h); |
2724 | $self->SUPER::configure ($x, $y, $w, $h); |
2578 | |
2725 | |
2579 | for my $child (@{$self->{children}}) { |
2726 | for my $child ($self->children) { |
2580 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2727 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2581 | |
2728 | |
2582 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2729 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2583 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2730 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2584 | $child->configure ($X, $Y, $W,$H); |
2731 | $child->configure ($X, $Y, $W, $H); |
2585 | } |
2732 | } |
2586 | } |
2733 | } |
2587 | |
2734 | |
2588 | sub _topleft { |
2735 | sub _topleft { |
2589 | my ($self, $x, $y) = @_; |
2736 | my ($self, $x, $y) = @_; |
… | |
… | |
2634 | $self->_draw; |
2781 | $self->_draw; |
2635 | } |
2782 | } |
2636 | |
2783 | |
2637 | ############################################################################# |
2784 | ############################################################################# |
2638 | |
2785 | |
2639 | package CFClient::UI::Inventory; |
|
|
2640 | |
|
|
2641 | our @ISA = CFClient::UI::ScrolledWindow::; |
|
|
2642 | |
|
|
2643 | sub new { |
|
|
2644 | my $class = shift; |
|
|
2645 | |
|
|
2646 | my $self = $class->SUPER::new ( |
|
|
2647 | scrolled => (new CFClient::UI::VBox), |
|
|
2648 | @_, |
|
|
2649 | ); |
|
|
2650 | |
|
|
2651 | $self |
|
|
2652 | } |
|
|
2653 | |
|
|
2654 | sub set_items { |
|
|
2655 | my ($self, $items) = @_; |
|
|
2656 | |
|
|
2657 | $self->{scrolled}->clear; |
|
|
2658 | return unless $items; |
|
|
2659 | |
|
|
2660 | my @items = sort { $a->{type} <=> $b->{type} } @$items; |
|
|
2661 | |
|
|
2662 | $self->{real_items} = \@items; |
|
|
2663 | |
|
|
2664 | for my $item (@items) { |
|
|
2665 | my $desc = $item->{nrof} < 2 |
|
|
2666 | ? $item->{name} |
|
|
2667 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2668 | |
|
|
2669 | my $hb = new CFClient::UI::HBox; |
|
|
2670 | |
|
|
2671 | $hb->add (my $f = new CFClient::UI::Face |
|
|
2672 | can_events => 0, |
|
|
2673 | face => $item->{face}, |
|
|
2674 | anim => $item->{anim}, |
|
|
2675 | animspeed => $item->{animspeed}, |
|
|
2676 | expand => 1, |
|
|
2677 | ); |
|
|
2678 | $hb->add (new CFClient::UI::Label text => $desc, expand => 1); |
|
|
2679 | $self->{scrolled}->add ($hb); |
|
|
2680 | } |
|
|
2681 | |
|
|
2682 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
|
|
2683 | } |
|
|
2684 | |
|
|
2685 | sub size_request { |
|
|
2686 | my ($self) = @_; |
|
|
2687 | (100, 200) |
|
|
2688 | } |
|
|
2689 | |
|
|
2690 | ############################################################################# |
|
|
2691 | |
|
|
2692 | package CFClient::UI; |
2786 | package CFClient::UI; |
2693 | |
2787 | |
2694 | $ROOT = new CFClient::UI::Root; |
2788 | $ROOT = new CFClient::UI::Root; |
2695 | $TOOLTIP = new CFClient::UI::Tooltip; |
2789 | $TOOLTIP = new CFClient::UI::Tooltip; |
2696 | |
2790 | |