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.209 by root, Wed May 17 00:26:55 2006 UTC vs.
Revision 1.214 by root, Wed May 17 22:59:13 2006 UTC

140 140
141# call when resolution changes etc. 141# call when resolution changes etc.
142sub rescale_widgets { 142sub rescale_widgets {
143 my ($sx, $sy) = @_; 143 my ($sx, $sy) = @_;
144 144
145 # make a copy, otherwise for complains about freed values.
145 for my $widget (values %WIDGET) { 146 my @widgets = values %WIDGET;
147
148 for my $widget (@widgets) {
146 if ($widget->{toplevel}) { 149 if ($widget->{toplevel}) {
147 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; 150 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x};
148 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; 151 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
149 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; 152 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w};
150 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; 153 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w};
1297 #bg => none 1300 #bg => none
1298 #active_bg => none 1301 #active_bg => none
1299 #font => default_font 1302 #font => default_font
1300 #text => initial text 1303 #text => initial text
1301 #markup => initial narkup 1304 #markup => initial narkup
1305 #max_w => maximum pixel width
1306 ellipsise => 3, # end
1302 layout => (new CFClient::Layout), 1307 layout => (new CFClient::Layout),
1303 fontsize => 1, 1308 fontsize => 1,
1304 align => -1, 1309 align => -1,
1305 valign => -1, 1310 valign => -1,
1306 padding => 2, 1311 padding => 2,
1371sub size_request { 1376sub size_request {
1372 my ($self) = @_; 1377 my ($self) = @_;
1373 1378
1374 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1379 $self->{layout}->set_font ($self->{font}) if $self->{font};
1375 $self->{layout}->set_width ($self->{max_w} || -1); 1380 $self->{layout}->set_width ($self->{max_w} || -1);
1381 $self->{layout}->set_ellipsise ($self->{ellipsise});
1382 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1376 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1383 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1377 1384
1378 my ($w, $h) = $self->{layout}->size; 1385 my ($w, $h) = $self->{layout}->size;
1379 1386
1380 if (exists $self->{template}) { 1387 if (exists $self->{template}) {
1416 1423
1417 my $tex = $self->{texture} ||= do { 1424 my $tex = $self->{texture} ||= do {
1418 $self->{layout}->set_foreground (@{$self->{fg}}); 1425 $self->{layout}->set_foreground (@{$self->{fg}});
1419 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1426 $self->{layout}->set_font ($self->{font}) if $self->{font};
1420 $self->{layout}->set_width ($self->{w}); 1427 $self->{layout}->set_width ($self->{w});
1428 $self->{layout}->set_ellipsise ($self->{ellipsise});
1429 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1421 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1430 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1422 1431
1423 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1432 my $tex = new_from_layout CFClient::Texture $self->{layout};
1424 1433
1425 $self->{ox} = int ($self->{align} < 0 ? $self->{padding} 1434 $self->{ox} = int ($self->{align} < 0 ? $self->{padding}
1426 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1435 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
2148 glScale $self->{w}, $self->{h}; 2157 glScale $self->{w}, $self->{h};
2149 2158
2150 if ($self->{vertical}) { 2159 if ($self->{vertical}) {
2151 # draw a vertical slider like a rotated horizontal slider 2160 # draw a vertical slider like a rotated horizontal slider
2152 2161
2162 glTranslate 1, 0, 0;
2153 glRotate 90, 0, 0, 1; 2163 glRotate 90, 0, 0, 1;
2154 glTranslate 0, 1, 0;
2155 } 2164 }
2156 2165
2157 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 2166 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
2158 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 2167 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
2159 2168
2426 2435
2427sub set_tooltip_from { 2436sub set_tooltip_from {
2428 my ($self, $widget) = @_; 2437 my ($self, $widget) = @_;
2429 2438
2430 $self->add (new CFClient::UI::Label 2439 $self->add (new CFClient::UI::Label
2431 markup => $widget->{tooltip}, 2440 markup => $widget->{tooltip},
2432 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2441 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2433 fontsize => 0.8, 2442 fontsize => 0.8,
2434 fg => [0, 0, 0, 1], 2443 fg => [0, 0, 0, 1],
2444 ellipsise => 0,
2435 font => ($widget->{tooltip_font} || $::FONT_PROP), 2445 font => ($widget->{tooltip_font} || $::FONT_PROP),
2436 ); 2446 );
2437} 2447}
2438 2448
2439sub size_request { 2449sub size_request {
2440 my ($self) = @_; 2450 my ($self) = @_;
2518 2528
2519package CFClient::UI::InventoryItem; 2529package CFClient::UI::InventoryItem;
2520 2530
2521our @ISA = CFClient::UI::HBox::; 2531our @ISA = CFClient::UI::HBox::;
2522 2532
2523sub new { 2533sub _item_to_desc {
2524 my $class = shift; 2534 my ($item) = @_;
2525 2535
2526 my %args = @_; 2536 my $desc =
2527
2528 my $item = delete $args{item};
2529
2530 my $desc = $item->{nrof} < 2 2537 $item->{nrof} < 2
2531 ? $item->{name} 2538 ? $item->{name}
2532 : "$item->{nrof} $item->{name_pl}"; 2539 : "$item->{nrof} $item->{name_pl}";
2533 2540
2534 $item->{flags} & Crossfire::Protocol::F_OPEN 2541 $item->{flags} & Crossfire::Protocol::F_OPEN
2535 and $desc .= " (open)"; 2542 and $desc .= " (open)";
2536 $item->{flags} & Crossfire::Protocol::F_APPLIED 2543 $item->{flags} & Crossfire::Protocol::F_APPLIED
2537 and $desc .= " (applied)"; 2544 and $desc .= " (applied)";
2544 $item->{flags} & Crossfire::Protocol::F_DAMNED 2551 $item->{flags} & Crossfire::Protocol::F_DAMNED
2545 and $desc .= " (damned)"; 2552 and $desc .= " (damned)";
2546 $item->{flags} & Crossfire::Protocol::F_LOCKED 2553 $item->{flags} & Crossfire::Protocol::F_LOCKED
2547 and $desc .= " *"; 2554 and $desc .= " *";
2548 2555
2556 $desc
2557}
2558
2559sub new {
2560 my $class = shift;
2561
2562 my %args = @_;
2563
2564 my $item = delete $args{item};
2565
2566 my $desc = _item_to_desc ($item);
2567
2549 my $self = $class->SUPER::new ( 2568 my $self = $class->SUPER::new (
2550 can_hover => 1, 2569 can_hover => 1,
2551 can_events => 1, 2570 can_events => 1,
2552 tooltip => ((CFClient::UI::Label::escape $desc) 2571 tooltip => ((CFClient::UI::Label::escape $desc)
2553 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), 2572 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
2554 connect_button_down => sub { 2573 connect_button_down => sub {
2555 my ($self, $ev, $x, $y) = @_; 2574 my ($self, $ev, $x, $y) = @_;
2556 2575
2557 # todo: maybe put examine on 1? but should just be a tooltip :( 2576 # todo: maybe put examine on 1? but should just be a tooltip :(
2558 if ($ev->{button} == 1) { 2577 if ($ev->{button} == 1) {
2578 my $targ = $::CONN->{player}{tag};
2579
2580 if ($item->{container} == $::CONN->{player}{tag}) {
2581 $targ = $main::OPENCONT;
2582 }
2583
2559 $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); 2584 $::CONN->send ("move $targ $item->{tag} 0");
2560 } elsif ($ev->{button} == 2) { 2585 } elsif ($ev->{button} == 2) {
2561 $::CONN->send ("apply $item->{tag}"); 2586 $::CONN->send ("apply $item->{tag}");
2562 } elsif ($ev->{button} == 3) { 2587 } elsif ($ev->{button} == 3) {
2563 my @menu_items = ( 2588 my @menu_items = (
2564 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2589 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2565 ["mark", sub { $::CONN->send ("mark $item->{tag}") }], 2590 ["mark", sub { $::CONN->send ("mark $item->{tag}") }],
2566 ["apply", sub { $::CONN->send ("apply $item->{tag}") }], 2591 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2567 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], 2592 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2568 [ 2593 [
2569 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", 2594 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2570 sub { $::CONN->send ("lock ". () ."$item->{tag}") }, 2595 sub { $::CONN->send ("lock $item->{tag}") },
2571 ], 2596 ],
2572 ); 2597 );
2573 2598
2574 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 2599 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2575 } 2600 }
2576 2601
2577 1 2602 1
2578 }, 2603 },
2579 %args 2604 %args
2580 ); 2605 );
2606
2581 2607
2582 $self->add (new CFClient::UI::Face 2608 $self->add (new CFClient::UI::Face
2583 can_events => 0, 2609 can_events => 0,
2584 face => $item->{face}, 2610 face => $item->{face},
2585 anim => $item->{anim}, 2611 anim => $item->{anim},
2586 animspeed => $item->{animspeed}, 2612 animspeed => $item->{animspeed},
2587 ); 2613 );
2588 2614
2589 $self->add (new CFClient::UI::Label 2615 $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0);
2590 can_events => 0, 2616
2591 text => $desc, 2617 $self->{item} = $item;
2592 ); 2618
2619 $self->update_item;
2593 2620
2594 $self 2621 $self
2622}
2623
2624sub update_item {
2625 my ($self) = @_;
2626
2627 my $desc = _item_to_desc ($self->{item});
2628
2629 $self->{name_lbl}->set_text ($desc);
2595} 2630}
2596 2631
2597############################################################################# 2632#############################################################################
2598 2633
2599package CFClient::UI::Inventory; 2634package CFClient::UI::Inventory;
2623 } @$items; 2658 } @$items;
2624 2659
2625 $self->{real_items} = \@items; 2660 $self->{real_items} = \@items;
2626 2661
2627 for my $item (@items) { 2662 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; 2663 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2664 $item->update_item ();
2633 } 2665 }
2634 2666
2635 $self->{scrolled}->add (@items); 2667 $self->{scrolled}->add (@items);
2636 2668
2637# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2669# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2718 2750
2719package CFClient::UI::Statusbox; 2751package CFClient::UI::Statusbox;
2720 2752
2721our @ISA = CFClient::UI::VBox::; 2753our @ISA = CFClient::UI::VBox::;
2722 2754
2755sub new {
2756 my $class = shift;
2757
2758 $class->SUPER::new (
2759 fontsize => 0.8,
2760 @_,
2761 )
2762}
2763
2723sub reorder { 2764sub reorder {
2724 my ($self) = @_; 2765 my ($self) = @_;
2725 my $NOW = time; 2766 my $NOW = time;
2726 2767
2727 while (my ($k, $v) = each %{ $self->{item} }) { 2768 while (my ($k, $v) = each %{ $self->{item} }) {
2746 : $item->{text}; 2787 : $item->{text};
2747 2788
2748 for ($short) { 2789 for ($short) {
2749 s/^\s+//; 2790 s/^\s+//;
2750 s/\s+/ /g; 2791 s/\s+/ /g;
2751 my $len = int 40 / $item->{fontsize};
2752 substr $_, $len, length, "…" if $len < length;
2753 } 2792 }
2754 2793
2755 new CFClient::UI::Label 2794 new CFClient::UI::Label
2756 markup => $short, 2795 markup => $short,
2757 tooltip => $item->{tooltip}, 2796 tooltip => $item->{tooltip},
2758 tooltip_font => $::FONT_PROP, 2797 tooltip_font => $::FONT_PROP,
2759 tooltip_width => 0.67, 2798 tooltip_width => 0.67,
2760 fontsize => $item->{fontsize}, 2799 fontsize => $item->{fontsize} || $self->{fontsize},
2800 max_w => $::WIDTH * 0.44,
2761 fg => $item->{fg}, 2801 fg => $item->{fg},
2762 can_events => 1, 2802 can_events => 1,
2763 can_hover => 1 2803 can_hover => 1
2764 }; 2804 };
2765 } 2805 }
2792 $self->{item}{$group} = { 2832 $self->{item}{$group} = {
2793 id => ++$self->{id}, 2833 id => ++$self->{id},
2794 text => $text, 2834 text => $text,
2795 timeout => $timeout, 2835 timeout => $timeout,
2796 tooltip => $text, 2836 tooltip => $text,
2797 fontsize => 0.8,
2798 fg => [0.8, 0.8, 0.8, 0.8], 2837 fg => [0.8, 0.8, 0.8, 0.8],
2799 pri => 0, 2838 pri => 0,
2800 count => 1, 2839 count => 1,
2801 %arg, 2840 %arg,
2802 }; 2841 };
2803 } 2842 }
2804 2843
2805 $self->reorder; 2844 $self->reorder;
2845}
2846
2847sub reconfigure {
2848 my ($self) = @_;
2849
2850 delete $_->{label}
2851 for values %{ $self->{item} || {} };
2852
2853 $self->reorder;
2854 $self->SUPER::reconfigure;
2806} 2855}
2807 2856
2808############################################################################# 2857#############################################################################
2809 2858
2810package CFClient::UI::Root; 2859package CFClient::UI::Root;
2985############################################################################# 3034#############################################################################
2986 3035
2987package CFClient::UI; 3036package CFClient::UI;
2988 3037
2989$ROOT = new CFClient::UI::Root; 3038$ROOT = new CFClient::UI::Root;
2990$TOOLTIP = new CFClient::UI::Tooltip; 3039$TOOLTIP = new CFClient::UI::Tooltip z => 900;
2991 3040
29921 30411
2993 3042

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines