… | |
… | |
140 | |
140 | |
141 | # call when resolution changes etc. |
141 | # call when resolution changes etc. |
142 | sub rescale_widgets { |
142 | sub 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}; |
… | |
… | |
688 | $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 { |
689 | glClearColor 0, 0, 0, 0; |
692 | glClearColor 0, 0, 0, 0; |
690 | glClear GL_COLOR_BUFFER_BIT; |
693 | glClear GL_COLOR_BUFFER_BIT; |
691 | |
694 | |
692 | $self->_render; |
695 | $self->_render; |
693 | # glColorMask 1, 1, 1, 0; |
|
|
694 | # glEnable GL_BLEND; |
|
|
695 | # glBlendFunc GL_SRC_ALPHA, GL_ZERO; |
|
|
696 | # glRasterPos 0, 0; |
|
|
697 | # glCopyPixels 0, 0, $self->{w}, $self->{h}; |
|
|
698 | # glDisable GL_BLEND; |
|
|
699 | # glColorMask 1, 1, 1, 1; |
|
|
700 | }; |
696 | }; |
701 | } |
697 | } |
702 | |
698 | |
703 | sub _draw { |
699 | sub _draw { |
704 | my ($self) = @_; |
700 | my ($self) = @_; |
… | |
… | |
708 | my $tex = $self->{texture} |
704 | my $tex = $self->{texture} |
709 | or return; |
705 | or return; |
710 | |
706 | |
711 | glEnable GL_TEXTURE_2D; |
707 | glEnable GL_TEXTURE_2D; |
712 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
708 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
713 | glColor 0, 0, 0, 1; |
709 | glColor 1, 1, 1, 1; |
714 | |
710 | |
715 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
711 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
716 | |
712 | |
717 | glDisable GL_TEXTURE_2D; |
713 | glDisable GL_TEXTURE_2D; |
718 | } |
714 | } |
… | |
… | |
801 | $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})); |
802 | }, |
798 | }, |
803 | ; |
799 | ; |
804 | |
800 | |
805 | $self = $class->SUPER::new ( |
801 | $self = $class->SUPER::new ( |
806 | vp => (new CFClient::UI::ViewPort), |
802 | vp => (new CFClient::UI::ViewPort expand => 1), |
807 | slider => $slider, |
803 | slider => $slider, |
808 | @_, |
804 | @_, |
809 | ); |
805 | ); |
810 | |
806 | |
811 | $self->{vp}->add ($self->{scrolled}); |
807 | $self->{vp}->add ($self->{scrolled}); |
… | |
… | |
1297 | #bg => none |
1293 | #bg => none |
1298 | #active_bg => none |
1294 | #active_bg => none |
1299 | #font => default_font |
1295 | #font => default_font |
1300 | #text => initial text |
1296 | #text => initial text |
1301 | #markup => initial narkup |
1297 | #markup => initial narkup |
|
|
1298 | #max_w => maximum pixel width |
|
|
1299 | ellipsise => 3, # end |
1302 | layout => (new CFClient::Layout), |
1300 | layout => (new CFClient::Layout), |
1303 | fontsize => 1, |
1301 | fontsize => 1, |
1304 | align => -1, |
1302 | align => -1, |
1305 | valign => -1, |
1303 | valign => -1, |
1306 | padding => 2, |
1304 | padding => 2, |
… | |
… | |
1371 | sub size_request { |
1369 | sub size_request { |
1372 | my ($self) = @_; |
1370 | my ($self) = @_; |
1373 | |
1371 | |
1374 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1372 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1375 | $self->{layout}->set_width ($self->{max_w} || -1); |
1373 | $self->{layout}->set_width ($self->{max_w} || -1); |
|
|
1374 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
|
|
1375 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1376 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1376 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1377 | |
1377 | |
1378 | my ($w, $h) = $self->{layout}->size; |
1378 | my ($w, $h) = $self->{layout}->size; |
1379 | |
1379 | |
1380 | if (exists $self->{template}) { |
1380 | if (exists $self->{template}) { |
… | |
… | |
1416 | |
1416 | |
1417 | my $tex = $self->{texture} ||= do { |
1417 | my $tex = $self->{texture} ||= do { |
1418 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1418 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1419 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1419 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1420 | $self->{layout}->set_width ($self->{w}); |
1420 | $self->{layout}->set_width ($self->{w}); |
|
|
1421 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
|
|
1422 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1421 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1423 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1422 | |
1424 | |
1423 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1425 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
1424 | |
1426 | |
1425 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding} |
1427 | $self->{ox} = int ($self->{align} < 0 ? $self->{padding} |
1426 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1428 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
… | |
… | |
2048 | range => [0, 0, 100, 10], |
2050 | range => [0, 0, 100, 10], |
2049 | req_w => $::WIDTH / 80, |
2051 | req_w => $::WIDTH / 80, |
2050 | req_h => $::WIDTH / 80, |
2052 | req_h => $::WIDTH / 80, |
2051 | vertical => 0, |
2053 | vertical => 0, |
2052 | can_hover => 1, |
2054 | can_hover => 1, |
2053 | inner_pad => .05, |
2055 | inner_pad => 0.02, |
2054 | @_ |
2056 | @_ |
2055 | ); |
2057 | ); |
2056 | |
2058 | |
2057 | $self->set_value ($self->{range}[0]); |
2059 | $self->set_value ($self->{range}[0]); |
2058 | $self->update; |
2060 | $self->update; |
… | |
… | |
2148 | glScale $self->{w}, $self->{h}; |
2150 | glScale $self->{w}, $self->{h}; |
2149 | |
2151 | |
2150 | if ($self->{vertical}) { |
2152 | if ($self->{vertical}) { |
2151 | # draw a vertical slider like a rotated horizontal slider |
2153 | # draw a vertical slider like a rotated horizontal slider |
2152 | |
2154 | |
|
|
2155 | glTranslate 1, 0, 0; |
2153 | glRotate 90, 0, 0, 1; |
2156 | glRotate 90, 0, 0, 1; |
2154 | glTranslate 0, 1, 0; |
|
|
2155 | } |
2157 | } |
2156 | |
2158 | |
2157 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2159 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
2158 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2160 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
2159 | |
2161 | |
… | |
… | |
2275 | |
2277 | |
2276 | delete $self->{texture}; |
2278 | delete $self->{texture}; |
2277 | } |
2279 | } |
2278 | |
2280 | |
2279 | $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 { |
2280 | glClearColor 0, 0, 0, 0; |
2282 | glClearColor 0.5, 0.5, 0.5, 0; |
2281 | glClear GL_COLOR_BUFFER_BIT; |
2283 | glClear GL_COLOR_BUFFER_BIT; |
2282 | |
2284 | |
2283 | glEnable GL_TEXTURE_2D; |
2285 | glEnable GL_TEXTURE_2D; |
2284 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2286 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2285 | |
2287 | |
… | |
… | |
2317 | my ($self) = @_; |
2319 | my ($self) = @_; |
2318 | |
2320 | |
2319 | glEnable GL_TEXTURE_2D; |
2321 | glEnable GL_TEXTURE_2D; |
2320 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2322 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2321 | glColor 1, 1, 1, 1; |
2323 | glColor 1, 1, 1, 1; |
2322 | $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}); |
2323 | glDisable GL_TEXTURE_2D; |
2325 | glDisable GL_TEXTURE_2D; |
2324 | |
2326 | |
2325 | $self->{children}[1]->draw; |
2327 | $self->{children}[1]->draw; |
2326 | |
2328 | |
2327 | } |
2329 | } |
… | |
… | |
2426 | |
2428 | |
2427 | sub set_tooltip_from { |
2429 | sub set_tooltip_from { |
2428 | my ($self, $widget) = @_; |
2430 | my ($self, $widget) = @_; |
2429 | |
2431 | |
2430 | $self->add (new CFClient::UI::Label |
2432 | $self->add (new CFClient::UI::Label |
2431 | markup => $widget->{tooltip}, |
2433 | markup => $widget->{tooltip}, |
2432 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2434 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
2433 | fontsize => 0.8, |
2435 | fontsize => 0.8, |
2434 | fg => [0, 0, 0, 1], |
2436 | fg => [0, 0, 0, 1], |
|
|
2437 | ellipsise => 0, |
2435 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
2438 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
2436 | ); |
2439 | ); |
2437 | } |
2440 | } |
2438 | |
2441 | |
2439 | sub size_request { |
2442 | sub size_request { |
2440 | my ($self) = @_; |
2443 | my ($self) = @_; |
… | |
… | |
2486 | use CFClient::OpenGL; |
2489 | use CFClient::OpenGL; |
2487 | |
2490 | |
2488 | sub new { |
2491 | sub new { |
2489 | my $class = shift; |
2492 | my $class = shift; |
2490 | |
2493 | |
2491 | $class->SUPER::new ( |
2494 | my $self = $class->SUPER::new ( |
2492 | aspect => 1, |
2495 | aspect => 1, |
2493 | @_, |
2496 | @_, |
2494 | ) |
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 |
2495 | } |
2514 | } |
2496 | |
2515 | |
2497 | sub size_request { |
2516 | sub size_request { |
2498 | (32, 8) |
2517 | (32, 8) |
2499 | } |
2518 | } |
2500 | |
2519 | |
2501 | sub _draw { |
2520 | sub _draw { |
2502 | my ($self) = @_; |
2521 | my ($self) = @_; |
2503 | |
2522 | |
2504 | 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 | |
2505 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2534 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]]; |
2506 | |
2535 | |
2507 | # TODO animation |
|
|
2508 | if ($tex) { |
2536 | if ($tex) { |
2509 | glEnable GL_TEXTURE_2D; |
2537 | glEnable GL_TEXTURE_2D; |
2510 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2538 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2511 | glColor 1, 1, 1, 1; |
2539 | glColor 1, 1, 1, 1; |
2512 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2540 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2513 | glDisable GL_TEXTURE_2D; |
2541 | glDisable GL_TEXTURE_2D; |
2514 | } |
2542 | } |
2515 | } |
2543 | } |
2516 | |
2544 | |
|
|
2545 | sub DESTROY { |
|
|
2546 | my ($self) = @_; |
|
|
2547 | |
|
|
2548 | $self->{timer}->cancel |
|
|
2549 | if $self->{timer}; |
|
|
2550 | |
|
|
2551 | $self->SUPER::DESTROY; |
|
|
2552 | } |
|
|
2553 | |
2517 | ############################################################################# |
2554 | ############################################################################# |
2518 | |
2555 | |
2519 | package CFClient::UI::InventoryItem; |
2556 | package CFClient::UI::InventoryItem; |
2520 | |
2557 | |
2521 | our @ISA = CFClient::UI::HBox::; |
2558 | our @ISA = CFClient::UI::HBox::; |
2522 | |
2559 | |
2523 | sub new { |
2560 | sub _item_to_desc { |
2524 | my $class = shift; |
2561 | my ($item) = @_; |
2525 | |
2562 | |
2526 | my %args = @_; |
2563 | my $desc = |
2527 | |
|
|
2528 | my $item = delete $args{item}; |
|
|
2529 | |
|
|
2530 | my $desc = $item->{nrof} < 2 |
2564 | $item->{nrof} < 2 |
2531 | ? $item->{name} |
2565 | ? $item->{name} |
2532 | : "$item->{nrof} $item->{name_pl}"; |
2566 | : "$item->{nrof} × $item->{name_pl}"; |
2533 | |
2567 | |
2534 | $item->{flags} & Crossfire::Protocol::F_OPEN |
2568 | $item->{flags} & Crossfire::Protocol::F_OPEN |
2535 | and $desc .= " (open)"; |
2569 | and $desc .= " (open)"; |
2536 | $item->{flags} & Crossfire::Protocol::F_APPLIED |
2570 | $item->{flags} & Crossfire::Protocol::F_APPLIED |
2537 | and $desc .= " (applied)"; |
2571 | and $desc .= " (applied)"; |
… | |
… | |
2544 | $item->{flags} & Crossfire::Protocol::F_DAMNED |
2578 | $item->{flags} & Crossfire::Protocol::F_DAMNED |
2545 | and $desc .= " (damned)"; |
2579 | and $desc .= " (damned)"; |
2546 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
2580 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
2547 | and $desc .= " *"; |
2581 | and $desc .= " *"; |
2548 | |
2582 | |
|
|
2583 | $desc |
|
|
2584 | } |
|
|
2585 | |
|
|
2586 | sub new { |
|
|
2587 | my $class = shift; |
|
|
2588 | |
|
|
2589 | my %args = @_; |
|
|
2590 | |
|
|
2591 | my $item = delete $args{item}; |
|
|
2592 | |
|
|
2593 | my $desc = _item_to_desc ($item); |
|
|
2594 | |
2549 | my $self = $class->SUPER::new ( |
2595 | my $self = $class->SUPER::new ( |
2550 | can_hover => 1, |
2596 | can_hover => 1, |
2551 | can_events => 1, |
2597 | can_events => 1, |
2552 | tooltip => ((CFClient::UI::Label::escape $desc) |
2598 | tooltip => ((CFClient::UI::Label::escape $desc) |
2553 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2599 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
2554 | connect_button_down => sub { |
2600 | connect_button_down => sub { |
2555 | my ($self, $ev, $x, $y) = @_; |
2601 | my ($self, $ev, $x, $y) = @_; |
2556 | |
2602 | |
2557 | # 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 :( |
2558 | if ($ev->{button} == 1) { |
2604 | if ($ev->{button} == 1) { |
|
|
2605 | my $targ = $::CONN->{player}{tag}; |
|
|
2606 | |
|
|
2607 | if ($item->{container} == $::CONN->{player}{tag}) { |
|
|
2608 | $targ = $main::OPENCONT; |
|
|
2609 | } |
|
|
2610 | |
2559 | $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); |
2611 | $::CONN->send ("move $targ $item->{tag} 0"); |
2560 | } elsif ($ev->{button} == 2) { |
2612 | } elsif ($ev->{button} == 2) { |
2561 | $::CONN->send ("apply $item->{tag}"); |
2613 | $::CONN->send ("apply $item->{tag}"); |
2562 | } elsif ($ev->{button} == 3) { |
2614 | } elsif ($ev->{button} == 3) { |
2563 | my @menu_items = ( |
2615 | my @menu_items = ( |
2564 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2616 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
2565 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
2617 | ["mark", sub { $::CONN->send ("mark $item->{tag}") }], |
2566 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
2618 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
2567 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
2619 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
2568 | [ |
2620 | [ |
2569 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
2621 | $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock", |
2570 | sub { $::CONN->send ("lock ". () ."$item->{tag}") }, |
2622 | sub { $::CONN->send ("lock $item->{tag}") }, |
2571 | ], |
2623 | ], |
2572 | ); |
2624 | ); |
2573 | |
2625 | |
2574 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2626 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
2575 | } |
2627 | } |
2576 | |
2628 | |
2577 | 1 |
2629 | 1 |
2578 | }, |
2630 | }, |
2579 | %args |
2631 | %args |
2580 | ); |
2632 | ); |
|
|
2633 | |
2581 | |
2634 | |
2582 | $self->add (new CFClient::UI::Face |
2635 | $self->add (new CFClient::UI::Face |
2583 | can_events => 0, |
2636 | can_events => 0, |
2584 | face => $item->{face}, |
2637 | face => $item->{face}, |
2585 | anim => $item->{anim}, |
2638 | anim => $item->{anim}, |
2586 | animspeed => $item->{animspeed}, |
2639 | animspeed => $item->{animspeed}, |
2587 | ); |
2640 | ); |
2588 | |
2641 | |
2589 | $self->add (new CFClient::UI::Label |
2642 | $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0); |
2590 | can_events => 0, |
2643 | |
2591 | text => $desc, |
2644 | $self->{item} = $item; |
2592 | ); |
2645 | |
|
|
2646 | $self->update_item; |
2593 | |
2647 | |
2594 | $self |
2648 | $self |
|
|
2649 | } |
|
|
2650 | |
|
|
2651 | sub update_item { |
|
|
2652 | my ($self) = @_; |
|
|
2653 | |
|
|
2654 | my $desc = _item_to_desc ($self->{item}); |
|
|
2655 | |
|
|
2656 | $self->{name_lbl}->set_text ($desc); |
2595 | } |
2657 | } |
2596 | |
2658 | |
2597 | ############################################################################# |
2659 | ############################################################################# |
2598 | |
2660 | |
2599 | package CFClient::UI::Inventory; |
2661 | package CFClient::UI::Inventory; |
… | |
… | |
2623 | } @$items; |
2685 | } @$items; |
2624 | |
2686 | |
2625 | $self->{real_items} = \@items; |
2687 | $self->{real_items} = \@items; |
2626 | |
2688 | |
2627 | for my $item (@items) { |
2689 | 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; |
2690 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
|
|
2691 | $item->update_item (); |
2633 | } |
2692 | } |
2634 | |
2693 | |
2635 | $self->{scrolled}->add (@items); |
2694 | $self->{scrolled}->add (@items); |
2636 | |
2695 | |
2637 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2696 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
… | |
… | |
2718 | |
2777 | |
2719 | package CFClient::UI::Statusbox; |
2778 | package CFClient::UI::Statusbox; |
2720 | |
2779 | |
2721 | our @ISA = CFClient::UI::VBox::; |
2780 | our @ISA = CFClient::UI::VBox::; |
2722 | |
2781 | |
|
|
2782 | sub new { |
|
|
2783 | my $class = shift; |
|
|
2784 | |
|
|
2785 | $class->SUPER::new ( |
|
|
2786 | fontsize => 0.8, |
|
|
2787 | @_, |
|
|
2788 | ) |
|
|
2789 | } |
|
|
2790 | |
2723 | sub reorder { |
2791 | sub reorder { |
2724 | my ($self) = @_; |
2792 | my ($self) = @_; |
2725 | my $NOW = time; |
2793 | my $NOW = time; |
2726 | |
2794 | |
2727 | while (my ($k, $v) = each %{ $self->{item} }) { |
2795 | while (my ($k, $v) = each %{ $self->{item} }) { |
… | |
… | |
2746 | : $item->{text}; |
2814 | : $item->{text}; |
2747 | |
2815 | |
2748 | for ($short) { |
2816 | for ($short) { |
2749 | s/^\s+//; |
2817 | s/^\s+//; |
2750 | s/\s+/ /g; |
2818 | s/\s+/ /g; |
2751 | my $len = int 40 / $item->{fontsize}; |
|
|
2752 | substr $_, $len, length, "…" if $len < length; |
|
|
2753 | } |
2819 | } |
2754 | |
2820 | |
2755 | new CFClient::UI::Label |
2821 | new CFClient::UI::Label |
2756 | markup => $short, |
2822 | markup => $short, |
2757 | tooltip => $item->{tooltip}, |
2823 | tooltip => $item->{tooltip}, |
2758 | tooltip_font => $::FONT_PROP, |
2824 | tooltip_font => $::FONT_PROP, |
2759 | tooltip_width => 0.67, |
2825 | tooltip_width => 0.67, |
2760 | fontsize => $item->{fontsize}, |
2826 | fontsize => $item->{fontsize} || $self->{fontsize}, |
|
|
2827 | max_w => $::WIDTH * 0.44, |
2761 | fg => $item->{fg}, |
2828 | fg => $item->{fg}, |
2762 | can_events => 1, |
2829 | can_events => 1, |
2763 | can_hover => 1 |
2830 | can_hover => 1 |
2764 | }; |
2831 | }; |
2765 | } |
2832 | } |
… | |
… | |
2792 | $self->{item}{$group} = { |
2859 | $self->{item}{$group} = { |
2793 | id => ++$self->{id}, |
2860 | id => ++$self->{id}, |
2794 | text => $text, |
2861 | text => $text, |
2795 | timeout => $timeout, |
2862 | timeout => $timeout, |
2796 | tooltip => $text, |
2863 | tooltip => $text, |
2797 | fontsize => 0.8, |
|
|
2798 | fg => [0.8, 0.8, 0.8, 0.8], |
2864 | fg => [0.8, 0.8, 0.8, 0.8], |
2799 | pri => 0, |
2865 | pri => 0, |
2800 | count => 1, |
2866 | count => 1, |
2801 | %arg, |
2867 | %arg, |
2802 | }; |
2868 | }; |
2803 | } |
2869 | } |
2804 | |
2870 | |
2805 | $self->reorder; |
2871 | $self->reorder; |
|
|
2872 | } |
|
|
2873 | |
|
|
2874 | sub reconfigure { |
|
|
2875 | my ($self) = @_; |
|
|
2876 | |
|
|
2877 | delete $_->{label} |
|
|
2878 | for values %{ $self->{item} || {} }; |
|
|
2879 | |
|
|
2880 | $self->reorder; |
|
|
2881 | $self->SUPER::reconfigure; |
2806 | } |
2882 | } |
2807 | |
2883 | |
2808 | ############################################################################# |
2884 | ############################################################################# |
2809 | |
2885 | |
2810 | package CFClient::UI::Root; |
2886 | package CFClient::UI::Root; |
… | |
… | |
2985 | ############################################################################# |
3061 | ############################################################################# |
2986 | |
3062 | |
2987 | package CFClient::UI; |
3063 | package CFClient::UI; |
2988 | |
3064 | |
2989 | $ROOT = new CFClient::UI::Root; |
3065 | $ROOT = new CFClient::UI::Root; |
2990 | $TOOLTIP = new CFClient::UI::Tooltip; |
3066 | $TOOLTIP = new CFClient::UI::Tooltip z => 900; |
2991 | |
3067 | |
2992 | 1 |
3068 | 1 |
2993 | |
3069 | |