… | |
… | |
237 | $self->{w} = $w; |
237 | $self->{w} = $w; |
238 | $self->{h} = $h; |
238 | $self->{h} = $h; |
239 | |
239 | |
240 | $self->size_allocate ($w, $h); |
240 | $self->size_allocate ($w, $h); |
241 | $self->update; |
241 | $self->update; |
|
|
242 | $self->emit (size_allocate => $w, $h); |
242 | } |
243 | } |
243 | } |
244 | } |
244 | |
245 | |
245 | sub size_allocate { |
246 | sub size_allocate { |
246 | # nothing to be done |
247 | # nothing to be done |
247 | } |
248 | } |
248 | |
249 | |
249 | sub children { |
250 | sub children { |
250 | } |
251 | } |
251 | |
252 | |
252 | # call when resoltuion changes etc. |
253 | # call when resolution changes etc. |
253 | sub reconfigure { |
254 | sub reconfigure { |
254 | my ($self) = @_; |
255 | my ($self) = @_; |
255 | |
256 | |
256 | $_->reconfigure |
257 | $_->reconfigure |
257 | for $self->children; |
258 | for $self->children; |
258 | |
259 | |
259 | $_->check_size; |
260 | $self->check_size; |
|
|
261 | $self->size_allocate ($self->{w}, $self->{h}); |
|
|
262 | $self->update; |
260 | } |
263 | } |
261 | |
264 | |
262 | sub set_max_size { |
265 | sub set_max_size { |
263 | my ($self, $w, $h) = @_; |
266 | my ($self, $w, $h) = @_; |
264 | |
267 | |
… | |
… | |
400 | } |
403 | } |
401 | |
404 | |
402 | sub check_size { |
405 | sub check_size { |
403 | my ($self) = @_; |
406 | my ($self) = @_; |
404 | |
407 | |
|
|
408 | $self->_check_size; |
|
|
409 | return; |
|
|
410 | my $check_size = $CFClient::UI::ROOT->{_check_size} ||= {}; |
|
|
411 | |
|
|
412 | $check_size->{$self} = $self; |
|
|
413 | |
|
|
414 | $CFClient::UI::ROOT->on_refresh (_check_size => sub { |
|
|
415 | while (%$check_size) { |
|
|
416 | my @widgets = values %$check_size; |
|
|
417 | $_->_check_size |
|
|
418 | for @widgets; |
|
|
419 | } |
|
|
420 | }); |
|
|
421 | } |
|
|
422 | |
|
|
423 | sub _check_size { |
|
|
424 | my ($self) = @_; |
|
|
425 | |
|
|
426 | delete $CFClient::UI::ROOT->{_check_size}{$self}; |
|
|
427 | |
405 | $self->{parent} |
428 | $self->{parent} |
406 | or return 1; |
429 | or return 1; |
407 | |
430 | |
408 | my ($w, $h) = $self->{user_w} && $self->{user_h} |
431 | my ($w, $h) = $self->{user_w} && $self->{user_h} |
409 | ? @$self{qw(user_w user_h)} |
432 | ? @$self{qw(user_w user_h)} |
… | |
… | |
411 | |
434 | |
412 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
435 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
413 | $self->{req_w} = $w; |
436 | $self->{req_w} = $w; |
414 | $self->{req_h} = $h; |
437 | $self->{req_h} = $h; |
415 | |
438 | |
416 | $self->{parent}->check_size |
439 | $self->{parent}->_check_size |
417 | or $self->size_allocate ( |
440 | or $self->size_allocate ( |
418 | (List::Util::max $self->{w}, $w), |
441 | (List::Util::max $self->{w}, $w), |
419 | (List::Util::max $self->{h}, $h), |
442 | (List::Util::max $self->{h}, $h), |
420 | ); |
443 | ); |
421 | |
444 | |
… | |
… | |
426 | } |
449 | } |
427 | |
450 | |
428 | sub update { |
451 | sub update { |
429 | my ($self) = @_; |
452 | my ($self) = @_; |
430 | |
453 | |
431 | $self->{parent}->update |
454 | my $update = $CFClient::UI::ROOT->{_update} ||= {}; |
432 | if $self->{parent}; |
455 | |
|
|
456 | $update->{$self} = $self; |
|
|
457 | |
|
|
458 | $CFClient::UI::ROOT->on_refresh (_update => sub { |
|
|
459 | while (%$update) { |
|
|
460 | my @widgets = values %$update; |
|
|
461 | %$update = (); |
|
|
462 | |
|
|
463 | $_->{parent} && $_->{parent}->update |
|
|
464 | for @widgets; |
|
|
465 | } |
|
|
466 | }); |
433 | } |
467 | } |
434 | |
468 | |
435 | sub connect { |
469 | sub connect { |
436 | my ($self, $signal, $cb) = @_; |
470 | my ($self, $signal, $cb) = @_; |
437 | |
471 | |
… | |
… | |
527 | |
561 | |
528 | $self |
562 | $self |
529 | } |
563 | } |
530 | |
564 | |
531 | sub add { |
565 | sub add { |
532 | my ($self, $child) = @_; |
566 | my ($self, @widgets) = @_; |
533 | |
567 | |
534 | $child->set_parent ($self); |
568 | $_->set_parent ($self) |
|
|
569 | for @widgets; |
535 | |
570 | |
536 | use sort 'stable'; |
571 | use sort 'stable'; |
537 | |
572 | |
538 | $self->{children} = [ |
573 | $self->{children} = [ |
539 | sort { $a->{z} <=> $b->{z} } |
574 | sort { $a->{z} <=> $b->{z} } |
540 | @{$self->{children}}, $child |
575 | @{$self->{children}}, @widgets |
541 | ]; |
576 | ]; |
542 | |
577 | |
543 | $child->check_size; |
578 | $_->check_size |
|
|
579 | for @widgets; |
|
|
580 | |
|
|
581 | $self->update; |
544 | } |
582 | } |
545 | |
583 | |
546 | sub children { |
584 | sub children { |
547 | @{ $_[0]{children} } |
585 | @{ $_[0]{children} } |
548 | } |
586 | } |
… | |
… | |
567 | |
605 | |
568 | for (@$children) { |
606 | for (@$children) { |
569 | delete $_->{parent}; |
607 | delete $_->{parent}; |
570 | $_->hide; |
608 | $_->hide; |
571 | } |
609 | } |
|
|
610 | |
|
|
611 | $self->check_size; |
|
|
612 | $self->update; |
572 | } |
613 | } |
573 | |
614 | |
574 | sub find_widget { |
615 | sub find_widget { |
575 | my ($self, $x, $y) = @_; |
616 | my ($self, $x, $y) = @_; |
576 | |
617 | |
… | |
… | |
662 | |
703 | |
663 | $self->SUPER::size_allocate ($w, $h); |
704 | $self->SUPER::size_allocate ($w, $h); |
664 | $self->update; |
705 | $self->update; |
665 | } |
706 | } |
666 | |
707 | |
|
|
708 | sub _render { |
|
|
709 | $_[0]{children}[0]->draw; |
|
|
710 | } |
|
|
711 | |
667 | sub render_child { |
712 | sub render_child { |
668 | my ($self) = @_; |
713 | my ($self) = @_; |
669 | |
714 | |
670 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
715 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
671 | glClearColor 0, 0, 0, 0; |
716 | glClearColor 0, 0, 0, 0; |
672 | glClear GL_COLOR_BUFFER_BIT; |
717 | glClear GL_COLOR_BUFFER_BIT; |
673 | $self->child->draw; |
718 | |
|
|
719 | $self->_render; |
674 | # glColorMask 1, 1, 1, 0; |
720 | # glColorMask 1, 1, 1, 0; |
675 | # glEnable GL_BLEND; |
721 | # glEnable GL_BLEND; |
676 | # glBlendFunc GL_SRC_ALPHA, GL_ZERO; |
722 | # glBlendFunc GL_SRC_ALPHA, GL_ZERO; |
677 | # glRasterPos 0, 0; |
723 | # glRasterPos 0, 0; |
678 | # glCopyPixels 0, 0, $self->{w}, $self->{h}; |
724 | # glCopyPixels 0, 0, $self->{w}, $self->{h}; |
… | |
… | |
705 | |
751 | |
706 | package CFClient::UI::ViewPort; |
752 | package CFClient::UI::ViewPort; |
707 | |
753 | |
708 | our @ISA = CFClient::UI::Window::; |
754 | our @ISA = CFClient::UI::Window::; |
709 | |
755 | |
710 | sub new { die } |
|
|
711 | |
|
|
712 | sub size_request { |
756 | sub size_request { |
713 | my ($self) = @_; |
757 | my ($self) = @_; |
714 | |
758 | |
715 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
759 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
716 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
760 | $self->child->configure (0, 0, @$self{qw(child_w child_h)}); |
717 | |
761 | |
718 | @$self{qw(child_w child_h)} |
762 | @$self{qw(child_w child_h)} |
719 | } |
763 | } |
720 | |
764 | |
721 | sub _draw { |
765 | sub size_allocate { |
722 | my ($self) = @_; |
766 | my ($self, $w, $h) = @_; |
723 | |
767 | |
724 | $self->{children}[1]->draw; |
768 | $self->update; |
725 | } |
769 | } |
726 | |
770 | |
|
|
771 | sub set_offset { |
|
|
772 | my ($self, $x, $y) = @_; |
|
|
773 | |
|
|
774 | $self->{view_x} = int $x; |
|
|
775 | $self->{view_y} = int $y; |
|
|
776 | |
|
|
777 | $self->update; |
|
|
778 | } |
|
|
779 | |
|
|
780 | # hmm, this does not work for topleft of $self... but we should not aks for that |
|
|
781 | sub _topleft { |
|
|
782 | my ($self, $x, $y) = @_; |
|
|
783 | |
|
|
784 | $self->SUPER::_topleft ($x - $self->{view_x}, $y - $self->{view_y}) |
|
|
785 | } |
|
|
786 | |
|
|
787 | sub find_widget { |
|
|
788 | my ($self, $x, $y) = @_; |
|
|
789 | |
|
|
790 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
791 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
|
|
792 | ) { |
|
|
793 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
|
|
794 | } else { |
|
|
795 | $self->CFClient::UI::Base::find_widget ($x, $y) |
|
|
796 | } |
|
|
797 | } |
|
|
798 | |
|
|
799 | sub _render { |
|
|
800 | my ($self) = @_; |
|
|
801 | |
|
|
802 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
|
|
803 | |
|
|
804 | $self->SUPER::_render; |
|
|
805 | } |
|
|
806 | |
|
|
807 | ############################################################################# |
|
|
808 | |
|
|
809 | package CFClient::UI::ScrolledWindow; |
|
|
810 | |
|
|
811 | our @ISA = CFClient::UI::HBox::; |
|
|
812 | |
|
|
813 | sub new { |
|
|
814 | my $class = shift; |
|
|
815 | |
|
|
816 | my $self; |
|
|
817 | |
|
|
818 | my $slider = new CFClient::UI::Slider |
|
|
819 | vertical => 1, |
|
|
820 | range => [0, 0, 1, 0.01], # HACK fix |
|
|
821 | connect_changed => sub { |
|
|
822 | $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); |
|
|
823 | }, |
|
|
824 | ; |
|
|
825 | |
|
|
826 | $self = $class->SUPER::new ( |
|
|
827 | vp => (new CFClient::UI::ViewPort), |
|
|
828 | slider => $slider, |
|
|
829 | @_, |
|
|
830 | ); |
|
|
831 | |
|
|
832 | $self->{vp}->add ($self->{scrolled}); |
|
|
833 | $self->add ($self->{vp}); |
|
|
834 | $self->add ($self->{slider}); |
|
|
835 | |
|
|
836 | $self |
|
|
837 | } |
|
|
838 | |
|
|
839 | #TODO# update range on size_allocate depeneing on child |
|
|
840 | # update viewport offset on scroll |
727 | |
841 | |
728 | ############################################################################# |
842 | ############################################################################# |
729 | |
843 | |
730 | package CFClient::UI::Frame; |
844 | package CFClient::UI::Frame; |
731 | |
845 | |
… | |
… | |
1244 | |
1358 | |
1245 | delete $self->{texture}; |
1359 | delete $self->{texture}; |
1246 | $self->SUPER::update; |
1360 | $self->SUPER::update; |
1247 | } |
1361 | } |
1248 | |
1362 | |
1249 | sub reconfigure { |
|
|
1250 | my ($self) = @_; |
|
|
1251 | |
|
|
1252 | delete $self->{texture}; |
|
|
1253 | } |
|
|
1254 | |
|
|
1255 | sub set_text { |
1363 | sub set_text { |
1256 | my ($self, $text) = @_; |
1364 | my ($self, $text) = @_; |
1257 | |
1365 | |
1258 | return if $self->{text} eq "T$text"; |
1366 | return if $self->{text} eq "T$text"; |
1259 | $self->{text} = "T$text"; |
1367 | $self->{text} = "T$text"; |
… | |
… | |
1312 | sub set_fontsize { |
1420 | sub set_fontsize { |
1313 | my ($self, $fontsize) = @_; |
1421 | my ($self, $fontsize) = @_; |
1314 | |
1422 | |
1315 | $self->{fontsize} = $fontsize; |
1423 | $self->{fontsize} = $fontsize; |
1316 | delete $self->{texture}; |
1424 | delete $self->{texture}; |
|
|
1425 | |
|
|
1426 | $self->update; |
1317 | $self->check_size; |
1427 | $self->check_size; |
1318 | $self->update; |
|
|
1319 | } |
1428 | } |
1320 | |
1429 | |
1321 | sub _draw { |
1430 | sub _draw { |
1322 | my ($self) = @_; |
1431 | my ($self) = @_; |
1323 | |
1432 | |
… | |
… | |
1957 | # TODO: calculations are off |
2066 | # TODO: calculations are off |
1958 | my $self = $class->SUPER::new ( |
2067 | my $self = $class->SUPER::new ( |
1959 | fg => [1, 1, 1], |
2068 | fg => [1, 1, 1], |
1960 | active_fg => [0, 0, 0], |
2069 | active_fg => [0, 0, 0], |
1961 | range => [0, 0, 100, 10], |
2070 | range => [0, 0, 100, 10], |
1962 | req_w => 20, |
2071 | req_w => $::WIDTH / 80, |
1963 | req_h => 20, |
2072 | req_h => $::WIDTH / 80, |
1964 | vertical => 0, |
2073 | vertical => 0, |
1965 | can_hover => 1, |
2074 | can_hover => 1, |
1966 | inner_pad => 5, |
2075 | inner_pad => 5, |
1967 | @_ |
2076 | @_ |
1968 | ); |
2077 | ); |
… | |
… | |
2405 | } |
2514 | } |
2406 | |
2515 | |
2407 | sub _draw { |
2516 | sub _draw { |
2408 | my ($self) = @_; |
2517 | my ($self) = @_; |
2409 | |
2518 | |
|
|
2519 | return unless $::CONN;#d# manage and cache textures differently |
2410 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2520 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2411 | |
2521 | |
2412 | # TODO animation |
2522 | # TODO animation |
2413 | if ($tex) { |
2523 | if ($tex) { |
2414 | glEnable GL_BLEND; |
2524 | glEnable GL_BLEND; |
… | |
… | |
2422 | } |
2532 | } |
2423 | } |
2533 | } |
2424 | |
2534 | |
2425 | ############################################################################# |
2535 | ############################################################################# |
2426 | |
2536 | |
|
|
2537 | package CFClient::UI::InventoryItem; |
|
|
2538 | |
|
|
2539 | our @ISA = CFClient::UI::HBox::; |
|
|
2540 | |
|
|
2541 | sub new { |
|
|
2542 | my $class = shift; |
|
|
2543 | |
|
|
2544 | my %args = @_; |
|
|
2545 | |
|
|
2546 | my $item = $args{item}; |
|
|
2547 | |
|
|
2548 | my $desc = $item->{nrof} < 2 |
|
|
2549 | ? $item->{name} |
|
|
2550 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2551 | |
|
|
2552 | |
|
|
2553 | my $self = $class->SUPER::new ( |
|
|
2554 | can_hover => 1, |
|
|
2555 | can_events => 1, |
|
|
2556 | tooltip => (CFClient::UI::Label->escape ($desc) |
|
|
2557 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
2558 | connect_button_down => sub { |
|
|
2559 | my ($self, $ev, $x, $y) = @_; |
|
|
2560 | |
|
|
2561 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
2562 | if ($ev->{button} == 1) { |
|
|
2563 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
|
|
2564 | } elsif ($ev->{button} == 2) { |
|
|
2565 | $::CONN->send ("apply $item->{tag}"); |
|
|
2566 | } elsif ($ev->{button} == 3) { |
|
|
2567 | CFClient::UI::Menu->new ( |
|
|
2568 | items => [ |
|
|
2569 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
|
|
2570 | [ |
|
|
2571 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
|
|
2572 | sub { $::CONN->send ("lock $item->{tag}") }, |
|
|
2573 | ], |
|
|
2574 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
|
|
2575 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2576 | ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }], |
|
|
2577 | ], |
|
|
2578 | )->popup ($ev); |
|
|
2579 | } |
|
|
2580 | |
|
|
2581 | 1 |
|
|
2582 | }, |
|
|
2583 | %args |
|
|
2584 | ); |
|
|
2585 | $self->add(new CFClient::UI::Face |
|
|
2586 | can_events => 0, |
|
|
2587 | face => $item->{face}, |
|
|
2588 | anim => $item->{anim}, |
|
|
2589 | animspeed => $item->{animspeed}); |
|
|
2590 | $self->add(new CFClient::UI::Label |
|
|
2591 | can_events => 0, |
|
|
2592 | text => $desc); |
|
|
2593 | |
|
|
2594 | $self |
|
|
2595 | } |
|
|
2596 | |
|
|
2597 | ############################################################################# |
|
|
2598 | |
|
|
2599 | package CFClient::UI::Inventory; |
|
|
2600 | |
|
|
2601 | our @ISA = CFClient::UI::ScrolledWindow::; |
|
|
2602 | |
|
|
2603 | sub new { |
|
|
2604 | my $class = shift; |
|
|
2605 | |
|
|
2606 | my $self = $class->SUPER::new ( |
|
|
2607 | scrolled => (new CFClient::UI::VBox), |
|
|
2608 | @_, |
|
|
2609 | ); |
|
|
2610 | |
|
|
2611 | $self |
|
|
2612 | } |
|
|
2613 | |
|
|
2614 | sub set_items { |
|
|
2615 | my ($self, $items) = @_; |
|
|
2616 | |
|
|
2617 | $self->{scrolled}->clear; |
|
|
2618 | return unless $items; |
|
|
2619 | |
|
|
2620 | my @items = sort { $a->{type} <=> $b->{type} } @$items; |
|
|
2621 | |
|
|
2622 | $self->{real_items} = \@items; |
|
|
2623 | |
|
|
2624 | for my $item (@items) { |
|
|
2625 | my $desc = $item->{nrof} < 2 |
|
|
2626 | ? $item->{name} |
|
|
2627 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2628 | |
|
|
2629 | $self->{scrolled}->add (new CFClient::UI::InventoryItem item => $item); |
|
|
2630 | } |
|
|
2631 | |
|
|
2632 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
|
|
2633 | } |
|
|
2634 | |
|
|
2635 | sub size_request { |
|
|
2636 | my ($self) = @_; |
|
|
2637 | ($self->{req_w}, $self->{req_h}); |
|
|
2638 | } |
|
|
2639 | |
|
|
2640 | ############################################################################# |
|
|
2641 | |
2427 | package CFClient::UI::Menu; |
2642 | package CFClient::UI::Menu; |
2428 | |
2643 | |
2429 | our @ISA = CFClient::UI::FancyFrame::; |
2644 | our @ISA = CFClient::UI::FancyFrame::; |
2430 | |
2645 | |
2431 | use CFClient::OpenGL; |
2646 | use CFClient::OpenGL; |
… | |
… | |
2475 | } |
2690 | } |
2476 | |
2691 | |
2477 | sub mouse_motion { |
2692 | sub mouse_motion { |
2478 | my ($self, $ev, $x, $y) = @_; |
2693 | my ($self, $ev, $x, $y) = @_; |
2479 | |
2694 | |
2480 | # TODO: should use vbox->fdind_widget or so |
2695 | # TODO: should use vbox->find_widget or so |
2481 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2696 | $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); |
2482 | $self->{hover} = $self->{item}{$HOVER}; |
2697 | $self->{hover} = $self->{item}{$HOVER}; |
2483 | } |
2698 | } |
2484 | |
2699 | |
2485 | sub button_up { |
2700 | sub button_up { |
… | |
… | |
2503 | use CFClient::OpenGL; |
2718 | use CFClient::OpenGL; |
2504 | |
2719 | |
2505 | sub check_size { |
2720 | sub check_size { |
2506 | my ($self) = @_; |
2721 | my ($self) = @_; |
2507 | |
2722 | |
2508 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
2723 | $self->configure (0, 0, $self->{w}, $self->{h}); |
2509 | } |
2724 | } |
2510 | |
2725 | |
2511 | sub size_request { |
2726 | sub size_request { |
2512 | ($::WIDTH, $::HEIGHT) |
2727 | my ($self) = @_; |
|
|
2728 | |
|
|
2729 | ($self->{w}, $self->{h}) |
|
|
2730 | } |
|
|
2731 | |
|
|
2732 | sub size_allocate { |
|
|
2733 | my ($self, $w, $h) = @_; |
|
|
2734 | |
|
|
2735 | my $old_w = $self->{old_w}; |
|
|
2736 | my $old_h = $self->{old_h}; |
|
|
2737 | |
|
|
2738 | if ($old_w && $old_h) { |
|
|
2739 | for my $child ($self->children) { |
|
|
2740 | $child->{x} = int 0.5 + $child->{x} * $w / $old_w; |
|
|
2741 | $child->{w} = int 0.5 + $child->{w} * $w / $old_w; |
|
|
2742 | $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w}; |
|
|
2743 | $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w}; |
|
|
2744 | $child->{y} = int 0.5 + $child->{y} * $h / $old_h; |
|
|
2745 | $child->{h} = int 0.5 + $child->{h} * $h / $old_h; |
|
|
2746 | $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h}; |
|
|
2747 | $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h}; |
|
|
2748 | } |
|
|
2749 | } |
|
|
2750 | |
|
|
2751 | $self->{old_w} = $w; |
|
|
2752 | $self->{old_h} = $h; |
2513 | } |
2753 | } |
2514 | |
2754 | |
2515 | sub configure { |
2755 | sub configure { |
2516 | my ($self, $x, $y, $w, $h) = @_; |
2756 | my ($self, $x, $y, $w, $h) = @_; |
2517 | |
2757 | |
2518 | $self->SUPER::configure ($x, $y, $w, $h); |
2758 | $self->SUPER::configure ($x, $y, $w, $h); |
2519 | |
2759 | |
2520 | for my $child (@{$self->{children}}) { |
2760 | for my $child ($self->children) { |
2521 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2761 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2522 | |
2762 | |
2523 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2763 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2524 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2764 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2525 | $child->configure ($X, $Y, $W,$H); |
2765 | $child->configure ($X, $Y, $W, $H); |
2526 | } |
2766 | } |
2527 | } |
2767 | } |
2528 | |
2768 | |
2529 | sub _topleft { |
2769 | sub _topleft { |
2530 | my ($self, $x, $y) = @_; |
2770 | my ($self, $x, $y) = @_; |
… | |
… | |
2575 | $self->_draw; |
2815 | $self->_draw; |
2576 | } |
2816 | } |
2577 | |
2817 | |
2578 | ############################################################################# |
2818 | ############################################################################# |
2579 | |
2819 | |
2580 | package CFClient::UI::Inventory; |
|
|
2581 | |
|
|
2582 | our @ISA = CFClient::UI::Container::; |
|
|
2583 | |
|
|
2584 | use CFClient::OpenGL; |
|
|
2585 | |
|
|
2586 | sub new { |
|
|
2587 | my $class = shift; |
|
|
2588 | |
|
|
2589 | my $self = $class->SUPER::new (@_); |
|
|
2590 | |
|
|
2591 | $self |
|
|
2592 | } |
|
|
2593 | |
|
|
2594 | sub size_allocate { |
|
|
2595 | my ($self, $w, $h) = @_; |
|
|
2596 | |
|
|
2597 | $self->{w} = $w; |
|
|
2598 | $self->{h} = $h; |
|
|
2599 | |
|
|
2600 | $self->check_size; |
|
|
2601 | } |
|
|
2602 | |
|
|
2603 | sub set_items { |
|
|
2604 | my ($self, $items) = @_; |
|
|
2605 | my @items = values %{$items}; |
|
|
2606 | @items = sort { $a->{type} <=> $b->{type} } @items; |
|
|
2607 | |
|
|
2608 | $self->{real_items} = \@items; |
|
|
2609 | |
|
|
2610 | for my $item (@items) { |
|
|
2611 | my $desc = $item->{nrof} < 2 |
|
|
2612 | ? $item->{name} |
|
|
2613 | : "$item->{nrof} $item->{name_pl}"; |
|
|
2614 | |
|
|
2615 | $self->add (my $hb = new CFClient::UI::HBox); |
|
|
2616 | |
|
|
2617 | $hb->add (my $f = new CFClient::UI::Face |
|
|
2618 | can_events => 0, |
|
|
2619 | face => $item->{face}, |
|
|
2620 | anim => $item->{anim}, |
|
|
2621 | animspeed => $item->{animspeed}, |
|
|
2622 | expand => 1, |
|
|
2623 | ); |
|
|
2624 | $hb->add (new CFClient::UI::Label text => $desc, expand => 1); |
|
|
2625 | } |
|
|
2626 | |
|
|
2627 | $self->{max_pos} = (scalar @items) - 1; |
|
|
2628 | |
|
|
2629 | my $range = $self->{range}; |
|
|
2630 | my $page = $self->{h} / 32; # what information source to use for face size? |
|
|
2631 | # it should be configurable I guess... |
|
|
2632 | $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
|
|
2633 | $range->update; |
|
|
2634 | } |
|
|
2635 | |
|
|
2636 | sub size_request { |
|
|
2637 | my ($self) = @_; |
|
|
2638 | (100, 200) |
|
|
2639 | } |
|
|
2640 | |
|
|
2641 | sub set_range { |
|
|
2642 | my ($self, $range) = @_; |
|
|
2643 | |
|
|
2644 | $self->{range} = $range; |
|
|
2645 | $range->connect (changed => sub { $self->update }); |
|
|
2646 | |
|
|
2647 | my $page = $self->{h} / 32; # waht information souce to use for face size? |
|
|
2648 | # it should be configurable i guess... |
|
|
2649 | |
|
|
2650 | $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
|
|
2651 | $range->update; |
|
|
2652 | |
|
|
2653 | $self->update; |
|
|
2654 | } |
|
|
2655 | |
|
|
2656 | sub _draw { |
|
|
2657 | my ($self) = @_; |
|
|
2658 | |
|
|
2659 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
2660 | |
|
|
2661 | $self->{pos} = int $self->{range}{range}[0]; |
|
|
2662 | |
|
|
2663 | my $y = 0; |
|
|
2664 | my $cnt = 0; |
|
|
2665 | my $hrem = $self->{h}; # horiz. remaining space |
|
|
2666 | |
|
|
2667 | for (my $i = $self->{pos}; $i < @{$self->{children} || []}; $i++) { |
|
|
2668 | my $chld = $self->{children}->[$i]; |
|
|
2669 | |
|
|
2670 | if ($hrem >= $chld->{h}) { |
|
|
2671 | $chld->configure (0, $y, $chld->{w}, $chld->{h}); |
|
|
2672 | |
|
|
2673 | $chld->draw; |
|
|
2674 | |
|
|
2675 | $hrem -= $chld->{h}; |
|
|
2676 | $y += $chld->{h}; |
|
|
2677 | } else { |
|
|
2678 | last |
|
|
2679 | } |
|
|
2680 | } |
|
|
2681 | } |
|
|
2682 | |
|
|
2683 | |
|
|
2684 | ############################################################################# |
|
|
2685 | |
|
|
2686 | package CFClient::UI; |
2820 | package CFClient::UI; |
2687 | |
2821 | |
2688 | $ROOT = new CFClient::UI::Root; |
2822 | $ROOT = new CFClient::UI::Root; |
2689 | $TOOLTIP = new CFClient::UI::Tooltip; |
2823 | $TOOLTIP = new CFClient::UI::Tooltip; |
2690 | |
2824 | |