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.211 by elmex, Wed May 17 10:33:03 2006 UTC vs.
Revision 1.220 by root, Mon May 22 03:28:55 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};
688 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 699 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
689 glClearColor 0, 0, 0, 0; 700 glClearColor 0, 0, 0, 0;
690 glClear GL_COLOR_BUFFER_BIT; 701 glClear GL_COLOR_BUFFER_BIT;
691 702
692 $self->_render; 703 $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 }; 704 };
701} 705}
702 706
703sub _draw { 707sub _draw {
704 my ($self) = @_; 708 my ($self) = @_;
708 my $tex = $self->{texture} 712 my $tex = $self->{texture}
709 or return; 713 or return;
710 714
711 glEnable GL_TEXTURE_2D; 715 glEnable GL_TEXTURE_2D;
712 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 716 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
713 glColor 0, 0, 0, 1; 717 glColor 1, 1, 1, 1;
714 718
715 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 719 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
716 720
717 glDisable GL_TEXTURE_2D; 721 glDisable GL_TEXTURE_2D;
718} 722}
801 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); 805 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h}));
802 }, 806 },
803 ; 807 ;
804 808
805 $self = $class->SUPER::new ( 809 $self = $class->SUPER::new (
806 vp => (new CFClient::UI::ViewPort), 810 vp => (new CFClient::UI::ViewPort expand => 1),
807 slider => $slider, 811 slider => $slider,
808 @_, 812 @_,
809 ); 813 );
810 814
811 $self->{vp}->add ($self->{scrolled}); 815 $self->{vp}->add ($self->{scrolled});
1297 #bg => none 1301 #bg => none
1298 #active_bg => none 1302 #active_bg => none
1299 #font => default_font 1303 #font => default_font
1300 #text => initial text 1304 #text => initial text
1301 #markup => initial narkup 1305 #markup => initial narkup
1306 #max_w => maximum pixel width
1307 ellipsise => 3, # end
1302 layout => (new CFClient::Layout), 1308 layout => (new CFClient::Layout),
1303 fontsize => 1, 1309 fontsize => 1,
1304 align => -1, 1310 align => -1,
1305 valign => -1, 1311 valign => -1,
1306 padding => 2, 1312 padding => 2,
1371sub size_request { 1377sub size_request {
1372 my ($self) = @_; 1378 my ($self) = @_;
1373 1379
1374 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1380 $self->{layout}->set_font ($self->{font}) if $self->{font};
1375 $self->{layout}->set_width ($self->{max_w} || -1); 1381 $self->{layout}->set_width ($self->{max_w} || -1);
1382 $self->{layout}->set_ellipsise ($self->{ellipsise});
1383 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1376 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1384 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1377 1385
1378 my ($w, $h) = $self->{layout}->size; 1386 my ($w, $h) = $self->{layout}->size;
1379 1387
1380 if (exists $self->{template}) { 1388 if (exists $self->{template}) {
1416 1424
1417 my $tex = $self->{texture} ||= do { 1425 my $tex = $self->{texture} ||= do {
1418 $self->{layout}->set_foreground (@{$self->{fg}}); 1426 $self->{layout}->set_foreground (@{$self->{fg}});
1419 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1427 $self->{layout}->set_font ($self->{font}) if $self->{font};
1420 $self->{layout}->set_width ($self->{w}); 1428 $self->{layout}->set_width ($self->{w});
1429 $self->{layout}->set_ellipsise ($self->{ellipsise});
1430 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1421 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1431 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1422 1432
1423 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1433 my $tex = new_from_layout CFClient::Texture $self->{layout};
1424 1434
1425 $self->{ox} = int ($self->{align} < 0 ? $self->{padding} 1435 $self->{ox} = int ($self->{align} < 0 ? $self->{padding}
1426 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1436 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
2048 range => [0, 0, 100, 10], 2058 range => [0, 0, 100, 10],
2049 req_w => $::WIDTH / 80, 2059 req_w => $::WIDTH / 80,
2050 req_h => $::WIDTH / 80, 2060 req_h => $::WIDTH / 80,
2051 vertical => 0, 2061 vertical => 0,
2052 can_hover => 1, 2062 can_hover => 1,
2053 inner_pad => .05, 2063 inner_pad => 0.02,
2054 @_ 2064 @_
2055 ); 2065 );
2056 2066
2057 $self->set_value ($self->{range}[0]); 2067 $self->set_value ($self->{range}[0]);
2058 $self->update; 2068 $self->update;
2148 glScale $self->{w}, $self->{h}; 2158 glScale $self->{w}, $self->{h};
2149 2159
2150 if ($self->{vertical}) { 2160 if ($self->{vertical}) {
2151 # draw a vertical slider like a rotated horizontal slider 2161 # draw a vertical slider like a rotated horizontal slider
2152 2162
2163 glTranslate 1, 0, 0;
2153 glRotate 90, 0, 0, 1; 2164 glRotate 90, 0, 0, 1;
2154 glTranslate 0, 1, 0;
2155 } 2165 }
2156 2166
2157 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 2167 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
2158 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 2168 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
2159 2169
2205 2215
2206 $self->{fontsize} = $fontsize; 2216 $self->{fontsize} = $fontsize;
2207 $self->reflow; 2217 $self->reflow;
2208} 2218}
2209 2219
2220sub size_allocate {
2221 my ($self, $w, $h) = @_;
2222
2223 $self->SUPER::size_allocate ($w, $h);
2224
2225 $self->{layout}->set_font ($self->{font}) if $self->{font};
2226 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2227 $self->{layout}->set_width ($self->{children}[0]{w});
2228
2229 $self->reflow;
2230}
2231
2210sub text_height { 2232sub text_height {
2211 my ($self, $text) = @_; 2233 my ($self, $text, $indent) = @_;
2212 2234
2213 my $layout = $self->{layout}; 2235 my $layout = $self->{layout};
2214 2236
2215 $layout->set_height ($self->{fontsize} * $::FONTSIZE); 2237 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2216 $layout->set_width ($self->{children}[0]{w}); 2238 $layout->set_width ($self->{children}[0]{w} - $indent);
2217 $layout->set_markup ($text); 2239 $layout->set_markup ($text);
2218 2240
2219 ($layout->size)[1] 2241 ($layout->size)[1]
2220} 2242}
2221 2243
2224 2246
2225 $self->{need_reflow}++; 2247 $self->{need_reflow}++;
2226 $self->update; 2248 $self->update;
2227} 2249}
2228 2250
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 { 2251sub add_paragraph {
2242 my ($self, $color, $text) = @_; 2252 my ($self, $color, $text, $indent) = @_;
2243 2253
2244 #TODO: intelligently "reformat" paragraph 2254 #TODO: intelligently "reformat" paragraph
2245 2255
2256 for my $line (split /\n/, $text) {
2246 my $height = $self->text_height ($text); 2257 my $height = $self->text_height ($line);
2247
2248 $self->{height} += $height; 2258 $self->{height} += $height;
2249
2250 push @{$self->{par}}, [$height, $color, $text]; 2259 push @{$self->{par}}, [$height, $color, $indent, $line];
2260 }
2251 2261
2252 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; 2262 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}];
2253 $self->{children}[1]->update; 2263 $self->{children}[1]->update;
2254} 2264}
2255 2265
2264 2274
2265 $ROOT->on_post_alloc ($self, sub { 2275 $ROOT->on_post_alloc ($self, sub {
2266 if (delete $self->{need_reflow}) { 2276 if (delete $self->{need_reflow}) {
2267 my $height = 0; 2277 my $height = 0;
2268 2278
2269 $height += $_->[0] = $self->text_height ($_->[2]) 2279 $height += $_->[0] = $self->text_height ($_->[3], $_->[2])
2270 for @{$self->{par}}; 2280 for @{$self->{par}};
2271 2281
2272 $self->{height} = $height; 2282 $self->{height} = $height;
2273 2283
2274 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2284 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
2285 $self->{children}[1]->update;
2275 2286
2276 delete $self->{texture}; 2287 delete $self->{texture};
2277 } 2288 }
2278 2289
2279 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2290 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2280 glClearColor 0, 0, 0, 0; 2291 glClearColor 0.5, 0.5, 0.5, 0;
2281 glClear GL_COLOR_BUFFER_BIT; 2292 glClear GL_COLOR_BUFFER_BIT;
2282
2283 glEnable GL_TEXTURE_2D;
2284 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2285 2293
2286 my $top = int $self->{children}[1]{range}[0]; 2294 my $top = int $self->{children}[1]{range}[0];
2287 2295
2288 my $y0 = $top; 2296 my $y0 = $top;
2289 my $y1 = $top + $self->{h}; 2297 my $y1 = $top + $self->{h};
2292 2300
2293 my $layout = $self->{layout}; 2301 my $layout = $self->{layout};
2294 2302
2295 $layout->set_font ($self->{font}) if $self->{font}; 2303 $layout->set_font ($self->{font}) if $self->{font};
2296 2304
2305 glEnable GL_BLEND;
2306 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2307
2297 for my $par (@{$self->{par}}) { 2308 for my $par (@{$self->{par}}) {
2298 my $h = $par->[0]; 2309 my $h = $par->[0];
2299 2310
2300 if ($y0 < $y + $h && $y < $y1) { 2311 if ($y0 < $y + $h && $y < $y1) {
2301 $layout->set_foreground (@{ $par->[1] }); 2312 $layout->set_foreground (@{ $par->[1] });
2313 $layout->set_width ($self->{w} - $par->[2]);
2302 $layout->set_markup ($par->[2]); 2314 $layout->set_markup ($par->[3]);
2303 2315
2304 my ($W, $H) = $layout->size; 2316 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2305 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); 2317
2318 glRasterPos $par->[2], $y - $y0;
2319 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2306 } 2320 }
2307 2321
2308 $y += $h; 2322 $y += $h;
2309 } 2323 }
2310 2324
2311 glDisable GL_TEXTURE_2D; 2325 glDisable GL_BLEND;
2312 }; 2326 };
2313 }); 2327 });
2314} 2328}
2315 2329
2316sub _draw { 2330sub _draw {
2317 my ($self) = @_; 2331 my ($self) = @_;
2318 2332
2319 glEnable GL_TEXTURE_2D; 2333 glEnable GL_TEXTURE_2D;
2320 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2334 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2321 glColor 1, 1, 1, 1; 2335 glColor 1, 1, 1, 1;
2322 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2336 $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2323 glDisable GL_TEXTURE_2D; 2337 glDisable GL_TEXTURE_2D;
2324 2338
2325 $self->{children}[1]->draw; 2339 $self->{children}[1]->draw;
2326 2340
2327} 2341}
2426 2440
2427sub set_tooltip_from { 2441sub set_tooltip_from {
2428 my ($self, $widget) = @_; 2442 my ($self, $widget) = @_;
2429 2443
2430 $self->add (new CFClient::UI::Label 2444 $self->add (new CFClient::UI::Label
2431 markup => $widget->{tooltip}, 2445 markup => $widget->{tooltip},
2432 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2446 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2433 fontsize => 0.8, 2447 fontsize => 0.8,
2434 fg => [0, 0, 0, 1], 2448 fg => [0, 0, 0, 1],
2449 ellipsise => 0,
2435 font => ($widget->{tooltip_font} || $::FONT_PROP), 2450 font => ($widget->{tooltip_font} || $::FONT_PROP),
2436 ); 2451 );
2437} 2452}
2438 2453
2439sub size_request { 2454sub size_request {
2440 my ($self) = @_; 2455 my ($self) = @_;
2486use CFClient::OpenGL; 2501use CFClient::OpenGL;
2487 2502
2488sub new { 2503sub new {
2489 my $class = shift; 2504 my $class = shift;
2490 2505
2491 $class->SUPER::new ( 2506 my $self = $class->SUPER::new (
2492 aspect => 1, 2507 aspect => 1,
2493 @_, 2508 @_,
2494 ) 2509 );
2510
2511 if ($self->{anim} && $self->{animspeed}) {
2512 Scalar::Util::weaken (my $widget = $self);
2513
2514 $self->{timer} = Event->timer (
2515 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
2516 hard => 1,
2517 interval => $self->{animspeed},
2518 cb => sub {
2519 ++$widget->{frame};
2520 $widget->update;
2521 },
2522 );
2523 }
2524
2525 $self
2495} 2526}
2496 2527
2497sub size_request { 2528sub size_request {
2498 (32, 8) 2529 (32, 8)
2499} 2530}
2500 2531
2501sub _draw { 2532sub _draw {
2502 my ($self) = @_; 2533 my ($self) = @_;
2503 2534
2504 return unless $::CONN;#d# manage and cache textures differently 2535 return unless $::CONN;#d# manage and cache textures differently
2536
2537 my $face;
2538
2539 if ($self->{frame}) {
2540 my $anim = $::CONN->{anim}[$self->{anim}];
2541
2542 $face = $anim->[ $self->{frame} % @$anim ]
2543 if $anim && @$anim;
2544 }
2545
2505 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2546 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]];
2506 2547
2507 # TODO animation
2508 if ($tex) { 2548 if ($tex) {
2509 glEnable GL_TEXTURE_2D; 2549 glEnable GL_TEXTURE_2D;
2510 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2550 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2511 glColor 1, 1, 1, 1; 2551 glColor 1, 1, 1, 1;
2512 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2552 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2513 glDisable GL_TEXTURE_2D; 2553 glDisable GL_TEXTURE_2D;
2514 } 2554 }
2515} 2555}
2516 2556
2557sub DESTROY {
2558 my ($self) = @_;
2559
2560 $self->{timer}->cancel
2561 if $self->{timer};
2562
2563 $self->SUPER::DESTROY;
2564}
2565
2517############################################################################# 2566#############################################################################
2518 2567
2519package CFClient::UI::InventoryItem; 2568package CFClient::UI::InventoryItem;
2520 2569
2521our @ISA = CFClient::UI::HBox::; 2570our @ISA = CFClient::UI::HBox::;
2522 2571
2523sub new { 2572sub _item_to_desc {
2524 my $class = shift; 2573 my ($item) = @_;
2525 2574
2526 my %args = @_; 2575 my $desc =
2527
2528 my $item = delete $args{item};
2529
2530 my $desc = $item->{nrof} < 2 2576 $item->{nrof} < 2
2531 ? $item->{name} 2577 ? $item->{name}
2532 : "$item->{nrof} $item->{name_pl}"; 2578 : "$item->{nrof} × $item->{name_pl}";
2533 2579
2534 $item->{flags} & Crossfire::Protocol::F_OPEN 2580 $item->{flags} & Crossfire::Protocol::F_OPEN
2535 and $desc .= " (open)"; 2581 and $desc .= " (open)";
2536 $item->{flags} & Crossfire::Protocol::F_APPLIED 2582 $item->{flags} & Crossfire::Protocol::F_APPLIED
2537 and $desc .= " (applied)"; 2583 and $desc .= " (applied)";
2544 $item->{flags} & Crossfire::Protocol::F_DAMNED 2590 $item->{flags} & Crossfire::Protocol::F_DAMNED
2545 and $desc .= " (damned)"; 2591 and $desc .= " (damned)";
2546 $item->{flags} & Crossfire::Protocol::F_LOCKED 2592 $item->{flags} & Crossfire::Protocol::F_LOCKED
2547 and $desc .= " *"; 2593 and $desc .= " *";
2548 2594
2595 $desc
2596}
2597
2598sub new {
2599 my $class = shift;
2600
2601 my %args = @_;
2602
2603 my $item = delete $args{item};
2604
2605 my $desc = _item_to_desc ($item);
2606
2549 my $self = $class->SUPER::new ( 2607 my $self = $class->SUPER::new (
2550 can_hover => 1, 2608 can_hover => 1,
2551 can_events => 1, 2609 can_events => 1,
2552 tooltip => ((CFClient::UI::Label::escape $desc) 2610 tooltip => ((CFClient::UI::Label::escape $desc)
2553 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), 2611 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
2554 connect_button_down => sub { 2612 connect_button_down => sub {
2555 my ($self, $ev, $x, $y) = @_; 2613 my ($self, $ev, $x, $y) = @_;
2556 2614
2557 # todo: maybe put examine on 1? but should just be a tooltip :( 2615 # todo: maybe put examine on 1? but should just be a tooltip :(
2566 } elsif ($ev->{button} == 2) { 2624 } elsif ($ev->{button} == 2) {
2567 $::CONN->send ("apply $item->{tag}"); 2625 $::CONN->send ("apply $item->{tag}");
2568 } elsif ($ev->{button} == 3) { 2626 } elsif ($ev->{button} == 3) {
2569 my @menu_items = ( 2627 my @menu_items = (
2570 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2628 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2571 ["mark", sub { $::CONN->send ("mark $item->{tag}") }], 2629 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2572 ["apply", sub { $::CONN->send ("apply $item->{tag}") }], 2630 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2631 (
2632 $item->{flags} & Crossfire::Protocol::F_LOCKED
2633 ? (
2634 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2635 )
2636 : (
2637 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2573 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], 2638 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2574 [ 2639 )
2575 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2576 sub { $::CONN->send ("lock $item->{tag}") },
2577 ], 2640 ),
2578 ); 2641 );
2579 2642
2580 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 2643 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2581 } 2644 }
2582 2645
2583 1 2646 1
2584 }, 2647 },
2585 %args 2648 %args
2586 ); 2649 );
2650
2587 2651
2588 $self->add (new CFClient::UI::Face 2652 $self->add (new CFClient::UI::Face
2589 can_events => 0, 2653 can_events => 0,
2590 face => $item->{face}, 2654 face => $item->{face},
2591 anim => $item->{anim}, 2655 anim => $item->{anim},
2592 animspeed => $item->{animspeed}, 2656 animspeed => $item->{animspeed},
2593 ); 2657 );
2594 2658
2595 $self->add (new CFClient::UI::Label 2659 $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0);
2596 can_events => 0, 2660
2597 text => $desc, 2661 $self->{item} = $item;
2598 ); 2662
2663 $self->update_item;
2599 2664
2600 $self 2665 $self
2666}
2667
2668sub update_item {
2669 my ($self) = @_;
2670
2671 my $desc = _item_to_desc ($self->{item});
2672
2673 $self->{name_lbl}->set_text ($desc);
2601} 2674}
2602 2675
2603############################################################################# 2676#############################################################################
2604 2677
2605package CFClient::UI::Inventory; 2678package CFClient::UI::Inventory;
2629 } @$items; 2702 } @$items;
2630 2703
2631 $self->{real_items} = \@items; 2704 $self->{real_items} = \@items;
2632 2705
2633 for my $item (@items) { 2706 for my $item (@items) {
2634 my $desc = $item->{nrof} < 2
2635 ? $item->{name}
2636 : "$item->{nrof} $item->{name_pl}";
2637
2638 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; 2707 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2708 $item->update_item ();
2639 } 2709 }
2640 2710
2641 $self->{scrolled}->add (@items); 2711 $self->{scrolled}->add (@items);
2642 2712
2643# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2713# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2758 # TODO: doesn't handle markup well (read as: at all) 2828 # TODO: doesn't handle markup well (read as: at all)
2759 my $short = $item->{count} > 1 2829 my $short = $item->{count} > 1
2760 ? "<b>$item->{count} ×</b> $item->{text}" 2830 ? "<b>$item->{count} ×</b> $item->{text}"
2761 : $item->{text}; 2831 : $item->{text};
2762 2832
2763 my $fontsize = $item->{fontsize} || $self->{fontsize};
2764
2765 for ($short) { 2833 for ($short) {
2766 s/^\s+//; 2834 s/^\s+//;
2767 s/\s+/ /g; 2835 s/\s+/ /g;
2768 my $len = int 40 / $fontsize;
2769 substr $_, $len, length, "…" if $len < length;
2770 } 2836 }
2771 2837
2772 new CFClient::UI::Label 2838 new CFClient::UI::Label
2773 markup => $short, 2839 markup => $short,
2774 tooltip => $item->{tooltip}, 2840 tooltip => $item->{tooltip},
2775 tooltip_font => $::FONT_PROP, 2841 tooltip_font => $::FONT_PROP,
2776 tooltip_width => 0.67, 2842 tooltip_width => 0.67,
2777 fontsize => $fontsize, 2843 fontsize => $item->{fontsize} || $self->{fontsize},
2844 max_w => $::WIDTH * 0.44,
2778 fg => $item->{fg}, 2845 fg => $item->{fg},
2779 can_events => 1, 2846 can_events => 1,
2780 can_hover => 1 2847 can_hover => 1
2781 }; 2848 };
2782 } 2849 }
2819 } 2886 }
2820 2887
2821 $self->reorder; 2888 $self->reorder;
2822} 2889}
2823 2890
2891sub reconfigure {
2892 my ($self) = @_;
2893
2894 delete $_->{label}
2895 for values %{ $self->{item} || {} };
2896
2897 $self->reorder;
2898 $self->SUPER::reconfigure;
2899}
2900
2824############################################################################# 2901#############################################################################
2825 2902
2826package CFClient::UI::Root; 2903package CFClient::UI::Root;
2827 2904
2828our @ISA = CFClient::UI::Container::; 2905our @ISA = CFClient::UI::Container::;
2989 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 3066 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2990 glClear GL_COLOR_BUFFER_BIT; 3067 glClear GL_COLOR_BUFFER_BIT;
2991 3068
2992 glMatrixMode GL_PROJECTION; 3069 glMatrixMode GL_PROJECTION;
2993 glLoadIdentity; 3070 glLoadIdentity;
2994 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; 3071 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
2995 glMatrixMode GL_MODELVIEW; 3072 glMatrixMode GL_MODELVIEW;
2996 glLoadIdentity; 3073 glLoadIdentity;
2997 3074
2998 $self->_draw; 3075 $self->_draw;
2999} 3076}
3001############################################################################# 3078#############################################################################
3002 3079
3003package CFClient::UI; 3080package CFClient::UI;
3004 3081
3005$ROOT = new CFClient::UI::Root; 3082$ROOT = new CFClient::UI::Root;
3006$TOOLTIP = new CFClient::UI::Tooltip; 3083$TOOLTIP = new CFClient::UI::Tooltip z => 900;
3007 3084
30081 30851
3009 3086

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines