… | |
… | |
2518 | |
2518 | |
2519 | package CFClient::UI::InventoryItem; |
2519 | package CFClient::UI::InventoryItem; |
2520 | |
2520 | |
2521 | our @ISA = CFClient::UI::HBox::; |
2521 | our @ISA = CFClient::UI::HBox::; |
2522 | |
2522 | |
2523 | sub new { |
2523 | sub _item_to_desc { |
2524 | my $class = shift; |
2524 | my ($item) = @_; |
2525 | |
2525 | |
2526 | my %args = @_; |
2526 | my $desc = |
2527 | |
|
|
2528 | my $item = delete $args{item}; |
|
|
2529 | |
|
|
2530 | my $desc = $item->{nrof} < 2 |
2527 | $item->{nrof} < 2 |
2531 | ? $item->{name} |
2528 | ? $item->{name} |
2532 | : "$item->{nrof} $item->{name_pl}"; |
2529 | : "$item->{nrof} $item->{name_pl}"; |
2533 | |
2530 | |
2534 | $item->{flags} & Crossfire::Protocol::F_OPEN |
2531 | $item->{flags} & Crossfire::Protocol::F_OPEN |
2535 | and $desc .= " (open)"; |
2532 | and $desc .= " (open)"; |
2536 | $item->{flags} & Crossfire::Protocol::F_APPLIED |
2533 | $item->{flags} & Crossfire::Protocol::F_APPLIED |
2537 | and $desc .= " (applied)"; |
2534 | and $desc .= " (applied)"; |
… | |
… | |
2544 | $item->{flags} & Crossfire::Protocol::F_DAMNED |
2541 | $item->{flags} & Crossfire::Protocol::F_DAMNED |
2545 | and $desc .= " (damned)"; |
2542 | and $desc .= " (damned)"; |
2546 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
2543 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
2547 | and $desc .= " *"; |
2544 | and $desc .= " *"; |
2548 | |
2545 | |
|
|
2546 | $desc |
|
|
2547 | } |
|
|
2548 | |
|
|
2549 | sub new { |
|
|
2550 | my $class = shift; |
|
|
2551 | |
|
|
2552 | my %args = @_; |
|
|
2553 | |
|
|
2554 | my $item = delete $args{item}; |
|
|
2555 | |
|
|
2556 | my $desc = _item_to_desc ($item); |
|
|
2557 | |
2549 | my $self = $class->SUPER::new ( |
2558 | my $self = $class->SUPER::new ( |
2550 | can_hover => 1, |
2559 | can_hover => 1, |
2551 | can_events => 1, |
2560 | can_events => 1, |
2552 | tooltip => ((CFClient::UI::Label::escape $desc) |
2561 | tooltip => ((CFClient::UI::Label::escape $desc) |
2553 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2562 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2554 | connect_button_down => sub { |
2563 | connect_button_down => sub { |
2555 | my ($self, $ev, $x, $y) = @_; |
2564 | my ($self, $ev, $x, $y) = @_; |
2556 | |
2565 | |
2557 | # todo: maybe put examine on 1? but should just be a tooltip :( |
2566 | # todo: maybe put examine on 1? but should just be a tooltip :( |
2558 | if ($ev->{button} == 1) { |
2567 | if ($ev->{button} == 1) { |
|
|
2568 | my $targ = $::CONN->{player}{tag}; |
|
|
2569 | |
|
|
2570 | if ($item->{container} == $::CONN->{player}{tag}) { |
|
|
2571 | $targ = $main::OPENCONT; |
|
|
2572 | } |
|
|
2573 | |
2559 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
2574 | $::CONN->send ("move $targ $item->{tag} 0"); |
2560 | } elsif ($ev->{button} == 2) { |
2575 | } elsif ($ev->{button} == 2) { |
2561 | $::CONN->send ("apply $item->{tag}"); |
2576 | $::CONN->send ("apply $item->{tag}"); |
2562 | } elsif ($ev->{button} == 3) { |
2577 | } elsif ($ev->{button} == 3) { |
2563 | my @menu_items = ( |
2578 | my @menu_items = ( |
2564 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2579 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2565 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
2580 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
2566 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
2581 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
2567 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
2582 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
2568 | [ |
2583 | [ |
2569 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
2584 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
2570 | sub { $::CONN->send ("lock ". () ."$item->{tag}") }, |
2585 | sub { $::CONN->send ("lock $item->{tag}") }, |
2571 | ], |
2586 | ], |
2572 | ); |
2587 | ); |
2573 | |
2588 | |
2574 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2589 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2575 | } |
2590 | } |
2576 | |
2591 | |
2577 | 1 |
2592 | 1 |
2578 | }, |
2593 | }, |
2579 | %args |
2594 | %args |
2580 | ); |
2595 | ); |
|
|
2596 | |
2581 | |
2597 | |
2582 | $self->add (new CFClient::UI::Face |
2598 | $self->add (new CFClient::UI::Face |
2583 | can_events => 0, |
2599 | can_events => 0, |
2584 | face => $item->{face}, |
2600 | face => $item->{face}, |
2585 | anim => $item->{anim}, |
2601 | anim => $item->{anim}, |
2586 | animspeed => $item->{animspeed}, |
2602 | animspeed => $item->{animspeed}, |
2587 | ); |
2603 | ); |
2588 | |
2604 | |
2589 | $self->add (new CFClient::UI::Label |
2605 | $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0); |
2590 | can_events => 0, |
2606 | |
2591 | text => $desc, |
2607 | $self->{item} = $item; |
2592 | ); |
2608 | |
|
|
2609 | $self->update_item; |
2593 | |
2610 | |
2594 | $self |
2611 | $self |
|
|
2612 | } |
|
|
2613 | |
|
|
2614 | sub update_item { |
|
|
2615 | my ($self) = @_; |
|
|
2616 | |
|
|
2617 | my $desc = _item_to_desc ($self->{item}); |
|
|
2618 | |
|
|
2619 | $self->{name_lbl}->set_text ($desc); |
2595 | } |
2620 | } |
2596 | |
2621 | |
2597 | ############################################################################# |
2622 | ############################################################################# |
2598 | |
2623 | |
2599 | package CFClient::UI::Inventory; |
2624 | package CFClient::UI::Inventory; |
… | |
… | |
2623 | } @$items; |
2648 | } @$items; |
2624 | |
2649 | |
2625 | $self->{real_items} = \@items; |
2650 | $self->{real_items} = \@items; |
2626 | |
2651 | |
2627 | for my $item (@items) { |
2652 | for my $item (@items) { |
2628 | my $desc = $item->{nrof} < 2 |
|
|
2629 | ? $item->{name} |
|
|
2630 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2631 | |
|
|
2632 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
2653 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
|
|
2654 | $item->update_item (); |
2633 | } |
2655 | } |
2634 | |
2656 | |
2635 | $self->{scrolled}->add (@items); |
2657 | $self->{scrolled}->add (@items); |
2636 | |
2658 | |
2637 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2659 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
… | |
… | |
2718 | |
2740 | |
2719 | package CFClient::UI::Statusbox; |
2741 | package CFClient::UI::Statusbox; |
2720 | |
2742 | |
2721 | our @ISA = CFClient::UI::VBox::; |
2743 | our @ISA = CFClient::UI::VBox::; |
2722 | |
2744 | |
|
|
2745 | sub new { |
|
|
2746 | my $class = shift; |
|
|
2747 | |
|
|
2748 | $class->SUPER::new ( |
|
|
2749 | fontsize => 0.8, |
|
|
2750 | @_, |
|
|
2751 | ) |
|
|
2752 | } |
|
|
2753 | |
2723 | sub reorder { |
2754 | sub reorder { |
2724 | my ($self) = @_; |
2755 | my ($self) = @_; |
2725 | my $NOW = time; |
2756 | my $NOW = time; |
2726 | |
2757 | |
2727 | while (my ($k, $v) = each %{ $self->{item} }) { |
2758 | while (my ($k, $v) = each %{ $self->{item} }) { |
… | |
… | |
2743 | # TODO: doesn't handle markup well (read as: at all) |
2774 | # TODO: doesn't handle markup well (read as: at all) |
2744 | my $short = $item->{count} > 1 |
2775 | my $short = $item->{count} > 1 |
2745 | ? "<b>$item->{count} ×</b> $item->{text}" |
2776 | ? "<b>$item->{count} ×</b> $item->{text}" |
2746 | : $item->{text}; |
2777 | : $item->{text}; |
2747 | |
2778 | |
|
|
2779 | my $fontsize = $item->{fontsize} || $self->{fontsize}; |
|
|
2780 | |
2748 | for ($short) { |
2781 | for ($short) { |
2749 | s/^\s+//; |
2782 | s/^\s+//; |
2750 | s/\s+/ /g; |
2783 | s/\s+/ /g; |
2751 | my $len = int 40 / $item->{fontsize}; |
2784 | my $len = int 40 / $fontsize; |
2752 | substr $_, $len, length, "…" if $len < length; |
2785 | substr $_, $len, length, "…" if $len < length; |
2753 | } |
2786 | } |
2754 | |
2787 | |
2755 | new CFClient::UI::Label |
2788 | new CFClient::UI::Label |
2756 | markup => $short, |
2789 | markup => $short, |
2757 | tooltip => $item->{tooltip}, |
2790 | tooltip => $item->{tooltip}, |
2758 | tooltip_font => $::FONT_PROP, |
2791 | tooltip_font => $::FONT_PROP, |
2759 | tooltip_width => 0.67, |
2792 | tooltip_width => 0.67, |
2760 | fontsize => $item->{fontsize}, |
2793 | fontsize => $fontsize, |
2761 | fg => $item->{fg}, |
2794 | fg => $item->{fg}, |
2762 | can_events => 1, |
2795 | can_events => 1, |
2763 | can_hover => 1 |
2796 | can_hover => 1 |
2764 | }; |
2797 | }; |
2765 | } |
2798 | } |
… | |
… | |
2792 | $self->{item}{$group} = { |
2825 | $self->{item}{$group} = { |
2793 | id => ++$self->{id}, |
2826 | id => ++$self->{id}, |
2794 | text => $text, |
2827 | text => $text, |
2795 | timeout => $timeout, |
2828 | timeout => $timeout, |
2796 | tooltip => $text, |
2829 | tooltip => $text, |
2797 | fontsize => 0.8, |
|
|
2798 | fg => [0.8, 0.8, 0.8, 0.8], |
2830 | fg => [0.8, 0.8, 0.8, 0.8], |
2799 | pri => 0, |
2831 | pri => 0, |
2800 | count => 1, |
2832 | count => 1, |
2801 | %arg, |
2833 | %arg, |
2802 | }; |
2834 | }; |