… | |
… | |
11 | use DC::Macro; |
11 | use DC::Macro; |
12 | |
12 | |
13 | our @ISA = DC::UI::Base::; |
13 | our @ISA = DC::UI::Base::; |
14 | |
14 | |
15 | my $magicmap_tex = |
15 | my $magicmap_tex = |
16 | new_from_file DC::Texture DC::find_rcfile "magicmap.png", |
16 | new_from_resource DC::Texture "magicmap.png", |
17 | mipmap => 1, wrap => 0, internalformat => GL_ALPHA; |
17 | mipmap => 1, wrap => 0, internalformat => GL_ALPHA; |
18 | |
18 | |
19 | sub new { |
19 | sub new { |
20 | my $class = shift; |
20 | my $class = shift; |
21 | |
21 | |
… | |
… | |
25 | tilesize => 32, |
25 | tilesize => 32, |
26 | @_ |
26 | @_ |
27 | ); |
27 | ); |
28 | |
28 | |
29 | $self |
29 | $self |
30 | } |
|
|
31 | |
|
|
32 | sub set_tilesize { |
|
|
33 | my ($self, $tilesize) = @_; |
|
|
34 | |
|
|
35 | $self->{tilesize} = $tilesize; |
|
|
36 | } |
30 | } |
37 | |
31 | |
38 | sub add_command { |
32 | sub add_command { |
39 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
33 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
40 | |
34 | |
… | |
… | |
169 | sub invoke_button_down { |
163 | sub invoke_button_down { |
170 | my ($self, $ev, $x, $y) = @_; |
164 | my ($self, $ev, $x, $y) = @_; |
171 | |
165 | |
172 | if ($ev->{button} == 1) { |
166 | if ($ev->{button} == 1) { |
173 | $self->grab_focus; |
167 | $self->grab_focus; |
174 | return unless $::CONN; |
168 | return unless $::CONN && $self->{ctilesize}; |
175 | |
169 | |
176 | my $x = $self->{dx} + DC::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize}; |
170 | my $x = $self->{dx} + DC::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize}; |
177 | my $y = $self->{dy} + DC::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize}; |
171 | my $y = $self->{dy} + DC::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize}; |
178 | |
172 | |
179 | $x -= DC::floor $::MAP->w * 0.5; |
173 | $x -= DC::floor $::MAP->w * 0.5; |
… | |
… | |
207 | ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], |
201 | ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], |
208 | ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], |
202 | ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], |
209 | ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
203 | ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
210 | ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }], |
204 | ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }], |
211 | # ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], |
205 | # ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], |
212 | [ |
|
|
213 | $::PICKUP_ENABLE->{state} |
|
|
214 | ? "Disable automatic pickup" |
|
|
215 | : "Enable automatic pickup", |
|
|
216 | sub { $::PICKUP_ENABLE->toggle } |
|
|
217 | ], |
|
|
218 | ); |
206 | ); |
219 | |
207 | |
220 | if ($::CONN && $::CONN->{editor_support}) { |
208 | if ($::CONN && $::CONN->{editor_support}) { |
221 | # push @items, [ |
209 | # push @items, [ |
222 | # "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>", |
210 | # "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>", |
… | |
… | |
291 | $self->{need_update} = 1; |
279 | $self->{need_update} = 1; |
292 | $self->SUPER::update; |
280 | $self->SUPER::update; |
293 | } |
281 | } |
294 | |
282 | |
295 | my %DIR = ( |
283 | my %DIR = ( |
296 | ( "," . DC::SDLK_KP5 ), [0, "stay fire"], |
284 | ( "," . DC::SDLK_KP5 ), [0, "stay fire"], |
297 | ( "," . DC::SDLK_KP8 ), [1, "north"], |
285 | ( "," . DC::SDLK_KP8 ), [1, "north"], |
298 | ( "," . DC::SDLK_KP9 ), [2, "northeast"], |
286 | ( "," . DC::SDLK_KP9 ), [2, "northeast"], |
299 | ( "," . DC::SDLK_KP6 ), [3, "east"], |
287 | ( "," . DC::SDLK_KP6 ), [3, "east"], |
300 | ( "," . DC::SDLK_KP3 ), [4, "southeast"], |
288 | ( "," . DC::SDLK_KP3 ), [4, "southeast"], |
301 | ( "," . DC::SDLK_KP2 ), [5, "south"], |
289 | ( "," . DC::SDLK_KP2 ), [5, "south"], |
302 | ( "," . DC::SDLK_KP1 ), [6, "southwest"], |
290 | ( "," . DC::SDLK_KP1 ), [6, "southwest"], |
303 | ( "," . DC::SDLK_KP4 ), [7, "west"], |
291 | ( "," . DC::SDLK_KP4 ), [7, "west"], |
304 | ( "," . DC::SDLK_KP7 ), [8, "northwest"], |
292 | ( "," . DC::SDLK_KP7 ), [8, "northwest"], |
305 | |
293 | |
|
|
294 | ( "," . DC::SDLK_PAGEUP ), [2, "northeast"], |
|
|
295 | ( "," . DC::SDLK_PAGEDOWN ), [4, "southeast"], |
|
|
296 | ( "," . DC::SDLK_END ), [6, "southwest"], |
|
|
297 | ( "," . DC::SDLK_HOME ), [8, "northwest"], |
|
|
298 | |
306 | ( "," . DC::SDLK_UP ), [1, "north"], |
299 | ( "," . DC::SDLK_UP ), [1, "north"], |
307 | ("1," . DC::SDLK_UP ), [2, "northeast"], |
300 | ("1," . DC::SDLK_UP ), [2, "northeast"], |
308 | ( "," . DC::SDLK_RIGHT), [3, "east"], |
301 | ( "," . DC::SDLK_RIGHT ), [3, "east"], |
309 | ("1," . DC::SDLK_RIGHT), [4, "southeast"], |
302 | ("1," . DC::SDLK_RIGHT ), [4, "southeast"], |
310 | ( "," . DC::SDLK_DOWN ), [5, "south"], |
303 | ( "," . DC::SDLK_DOWN ), [5, "south"], |
311 | ("1," . DC::SDLK_DOWN ), [6, "southwest"], |
304 | ("1," . DC::SDLK_DOWN ), [6, "southwest"], |
312 | ( "," . DC::SDLK_LEFT ), [7, "west"], |
305 | ( "," . DC::SDLK_LEFT ), [7, "west"], |
313 | ("1," . DC::SDLK_LEFT ), [8, "northwest"], |
306 | ("1," . DC::SDLK_LEFT ), [8, "northwest"], |
314 | ); |
307 | ); |
315 | |
308 | |
316 | sub invoke_key_down { |
309 | sub invoke_key_down { |
317 | my ($self, $ev) = @_; |
310 | my ($self, $ev) = @_; |
318 | |
311 | |
319 | my $mod = $ev->{mod}; |
312 | my $mod = $ev->{mod}; |
320 | my $sym = $ev->{sym}; |
313 | my $sym = $ev->{sym}; |
321 | my $uni = $ev->{unicode}; |
314 | my $uni = $ev->{unicode}; |
322 | |
315 | |
323 | $mod &= DC::KMOD_CTRL | DC::KMOD_ALT | DC::KMOD_SHIFT; |
316 | $mod &= DC::KMOD_CTRL | DC::KMOD_ALT | DC::KMOD_META | DC::KMOD_SHIFT; |
324 | |
317 | |
325 | # ignore repeated keypresses |
318 | # ignore repeated keypresses |
326 | return if $self->{last_mod} == $mod && $self->{last_sym} == $sym; |
319 | return if $self->{last_mod} == $mod && $self->{last_sym} == $sym; |
327 | $self->{last_mod} = $mod; |
320 | $self->{last_mod} = $mod; |
328 | $self->{last_sym} = $sym; |
321 | $self->{last_sym} = $sym; |
329 | |
322 | |
330 | if ($::CONN && (my $dir = $DIR{(!!($mod & DC::KMOD_ALT)) . ",$sym"})) { |
323 | my $dir = $DIR{ (!!($mod & (DC::KMOD_ALT | DC::KMOD_META))) . ",$sym" }; |
|
|
324 | |
|
|
325 | if ($::CONN && $dir) { |
331 | if ($mod & DC::KMOD_SHIFT) { |
326 | if ($mod & DC::KMOD_SHIFT) { |
332 | $self->{shft}++; |
327 | $self->{shft}++; |
333 | if ($dir->[0] != $self->{fire_dir}) { |
328 | if ($dir->[0] != $self->{fire_dir}) { |
334 | $::CONN->user_send ("fire $dir->[0]"); |
329 | $::CONN->user_send ("fire $dir->[0]"); |
335 | } |
330 | } |
… | |
… | |
352 | |
347 | |
353 | my $res = 0; |
348 | my $res = 0; |
354 | my $mod = $ev->{mod}; |
349 | my $mod = $ev->{mod}; |
355 | my $sym = $ev->{sym}; |
350 | my $sym = $ev->{sym}; |
356 | |
351 | |
|
|
352 | delete $self->{last_mod}; |
|
|
353 | delete $self->{last_sym}; |
|
|
354 | |
357 | if ($::CFG->{shift_fire_stop}) { |
355 | if ($::CFG->{shift_fire_stop}) { |
358 | if (!($mod & DC::KMOD_SHIFT) && delete $self->{shft}) { |
356 | if (!($mod & DC::KMOD_SHIFT) && delete $self->{shft}) { |
359 | $::CONN->user_send ("fire_stop"); |
357 | $::CONN->user_send ("fire_stop"); |
360 | delete $self->{fire_dir}; |
358 | delete $self->{fire_dir}; |
361 | $res = 1; |
359 | $res = 1; |
362 | } |
360 | } |
363 | } else { |
361 | } else { |
364 | if (exists $DIR{(!!($mod & DC::KMOD_ALT)) . ",$sym"} && delete $self->{shft}) { |
362 | my $dir = $DIR{ (!!($mod & (DC::KMOD_ALT | DC::KMOD_META))) . ",$sym" }; |
|
|
363 | |
|
|
364 | if ($dir && delete $self->{shft}) { |
365 | $::CONN->user_send ("fire_stop"); |
365 | $::CONN->user_send ("fire_stop"); |
366 | delete $self->{fire_dir}; |
366 | delete $self->{fire_dir}; |
367 | $res = 1; |
367 | $res = 1; |
368 | } elsif (($sym == DC::SDLK_LSHIFT || $sym == DC::SDLK_RSHIFT) |
368 | } elsif (($sym == DC::SDLK_LSHIFT || $sym == DC::SDLK_RSHIFT) |
369 | && delete $self->{shft}) { # XXX: is RSHIFT ok? |
369 | && delete $self->{shft}) { # XXX: is RSHIFT ok? |
… | |
… | |
371 | delete $self->{fire_dir}; |
371 | delete $self->{fire_dir}; |
372 | $res = 1; |
372 | $res = 1; |
373 | } |
373 | } |
374 | } |
374 | } |
375 | |
375 | |
376 | if (!($mod & DC::KMOD_CTRL ) && delete $self->{ctrl}) { |
376 | if (!($mod & DC::KMOD_CTRL) && delete $self->{ctrl}) { |
377 | $::CONN->user_send ("run_stop"); |
377 | $::CONN->user_send ("run_stop"); |
378 | $res = 1; |
378 | $res = 1; |
379 | } |
379 | } |
380 | |
380 | |
381 | $res |
381 | $res |
… | |
… | |
387 | $self->refresh_hook; |
387 | $self->refresh_hook; |
388 | |
388 | |
389 | 0 |
389 | 0 |
390 | } |
390 | } |
391 | |
391 | |
|
|
392 | sub set_tilesize { |
|
|
393 | my ($self, $tilesize) = @_; |
|
|
394 | |
|
|
395 | $self->{tilesize} = $tilesize; |
|
|
396 | } |
|
|
397 | |
|
|
398 | sub scroll { |
|
|
399 | my ($self, $dx, $dy) = @_; |
|
|
400 | |
|
|
401 | $::MAP->scroll ($dx, $dy); |
|
|
402 | |
|
|
403 | $self->{last_fow_texture} = $self->{fow_texture}; |
|
|
404 | $self->{ldx} = $self->{sdx} + $dx * $self->{tilesize}; # smooth displacement |
|
|
405 | $self->{ldy} = $self->{sdy} + $dy * $self->{tilesize}; |
|
|
406 | |
|
|
407 | $self->movement_update; |
|
|
408 | |
|
|
409 | $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement |
|
|
410 | $self->{sdy} += $dy * $self->{tilesize}; |
|
|
411 | } |
|
|
412 | |
392 | sub set_magicmap { |
413 | sub set_magicmap { |
393 | my ($self, $w, $h, $x, $y, $data) = @_; |
414 | my ($self, $w, $h, $x, $y, $data) = @_; |
394 | |
415 | |
395 | $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w; |
416 | $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w; |
396 | $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h; |
417 | $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h; |
… | |
… | |
398 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
419 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
399 | |
420 | |
400 | $self->update; |
421 | $self->update; |
401 | } |
422 | } |
402 | |
423 | |
|
|
424 | sub movement_update { |
|
|
425 | my ($self) = @_; |
|
|
426 | |
|
|
427 | if ($::CFG->{smooth_movement}) { |
|
|
428 | if ($self->{sdx} || $self->{sdy}) { |
|
|
429 | my $diff = EV::time - ($self->{last_update} || $::LAST_REFRESH); |
|
|
430 | my $spd = $::CONN->{stat}{DC::Protocol::CS_STAT_SPEED}; |
|
|
431 | |
|
|
432 | # the minimum time for a single tile movement |
|
|
433 | my $mintime = DC::Protocol::TICK * DC::ceil 1 / ($spd * DC::Protocol::TICK || 1); |
|
|
434 | |
|
|
435 | $spd *= $self->{tilesize}; |
|
|
436 | |
|
|
437 | # jump if "impossibly high" speed |
|
|
438 | if ( |
|
|
439 | (max abs $self->{sdx}, abs $self->{sdy}) |
|
|
440 | > $spd * $mintime * 2.1 |
|
|
441 | ) { |
|
|
442 | #warn "jump ", (max abs $self->{sdx}, abs $self->{sdy}), " ", $spd * $mintime * 2.1;#d# |
|
|
443 | $self->{sdx} = $self->{sdy} = 0; |
|
|
444 | } else { |
|
|
445 | $spd *= $diff * 1.0001; # 1.0001 so that we don't accumulate rounding errors the wrong direction |
|
|
446 | |
|
|
447 | my $dx = $self->{sdx} < 0 ? -$spd : $spd; |
|
|
448 | my $dy = $self->{sdy} < 0 ? -$spd : $spd; |
|
|
449 | |
|
|
450 | if ($self->{sdx} * ($self->{sdx} - $dx) <= 0) { $self->{sdx} = 0 } else { $self->{sdx} -= $dx } |
|
|
451 | if ($self->{sdy} * ($self->{sdy} - $dy) <= 0) { $self->{sdy} = 0 } else { $self->{sdy} -= $dy } |
|
|
452 | } |
|
|
453 | |
|
|
454 | $self->update; |
|
|
455 | } |
|
|
456 | } else { |
|
|
457 | $self->{sdx} = $self->{sdy} = 0; |
|
|
458 | } |
|
|
459 | |
|
|
460 | $self->{last_update} = EV::time; |
|
|
461 | } |
|
|
462 | |
403 | sub refresh_hook { |
463 | sub refresh_hook { |
404 | my ($self) = @_; |
464 | my ($self) = @_; |
405 | |
465 | |
406 | if ($::MAP && $::CONN) { |
466 | if ($::MAP && $::CONN) { |
407 | if (delete $self->{need_update}) { |
467 | if (delete $self->{need_update}) { |
|
|
468 | $self->movement_update; |
|
|
469 | |
408 | my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; |
470 | my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; |
409 | |
471 | |
|
|
472 | my $sdx_t = DC::ceil $self->{sdx} / $tilesize; |
|
|
473 | my $sdy_t = DC::ceil $self->{sdy} / $tilesize; |
|
|
474 | |
|
|
475 | # width/height of map, in tiles |
410 | my $sw = $self->{sw} = 1 + DC::ceil $self->{w} / $tilesize; |
476 | my $sw = $self->{sw} = 2 + DC::ceil $self->{w} / $tilesize; |
411 | my $sh = $self->{sh} = 1 + DC::ceil $self->{h} / $tilesize; |
477 | my $sh = $self->{sh} = 2 + DC::ceil $self->{h} / $tilesize; |
412 | |
478 | |
|
|
479 | # the map displacement, in tiles |
413 | my $sx = DC::ceil $::CFG->{map_shift_x} / $tilesize; |
480 | my $sx = DC::ceil $::CFG->{map_shift_x} / $tilesize + $sdx_t; |
414 | my $sy = DC::ceil $::CFG->{map_shift_y} / $tilesize; |
481 | my $sy = DC::ceil $::CFG->{map_shift_y} / $tilesize + $sdy_t; |
415 | |
482 | |
|
|
483 | # the upper left "visible" corner, in pixels |
416 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
484 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
417 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
485 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
418 | |
486 | |
419 | my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx; |
487 | my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx; |
420 | my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy; |
488 | my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy; |
421 | |
489 | |
422 | if ($::CFG->{fow_enable}) { |
490 | if ($::CFG->{fow_enable}) { |
|
|
491 | my ($sdx_t, $sdy_t);#d# do not anchor at player |
|
|
492 | |
423 | my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); |
493 | my ($w, $h, $data) = $::MAP->fow_texture ( |
|
|
494 | $dx + (min 0, $sdx_t), |
|
|
495 | $dy + (min 0, $sdy_t), |
|
|
496 | $sw + abs $sdx_t, |
|
|
497 | $sh + abs $sdy_t |
|
|
498 | ); |
424 | |
499 | |
425 | $self->{fow_texture} = new DC::Texture |
500 | $self->{fow_texture} = new DC::Texture |
426 | w => $w, |
501 | w => $w, |
427 | h => $h, |
502 | h => $h, |
428 | data => $data, |
503 | data => $data, |
… | |
… | |
435 | glNewList ($self->{list} ||= glGenList); |
510 | glNewList ($self->{list} ||= glGenList); |
436 | |
511 | |
437 | glPushMatrix; |
512 | glPushMatrix; |
438 | glTranslate $sx0, $sy0; |
513 | glTranslate $sx0, $sy0; |
439 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
514 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
|
|
515 | glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy}; |
440 | |
516 | |
441 | $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize}); |
517 | $::MAP->draw ($dx, $dy, $sw, $sh, |
|
|
518 | $self->{tilesize}, |
|
|
519 | $::CONN->{player}{tag}, |
|
|
520 | -$self->{sdx}, -$self->{sdy}); |
442 | |
521 | |
|
|
522 | #d#glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player |
443 | glScale $self->{tilesize}, $self->{tilesize}; |
523 | glScale $self->{tilesize}, $self->{tilesize}; |
444 | |
524 | |
445 | if (my $tex = $self->{fow_texture}) { |
525 | if (my $tex = $self->{fow_texture}) { |
|
|
526 | glEnable GL_TEXTURE_2D; |
|
|
527 | glEnable GL_BLEND; |
|
|
528 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
529 | glBlendEquation GL_FUNC_REVERSE_SUBTRACT; |
|
|
530 | glBlendFunc GL_ONE, GL_ZERO; |
|
|
531 | |
|
|
532 | my $a1 = 0.9; |
|
|
533 | |
|
|
534 | if (0 && $self->{last_fow_texture}) { |
|
|
535 | my $d1 = ($self->{sdx} ** 2 + $self->{sdy} ** 2) ** 0.5; |
|
|
536 | my $d2 = ($self->{ldx} ** 2 + $self->{ldy} ** 2) ** 0.5; |
|
|
537 | |
|
|
538 | if ($d1 * $d2) { |
|
|
539 | my $a2 = $d1 / $d2; |
|
|
540 | |
|
|
541 | $a1 = 1 - $a2; |
|
|
542 | |
|
|
543 | #$a1 *= 0.9; |
|
|
544 | #$a2 *= 0.9; |
|
|
545 | |
|
|
546 | printf "%4g %4g %4g %4g\n", $d1, $d2, $a1, $a2;#d# |
|
|
547 | |
|
|
548 | #$a1 = 1 - (1-$a1) * 0.707; |
|
|
549 | #$a2 = 1 - (1-$a2) * 0.707; |
|
|
550 | |
|
|
551 | glColor 1,0,0,1; |
|
|
552 | glBegin GL_QUADS; |
|
|
553 | glVertex 10 + $sdx_t, 10; |
|
|
554 | glVertex 11 + $sdx_t, 10; |
|
|
555 | glVertex 11 + $sdx_t, 11; |
|
|
556 | glVertex 10 + $sdx_t, 11; |
|
|
557 | glEnd; |
|
|
558 | |
|
|
559 | glColor +($::CFG->{fow_intensity}) x 3, $a2; |
|
|
560 | glPushMatrix; |
|
|
561 | glTranslate $sdx_t, $sdy_t; # anchor at player |
|
|
562 | glTranslate $self->{ldx} / -$tilesize, $self->{ldy} / -$tilesize; |
|
|
563 | glScale 1/3, 1/3; |
|
|
564 | $self->{last_fow_texture}->draw_quad_alpha (0, 0); |
|
|
565 | glPopMatrix; |
|
|
566 | } else { |
|
|
567 | delete $self->{last_fow_texture}; |
|
|
568 | } |
|
|
569 | } |
|
|
570 | |
|
|
571 | glColor +($::CFG->{fow_intensity}) x 3, $a1; |
446 | glPushMatrix; |
572 | glPushMatrix; |
|
|
573 | #d#glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); # anchor at player |
447 | glScale 1/3, 1/3; |
574 | glScale 1/3, 1/3; |
448 | glEnable GL_TEXTURE_2D; |
|
|
449 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
450 | |
|
|
451 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
|
|
452 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
575 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
|
|
576 | glPopMatrix; |
453 | |
577 | |
|
|
578 | glBlendEquation GL_FUNC_ADD; |
454 | glDisable GL_TEXTURE_2D; |
579 | glDisable GL_TEXTURE_2D; |
455 | glPopMatrix; |
580 | glDisable GL_BLEND; |
456 | } |
581 | } |
457 | |
582 | |
458 | if ($self->{magicmap}) { |
583 | if ($self->{magicmap}) { |
459 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
584 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
460 | |
585 | |
… | |
… | |
530 | sub refresh_hook { |
655 | sub refresh_hook { |
531 | my ($self) = @_; |
656 | my ($self) = @_; |
532 | |
657 | |
533 | if ($::MAP && $self->{texture_atime} < time) { |
658 | if ($::MAP && $self->{texture_atime} < time) { |
534 | my ($w, $h) = @$self{qw(w h)}; |
659 | my ($w, $h) = @$self{qw(w h)}; |
|
|
660 | |
|
|
661 | return unless $w && $h; |
535 | |
662 | |
536 | my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
663 | my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
537 | my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
664 | my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
538 | |
665 | |
539 | my $ox = 0.5 * ($w - $sw); |
666 | my $ox = 0.5 * ($w - $sw); |
… | |
… | |
768 | my $text = $self->{entry}->get_text; |
895 | my $text = $self->{entry}->get_text; |
769 | |
896 | |
770 | length $text |
897 | length $text |
771 | or return $self->hide; |
898 | or return $self->hide; |
772 | |
899 | |
773 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
|
|
774 | |
|
|
775 | if ($text ne $self->{last_search}) { |
900 | if ($text ne $self->{last_search}) { |
776 | my @match; |
901 | my @match; |
777 | |
902 | |
778 | if ($text =~ /^(.*?)\s+$/) { |
903 | if ($text =~ /^(.*?)\s+$/) { |
|
|
904 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
779 | @match = [$cmd, "(appended whitespace suppresses completion)"]; |
905 | @match = ([[$cmd,'(appended whitespace suppresses completion)'],$text]); |
780 | } else { |
906 | } else { |
|
|
907 | # @match is [command, penalty, command with arguments] until sort |
|
|
908 | |
|
|
909 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
|
|
910 | |
781 | my $regexp = do { |
911 | my $regexp_abbrev = do { |
782 | my ($beg, @chr) = split //, lc $cmd; |
912 | my ($beg, @chr) = split //, lc $cmd; |
783 | |
913 | |
784 | # the following regex is used to match our "completion entry" |
914 | # the following regex is used to match our "completion entry" |
785 | # to an actual command - the parentheses match kind of "overhead" |
915 | # to an actual command - the parentheses match kind of "overhead" |
786 | # - the more characters the parentheses match, the less attractive |
916 | # - the more characters the parentheses match, the less attractive |
… | |
… | |
788 | my $regexp = "^\Q$beg\E" |
918 | my $regexp = "^\Q$beg\E" |
789 | . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; |
919 | . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; |
790 | qr<$regexp> |
920 | qr<$regexp> |
791 | }; |
921 | }; |
792 | |
922 | |
793 | my @penalty; |
923 | my $regexp_partial = do { |
|
|
924 | my $regexp = "^\Q$text\E(.*)"; |
|
|
925 | qr<$regexp> |
|
|
926 | }; |
794 | |
927 | |
795 | for (keys %{$self->{command}}) { |
928 | for (keys %{$self->{command}}) { |
796 | if (@penalty = $_ =~ $regexp) { |
929 | my @scores; |
797 | push @match, [$_, length join "", map "::$_", grep defined, @penalty]; |
930 | |
|
|
931 | # 1. Complete command [with args] |
|
|
932 | # command is a prefix of the text |
|
|
933 | # score is length of complete command matched |
|
|
934 | # e.g. "invoke summon pet monster bat" |
|
|
935 | # "invoke" "summon pet monster bat" = 6 |
|
|
936 | # "invoke summon pet monster" "bat" = 25 |
|
|
937 | if ($text =~ /^\Q$_\E(.*)/) { |
|
|
938 | push @scores, [$_, length $_, $text]; |
798 | } |
939 | } |
|
|
940 | |
|
|
941 | # 2. Partial command |
|
|
942 | # text is a prefix of the full command |
|
|
943 | # score is the length of the input text |
|
|
944 | # e.g. "invoke s" |
|
|
945 | # "invoke small fireball" = 8 |
|
|
946 | # "invoke summon pet monster" = 8 |
|
|
947 | |
|
|
948 | if ($_ =~ $regexp_partial) { |
|
|
949 | push @scores, [$_, length $text, $_]; |
|
|
950 | } |
|
|
951 | |
|
|
952 | # 3. Abbreviation match |
|
|
953 | # attempts to use first word of text as an abbreviated command |
|
|
954 | # score is length of word + 1 - 3 per non-word-initial character |
|
|
955 | |
|
|
956 | if (my @penalty = $_ =~ $regexp_abbrev) { |
|
|
957 | push @scores, [$_, (length $cmd) + 1 - (length join "", map "::$_", grep defined, @penalty), "$_$arg"]; |
|
|
958 | } |
|
|
959 | |
|
|
960 | # Pick the best option for this command |
|
|
961 | push @match, (sort { |
|
|
962 | $b->[1] <=> $a->[1] |
|
|
963 | } @scores)[0]; |
799 | } |
964 | } |
800 | |
965 | |
|
|
966 | # @match is now [command object, command with arguments] |
801 | @match = map $self->{command}{$_->[0]}, |
967 | @match = map [$self->{command}{$_->[0]}, $_->[2]], |
802 | sort { |
968 | sort { |
803 | $a->[1] <=> $b->[1] |
969 | $b->[1] <=> $a->[1] |
804 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
970 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
805 | or (length $b->[0]) <=> (length $a->[0]) |
971 | or (length $b->[0]) <=> (length $a->[0]) |
806 | } @match; |
972 | } @match; |
807 | } |
973 | } |
808 | |
974 | |
… | |
… | |
827 | $label->{fg} = [1, 1, 1, 1]; |
993 | $label->{fg} = [1, 1, 1, 1]; |
828 | $label->{bg} = [0, 0, 0, 0]; |
994 | $label->{bg} = [0, 0, 0, 0]; |
829 | } |
995 | } |
830 | |
996 | |
831 | if (@matches) { |
997 | if (@matches) { |
832 | $self->{select} = "$matches[0][0]$arg"; |
998 | $self->{select} = "$matches[0][1]"; |
833 | |
999 | |
834 | $labels[0]->{fg} = [0, 0, 0, 1]; |
1000 | $labels[0]->{fg} = [0, 0, 0, 1]; |
835 | $labels[0]->{bg} = [1, 1, 1, 0.8]; |
1001 | $labels[0]->{bg} = [1, 1, 1, 0.8]; |
836 | } else { |
1002 | } else { |
837 | $self->{select} = "$cmd$arg"; |
1003 | $self->{select} = "$text"; |
838 | } |
1004 | } |
839 | |
1005 | |
840 | for my $match (@matches) { |
1006 | for my $match (@matches) { |
841 | my $label = shift @labels; |
1007 | my $label = shift @labels; |
842 | |
1008 | |
843 | if (@labels) { |
1009 | if (@labels) { |
844 | $label->set_text ("$match->[0]$arg"); |
1010 | $label->set_text ("$match->[1]"); |
845 | $label->set_tooltip ($match->[1]); |
1011 | $label->set_tooltip ("$match->[0][1]"); |
846 | } else { |
1012 | } else { |
847 | $label->set_text ("..."); |
1013 | $label->set_text ("..."); |
848 | $label->set_tooltip ("Use Cursor-Down to view more matches"); |
1014 | $label->set_tooltip ("Use Cursor-Down to view more matches"); |
849 | last; |
1015 | last; |
850 | } |
1016 | } |