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.223 by elmex, Tue May 23 18:10: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);
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 );
204} 227}
205 228
206sub hide { 229sub hide {
207 my ($self) = @_; 230 my ($self) = @_;
208 231
416 Scalar::Util::weaken ($self->{parent} = $parent); 439 Scalar::Util::weaken ($self->{parent} = $parent);
417 440
418 # TODO: req_w _does_change after ->reconfigure 441 # TODO: req_w _does_change after ->reconfigure
419 $self->check_size 442 $self->check_size
420 unless exists $self->{req_w}; 443 unless exists $self->{req_w};
444
445 $self->show;
421} 446}
422 447
423sub check_size { 448sub check_size {
424 my ($self, $forced) = @_; 449 my ($self, $forced) = @_;
425 450
688 $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 {
689 glClearColor 0, 0, 0, 0; 714 glClearColor 0, 0, 0, 0;
690 glClear GL_COLOR_BUFFER_BIT; 715 glClear GL_COLOR_BUFFER_BIT;
691 716
692 $self->_render; 717 $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 }; 718 };
701} 719}
702 720
703sub _draw { 721sub _draw {
704 my ($self) = @_; 722 my ($self) = @_;
708 my $tex = $self->{texture} 726 my $tex = $self->{texture}
709 or return; 727 or return;
710 728
711 glEnable GL_TEXTURE_2D; 729 glEnable GL_TEXTURE_2D;
712 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 730 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
713 glColor 0, 0, 0, 1; 731 glColor 1, 1, 1, 1;
714 732
715 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 733 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
716 734
717 glDisable GL_TEXTURE_2D; 735 glDisable GL_TEXTURE_2D;
718} 736}
801 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); 819 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h}));
802 }, 820 },
803 ; 821 ;
804 822
805 $self = $class->SUPER::new ( 823 $self = $class->SUPER::new (
806 vp => (new CFClient::UI::ViewPort), 824 vp => (new CFClient::UI::ViewPort expand => 1),
807 slider => $slider, 825 slider => $slider,
808 @_, 826 @_,
809 ); 827 );
810 828
811 $self->{vp}->add ($self->{scrolled}); 829 $self->{vp}->add ($self->{scrolled});
1297 #bg => none 1315 #bg => none
1298 #active_bg => none 1316 #active_bg => none
1299 #font => default_font 1317 #font => default_font
1300 #text => initial text 1318 #text => initial text
1301 #markup => initial narkup 1319 #markup => initial narkup
1320 #max_w => maximum pixel width
1321 ellipsise => 3, # end
1302 layout => (new CFClient::Layout), 1322 layout => (new CFClient::Layout),
1303 fontsize => 1, 1323 fontsize => 1,
1304 align => -1, 1324 align => -1,
1305 valign => -1, 1325 valign => -1,
1306 padding => 2, 1326 padding => 2,
1371sub size_request { 1391sub size_request {
1372 my ($self) = @_; 1392 my ($self) = @_;
1373 1393
1374 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1394 $self->{layout}->set_font ($self->{font}) if $self->{font};
1375 $self->{layout}->set_width ($self->{max_w} || -1); 1395 $self->{layout}->set_width ($self->{max_w} || -1);
1396 $self->{layout}->set_ellipsise ($self->{ellipsise});
1397 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1376 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1398 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1377 1399
1378 my ($w, $h) = $self->{layout}->size; 1400 my ($w, $h) = $self->{layout}->size;
1379 1401
1380 if (exists $self->{template}) { 1402 if (exists $self->{template}) {
1416 1438
1417 my $tex = $self->{texture} ||= do { 1439 my $tex = $self->{texture} ||= do {
1418 $self->{layout}->set_foreground (@{$self->{fg}}); 1440 $self->{layout}->set_foreground (@{$self->{fg}});
1419 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1441 $self->{layout}->set_font ($self->{font}) if $self->{font};
1420 $self->{layout}->set_width ($self->{w}); 1442 $self->{layout}->set_width ($self->{w});
1443 $self->{layout}->set_ellipsise ($self->{ellipsise});
1444 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1421 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1445 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1422 1446
1423 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1447 my $tex = new_from_layout CFClient::Texture $self->{layout};
1424 1448
1425 $self->{ox} = int ($self->{align} < 0 ? $self->{padding} 1449 $self->{ox} = int ($self->{align} < 0 ? $self->{padding}
1426 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1450 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
2048 range => [0, 0, 100, 10], 2072 range => [0, 0, 100, 10],
2049 req_w => $::WIDTH / 80, 2073 req_w => $::WIDTH / 80,
2050 req_h => $::WIDTH / 80, 2074 req_h => $::WIDTH / 80,
2051 vertical => 0, 2075 vertical => 0,
2052 can_hover => 1, 2076 can_hover => 1,
2053 inner_pad => .05, 2077 inner_pad => 0.02,
2054 @_ 2078 @_
2055 ); 2079 );
2056 2080
2057 $self->set_value ($self->{range}[0]); 2081 $self->set_value ($self->{range}[0]);
2058 $self->update; 2082 $self->update;
2148 glScale $self->{w}, $self->{h}; 2172 glScale $self->{w}, $self->{h};
2149 2173
2150 if ($self->{vertical}) { 2174 if ($self->{vertical}) {
2151 # draw a vertical slider like a rotated horizontal slider 2175 # draw a vertical slider like a rotated horizontal slider
2152 2176
2177 glTranslate 1, 0, 0;
2153 glRotate 90, 0, 0, 1; 2178 glRotate 90, 0, 0, 1;
2154 glTranslate 0, 1, 0;
2155 } 2179 }
2156 2180
2157 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 2181 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
2158 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 2182 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
2159 2183
2205 2229
2206 $self->{fontsize} = $fontsize; 2230 $self->{fontsize} = $fontsize;
2207 $self->reflow; 2231 $self->reflow;
2208} 2232}
2209 2233
2234sub size_allocate {
2235 my ($self, $w, $h) = @_;
2236
2237 $self->SUPER::size_allocate ($w, $h);
2238
2239 $self->{layout}->set_font ($self->{font}) if $self->{font};
2240 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2241 $self->{layout}->set_width ($self->{children}[0]{w});
2242
2243 $self->reflow;
2244}
2245
2210sub text_height { 2246sub text_height {
2211 my ($self, $text) = @_; 2247 my ($self, $text, $indent) = @_;
2212 2248
2213 my $layout = $self->{layout}; 2249 my $layout = $self->{layout};
2214 2250
2215 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2251 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2216 $layout->set_width ($self->{children}[0]{w}); 2252 $layout->set_width ($self->{children}[0]{w} - $indent);
2217 $layout->set_markup ($text); 2253 $layout->set_markup ($text);
2218 2254
2219 ($layout->size)[1] 2255 ($layout->size)[1]
2220} 2256}
2221 2257
2224 2260
2225 $self->{need_reflow}++; 2261 $self->{need_reflow}++;
2226 $self->update; 2262 $self->update;
2227} 2263}
2228 2264
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 { 2265sub add_paragraph {
2242 my ($self, $color, $text) = @_; 2266 my ($self, $color, $text, $indent) = @_;
2243 2267
2244 #TODO: intelligently "reformat" paragraph 2268 #TODO: intelligently "reformat" paragraph
2245 2269
2270 for my $line (split /\n/, $text) {
2246 my $height = $self->text_height ($text); 2271 my $height = $self->text_height ($line);
2247
2248 $self->{height} += $height; 2272 $self->{height} += $height;
2249
2250 push @{$self->{par}}, [$height, $color, $text]; 2273 push @{$self->{par}}, [$height, $color, $indent, $line];
2274 }
2251 2275
2252 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; 2276 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}];
2253 $self->{children}[1]->update; 2277 $self->{children}[1]->update;
2254} 2278}
2255 2279
2264 2288
2265 $ROOT->on_post_alloc ($self, sub { 2289 $ROOT->on_post_alloc ($self, sub {
2266 if (delete $self->{need_reflow}) { 2290 if (delete $self->{need_reflow}) {
2267 my $height = 0; 2291 my $height = 0;
2268 2292
2269 $height += $_->[0] = $self->text_height ($_->[2]) 2293 $height += $_->[0] = $self->text_height ($_->[3], $_->[2])
2270 for @{$self->{par}}; 2294 for @{$self->{par}};
2271 2295
2272 $self->{height} = $height; 2296 $self->{height} = $height;
2273 2297
2274 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2298 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2299 $self->{children}[1]->update;
2275 2300
2276 delete $self->{texture}; 2301 delete $self->{texture};
2277 } 2302 }
2278 2303
2279 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2304 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2280 glClearColor 0, 0, 0, 0; 2305 glClearColor 0.5, 0.5, 0.5, 0;
2281 glClear GL_COLOR_BUFFER_BIT; 2306 glClear GL_COLOR_BUFFER_BIT;
2282
2283 glEnable GL_TEXTURE_2D;
2284 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2285 2307
2286 my $top = int $self->{children}[1]{range}[0]; 2308 my $top = int $self->{children}[1]{range}[0];
2287 2309
2288 my $y0 = $top; 2310 my $y0 = $top;
2289 my $y1 = $top + $self->{h}; 2311 my $y1 = $top + $self->{h};
2292 2314
2293 my $layout = $self->{layout}; 2315 my $layout = $self->{layout};
2294 2316
2295 $layout->set_font ($self->{font}) if $self->{font}; 2317 $layout->set_font ($self->{font}) if $self->{font};
2296 2318
2319 glEnable GL_BLEND;
2320 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2321
2297 for my $par (@{$self->{par}}) { 2322 for my $par (@{$self->{par}}) {
2298 my $h = $par->[0]; 2323 my $h = $par->[0];
2299 2324
2300 if ($y0 < $y + $h && $y < $y1) { 2325 if ($y0 < $y + $h && $y < $y1) {
2301 $layout->set_foreground (@{ $par->[1] }); 2326 $layout->set_foreground (@{ $par->[1] });
2327 $layout->set_width ($self->{w} - $par->[2]);
2302 $layout->set_markup ($par->[2]); 2328 $layout->set_markup ($par->[3]);
2303 2329
2304 my ($W, $H) = $layout->size; 2330 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2305 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); 2331
2332 glRasterPos $par->[2], $y - $y0;
2333 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2306 } 2334 }
2307 2335
2308 $y += $h; 2336 $y += $h;
2309 } 2337 }
2310 2338
2311 glDisable GL_TEXTURE_2D; 2339 glDisable GL_BLEND;
2312 }; 2340 };
2313 }); 2341 });
2314} 2342}
2315 2343
2316sub _draw { 2344sub _draw {
2317 my ($self) = @_; 2345 my ($self) = @_;
2318 2346
2319 glEnable GL_TEXTURE_2D; 2347 glEnable GL_TEXTURE_2D;
2320 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2348 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2321 glColor 1, 1, 1, 1; 2349 glColor 1, 1, 1, 1;
2322 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2350 $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2323 glDisable GL_TEXTURE_2D; 2351 glDisable GL_TEXTURE_2D;
2324 2352
2325 $self->{children}[1]->draw; 2353 $self->{children}[1]->draw;
2326 2354
2327} 2355}
2426 2454
2427sub set_tooltip_from { 2455sub set_tooltip_from {
2428 my ($self, $widget) = @_; 2456 my ($self, $widget) = @_;
2429 2457
2430 $self->add (new CFClient::UI::Label 2458 $self->add (new CFClient::UI::Label
2431 markup => $widget->{tooltip}, 2459 markup => $widget->{tooltip},
2432 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2460 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2433 fontsize => 0.8, 2461 fontsize => 0.8,
2434 fg => [0, 0, 0, 1], 2462 fg => [0, 0, 0, 1],
2463 ellipsise => 0,
2435 font => ($widget->{tooltip_font} || $::FONT_PROP), 2464 font => ($widget->{tooltip_font} || $::FONT_PROP),
2436 ); 2465 );
2437} 2466}
2438 2467
2439sub size_request { 2468sub size_request {
2440 my ($self) = @_; 2469 my ($self) = @_;
2486use CFClient::OpenGL; 2515use CFClient::OpenGL;
2487 2516
2488sub new { 2517sub new {
2489 my $class = shift; 2518 my $class = shift;
2490 2519
2491 $class->SUPER::new ( 2520 my $self = $class->SUPER::new (
2492 aspect => 1, 2521 aspect => 1,
2493 @_, 2522 @_,
2494 ) 2523 );
2524
2525 if ($self->{anim} && $self->{animspeed}) {
2526 Scalar::Util::weaken (my $widget = $self);
2527
2528 $self->{timer} = Event->timer (
2529 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
2530 hard => 1,
2531 interval => $self->{animspeed},
2532 cb => sub {
2533 ++$widget->{frame};
2534 $widget->update;
2535 },
2536 );
2537 }
2538
2539 $self
2495} 2540}
2496 2541
2497sub size_request { 2542sub size_request {
2498 (32, 8) 2543 (32, 8)
2499} 2544}
2500 2545
2546sub update {
2547 my ($self) = @_;
2548
2549 return unless $self->{visible};
2550
2551 $self->SUPER::update;
2552}
2553
2501sub _draw { 2554sub _draw {
2502 my ($self) = @_; 2555 my ($self) = @_;
2503 2556
2504 return unless $::CONN;#d# manage and cache textures differently 2557 return unless $::CONN;#d# manage and cache textures differently
2558
2559 my $face;
2560
2561 if ($self->{frame}) {
2562 my $anim = $::CONN->{anim}[$self->{anim}];
2563
2564 $face = $anim->[ $self->{frame} % @$anim ]
2565 if $anim && @$anim;
2566 }
2567
2505 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2568 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]];
2506 2569
2507 # TODO animation
2508 if ($tex) { 2570 if ($tex) {
2509 glEnable GL_TEXTURE_2D; 2571 glEnable GL_TEXTURE_2D;
2510 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2572 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2511 glColor 1, 1, 1, 1; 2573 glColor 1, 1, 1, 1;
2512 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2574 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2513 glDisable GL_TEXTURE_2D; 2575 glDisable GL_TEXTURE_2D;
2514 } 2576 }
2515} 2577}
2516 2578
2579sub DESTROY {
2580 my ($self) = @_;
2581
2582 $self->{timer}->cancel
2583 if $self->{timer};
2584
2585 $self->SUPER::DESTROY;
2586}
2587
2517############################################################################# 2588#############################################################################
2518 2589
2519package CFClient::UI::InventoryItem; 2590package CFClient::UI::InventoryItem;
2520 2591
2521our @ISA = CFClient::UI::HBox::; 2592our @ISA = CFClient::UI::HBox::;
2524 my ($item) = @_; 2595 my ($item) = @_;
2525 2596
2526 my $desc = 2597 my $desc =
2527 $item->{nrof} < 2 2598 $item->{nrof} < 2
2528 ? $item->{name} 2599 ? $item->{name}
2529 : "$item->{nrof} $item->{name_pl}"; 2600 : "$item->{nrof} × $item->{name_pl}";
2530 2601
2531 $item->{flags} & Crossfire::Protocol::F_OPEN 2602 $item->{flags} & Crossfire::Protocol::F_OPEN
2532 and $desc .= " (open)"; 2603 and $desc .= " (open)";
2533 $item->{flags} & Crossfire::Protocol::F_APPLIED 2604 $item->{flags} & Crossfire::Protocol::F_APPLIED
2534 and $desc .= " (applied)"; 2605 and $desc .= " (applied)";
2554 my $item = delete $args{item}; 2625 my $item = delete $args{item};
2555 2626
2556 my $desc = _item_to_desc ($item); 2627 my $desc = _item_to_desc ($item);
2557 2628
2558 my $self = $class->SUPER::new ( 2629 my $self = $class->SUPER::new (
2559 can_hover => 1, 2630 can_hover => 1,
2560 can_events => 1, 2631 can_events => 1,
2561 tooltip => ((CFClient::UI::Label::escape $desc) 2632 tooltip => ((CFClient::UI::Label::escape $desc)
2562 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), 2633 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
2563 connect_button_down => sub { 2634 connect_button_down => sub {
2564 my ($self, $ev, $x, $y) = @_; 2635 my ($self, $ev, $x, $y) = @_;
2565 2636
2566 # todo: maybe put examine on 1? but should just be a tooltip :( 2637 # todo: maybe put examine on 1? but should just be a tooltip :(
2575 } elsif ($ev->{button} == 2) { 2646 } elsif ($ev->{button} == 2) {
2576 $::CONN->send ("apply $item->{tag}"); 2647 $::CONN->send ("apply $item->{tag}");
2577 } elsif ($ev->{button} == 3) { 2648 } elsif ($ev->{button} == 3) {
2578 my @menu_items = ( 2649 my @menu_items = (
2579 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2650 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2580 ["mark", sub { $::CONN->send ("mark $item->{tag}") }], 2651 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2581 ["apply", sub { $::CONN->send ("apply $item->{tag}") }], 2652 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2653 (
2654 $item->{flags} & Crossfire::Protocol::F_LOCKED
2655 ? (
2656 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2657 )
2658 : (
2659 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2582 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], 2660 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2583 [ 2661 )
2584 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2585 sub { $::CONN->send ("lock $item->{tag}") },
2586 ], 2662 ),
2587 ); 2663 );
2588 2664
2589 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 2665 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2590 } 2666 }
2591 2667
2774 # TODO: doesn't handle markup well (read as: at all) 2850 # TODO: doesn't handle markup well (read as: at all)
2775 my $short = $item->{count} > 1 2851 my $short = $item->{count} > 1
2776 ? "<b>$item->{count} ×</b> $item->{text}" 2852 ? "<b>$item->{count} ×</b> $item->{text}"
2777 : $item->{text}; 2853 : $item->{text};
2778 2854
2779 my $fontsize = $item->{fontsize} || $self->{fontsize};
2780
2781 for ($short) { 2855 for ($short) {
2782 s/^\s+//; 2856 s/^\s+//;
2783 s/\s+/ /g; 2857 s/\s+/ /g;
2784 my $len = int 40 / $fontsize;
2785 substr $_, $len, length, "…" if $len < length;
2786 } 2858 }
2787 2859
2788 new CFClient::UI::Label 2860 new CFClient::UI::Label
2789 markup => $short, 2861 markup => $short,
2790 tooltip => $item->{tooltip}, 2862 tooltip => $item->{tooltip},
2791 tooltip_font => $::FONT_PROP, 2863 tooltip_font => $::FONT_PROP,
2792 tooltip_width => 0.67, 2864 tooltip_width => 0.67,
2793 fontsize => $fontsize, 2865 fontsize => $item->{fontsize} || $self->{fontsize},
2866 max_w => $::WIDTH * 0.44,
2794 fg => $item->{fg}, 2867 fg => $item->{fg},
2795 can_events => 1, 2868 can_events => 1,
2796 can_hover => 1 2869 can_hover => 1
2797 }; 2870 };
2798 } 2871 }
2835 } 2908 }
2836 2909
2837 $self->reorder; 2910 $self->reorder;
2838} 2911}
2839 2912
2913sub reconfigure {
2914 my ($self) = @_;
2915
2916 delete $_->{label}
2917 for values %{ $self->{item} || {} };
2918
2919 $self->reorder;
2920 $self->SUPER::reconfigure;
2921}
2922
2840############################################################################# 2923#############################################################################
2841 2924
2842package CFClient::UI::Root; 2925package CFClient::UI::Root;
2843 2926
2844our @ISA = CFClient::UI::Container::; 2927our @ISA = CFClient::UI::Container::;
2927 $child->{x} = int $child->{x}; 3010 $child->{x} = int $child->{x};
2928 $child->{y} = int $child->{y}; 3011 $child->{y} = int $child->{y};
2929 } 3012 }
2930 3013
2931 $self->SUPER::add (@children); 3014 $self->SUPER::add (@children);
3015
3016 while (@children) {
3017 my $w = pop @children;
3018 push @children, $w->children;
3019 $w->{visible} = 1;
3020 }
3021}
3022
3023sub remove {
3024 my ($self, @children) = @_;
3025
3026 $self->SUPER::remove (@children);
3027
3028 while (@children) {
3029 my $w = pop @children;
3030 push @children, $w->children;
3031 delete $w->{visible};
3032 }
2932} 3033}
2933 3034
2934sub on_refresh { 3035sub on_refresh {
2935 my ($self, $id, $cb) = @_; 3036 my ($self, $id, $cb) = @_;
2936 3037
3005 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 3106 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
3006 glClear GL_COLOR_BUFFER_BIT; 3107 glClear GL_COLOR_BUFFER_BIT;
3007 3108
3008 glMatrixMode GL_PROJECTION; 3109 glMatrixMode GL_PROJECTION;
3009 glLoadIdentity; 3110 glLoadIdentity;
3010 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; 3111 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3011 glMatrixMode GL_MODELVIEW; 3112 glMatrixMode GL_MODELVIEW;
3012 glLoadIdentity; 3113 glLoadIdentity;
3013 3114
3014 $self->_draw; 3115 $self->_draw;
3015} 3116}
3017############################################################################# 3118#############################################################################
3018 3119
3019package CFClient::UI; 3120package CFClient::UI;
3020 3121
3021$ROOT = new CFClient::UI::Root; 3122$ROOT = new CFClient::UI::Root;
3022$TOOLTIP = new CFClient::UI::Tooltip; 3123$TOOLTIP = new CFClient::UI::Tooltip z => 900;
3023 3124
30241 31251
3025 3126

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines