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.212 by elmex, Wed May 17 14:55:14 2006 UTC vs.
Revision 1.222 by root, Mon May 22 03:59:51 2006 UTC

136 $rem += $_ - $i; 136 $rem += $_ - $i;
137 $_ = $i; 137 $_ = $i;
138 } 138 }
139} 139}
140 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;
147}
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) = @_;
144 152
153 # make a copy, otherwise for complains about freed values.
145 for my $widget (values %WIDGET) { 154 my @widgets = values %WIDGET;
155
156 for my $widget (@widgets) {
146 if ($widget->{toplevel}) { 157 if ($widget->{toplevel}) {
147 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; 158 $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}; 159 $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}; 160 $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}; 161 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w};
195 %$self = (); 206 %$self = ();
196} 207}
197 208
198sub show { 209sub show {
199 my ($self) = @_; 210 my ($self) = @_;
200
201 return if $self->{parent}; 211 return if $self->{parent};
202 212
203 $CFClient::UI::ROOT->add ($self); 213 $CFClient::UI::ROOT->add ($self);
204} 214}
205 215
416 Scalar::Util::weaken ($self->{parent} = $parent); 426 Scalar::Util::weaken ($self->{parent} = $parent);
417 427
418 # TODO: req_w _does_change after ->reconfigure 428 # TODO: req_w _does_change after ->reconfigure
419 $self->check_size 429 $self->check_size
420 unless exists $self->{req_w}; 430 unless exists $self->{req_w};
431
432 $self->show;
421} 433}
422 434
423sub check_size { 435sub check_size {
424 my ($self, $forced) = @_; 436 my ($self, $forced) = @_;
425 437
688 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 700 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
689 glClearColor 0, 0, 0, 0; 701 glClearColor 0, 0, 0, 0;
690 glClear GL_COLOR_BUFFER_BIT; 702 glClear GL_COLOR_BUFFER_BIT;
691 703
692 $self->_render; 704 $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 }; 705 };
701} 706}
702 707
703sub _draw { 708sub _draw {
704 my ($self) = @_; 709 my ($self) = @_;
708 my $tex = $self->{texture} 713 my $tex = $self->{texture}
709 or return; 714 or return;
710 715
711 glEnable GL_TEXTURE_2D; 716 glEnable GL_TEXTURE_2D;
712 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 717 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
713 glColor 0, 0, 0, 1; 718 glColor 1, 1, 1, 1;
714 719
715 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 720 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
716 721
717 glDisable GL_TEXTURE_2D; 722 glDisable GL_TEXTURE_2D;
718} 723}
801 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); 806 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h}));
802 }, 807 },
803 ; 808 ;
804 809
805 $self = $class->SUPER::new ( 810 $self = $class->SUPER::new (
806 vp => (new CFClient::UI::ViewPort), 811 vp => (new CFClient::UI::ViewPort expand => 1),
807 slider => $slider, 812 slider => $slider,
808 @_, 813 @_,
809 ); 814 );
810 815
811 $self->{vp}->add ($self->{scrolled}); 816 $self->{vp}->add ($self->{scrolled});
1297 #bg => none 1302 #bg => none
1298 #active_bg => none 1303 #active_bg => none
1299 #font => default_font 1304 #font => default_font
1300 #text => initial text 1305 #text => initial text
1301 #markup => initial narkup 1306 #markup => initial narkup
1307 #max_w => maximum pixel width
1308 ellipsise => 3, # end
1302 layout => (new CFClient::Layout), 1309 layout => (new CFClient::Layout),
1303 fontsize => 1, 1310 fontsize => 1,
1304 align => -1, 1311 align => -1,
1305 valign => -1, 1312 valign => -1,
1306 padding => 2, 1313 padding => 2,
1371sub size_request { 1378sub size_request {
1372 my ($self) = @_; 1379 my ($self) = @_;
1373 1380
1374 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1381 $self->{layout}->set_font ($self->{font}) if $self->{font};
1375 $self->{layout}->set_width ($self->{max_w} || -1); 1382 $self->{layout}->set_width ($self->{max_w} || -1);
1383 $self->{layout}->set_ellipsise ($self->{ellipsise});
1384 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1376 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1385 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1377 1386
1378 my ($w, $h) = $self->{layout}->size; 1387 my ($w, $h) = $self->{layout}->size;
1379 1388
1380 if (exists $self->{template}) { 1389 if (exists $self->{template}) {
1416 1425
1417 my $tex = $self->{texture} ||= do { 1426 my $tex = $self->{texture} ||= do {
1418 $self->{layout}->set_foreground (@{$self->{fg}}); 1427 $self->{layout}->set_foreground (@{$self->{fg}});
1419 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1428 $self->{layout}->set_font ($self->{font}) if $self->{font};
1420 $self->{layout}->set_width ($self->{w}); 1429 $self->{layout}->set_width ($self->{w});
1430 $self->{layout}->set_ellipsise ($self->{ellipsise});
1431 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1421 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1432 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1422 1433
1423 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1434 my $tex = new_from_layout CFClient::Texture $self->{layout};
1424 1435
1425 $self->{ox} = int ($self->{align} < 0 ? $self->{padding} 1436 $self->{ox} = int ($self->{align} < 0 ? $self->{padding}
1426 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1437 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
2048 range => [0, 0, 100, 10], 2059 range => [0, 0, 100, 10],
2049 req_w => $::WIDTH / 80, 2060 req_w => $::WIDTH / 80,
2050 req_h => $::WIDTH / 80, 2061 req_h => $::WIDTH / 80,
2051 vertical => 0, 2062 vertical => 0,
2052 can_hover => 1, 2063 can_hover => 1,
2053 inner_pad => .05, 2064 inner_pad => 0.02,
2054 @_ 2065 @_
2055 ); 2066 );
2056 2067
2057 $self->set_value ($self->{range}[0]); 2068 $self->set_value ($self->{range}[0]);
2058 $self->update; 2069 $self->update;
2148 glScale $self->{w}, $self->{h}; 2159 glScale $self->{w}, $self->{h};
2149 2160
2150 if ($self->{vertical}) { 2161 if ($self->{vertical}) {
2151 # draw a vertical slider like a rotated horizontal slider 2162 # draw a vertical slider like a rotated horizontal slider
2152 2163
2164 glTranslate 1, 0, 0;
2153 glRotate 90, 0, 0, 1; 2165 glRotate 90, 0, 0, 1;
2154 glTranslate 0, 1, 0;
2155 } 2166 }
2156 2167
2157 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 2168 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
2158 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 2169 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
2159 2170
2205 2216
2206 $self->{fontsize} = $fontsize; 2217 $self->{fontsize} = $fontsize;
2207 $self->reflow; 2218 $self->reflow;
2208} 2219}
2209 2220
2221sub size_allocate {
2222 my ($self, $w, $h) = @_;
2223
2224 $self->SUPER::size_allocate ($w, $h);
2225
2226 $self->{layout}->set_font ($self->{font}) if $self->{font};
2227 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2228 $self->{layout}->set_width ($self->{children}[0]{w});
2229
2230 $self->reflow;
2231}
2232
2210sub text_height { 2233sub text_height {
2211 my ($self, $text) = @_; 2234 my ($self, $text, $indent) = @_;
2212 2235
2213 my $layout = $self->{layout}; 2236 my $layout = $self->{layout};
2214 2237
2215 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2238 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2216 $layout->set_width ($self->{children}[0]{w}); 2239 $layout->set_width ($self->{children}[0]{w} - $indent);
2217 $layout->set_markup ($text); 2240 $layout->set_markup ($text);
2218 2241
2219 ($layout->size)[1] 2242 ($layout->size)[1]
2220} 2243}
2221 2244
2224 2247
2225 $self->{need_reflow}++; 2248 $self->{need_reflow}++;
2226 $self->update; 2249 $self->update;
2227} 2250}
2228 2251
2229sub size_allocate {
2230 my ($self, $w, $h) = @_;
2231
2232 $self->SUPER::size_allocate ($w, $h);
2233
2234 $self->{layout}->set_font ($self->{font}) if $self->{font};
2235 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2236 $self->{layout}->set_width ($self->{children}[0]{w});
2237
2238 $self->reflow;
2239}
2240
2241sub add_paragraph { 2252sub add_paragraph {
2242 my ($self, $color, $text) = @_; 2253 my ($self, $color, $text, $indent) = @_;
2243 2254
2244 #TODO: intelligently "reformat" paragraph 2255 #TODO: intelligently "reformat" paragraph
2245 2256
2257 for my $line (split /\n/, $text) {
2246 my $height = $self->text_height ($text); 2258 my $height = $self->text_height ($line);
2247
2248 $self->{height} += $height; 2259 $self->{height} += $height;
2249
2250 push @{$self->{par}}, [$height, $color, $text]; 2260 push @{$self->{par}}, [$height, $color, $indent, $line];
2261 }
2251 2262
2252 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; 2263 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}];
2253 $self->{children}[1]->update; 2264 $self->{children}[1]->update;
2254} 2265}
2255 2266
2264 2275
2265 $ROOT->on_post_alloc ($self, sub { 2276 $ROOT->on_post_alloc ($self, sub {
2266 if (delete $self->{need_reflow}) { 2277 if (delete $self->{need_reflow}) {
2267 my $height = 0; 2278 my $height = 0;
2268 2279
2269 $height += $_->[0] = $self->text_height ($_->[2]) 2280 $height += $_->[0] = $self->text_height ($_->[3], $_->[2])
2270 for @{$self->{par}}; 2281 for @{$self->{par}};
2271 2282
2272 $self->{height} = $height; 2283 $self->{height} = $height;
2273 2284
2274 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2285 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2286 $self->{children}[1]->update;
2275 2287
2276 delete $self->{texture}; 2288 delete $self->{texture};
2277 } 2289 }
2278 2290
2279 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2291 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2280 glClearColor 0, 0, 0, 0; 2292 glClearColor 0.5, 0.5, 0.5, 0;
2281 glClear GL_COLOR_BUFFER_BIT; 2293 glClear GL_COLOR_BUFFER_BIT;
2282
2283 glEnable GL_TEXTURE_2D;
2284 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2285 2294
2286 my $top = int $self->{children}[1]{range}[0]; 2295 my $top = int $self->{children}[1]{range}[0];
2287 2296
2288 my $y0 = $top; 2297 my $y0 = $top;
2289 my $y1 = $top + $self->{h}; 2298 my $y1 = $top + $self->{h};
2292 2301
2293 my $layout = $self->{layout}; 2302 my $layout = $self->{layout};
2294 2303
2295 $layout->set_font ($self->{font}) if $self->{font}; 2304 $layout->set_font ($self->{font}) if $self->{font};
2296 2305
2306 glEnable GL_BLEND;
2307 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2308
2297 for my $par (@{$self->{par}}) { 2309 for my $par (@{$self->{par}}) {
2298 my $h = $par->[0]; 2310 my $h = $par->[0];
2299 2311
2300 if ($y0 < $y + $h && $y < $y1) { 2312 if ($y0 < $y + $h && $y < $y1) {
2301 $layout->set_foreground (@{ $par->[1] }); 2313 $layout->set_foreground (@{ $par->[1] });
2314 $layout->set_width ($self->{w} - $par->[2]);
2302 $layout->set_markup ($par->[2]); 2315 $layout->set_markup ($par->[3]);
2303 2316
2304 my ($W, $H) = $layout->size; 2317 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2305 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); 2318
2319 glRasterPos $par->[2], $y - $y0;
2320 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2306 } 2321 }
2307 2322
2308 $y += $h; 2323 $y += $h;
2309 } 2324 }
2310 2325
2311 glDisable GL_TEXTURE_2D; 2326 glDisable GL_BLEND;
2312 }; 2327 };
2313 }); 2328 });
2314} 2329}
2315 2330
2316sub _draw { 2331sub _draw {
2317 my ($self) = @_; 2332 my ($self) = @_;
2318 2333
2319 glEnable GL_TEXTURE_2D; 2334 glEnable GL_TEXTURE_2D;
2320 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2335 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2321 glColor 1, 1, 1, 1; 2336 glColor 1, 1, 1, 1;
2322 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2337 $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2323 glDisable GL_TEXTURE_2D; 2338 glDisable GL_TEXTURE_2D;
2324 2339
2325 $self->{children}[1]->draw; 2340 $self->{children}[1]->draw;
2326 2341
2327} 2342}
2426 2441
2427sub set_tooltip_from { 2442sub set_tooltip_from {
2428 my ($self, $widget) = @_; 2443 my ($self, $widget) = @_;
2429 2444
2430 $self->add (new CFClient::UI::Label 2445 $self->add (new CFClient::UI::Label
2431 markup => $widget->{tooltip}, 2446 markup => $widget->{tooltip},
2432 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2447 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2433 fontsize => 0.8, 2448 fontsize => 0.8,
2434 fg => [0, 0, 0, 1], 2449 fg => [0, 0, 0, 1],
2450 ellipsise => 0,
2435 font => ($widget->{tooltip_font} || $::FONT_PROP), 2451 font => ($widget->{tooltip_font} || $::FONT_PROP),
2436 ); 2452 );
2437} 2453}
2438 2454
2439sub size_request { 2455sub size_request {
2440 my ($self) = @_; 2456 my ($self) = @_;
2486use CFClient::OpenGL; 2502use CFClient::OpenGL;
2487 2503
2488sub new { 2504sub new {
2489 my $class = shift; 2505 my $class = shift;
2490 2506
2491 $class->SUPER::new ( 2507 my $self = $class->SUPER::new (
2492 aspect => 1, 2508 aspect => 1,
2493 @_, 2509 @_,
2494 ) 2510 );
2511
2512 if ($self->{anim} && $self->{animspeed}) {
2513 Scalar::Util::weaken (my $widget = $self);
2514
2515 $self->{timer} = Event->timer (
2516 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
2517 hard => 1,
2518 interval => $self->{animspeed},
2519 cb => sub {
2520 ++$widget->{frame};
2521 $widget->update;
2522 },
2523 );
2524 }
2525
2526 $self
2495} 2527}
2496 2528
2497sub size_request { 2529sub size_request {
2498 (32, 8) 2530 (32, 8)
2499} 2531}
2500 2532
2533sub update {
2534 my ($self) = @_;
2535
2536 return unless $self->{visible};
2537
2538 $self->SUPER::update;
2539}
2540
2501sub _draw { 2541sub _draw {
2502 my ($self) = @_; 2542 my ($self) = @_;
2503 2543
2504 return unless $::CONN;#d# manage and cache textures differently 2544 return unless $::CONN;#d# manage and cache textures differently
2545
2546 my $face;
2547
2548 if ($self->{frame}) {
2549 my $anim = $::CONN->{anim}[$self->{anim}];
2550
2551 $face = $anim->[ $self->{frame} % @$anim ]
2552 if $anim && @$anim;
2553 }
2554
2505 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2555 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]];
2506 2556
2507 # TODO animation
2508 if ($tex) { 2557 if ($tex) {
2509 glEnable GL_TEXTURE_2D; 2558 glEnable GL_TEXTURE_2D;
2510 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2559 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2511 glColor 1, 1, 1, 1; 2560 glColor 1, 1, 1, 1;
2512 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2561 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2513 glDisable GL_TEXTURE_2D; 2562 glDisable GL_TEXTURE_2D;
2514 } 2563 }
2515} 2564}
2516 2565
2566sub DESTROY {
2567 my ($self) = @_;
2568
2569 $self->{timer}->cancel
2570 if $self->{timer};
2571
2572 $self->SUPER::DESTROY;
2573}
2574
2517############################################################################# 2575#############################################################################
2518 2576
2519package CFClient::UI::InventoryItem; 2577package CFClient::UI::InventoryItem;
2520 2578
2521our @ISA = CFClient::UI::HBox::; 2579our @ISA = CFClient::UI::HBox::;
2524 my ($item) = @_; 2582 my ($item) = @_;
2525 2583
2526 my $desc = 2584 my $desc =
2527 $item->{nrof} < 2 2585 $item->{nrof} < 2
2528 ? $item->{name} 2586 ? $item->{name}
2529 : "$item->{nrof} $item->{name_pl}"; 2587 : "$item->{nrof} × $item->{name_pl}";
2530 2588
2531 $item->{flags} & Crossfire::Protocol::F_OPEN 2589 $item->{flags} & Crossfire::Protocol::F_OPEN
2532 and $desc .= " (open)"; 2590 and $desc .= " (open)";
2533 $item->{flags} & Crossfire::Protocol::F_APPLIED 2591 $item->{flags} & Crossfire::Protocol::F_APPLIED
2534 and $desc .= " (applied)"; 2592 and $desc .= " (applied)";
2554 my $item = delete $args{item}; 2612 my $item = delete $args{item};
2555 2613
2556 my $desc = _item_to_desc ($item); 2614 my $desc = _item_to_desc ($item);
2557 2615
2558 my $self = $class->SUPER::new ( 2616 my $self = $class->SUPER::new (
2559 can_hover => 1, 2617 can_hover => 1,
2560 can_events => 1, 2618 can_events => 1,
2561 tooltip => ((CFClient::UI::Label::escape $desc) 2619 tooltip => ((CFClient::UI::Label::escape $desc)
2562 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), 2620 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
2563 connect_button_down => sub { 2621 connect_button_down => sub {
2564 my ($self, $ev, $x, $y) = @_; 2622 my ($self, $ev, $x, $y) = @_;
2565 2623
2566 # todo: maybe put examine on 1? but should just be a tooltip :( 2624 # todo: maybe put examine on 1? but should just be a tooltip :(
2575 } elsif ($ev->{button} == 2) { 2633 } elsif ($ev->{button} == 2) {
2576 $::CONN->send ("apply $item->{tag}"); 2634 $::CONN->send ("apply $item->{tag}");
2577 } elsif ($ev->{button} == 3) { 2635 } elsif ($ev->{button} == 3) {
2578 my @menu_items = ( 2636 my @menu_items = (
2579 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2637 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2580 ["mark", sub { $::CONN->send ("mark $item->{tag}") }], 2638 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2581 ["apply", sub { $::CONN->send ("apply $item->{tag}") }], 2639 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2640 (
2641 $item->{flags} & Crossfire::Protocol::F_LOCKED
2642 ? (
2643 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2644 )
2645 : (
2646 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2582 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], 2647 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2583 [ 2648 )
2584 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2585 sub { $::CONN->send ("lock $item->{tag}") },
2586 ], 2649 ),
2587 ); 2650 );
2588 2651
2589 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 2652 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2590 } 2653 }
2591 2654
2774 # TODO: doesn't handle markup well (read as: at all) 2837 # TODO: doesn't handle markup well (read as: at all)
2775 my $short = $item->{count} > 1 2838 my $short = $item->{count} > 1
2776 ? "<b>$item->{count} ×</b> $item->{text}" 2839 ? "<b>$item->{count} ×</b> $item->{text}"
2777 : $item->{text}; 2840 : $item->{text};
2778 2841
2779 my $fontsize = $item->{fontsize} || $self->{fontsize};
2780
2781 for ($short) { 2842 for ($short) {
2782 s/^\s+//; 2843 s/^\s+//;
2783 s/\s+/ /g; 2844 s/\s+/ /g;
2784 my $len = int 40 / $fontsize;
2785 substr $_, $len, length, "…" if $len < length;
2786 } 2845 }
2787 2846
2788 new CFClient::UI::Label 2847 new CFClient::UI::Label
2789 markup => $short, 2848 markup => $short,
2790 tooltip => $item->{tooltip}, 2849 tooltip => $item->{tooltip},
2791 tooltip_font => $::FONT_PROP, 2850 tooltip_font => $::FONT_PROP,
2792 tooltip_width => 0.67, 2851 tooltip_width => 0.67,
2793 fontsize => $fontsize, 2852 fontsize => $item->{fontsize} || $self->{fontsize},
2853 max_w => $::WIDTH * 0.44,
2794 fg => $item->{fg}, 2854 fg => $item->{fg},
2795 can_events => 1, 2855 can_events => 1,
2796 can_hover => 1 2856 can_hover => 1
2797 }; 2857 };
2798 } 2858 }
2835 } 2895 }
2836 2896
2837 $self->reorder; 2897 $self->reorder;
2838} 2898}
2839 2899
2900sub reconfigure {
2901 my ($self) = @_;
2902
2903 delete $_->{label}
2904 for values %{ $self->{item} || {} };
2905
2906 $self->reorder;
2907 $self->SUPER::reconfigure;
2908}
2909
2840############################################################################# 2910#############################################################################
2841 2911
2842package CFClient::UI::Root; 2912package CFClient::UI::Root;
2843 2913
2844our @ISA = CFClient::UI::Container::; 2914our @ISA = CFClient::UI::Container::;
2927 $child->{x} = int $child->{x}; 2997 $child->{x} = int $child->{x};
2928 $child->{y} = int $child->{y}; 2998 $child->{y} = int $child->{y};
2929 } 2999 }
2930 3000
2931 $self->SUPER::add (@children); 3001 $self->SUPER::add (@children);
3002
3003 while (@children) {
3004 my $w = pop @children;
3005 push @children, $w->children;
3006 $w->{visible} = 1;
3007 }
3008}
3009
3010sub remove {
3011 my ($self, @children) = @_;
3012
3013 $self->SUPER::remove (@children);
3014
3015 while (@children) {
3016 my $w = pop @children;
3017 push @children, $w->children;
3018 delete $w->{visible};
3019 }
2932} 3020}
2933 3021
2934sub on_refresh { 3022sub on_refresh {
2935 my ($self, $id, $cb) = @_; 3023 my ($self, $id, $cb) = @_;
2936 3024
3005 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 3093 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
3006 glClear GL_COLOR_BUFFER_BIT; 3094 glClear GL_COLOR_BUFFER_BIT;
3007 3095
3008 glMatrixMode GL_PROJECTION; 3096 glMatrixMode GL_PROJECTION;
3009 glLoadIdentity; 3097 glLoadIdentity;
3010 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; 3098 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3011 glMatrixMode GL_MODELVIEW; 3099 glMatrixMode GL_MODELVIEW;
3012 glLoadIdentity; 3100 glLoadIdentity;
3013 3101
3014 $self->_draw; 3102 $self->_draw;
3015} 3103}
3017############################################################################# 3105#############################################################################
3018 3106
3019package CFClient::UI; 3107package CFClient::UI;
3020 3108
3021$ROOT = new CFClient::UI::Root; 3109$ROOT = new CFClient::UI::Root;
3022$TOOLTIP = new CFClient::UI::Tooltip; 3110$TOOLTIP = new CFClient::UI::Tooltip z => 900;
3023 3111
30241 31121
3025 3113

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines