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.225 by root, Tue May 23 21:14:41 2006 UTC

134 for (@$vals) { 134 for (@$vals) {
135 my $i = int $_ + $rem; 135 my $i = int $_ + $rem;
136 $rem += $_ - $i; 136 $rem += $_ - $i;
137 $_ = $i; 137 $_ = $i;
138 } 138 }
139}
140
141sub full_refresh {
142 # make a copy, otherwise for complains about freed values.
143 my @widgets = values %WIDGET;
144
145 $_->update
146 for @widgets;
139} 147}
140 148
141# call when resolution changes etc. 149# call when resolution changes etc.
142sub rescale_widgets { 150sub rescale_widgets {
143 my ($sx, $sy) = @_; 151 my ($sx, $sy) = @_;
198 %$self = (); 206 %$self = ();
199} 207}
200 208
201sub show { 209sub show {
202 my ($self) = @_; 210 my ($self) = @_;
203
204 return if $self->{parent}; 211 return if $self->{parent};
205 212
206 $CFClient::UI::ROOT->add ($self); 213 $CFClient::UI::ROOT->add ($self);
214}
215
216sub show_centered {
217 my ($self) = @_;
218 return if $self->{parent};
219
220 $self->show;
221
222 $CFClient::UI::ROOT->on_post_alloc (
223 "centered $self" => sub {
224 $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5);
225 },
226 );
207} 227}
208 228
209sub hide { 229sub hide {
210 my ($self) = @_; 230 my ($self) = @_;
211 231
419 Scalar::Util::weaken ($self->{parent} = $parent); 439 Scalar::Util::weaken ($self->{parent} = $parent);
420 440
421 # TODO: req_w _does_change after ->reconfigure 441 # TODO: req_w _does_change after ->reconfigure
422 $self->check_size 442 $self->check_size
423 unless exists $self->{req_w}; 443 unless exists $self->{req_w};
444
445 $self->show;
424} 446}
425 447
426sub check_size { 448sub check_size {
427 my ($self, $forced) = @_; 449 my ($self, $forced) = @_;
428 450
691 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 713 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
692 glClearColor 0, 0, 0, 0; 714 glClearColor 0, 0, 0, 0;
693 glClear GL_COLOR_BUFFER_BIT; 715 glClear GL_COLOR_BUFFER_BIT;
694 716
695 $self->_render; 717 $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 }; 718 };
704} 719}
705 720
706sub _draw { 721sub _draw {
707 my ($self) = @_; 722 my ($self) = @_;
711 my $tex = $self->{texture} 726 my $tex = $self->{texture}
712 or return; 727 or return;
713 728
714 glEnable GL_TEXTURE_2D; 729 glEnable GL_TEXTURE_2D;
715 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 730 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
716 glColor 0, 0, 0, 1; 731 glColor 1, 1, 1, 1;
717 732
718 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 733 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
719 734
720 glDisable GL_TEXTURE_2D; 735 glDisable GL_TEXTURE_2D;
721} 736}
728 743
729sub size_request { 744sub size_request {
730 my ($self) = @_; 745 my ($self) = @_;
731 746
732 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; 747 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)};
733 $self->child->configure (0, 0, @$self{qw(child_w child_h)});
734 748
735 @$self{qw(child_w child_h)} 749 @$self{qw(child_w child_h)}
736} 750}
737 751
738sub size_allocate { 752sub size_allocate {
739 my ($self, $w, $h) = @_; 753 my ($self, $w, $h) = @_;
740 754
755 my ($cw, $ch) = @$self{qw(child_w child_h)};
756# $w = $self->{w};
757 $self->child->configure (0, 0, $cw, $ch);
741 $self->update; 758 $self->update;
742} 759}
743 760
744sub set_offset { 761sub set_offset {
745 my ($self, $x, $y) = @_; 762 my ($self, $x, $y) = @_;
804 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); 821 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h}));
805 }, 822 },
806 ; 823 ;
807 824
808 $self = $class->SUPER::new ( 825 $self = $class->SUPER::new (
809 vp => (new CFClient::UI::ViewPort), 826 vp => (new CFClient::UI::ViewPort expand => 1),
810 slider => $slider, 827 slider => $slider,
811 @_, 828 @_,
812 ); 829 );
813 830
814 $self->{vp}->add ($self->{scrolled}); 831 $self->{vp}->add ($self->{scrolled});
1473 active_fg => [0, 0, 0], 1490 active_fg => [0, 0, 0],
1474 can_hover => 1, 1491 can_hover => 1,
1475 can_focus => 1, 1492 can_focus => 1,
1476 valign => 0, 1493 valign => 0,
1477 can_events => 1, 1494 can_events => 1,
1495 #text => ...
1478 @_ 1496 @_
1479 ) 1497 )
1480} 1498}
1481 1499
1482sub _set_text { 1500sub _set_text {
2057 range => [0, 0, 100, 10], 2075 range => [0, 0, 100, 10],
2058 req_w => $::WIDTH / 80, 2076 req_w => $::WIDTH / 80,
2059 req_h => $::WIDTH / 80, 2077 req_h => $::WIDTH / 80,
2060 vertical => 0, 2078 vertical => 0,
2061 can_hover => 1, 2079 can_hover => 1,
2062 inner_pad => .05, 2080 inner_pad => 0.02,
2063 @_ 2081 @_
2064 ); 2082 );
2065 2083
2066 $self->set_value ($self->{range}[0]); 2084 $self->set_value ($self->{range}[0]);
2067 $self->update; 2085 $self->update;
2068 2086
2069 $self 2087 $self
2088}
2089
2090sub set_range {
2091 my ($self, $range) = @_;
2092
2093 $self->{range} = $range;
2094
2095 $self->update;
2070} 2096}
2071 2097
2072sub set_value { 2098sub set_value {
2073 my ($self, $value) = @_; 2099 my ($self, $value) = @_;
2074 2100
2175 # draw handle 2201 # draw handle
2176 $tex[0]->draw_quad_alpha ($self->{knob_x}, 0, $self->{knob_w}, 1); 2202 $tex[0]->draw_quad_alpha ($self->{knob_x}, 0, $self->{knob_w}, 1);
2177 2203
2178 glDisable GL_TEXTURE_2D; 2204 glDisable GL_TEXTURE_2D;
2179} 2205}
2206
2207#############################################################################
2208
2209package CFClient::UI::ValSlider;
2210
2211our @ISA = CFClient::UI::HBox::;
2212
2213sub new {
2214 my ($class, %arg) = @_;
2215
2216 my $range = delete $arg{range};
2217
2218 my $self = $class->SUPER::new (
2219 slider => (new CFClient::UI::Slider expand => 1, range => $range),
2220 entry => (new CFClient::UI::Label text => "", template => delete $arg{template}),
2221 to_value => sub { shift },
2222 from_value => sub { shift },
2223 %arg,
2224 );
2225
2226 $self->{slider}->connect (changed => sub {
2227 my ($self, $value) = @_;
2228 $self->{parent}{entry}->set_text ($self->{parent}{to_value}->($value));
2229 $self->{parent}->emit (changed => $value);
2230 });
2231
2232# $self->{entry}->connect (changed => sub {
2233# my ($self, $value) = @_;
2234# $self->{parent}{slider}->set_value ($self->{parent}{from_value}->($value));
2235# $self->{parent}->emit (changed => $value);
2236# });
2237
2238 $self->add ($self->{slider}, $self->{entry});
2239
2240 $self->{slider}->emit (changed => $self->{slider}{range}[0]);
2241
2242 $self
2243}
2244
2245sub set_range { shift->{slider}->set_range (@_) }
2246sub set_value { shift->{slider}->set_value (@_) }
2180 2247
2181############################################################################# 2248#############################################################################
2182 2249
2183package CFClient::UI::TextView; 2250package CFClient::UI::TextView;
2184 2251
2214 2281
2215 $self->{fontsize} = $fontsize; 2282 $self->{fontsize} = $fontsize;
2216 $self->reflow; 2283 $self->reflow;
2217} 2284}
2218 2285
2286sub size_allocate {
2287 my ($self, $w, $h) = @_;
2288
2289 $self->SUPER::size_allocate ($w, $h);
2290
2291 $self->{layout}->set_font ($self->{font}) if $self->{font};
2292 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2293 $self->{layout}->set_width ($self->{children}[0]{w});
2294
2295 $self->reflow;
2296}
2297
2219sub text_height { 2298sub text_height {
2220 my ($self, $text) = @_; 2299 my ($self, $text, $indent) = @_;
2221 2300
2222 my $layout = $self->{layout}; 2301 my $layout = $self->{layout};
2223 2302
2224 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2303 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2225 $layout->set_width ($self->{children}[0]{w}); 2304 $layout->set_width ($self->{children}[0]{w} - $indent);
2226 $layout->set_markup ($text); 2305 $layout->set_markup ($text);
2227 2306
2228 ($layout->size)[1] 2307 ($layout->size)[1]
2229} 2308}
2230 2309
2233 2312
2234 $self->{need_reflow}++; 2313 $self->{need_reflow}++;
2235 $self->update; 2314 $self->update;
2236} 2315}
2237 2316
2238sub size_allocate {
2239 my ($self, $w, $h) = @_;
2240
2241 $self->SUPER::size_allocate ($w, $h);
2242
2243 $self->{layout}->set_font ($self->{font}) if $self->{font};
2244 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2245 $self->{layout}->set_width ($self->{children}[0]{w});
2246
2247 $self->reflow;
2248}
2249
2250sub add_paragraph { 2317sub add_paragraph {
2251 my ($self, $color, $text) = @_; 2318 my ($self, $color, $text, $indent) = @_;
2252 2319
2253 #TODO: intelligently "reformat" paragraph 2320 #TODO: intelligently "reformat" paragraph
2254 2321
2322 for my $line (split /\n/, $text) {
2255 my $height = $self->text_height ($text); 2323 my $height = $self->text_height ($line);
2256
2257 $self->{height} += $height; 2324 $self->{height} += $height;
2258
2259 push @{$self->{par}}, [$height, $color, $text]; 2325 push @{$self->{par}}, [$height, $color, $indent, $line];
2326 }
2260 2327
2261 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; 2328 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}];
2262 $self->{children}[1]->update; 2329 $self->{children}[1]->update;
2263} 2330}
2264 2331
2273 2340
2274 $ROOT->on_post_alloc ($self, sub { 2341 $ROOT->on_post_alloc ($self, sub {
2275 if (delete $self->{need_reflow}) { 2342 if (delete $self->{need_reflow}) {
2276 my $height = 0; 2343 my $height = 0;
2277 2344
2278 $height += $_->[0] = $self->text_height ($_->[2]) 2345 $height += $_->[0] = $self->text_height ($_->[3], $_->[2])
2279 for @{$self->{par}}; 2346 for @{$self->{par}};
2280 2347
2281 $self->{height} = $height; 2348 $self->{height} = $height;
2282 2349
2283 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2350 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2351 $self->{children}[1]->update;
2284 2352
2285 delete $self->{texture}; 2353 delete $self->{texture};
2286 } 2354 }
2287 2355
2288 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2356 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2289 glClearColor 0, 0, 0, 0; 2357 glClearColor 0.5, 0.5, 0.5, 0;
2290 glClear GL_COLOR_BUFFER_BIT; 2358 glClear GL_COLOR_BUFFER_BIT;
2291
2292 glEnable GL_TEXTURE_2D;
2293 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2294 2359
2295 my $top = int $self->{children}[1]{range}[0]; 2360 my $top = int $self->{children}[1]{range}[0];
2296 2361
2297 my $y0 = $top; 2362 my $y0 = $top;
2298 my $y1 = $top + $self->{h}; 2363 my $y1 = $top + $self->{h};
2301 2366
2302 my $layout = $self->{layout}; 2367 my $layout = $self->{layout};
2303 2368
2304 $layout->set_font ($self->{font}) if $self->{font}; 2369 $layout->set_font ($self->{font}) if $self->{font};
2305 2370
2371 glEnable GL_BLEND;
2372 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2373
2306 for my $par (@{$self->{par}}) { 2374 for my $par (@{$self->{par}}) {
2307 my $h = $par->[0]; 2375 my $h = $par->[0];
2308 2376
2309 if ($y0 < $y + $h && $y < $y1) { 2377 if ($y0 < $y + $h && $y < $y1) {
2310 $layout->set_foreground (@{ $par->[1] }); 2378 $layout->set_foreground (@{ $par->[1] });
2379 $layout->set_width ($self->{w} - $par->[2]);
2311 $layout->set_markup ($par->[2]); 2380 $layout->set_markup ($par->[3]);
2312 2381
2313 my ($W, $H) = $layout->size; 2382 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2314 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); 2383
2384 glRasterPos $par->[2], $y - $y0;
2385 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2315 } 2386 }
2316 2387
2317 $y += $h; 2388 $y += $h;
2318 } 2389 }
2319 2390
2320 glDisable GL_TEXTURE_2D; 2391 glDisable GL_BLEND;
2321 }; 2392 };
2322 }); 2393 });
2323} 2394}
2324 2395
2325sub _draw { 2396sub _draw {
2326 my ($self) = @_; 2397 my ($self) = @_;
2327 2398
2328 glEnable GL_TEXTURE_2D; 2399 glEnable GL_TEXTURE_2D;
2329 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2400 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2330 glColor 1, 1, 1, 1; 2401 glColor 1, 1, 1, 1;
2331 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2402 $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2332 glDisable GL_TEXTURE_2D; 2403 glDisable GL_TEXTURE_2D;
2333 2404
2334 $self->{children}[1]->draw; 2405 $self->{children}[1]->draw;
2335 2406
2336} 2407}
2496use CFClient::OpenGL; 2567use CFClient::OpenGL;
2497 2568
2498sub new { 2569sub new {
2499 my $class = shift; 2570 my $class = shift;
2500 2571
2501 $class->SUPER::new ( 2572 my $self = $class->SUPER::new (
2502 aspect => 1, 2573 aspect => 1,
2503 @_, 2574 @_,
2504 ) 2575 );
2576
2577 if ($self->{anim} && $self->{animspeed}) {
2578 Scalar::Util::weaken (my $widget = $self);
2579
2580 $self->{timer} = Event->timer (
2581 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
2582 hard => 1,
2583 interval => $self->{animspeed},
2584 cb => sub {
2585 ++$widget->{frame};
2586 $widget->update;
2587 },
2588 );
2589 }
2590
2591 $self
2505} 2592}
2506 2593
2507sub size_request { 2594sub size_request {
2508 (32, 8) 2595 (32, 8)
2509} 2596}
2510 2597
2598sub update {
2599 my ($self) = @_;
2600
2601 return unless $self->{visible};
2602
2603 $self->SUPER::update;
2604}
2605
2511sub _draw { 2606sub _draw {
2512 my ($self) = @_; 2607 my ($self) = @_;
2513 2608
2514 return unless $::CONN;#d# manage and cache textures differently 2609 return unless $::CONN;#d# manage and cache textures differently
2610
2611 my $face;
2612
2613 if ($self->{frame}) {
2614 my $anim = $::CONN->{anim}[$self->{anim}];
2615
2616 $face = $anim->[ $self->{frame} % @$anim ]
2617 if $anim && @$anim;
2618 }
2619
2515 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2620 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]];
2516 2621
2517 # TODO animation
2518 if ($tex) { 2622 if ($tex) {
2519 glEnable GL_TEXTURE_2D; 2623 glEnable GL_TEXTURE_2D;
2520 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2624 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2521 glColor 1, 1, 1, 1; 2625 glColor 1, 1, 1, 1;
2522 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2626 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2523 glDisable GL_TEXTURE_2D; 2627 glDisable GL_TEXTURE_2D;
2524 } 2628 }
2525} 2629}
2526 2630
2631sub DESTROY {
2632 my ($self) = @_;
2633
2634 $self->{timer}->cancel
2635 if $self->{timer};
2636
2637 $self->SUPER::DESTROY;
2638}
2639
2527############################################################################# 2640#############################################################################
2528 2641
2529package CFClient::UI::InventoryItem; 2642package CFClient::UI::InventoryItem;
2530 2643
2531our @ISA = CFClient::UI::HBox::; 2644our @ISA = CFClient::UI::HBox::;
2534 my ($item) = @_; 2647 my ($item) = @_;
2535 2648
2536 my $desc = 2649 my $desc =
2537 $item->{nrof} < 2 2650 $item->{nrof} < 2
2538 ? $item->{name} 2651 ? $item->{name}
2539 : "$item->{nrof} $item->{name_pl}"; 2652 : "$item->{nrof} × $item->{name_pl}";
2540 2653
2541 $item->{flags} & Crossfire::Protocol::F_OPEN 2654 $item->{flags} & Crossfire::Protocol::F_OPEN
2542 and $desc .= " (open)"; 2655 and $desc .= " (open)";
2543 $item->{flags} & Crossfire::Protocol::F_APPLIED 2656 $item->{flags} & Crossfire::Protocol::F_APPLIED
2544 and $desc .= " (applied)"; 2657 and $desc .= " (applied)";
2564 my $item = delete $args{item}; 2677 my $item = delete $args{item};
2565 2678
2566 my $desc = _item_to_desc ($item); 2679 my $desc = _item_to_desc ($item);
2567 2680
2568 my $self = $class->SUPER::new ( 2681 my $self = $class->SUPER::new (
2569 can_hover => 1, 2682 can_hover => 1,
2570 can_events => 1, 2683 can_events => 1,
2571 tooltip => ((CFClient::UI::Label::escape $desc) 2684 tooltip => ((CFClient::UI::Label::escape $desc)
2572 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), 2685 . "\n<small>leftclick - examine\nshift+leftclick - move/pickup/drop\nmiddle click - apply\nrightclick - menu</small>"),
2573 connect_button_down => sub { 2686 connect_button_down => sub {
2574 my ($self, $ev, $x, $y) = @_; 2687 my ($self, $ev, $x, $y) = @_;
2575 2688
2576 # todo: maybe put examine on 1? but should just be a tooltip :( 2689 # todo: maybe put examine on 1? but should just be a tooltip :(
2577 if ($ev->{button} == 1) { 2690 if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) {
2578 my $targ = $::CONN->{player}{tag}; 2691 my $targ = $::CONN->{player}{tag};
2579 2692
2580 if ($item->{container} == $::CONN->{player}{tag}) { 2693 if ($item->{container} == $::CONN->{player}{tag}) {
2581 $targ = $main::OPENCONT; 2694 $targ = $main::OPENCONT;
2582 } 2695 }
2583 2696
2584 $::CONN->send ("move $targ $item->{tag} 0"); 2697 $::CONN->send ("move $targ $item->{tag} 0");
2698 } elsif ($ev->{button} == 1) {
2699 $::CONN->send ("examine $item->{tag}");
2585 } elsif ($ev->{button} == 2) { 2700 } elsif ($ev->{button} == 2) {
2586 $::CONN->send ("apply $item->{tag}"); 2701 $::CONN->send ("apply $item->{tag}");
2587 } elsif ($ev->{button} == 3) { 2702 } elsif ($ev->{button} == 3) {
2588 my @menu_items = ( 2703 my @menu_items = (
2589 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2704 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2590 ["mark", sub { $::CONN->send ("mark $item->{tag}") }], 2705 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2591 ["apply", sub { $::CONN->send ("apply $item->{tag}") }], 2706 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2707 (
2708 $item->{flags} & Crossfire::Protocol::F_LOCKED
2709 ? (
2710 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2711 )
2712 : (
2713 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2592 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], 2714 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2593 [ 2715 )
2594 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2595 sub { $::CONN->send ("lock $item->{tag}") },
2596 ], 2716 ),
2597 ); 2717 );
2598 2718
2599 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 2719 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2600 } 2720 }
2601 2721
2637 2757
2638sub new { 2758sub new {
2639 my $class = shift; 2759 my $class = shift;
2640 2760
2641 my $self = $class->SUPER::new ( 2761 my $self = $class->SUPER::new (
2642 scrolled => (new CFClient::UI::VBox), 2762 scrolled => (new CFClient::UI::Table),
2643 @_, 2763 @_,
2644 ); 2764 );
2645 2765
2646 $self 2766 $self
2647} 2767}
2658 } @$items; 2778 } @$items;
2659 2779
2660 $self->{real_items} = \@items; 2780 $self->{real_items} = \@items;
2661 2781
2662 for my $item (@items) { 2782 for my $item (@items) {
2783 $item->{item} = $item;
2663 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; 2784 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2664 $item->update_item (); 2785 $item->update_item ();
2665 } 2786 }
2666 2787
2788 my $i = 0;
2789 for (@items) {
2667 $self->{scrolled}->add (@items); 2790 $self->{scrolled}->add (0, $i, $_);
2791 my $nrof = $_->{item}->{nrof} || 1;
2792 $self->{scrolled}->add (1, $i++, new CFClient::UI::Label text => ($_->{item}->{weight} * $nrof) / 1000);
2793 }
2668 2794
2669# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2795# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2670} 2796}
2671 2797
2672sub size_request { 2798sub size_request {
2944 $child->{x} = int $child->{x}; 3070 $child->{x} = int $child->{x};
2945 $child->{y} = int $child->{y}; 3071 $child->{y} = int $child->{y};
2946 } 3072 }
2947 3073
2948 $self->SUPER::add (@children); 3074 $self->SUPER::add (@children);
3075
3076 while (@children) {
3077 my $w = pop @children;
3078 push @children, $w->children;
3079 $w->{visible} = 1;
3080 }
3081}
3082
3083sub remove {
3084 my ($self, @children) = @_;
3085
3086 $self->SUPER::remove (@children);
3087
3088 while (@children) {
3089 my $w = pop @children;
3090 push @children, $w->children;
3091 delete $w->{visible};
3092 }
2949} 3093}
2950 3094
2951sub on_refresh { 3095sub on_refresh {
2952 my ($self, $id, $cb) = @_; 3096 my ($self, $id, $cb) = @_;
2953 3097
3022 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 3166 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
3023 glClear GL_COLOR_BUFFER_BIT; 3167 glClear GL_COLOR_BUFFER_BIT;
3024 3168
3025 glMatrixMode GL_PROJECTION; 3169 glMatrixMode GL_PROJECTION;
3026 glLoadIdentity; 3170 glLoadIdentity;
3027 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; 3171 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3028 glMatrixMode GL_MODELVIEW; 3172 glMatrixMode GL_MODELVIEW;
3029 glLoadIdentity; 3173 glLoadIdentity;
3030 3174
3031 $self->_draw; 3175 $self->_draw;
3032} 3176}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines