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.214 by root, Wed May 17 22:59:13 2006 UTC vs.
Revision 1.218 by root, Sat May 20 15:37:27 2006 UTC

691 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 691 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
692 glClearColor 0, 0, 0, 0; 692 glClearColor 0, 0, 0, 0;
693 glClear GL_COLOR_BUFFER_BIT; 693 glClear GL_COLOR_BUFFER_BIT;
694 694
695 $self->_render; 695 $self->_render;
696# glColorMask 1, 1, 1, 0;
697# glEnable GL_BLEND;
698# glBlendFunc GL_SRC_ALPHA, GL_ZERO;
699# glRasterPos 0, 0;
700# glCopyPixels 0, 0, $self->{w}, $self->{h};
701# glDisable GL_BLEND;
702# glColorMask 1, 1, 1, 1;
703 }; 696 };
704} 697}
705 698
706sub _draw { 699sub _draw {
707 my ($self) = @_; 700 my ($self) = @_;
711 my $tex = $self->{texture} 704 my $tex = $self->{texture}
712 or return; 705 or return;
713 706
714 glEnable GL_TEXTURE_2D; 707 glEnable GL_TEXTURE_2D;
715 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 708 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
716 glColor 0, 0, 0, 1; 709 glColor 1, 1, 1, 1;
717 710
718 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 711 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
719 712
720 glDisable GL_TEXTURE_2D; 713 glDisable GL_TEXTURE_2D;
721} 714}
804 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); 797 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h}));
805 }, 798 },
806 ; 799 ;
807 800
808 $self = $class->SUPER::new ( 801 $self = $class->SUPER::new (
809 vp => (new CFClient::UI::ViewPort), 802 vp => (new CFClient::UI::ViewPort expand => 1),
810 slider => $slider, 803 slider => $slider,
811 @_, 804 @_,
812 ); 805 );
813 806
814 $self->{vp}->add ($self->{scrolled}); 807 $self->{vp}->add ($self->{scrolled});
2057 range => [0, 0, 100, 10], 2050 range => [0, 0, 100, 10],
2058 req_w => $::WIDTH / 80, 2051 req_w => $::WIDTH / 80,
2059 req_h => $::WIDTH / 80, 2052 req_h => $::WIDTH / 80,
2060 vertical => 0, 2053 vertical => 0,
2061 can_hover => 1, 2054 can_hover => 1,
2062 inner_pad => .05, 2055 inner_pad => 0.02,
2063 @_ 2056 @_
2064 ); 2057 );
2065 2058
2066 $self->set_value ($self->{range}[0]); 2059 $self->set_value ($self->{range}[0]);
2067 $self->update; 2060 $self->update;
2284 2277
2285 delete $self->{texture}; 2278 delete $self->{texture};
2286 } 2279 }
2287 2280
2288 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2281 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2289 glClearColor 0, 0, 0, 0; 2282 glClearColor 0.5, 0.5, 0.5, 0;
2290 glClear GL_COLOR_BUFFER_BIT; 2283 glClear GL_COLOR_BUFFER_BIT;
2291 2284
2292 glEnable GL_TEXTURE_2D; 2285 glEnable GL_TEXTURE_2D;
2293 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2286 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2294 2287
2326 my ($self) = @_; 2319 my ($self) = @_;
2327 2320
2328 glEnable GL_TEXTURE_2D; 2321 glEnable GL_TEXTURE_2D;
2329 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2322 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2330 glColor 1, 1, 1, 1; 2323 glColor 1, 1, 1, 1;
2331 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2324 $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2332 glDisable GL_TEXTURE_2D; 2325 glDisable GL_TEXTURE_2D;
2333 2326
2334 $self->{children}[1]->draw; 2327 $self->{children}[1]->draw;
2335 2328
2336} 2329}
2496use CFClient::OpenGL; 2489use CFClient::OpenGL;
2497 2490
2498sub new { 2491sub new {
2499 my $class = shift; 2492 my $class = shift;
2500 2493
2501 $class->SUPER::new ( 2494 my $self = $class->SUPER::new (
2502 aspect => 1, 2495 aspect => 1,
2503 @_, 2496 @_,
2504 ) 2497 );
2498
2499 if ($self->{anim} && $self->{animspeed}) {
2500 Scalar::Util::weaken (my $widget = $self);
2501
2502 $self->{timer} = Event->timer (
2503 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
2504 hard => 1,
2505 interval => $self->{animspeed},
2506 cb => sub {
2507 ++$widget->{frame};
2508 $widget->update;
2509 },
2510 );
2511 }
2512
2513 $self
2505} 2514}
2506 2515
2507sub size_request { 2516sub size_request {
2508 (32, 8) 2517 (32, 8)
2509} 2518}
2510 2519
2511sub _draw { 2520sub _draw {
2512 my ($self) = @_; 2521 my ($self) = @_;
2513 2522
2514 return unless $::CONN;#d# manage and cache textures differently 2523 return unless $::CONN;#d# manage and cache textures differently
2524
2525 my $face;
2526
2527 if ($self->{frame}) {
2528 my $anim = $::CONN->{anim}[$self->{anim}];
2529
2530 $face = $anim->[ $self->{frame} % @$anim ]
2531 if $anim && @$anim;
2532 }
2533
2515 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2534 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]];
2516 2535
2517 # TODO animation
2518 if ($tex) { 2536 if ($tex) {
2519 glEnable GL_TEXTURE_2D; 2537 glEnable GL_TEXTURE_2D;
2520 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2538 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2521 glColor 1, 1, 1, 1; 2539 glColor 1, 1, 1, 1;
2522 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2540 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2523 glDisable GL_TEXTURE_2D; 2541 glDisable GL_TEXTURE_2D;
2524 } 2542 }
2525} 2543}
2526 2544
2545sub DESTROY {
2546 my ($self) = @_;
2547
2548 $self->{timer}->cancel
2549 if $self->{timer};
2550
2551 $self->SUPER::DESTROY;
2552}
2553
2527############################################################################# 2554#############################################################################
2528 2555
2529package CFClient::UI::InventoryItem; 2556package CFClient::UI::InventoryItem;
2530 2557
2531our @ISA = CFClient::UI::HBox::; 2558our @ISA = CFClient::UI::HBox::;
2534 my ($item) = @_; 2561 my ($item) = @_;
2535 2562
2536 my $desc = 2563 my $desc =
2537 $item->{nrof} < 2 2564 $item->{nrof} < 2
2538 ? $item->{name} 2565 ? $item->{name}
2539 : "$item->{nrof} $item->{name_pl}"; 2566 : "$item->{nrof} × $item->{name_pl}";
2540 2567
2541 $item->{flags} & Crossfire::Protocol::F_OPEN 2568 $item->{flags} & Crossfire::Protocol::F_OPEN
2542 and $desc .= " (open)"; 2569 and $desc .= " (open)";
2543 $item->{flags} & Crossfire::Protocol::F_APPLIED 2570 $item->{flags} & Crossfire::Protocol::F_APPLIED
2544 and $desc .= " (applied)"; 2571 and $desc .= " (applied)";
2564 my $item = delete $args{item}; 2591 my $item = delete $args{item};
2565 2592
2566 my $desc = _item_to_desc ($item); 2593 my $desc = _item_to_desc ($item);
2567 2594
2568 my $self = $class->SUPER::new ( 2595 my $self = $class->SUPER::new (
2569 can_hover => 1, 2596 can_hover => 1,
2570 can_events => 1, 2597 can_events => 1,
2571 tooltip => ((CFClient::UI::Label::escape $desc) 2598 tooltip => ((CFClient::UI::Label::escape $desc)
2572 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), 2599 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
2573 connect_button_down => sub { 2600 connect_button_down => sub {
2574 my ($self, $ev, $x, $y) = @_; 2601 my ($self, $ev, $x, $y) = @_;
2575 2602
2576 # todo: maybe put examine on 1? but should just be a tooltip :( 2603 # todo: maybe put examine on 1? but should just be a tooltip :(
2585 } elsif ($ev->{button} == 2) { 2612 } elsif ($ev->{button} == 2) {
2586 $::CONN->send ("apply $item->{tag}"); 2613 $::CONN->send ("apply $item->{tag}");
2587 } elsif ($ev->{button} == 3) { 2614 } elsif ($ev->{button} == 3) {
2588 my @menu_items = ( 2615 my @menu_items = (
2589 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2616 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2590 ["mark", sub { $::CONN->send ("mark $item->{tag}") }], 2617 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2591 ["apply", sub { $::CONN->send ("apply $item->{tag}") }], 2618 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2619 (
2620 $item->{flags} & Crossfire::Protocol::F_LOCKED
2621 ? (
2622 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2623 )
2624 : (
2625 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2592 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], 2626 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2593 [ 2627 )
2594 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2595 sub { $::CONN->send ("lock $item->{tag}") },
2596 ], 2628 ),
2597 ); 2629 );
2598 2630
2599 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 2631 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2600 } 2632 }
2601 2633

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines