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.291 by root, Tue Jun 6 02:55:50 2006 UTC vs.
Revision 1.298 by root, Wed Jun 7 07:00:30 2006 UTC

315} 315}
316 316
317sub move_abs { 317sub move_abs {
318 my ($self, $x, $y, $z) = @_; 318 my ($self, $x, $y, $z) = @_;
319 319
320 $self->{x} = List::Util::max 0, int $x; 320 $self->{x} = List::Util::max 0, List::Util::min $self->{root}{w} - $self->{w}, int $x;
321 $self->{y} = List::Util::max 0, int $y; 321 $self->{y} = List::Util::max 0, List::Util::min $self->{root}{h} - $self->{h}, int $y;
322 $self->{z} = $z if defined $z; 322 $self->{z} = $z if defined $z;
323 323
324 $self->update; 324 $self->update;
325} 325}
326 326
1658 : ($self->{h} - $tex->{h}) * 0.5); 1658 : ($self->{h} - $tex->{h}) * 0.5);
1659 }; 1659 };
1660 1660
1661 glEnable GL_TEXTURE_2D; 1661 glEnable GL_TEXTURE_2D;
1662 1662
1663 my $w = List::Util::min $self->{w} + 4, $tex->{w};
1664 my $h = List::Util::min $self->{h} + 2, $tex->{h};
1665
1663 if ($tex->{format} == GL_ALPHA) { 1666 if ($tex->{format} == GL_ALPHA) {
1664 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1667 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1665 glColor @{$self->{fg}}; 1668 glColor @{$self->{fg}};
1666 $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); 1669 $tex->draw_quad_alpha ($self->{ox}, $self->{oy}, $w, $h);
1667 } else { 1670 } else {
1668 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1671 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1669 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); 1672 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}, $w, $h);
1670 } 1673 }
1671 1674
1672 glDisable GL_TEXTURE_2D; 1675 glDisable GL_TEXTURE_2D;
1673} 1676}
1674 1677
2304sub set_range { 2307sub set_range {
2305 my ($self, $range) = @_; 2308 my ($self, $range) = @_;
2306 2309
2307 ($range, $self->{range}) = ($self->{range}, $range); 2310 ($range, $self->{range}) = ($self->{range}, $range);
2308 2311
2309 $self->update
2310 if "@$range" ne "@{$self->{range}}"; 2312 if ("@$range" ne "@{$self->{range}}") {
2313 $self->update;
2314 $self->set_value ($self->{range}[0]);
2315 }
2311} 2316}
2312 2317
2313sub set_value { 2318sub set_value {
2314 my ($self, $value) = @_; 2319 my ($self, $value) = @_;
2315 2320
2462sub set_range { shift->{slider}->set_range (@_) } 2467sub set_range { shift->{slider}->set_range (@_) }
2463sub set_value { shift->{slider}->set_value (@_) } 2468sub set_value { shift->{slider}->set_value (@_) }
2464 2469
2465############################################################################# 2470#############################################################################
2466 2471
2467package CFClient::UI::TextView; 2472package CFClient::UI::TextScroller;
2468 2473
2469our @ISA = CFClient::UI::HBox::; 2474our @ISA = CFClient::UI::HBox::;
2470 2475
2471use CFClient::OpenGL; 2476use CFClient::OpenGL;
2472 2477
2474 my $class = shift; 2479 my $class = shift;
2475 2480
2476 my $self = $class->SUPER::new ( 2481 my $self = $class->SUPER::new (
2477 fontsize => 1, 2482 fontsize => 1,
2478 can_events => 0, 2483 can_events => 0,
2484 indent => 0,
2479 #font => default_font 2485 #font => default_font
2480 @_, 2486 @_,
2481 2487
2482 layout => (new CFClient::Layout 1), 2488 layout => (new CFClient::Layout 1),
2483 par => [], 2489 par => [],
2506 $self->SUPER::size_allocate ($w, $h); 2512 $self->SUPER::size_allocate ($w, $h);
2507 2513
2508 $self->{layout}->set_font ($self->{font}) if $self->{font}; 2514 $self->{layout}->set_font ($self->{font}) if $self->{font};
2509 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 2515 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2510 $self->{layout}->set_width ($self->{children}[0]{w}); 2516 $self->{layout}->set_width ($self->{children}[0]{w});
2517 $self->{layout}->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
2511 2518
2512 $self->reflow; 2519 $self->reflow;
2513} 2520}
2514 2521
2515sub text_size { 2522sub text_size {
2517 2524
2518 my $layout = $self->{layout}; 2525 my $layout = $self->{layout};
2519 2526
2520 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2527 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2521 $layout->set_width ($self->{children}[0]{w} - $indent); 2528 $layout->set_width ($self->{children}[0]{w} - $indent);
2529 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
2522 $layout->set_markup ($text); 2530 $layout->set_markup ($text);
2523 2531
2524 $layout->size 2532 $layout->size
2525} 2533}
2526 2534
2565 2573
2566 return unless $self->{h} > 0; 2574 return unless $self->{h} > 0;
2567 2575
2568 delete $self->{texture}; 2576 delete $self->{texture};
2569 2577
2570 $ROOT->on_post_alloc ($self, sub { 2578 $ROOT->on_post_alloc ($self => sub {
2571 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 2579 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2572 2580
2573 if (delete $self->{need_reflow}) { 2581 if (delete $self->{need_reflow}) {
2574 my $height = 0; 2582 my $height = 0;
2575 2583
2578 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2586 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2579 2587
2580 for (@{$self->{par}}) { 2588 for (@{$self->{par}}) {
2581 if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support 2589 if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support
2582 $layout->set_width ($W - $_->[3]); 2590 $layout->set_width ($W - $_->[3]);
2591 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
2583 $layout->set_markup ($_->[4]); 2592 $layout->set_markup ($_->[4]);
2584 my ($w, $h) = $layout->size; 2593 my ($w, $h) = $layout->size;
2585 $_->[0] = $w + $_->[3]; 2594 $_->[0] = $w + $_->[3];
2586 $_->[1] = $h; 2595 $_->[1] = $h;
2587 } 2596 }
2590 } 2599 }
2591 2600
2592 $self->{height} = $height; 2601 $self->{height} = $height;
2593 2602
2594 $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]); 2603 $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]);
2595 2604
2596 delete $self->{texture}; 2605 delete $self->{texture};
2597 } 2606 }
2598 2607
2599 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub { 2608 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub {
2600 glClearColor 0, 0, 0, 0; 2609 glClearColor 0, 0, 0, 0;
2619 my $h = $par->[1]; 2628 my $h = $par->[1];
2620 2629
2621 if ($y0 < $y + $h && $y < $y1) { 2630 if ($y0 < $y + $h && $y < $y1) {
2622 $layout->set_foreground (@{ $par->[2] }); 2631 $layout->set_foreground (@{ $par->[2] });
2623 $layout->set_width ($W - $par->[3]); 2632 $layout->set_width ($W - $par->[3]);
2633 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
2624 $layout->set_markup ($par->[4]); 2634 $layout->set_markup ($par->[4]);
2625 2635
2626 my ($w, $h, $data, $format, $internalformat) = $layout->render; 2636 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2627 2637
2628 glRasterPos $par->[3], $y - $y0; 2638 glRasterPos $par->[3], $y - $y0;
2742 $tooltip .= "\n\n" . (ref $widget) . "\n" 2752 $tooltip .= "\n\n" . (ref $widget) . "\n"
2743 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 2753 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
2744 . "req $widget->{req_w} $widget->{req_h}\n" 2754 . "req $widget->{req_w} $widget->{req_h}\n"
2745 . "visible $widget->{visible}"; 2755 . "visible $widget->{visible}";
2746 } 2756 }
2757
2758 $tooltip =~ s/^\n+//;
2759 $tooltip =~ s/\n+$//;
2747 2760
2748 $self->add (new CFClient::UI::Label 2761 $self->add (new CFClient::UI::Label
2749 markup => $tooltip, 2762 markup => $tooltip,
2750 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2763 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2751 fontsize => 0.8, 2764 fontsize => 0.8,
2779 or return; 2792 or return;
2780 2793
2781 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 2794 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2782 2795
2783 ($x, $y) = $widget->coord2global (-$self->{w}, 0) 2796 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2784 if $x + $self->{w} > $::WIDTH; 2797 if $x + $self->{w} > $self->{root}{w};
2785 2798
2786 $self->move_abs ($x, $y); 2799 $self->move_abs ($x, $y);
2787 }); 2800 });
2788} 2801}
2789 2802
2928 # handle various types of items, only text for now 2941 # handle various types of items, only text for now
2929 if (!ref $widget) { 2942 if (!ref $widget) {
2930 $widget = new CFClient::UI::Label 2943 $widget = new CFClient::UI::Label
2931 can_hover => 1, 2944 can_hover => 1,
2932 can_events => 1, 2945 can_events => 1,
2933 text => $widget, 2946 markup => $widget,
2934 tooltip => $tooltip 2947 tooltip => $tooltip
2935 } 2948 }
2936 2949
2937 $self->{item}{$widget} = $item; 2950 $self->{item}{$widget} = $item;
2938 2951
3100 3113
3101sub new { 3114sub new {
3102 my $class = shift; 3115 my $class = shift;
3103 3116
3104 my $self = $class->SUPER::new ( 3117 my $self = $class->SUPER::new (
3105 options => [], # [title, value, tooltip], ... 3118 options => [], # [value, title, longdesc], ...
3106 value => undef, 3119 value => undef,
3107 @_, 3120 @_,
3108 ); 3121 );
3109 3122
3110 $self->_set_value ($self->{value}); 3123 $self->_set_value ($self->{value});
3116 my ($self, $ev) = @_; 3129 my ($self, $ev) = @_;
3117 3130
3118 my @menu_items; 3131 my @menu_items;
3119 3132
3120 for (@{ $self->{options} }) { 3133 for (@{ $self->{options} }) {
3121 my ($title, $value, $tooltip) = @$_; 3134 my ($value, $title, $tooltip) = @$_;
3122 3135
3123 push @menu_items, [$tooltip, sub { $self->set_value ($value) }]; 3136 push @menu_items, [$tooltip || $title, sub { $self->set_value ($value) }];
3124 } 3137 }
3125 3138
3126 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 3139 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
3127} 3140}
3128 3141
3129sub _set_value { 3142sub _set_value {
3130 my ($self, $value) = @_; 3143 my ($self, $value) = @_;
3131 3144
3132 my ($item) = grep $_->[1] eq $value, @{ $self->{options} } 3145 my ($item) = grep $_->[0] eq $value, @{ $self->{options} }
3133 or return; 3146 or return;
3134 3147
3135 $self->{value} = $item->[1]; 3148 $self->{value} = $item->[0];
3136 $self->set_markup ("$item->[0] ⇓"); 3149 $self->set_markup ("$item->[1] ⇓");
3137 $self->set_tooltip ($item->[2]); 3150 $self->set_tooltip ($item->[2]);
3138} 3151}
3139 3152
3140sub set_value { 3153sub set_value {
3141 my ($self, $value) = @_; 3154 my ($self, $value) = @_;
3542 commands => [], 3555 commands => [],
3543 @_, 3556 @_,
3544 ) 3557 )
3545} 3558}
3546 3559
3560my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>";
3561
3562my @TOOLTIP_NAME = (align => 0, can_events => 1, can_hover => 1, tooltip =>
3563 "<b>Name</b>. The name of the spell.$TOOLTIP_ALL");
3547my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => 3564my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3548 "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell."); 3565 "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL");
3549my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => 3566my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3550 "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation."); 3567 "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL");
3551my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => 3568my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip =>
3552 "<b>Damage</b>. The amount of damage the spell deals when it hits."); 3569 "<b>Damage</b>. The amount of damage the spell deals when it hits.$TOOLTIP_ALL");
3553 3570
3554sub rebuild_spell_list { 3571sub rebuild_spell_list {
3555 my ($self) = @_; 3572 my ($self) = @_;
3556 3573
3557 $CFClient::UI::ROOT->on_refresh ($self => sub { 3574 $CFClient::UI::ROOT->on_refresh ($self => sub {
3558 $self->clear; 3575 $self->clear;
3559 3576
3560 $self->add (1, 0, new CFClient::UI::Label text => "Spell Name"); 3577 $self->add (1, 0, new CFClient::UI::Label text => "Spell Name", @TOOLTIP_NAME);
3561 $self->add (2, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); 3578 $self->add (2, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL);
3562 $self->add (3, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); 3579 $self->add (3, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP);
3563 $self->add (4, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); 3580 $self->add (4, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG);
3564 3581
3565 my $row = 0; 3582 my $row = 0;
3566 3583
3567 for (sort { $a cmp $b } keys %{ $self->{spell} }) { 3584 for (sort { $a cmp $b } keys %{ $self->{spell} }) {
3568 my $spell = $self->{spell}{$_}; 3585 my $spell = $self->{spell}{$_};
3569 3586
3570 $row++; 3587 $row++;
3588
3589 my $spell_cb = sub {
3590 my ($widget, $ev) = @_;
3591
3592 if ($ev->{button} == 1) {
3593 $::CONN->user_send ("cast $spell->{name}");
3594 } elsif ($ev->{button} == 2) {
3595 $::CONN->user_send ("invoke $spell->{name}");
3596 } elsif ($ev->{button} == 3) {
3597 (new CFClient::UI::Menu
3598 items => [
3599 ["bind <i>cast $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }],
3600 ["bind <i>invoke $spell->{name}</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["invoke $spell->{name}"]) }],
3601 ],
3602 )->popup ($ev);
3603 } else {
3604 return 0;
3605 }
3606
3607 1
3608 };
3571 3609
3572 $self->add (0, $row, new CFClient::UI::Face 3610 $self->add (0, $row, new CFClient::UI::Face
3573 face => $spell->{face}, 3611 face => $spell->{face},
3574 can_hover => 1, 3612 can_hover => 1,
3575 can_events => 1, 3613 can_events => 1,
3576 tooltip => $spell->{message}, 3614 tooltip => $spell->{message},
3615 on_button_down => $spell_cb,
3577 ); 3616 );
3578 3617
3579 $self->add (1, $row, new CFClient::UI::Label 3618 $self->add (1, $row, new CFClient::UI::Label
3580 expand => 1, 3619 expand => 1,
3581 text => $spell->{name}, 3620 text => $spell->{name},
3582 can_hover => 1, 3621 can_hover => 1,
3583 can_events => 1, 3622 can_events => 1,
3584 tooltip => $spell->{message}, 3623 tooltip => "$spell->{message}$TOOLTIP_ALL",
3624 on_button_down => $spell_cb,
3585 ); 3625 );
3586 3626
3587 $self->add (2, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); 3627 $self->add (2, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL);
3588 $self->add (3, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); 3628 $self->add (3, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP);
3589 $self->add (4, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); 3629 $self->add (4, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG);
3590
3591 # TODO: should be done via popup
3592 $self->add (5, $row, new CFClient::UI::Button
3593 text => "bind",
3594 tooltip => "bind spell readying (cast command) to key",
3595 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) },
3596 );
3597 } 3630 }
3598 }); 3631 });
3599} 3632}
3600 3633
3601sub add_spell { 3634sub add_spell {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines