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.210 by root, Wed May 17 10:14:52 2006 UTC vs.
Revision 1.221 by root, Mon May 22 03:48:50 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};
196} 207}
197 208
198sub show { 209sub show {
199 my ($self) = @_; 210 my ($self) = @_;
200 211
212 for (my @w = $self; @w; ) {
213 my $w = pop @w;
214 push @w, $w->children;
215 $w->{visible} = 1;
216 }
217
201 return if $self->{parent}; 218 return if $self->{parent};
202 219
203 $CFClient::UI::ROOT->add ($self); 220 $CFClient::UI::ROOT->add ($self);
204} 221}
205 222
206sub hide { 223sub hide {
207 my ($self) = @_; 224 my ($self) = @_;
225
226 for (my @w = $self; @w; ) {
227 my $w = pop @w;
228 push @w, $w->children;
229 $w->{visible} = 1;
230 }
208 231
209 undef $GRAB if $GRAB == $self; 232 undef $GRAB if $GRAB == $self;
210 undef $HOVER if $HOVER == $self; 233 undef $HOVER if $HOVER == $self;
211 234
212 $self->{parent}->remove ($self) 235 $self->{parent}->remove ($self)
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
2501sub _draw { 2546sub _draw {
2502 my ($self) = @_; 2547 my ($self) = @_;
2503 2548
2504 return unless $::CONN;#d# manage and cache textures differently 2549 return unless $::CONN;#d# manage and cache textures differently
2550
2551 my $face;
2552
2553 if ($self->{frame}) {
2554 my $anim = $::CONN->{anim}[$self->{anim}];
2555
2556 $face = $anim->[ $self->{frame} % @$anim ]
2557 if $anim && @$anim;
2558 }
2559
2505 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2560 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]];
2506 2561
2507 # TODO animation
2508 if ($tex) { 2562 if ($tex) {
2509 glEnable GL_TEXTURE_2D; 2563 glEnable GL_TEXTURE_2D;
2510 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2564 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2511 glColor 1, 1, 1, 1; 2565 glColor 1, 1, 1, 1;
2512 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2566 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2513 glDisable GL_TEXTURE_2D; 2567 glDisable GL_TEXTURE_2D;
2514 } 2568 }
2515} 2569}
2516 2570
2571sub DESTROY {
2572 my ($self) = @_;
2573
2574 $self->{timer}->cancel
2575 if $self->{timer};
2576
2577 $self->SUPER::DESTROY;
2578}
2579
2517############################################################################# 2580#############################################################################
2518 2581
2519package CFClient::UI::InventoryItem; 2582package CFClient::UI::InventoryItem;
2520 2583
2521our @ISA = CFClient::UI::HBox::; 2584our @ISA = CFClient::UI::HBox::;
2522 2585
2523sub new { 2586sub _item_to_desc {
2524 my $class = shift; 2587 my ($item) = @_;
2525 2588
2526 my %args = @_; 2589 my $desc =
2527
2528 my $item = delete $args{item};
2529
2530 my $desc = $item->{nrof} < 2 2590 $item->{nrof} < 2
2531 ? $item->{name} 2591 ? $item->{name}
2532 : "$item->{nrof} $item->{name_pl}"; 2592 : "$item->{nrof} × $item->{name_pl}";
2533 2593
2534 $item->{flags} & Crossfire::Protocol::F_OPEN 2594 $item->{flags} & Crossfire::Protocol::F_OPEN
2535 and $desc .= " (open)"; 2595 and $desc .= " (open)";
2536 $item->{flags} & Crossfire::Protocol::F_APPLIED 2596 $item->{flags} & Crossfire::Protocol::F_APPLIED
2537 and $desc .= " (applied)"; 2597 and $desc .= " (applied)";
2544 $item->{flags} & Crossfire::Protocol::F_DAMNED 2604 $item->{flags} & Crossfire::Protocol::F_DAMNED
2545 and $desc .= " (damned)"; 2605 and $desc .= " (damned)";
2546 $item->{flags} & Crossfire::Protocol::F_LOCKED 2606 $item->{flags} & Crossfire::Protocol::F_LOCKED
2547 and $desc .= " *"; 2607 and $desc .= " *";
2548 2608
2609 $desc
2610}
2611
2612sub new {
2613 my $class = shift;
2614
2615 my %args = @_;
2616
2617 my $item = delete $args{item};
2618
2619 my $desc = _item_to_desc ($item);
2620
2549 my $self = $class->SUPER::new ( 2621 my $self = $class->SUPER::new (
2550 can_hover => 1, 2622 can_hover => 1,
2551 can_events => 1, 2623 can_events => 1,
2552 tooltip => ((CFClient::UI::Label::escape $desc) 2624 tooltip => ((CFClient::UI::Label::escape $desc)
2553 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), 2625 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
2554 connect_button_down => sub { 2626 connect_button_down => sub {
2555 my ($self, $ev, $x, $y) = @_; 2627 my ($self, $ev, $x, $y) = @_;
2556 2628
2557 # todo: maybe put examine on 1? but should just be a tooltip :( 2629 # todo: maybe put examine on 1? but should just be a tooltip :(
2558 if ($ev->{button} == 1) { 2630 if ($ev->{button} == 1) {
2631 my $targ = $::CONN->{player}{tag};
2632
2633 if ($item->{container} == $::CONN->{player}{tag}) {
2634 $targ = $main::OPENCONT;
2635 }
2636
2559 $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); 2637 $::CONN->send ("move $targ $item->{tag} 0");
2560 } elsif ($ev->{button} == 2) { 2638 } elsif ($ev->{button} == 2) {
2561 $::CONN->send ("apply $item->{tag}"); 2639 $::CONN->send ("apply $item->{tag}");
2562 } elsif ($ev->{button} == 3) { 2640 } elsif ($ev->{button} == 3) {
2563 my @menu_items = ( 2641 my @menu_items = (
2564 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2642 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2565 ["mark", sub { $::CONN->send ("mark $item->{tag}") }], 2643 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2566 ["apply", sub { $::CONN->send ("apply $item->{tag}") }], 2644 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2645 (
2646 $item->{flags} & Crossfire::Protocol::F_LOCKED
2647 ? (
2648 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2649 )
2650 : (
2651 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2567 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], 2652 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2568 [ 2653 )
2569 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2570 sub { $::CONN->send ("lock ". () ."$item->{tag}") },
2571 ], 2654 ),
2572 ); 2655 );
2573 2656
2574 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); 2657 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2575 } 2658 }
2576 2659
2577 1 2660 1
2578 }, 2661 },
2579 %args 2662 %args
2580 ); 2663 );
2664
2581 2665
2582 $self->add (new CFClient::UI::Face 2666 $self->add (new CFClient::UI::Face
2583 can_events => 0, 2667 can_events => 0,
2584 face => $item->{face}, 2668 face => $item->{face},
2585 anim => $item->{anim}, 2669 anim => $item->{anim},
2586 animspeed => $item->{animspeed}, 2670 animspeed => $item->{animspeed},
2587 ); 2671 );
2588 2672
2589 $self->add (new CFClient::UI::Label 2673 $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0);
2590 can_events => 0, 2674
2591 text => $desc, 2675 $self->{item} = $item;
2592 ); 2676
2677 $self->update_item;
2593 2678
2594 $self 2679 $self
2680}
2681
2682sub update_item {
2683 my ($self) = @_;
2684
2685 my $desc = _item_to_desc ($self->{item});
2686
2687 $self->{name_lbl}->set_text ($desc);
2595} 2688}
2596 2689
2597############################################################################# 2690#############################################################################
2598 2691
2599package CFClient::UI::Inventory; 2692package CFClient::UI::Inventory;
2623 } @$items; 2716 } @$items;
2624 2717
2625 $self->{real_items} = \@items; 2718 $self->{real_items} = \@items;
2626 2719
2627 for my $item (@items) { 2720 for my $item (@items) {
2628 my $desc = $item->{nrof} < 2
2629 ? $item->{name}
2630 : "$item->{nrof} $item->{name_pl}";
2631
2632 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; 2721 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2722 $item->update_item ();
2633 } 2723 }
2634 2724
2635 $self->{scrolled}->add (@items); 2725 $self->{scrolled}->add (@items);
2636 2726
2637# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2727# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2752 # TODO: doesn't handle markup well (read as: at all) 2842 # TODO: doesn't handle markup well (read as: at all)
2753 my $short = $item->{count} > 1 2843 my $short = $item->{count} > 1
2754 ? "<b>$item->{count} ×</b> $item->{text}" 2844 ? "<b>$item->{count} ×</b> $item->{text}"
2755 : $item->{text}; 2845 : $item->{text};
2756 2846
2757 my $fontsize = $item->{fontsize} || $self->{fontsize};
2758
2759 for ($short) { 2847 for ($short) {
2760 s/^\s+//; 2848 s/^\s+//;
2761 s/\s+/ /g; 2849 s/\s+/ /g;
2762 my $len = int 40 / $fontsize;
2763 substr $_, $len, length, "…" if $len < length;
2764 } 2850 }
2765 2851
2766 new CFClient::UI::Label 2852 new CFClient::UI::Label
2767 markup => $short, 2853 markup => $short,
2768 tooltip => $item->{tooltip}, 2854 tooltip => $item->{tooltip},
2769 tooltip_font => $::FONT_PROP, 2855 tooltip_font => $::FONT_PROP,
2770 tooltip_width => 0.67, 2856 tooltip_width => 0.67,
2771 fontsize => $fontsize, 2857 fontsize => $item->{fontsize} || $self->{fontsize},
2858 max_w => $::WIDTH * 0.44,
2772 fg => $item->{fg}, 2859 fg => $item->{fg},
2773 can_events => 1, 2860 can_events => 1,
2774 can_hover => 1 2861 can_hover => 1
2775 }; 2862 };
2776 } 2863 }
2813 } 2900 }
2814 2901
2815 $self->reorder; 2902 $self->reorder;
2816} 2903}
2817 2904
2905sub reconfigure {
2906 my ($self) = @_;
2907
2908 delete $_->{label}
2909 for values %{ $self->{item} || {} };
2910
2911 $self->reorder;
2912 $self->SUPER::reconfigure;
2913}
2914
2818############################################################################# 2915#############################################################################
2819 2916
2820package CFClient::UI::Root; 2917package CFClient::UI::Root;
2821 2918
2822our @ISA = CFClient::UI::Container::; 2919our @ISA = CFClient::UI::Container::;
2983 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 3080 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2984 glClear GL_COLOR_BUFFER_BIT; 3081 glClear GL_COLOR_BUFFER_BIT;
2985 3082
2986 glMatrixMode GL_PROJECTION; 3083 glMatrixMode GL_PROJECTION;
2987 glLoadIdentity; 3084 glLoadIdentity;
2988 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; 3085 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
2989 glMatrixMode GL_MODELVIEW; 3086 glMatrixMode GL_MODELVIEW;
2990 glLoadIdentity; 3087 glLoadIdentity;
2991 3088
2992 $self->_draw; 3089 $self->_draw;
2993} 3090}
2995############################################################################# 3092#############################################################################
2996 3093
2997package CFClient::UI; 3094package CFClient::UI;
2998 3095
2999$ROOT = new CFClient::UI::Root; 3096$ROOT = new CFClient::UI::Root;
3000$TOOLTIP = new CFClient::UI::Tooltip; 3097$TOOLTIP = new CFClient::UI::Tooltip z => 900;
3001 3098
30021 30991
3003 3100

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines