… | |
… | |
309 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
309 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
310 | expand => 1, |
310 | expand => 1, |
311 | fontsize => $::CFG->{log_fontsize}, |
311 | fontsize => $::CFG->{log_fontsize}, |
312 | ); |
312 | ); |
313 | |
313 | |
314 | $vbox->add (my $input = new CFClient::UI::LineEntry |
314 | $vbox->add (my $input = new CFClient::UI::Entry |
|
|
315 | connect_focus_in => sub { |
|
|
316 | my ($input, $prev_focus) = @_; |
|
|
317 | |
|
|
318 | delete $input->{refocus_map}; |
|
|
319 | |
|
|
320 | if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) { |
|
|
321 | $input->{refocus_map} = 1; |
|
|
322 | } |
|
|
323 | delete $input->{auto_activated}; |
|
|
324 | }, |
315 | connect_activate => sub { |
325 | connect_activate => sub { |
316 | my ($input, $text) = @_; |
326 | my ($input, $text) = @_; |
317 | $input->set_text (''); |
327 | $input->set_text (''); |
318 | |
328 | |
319 | if ($text =~ /^\/(.*)/) { |
329 | if ($text =~ /^\/(.*)/) { |
320 | $::CONN->user_send ("command $1"); |
330 | $::CONN->user_send ("command $1"); |
321 | } else { |
331 | } else { |
322 | my $say_cmd = $::CFG->{say_command} || 'say'; |
332 | my $say_cmd = $::CFG->{say_command} || 'say'; |
323 | $::CONN->user_send ("command $say_cmd $text"); |
333 | $::CONN->user_send ("command $say_cmd $text"); |
|
|
334 | } |
|
|
335 | if ($input->{refocus_map}) { |
|
|
336 | delete $input->{refocus_map}; |
|
|
337 | $MAPWIDGET->focus_in |
324 | } |
338 | } |
325 | }, |
339 | }, |
326 | connect_escape => sub { |
340 | connect_escape => sub { |
327 | $MAPWIDGET->focus_in |
341 | $MAPWIDGET->focus_in |
328 | }, |
342 | }, |
… | |
… | |
402 | $MAPWIDGET->focus_in; |
416 | $MAPWIDGET->focus_in; |
403 | $MAPWIDGET->connect (activate_console => sub { |
417 | $MAPWIDGET->connect (activate_console => sub { |
404 | my ($mapwidget, $preset) = @_; |
418 | my ($mapwidget, $preset) = @_; |
405 | |
419 | |
406 | if ($CONSOLE) { |
420 | if ($CONSOLE) { |
|
|
421 | $CONSOLE->{input}->{auto_activated} = 1; |
407 | $CONSOLE->{input}->focus_in; |
422 | $CONSOLE->{input}->focus_in; |
408 | |
423 | |
409 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
424 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
410 | $CONSOLE->{input}->set_text ($preset); |
425 | $CONSOLE->{input}->set_text ($preset); |
411 | } |
426 | } |
… | |
… | |
421 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
436 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
422 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
437 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
423 | status "Configuration Saved"; |
438 | status "Configuration Saved"; |
424 | }); |
439 | }); |
425 | |
440 | |
426 | $BUTTONBAR->{children}[0]->emit ("activate"); |
441 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
427 | } |
442 | } |
428 | |
443 | |
429 | sub destroy_screen { |
444 | sub destroy_screen { |
430 | $CFClient::UI::ROOT->{children} = []; |
445 | $CFClient::UI::ROOT->{children} = []; |
431 | undef $SDL_ACTIVE; |
446 | undef $SDL_ACTIVE; |
… | |
… | |
494 | |
509 | |
495 | $self->send ($command); |
510 | $self->send ($command); |
496 | status $command; |
511 | status $command; |
497 | } |
512 | } |
498 | |
513 | |
|
|
514 | sub conn::map_scroll { |
|
|
515 | my ($self, $dx, $dy) = @_; |
|
|
516 | |
|
|
517 | $MAP->scroll ($dx, $dy); |
|
|
518 | } |
|
|
519 | |
499 | sub conn::feed_map1a { |
520 | sub conn::feed_map1a { |
500 | my ($self, $data) = @_; |
521 | my ($self, $data) = @_; |
501 | |
522 | |
502 | # $self->Crossfire::Protocol::feed_map1a ($data); |
523 | # $self->Crossfire::Protocol::feed_map1a ($data); |
503 | |
524 | |
504 | $MAP->scroll (delete $self->{delayed_scroll_x}, delete $self->{delayed_scroll_y}); |
|
|
505 | $MAP->map1a_update ($data); |
525 | $MAP->map1a_update ($data); |
506 | $MAPWIDGET->update; |
526 | $MAPWIDGET->update; |
507 | } |
527 | } |
508 | |
528 | |
509 | sub conn::flush_map { |
529 | sub conn::flush_map { |
… | |
… | |
523 | |
543 | |
524 | sub conn::map_clear { |
544 | sub conn::map_clear { |
525 | my ($self) = @_; |
545 | my ($self) = @_; |
526 | |
546 | |
527 | $self->flush_map; |
547 | $self->flush_map; |
|
|
548 | delete $self->{neigh}; |
528 | |
549 | |
529 | $MAP->clear; |
550 | $MAP->clear; |
530 | } |
551 | } |
531 | |
552 | |
532 | sub conn::map_info { |
|
|
533 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
534 | |
553 | |
535 | $self->flush_map; |
554 | sub conn::load_map($$$) { |
536 | |
555 | my ($self, $hash, $x, $y) = @_; |
537 | $x = $::MAP->ox - $x; |
|
|
538 | $y = $::MAP->oy - $y; |
|
|
539 | |
|
|
540 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
|
|
541 | |
556 | |
542 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
557 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
543 | $data = Compress::LZF::decompress $data; |
558 | $data = Compress::LZF::decompress $data; |
544 | warn sprintf "LOADmap[%s] length %d\n", $hash, length $data;#d# |
559 | warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
545 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
560 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
546 | my $data = $TILECACHE->get ($id) |
561 | my $data = $TILECACHE->get ($id) |
547 | or next; |
562 | or next; |
548 | |
563 | |
549 | $self->set_texture ($id => $data); |
564 | $self->set_texture ($id => $data); |
550 | } |
565 | } |
551 | } |
566 | } |
|
|
567 | } |
|
|
568 | |
|
|
569 | sub conn::flood_fill { |
|
|
570 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
|
|
571 | |
|
|
572 | # the server does not allow map paths > 6 |
|
|
573 | return if 6 <= length $path; |
|
|
574 | |
|
|
575 | for my $tile (1..4) { |
|
|
576 | next if $self->{neigh}{$hash}[$tile]; |
|
|
577 | next unless $flags & (1 << ($tile - 1)); |
|
|
578 | |
|
|
579 | my $neigh = $self->{neigh}{$hash} ||= []; |
|
|
580 | |
|
|
581 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
582 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
583 | |
|
|
584 | #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
|
|
585 | return if $mode ne "spatial"; |
|
|
586 | |
|
|
587 | $x += $MAP->ox; |
|
|
588 | $y += $MAP->oy; |
|
|
589 | |
|
|
590 | $self->load_map ($hash, $x, $y); |
|
|
591 | |
|
|
592 | $neigh->[$tile] = [$x, $y, $w, $h]; |
|
|
593 | |
|
|
594 | $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) |
|
|
595 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
596 | }); |
|
|
597 | } |
|
|
598 | } |
|
|
599 | |
|
|
600 | sub conn::map_change { |
|
|
601 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
602 | |
|
|
603 | $self->flush_map; |
|
|
604 | |
|
|
605 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
|
|
606 | |
|
|
607 | warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d# |
|
|
608 | |
|
|
609 | my $mapmapw = 250; |
|
|
610 | my $mapmaph = 250; |
|
|
611 | |
|
|
612 | $self->flood_fill ("", $hash, $flags, |
|
|
613 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
614 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5); |
|
|
615 | |
|
|
616 | $x += $ox; |
|
|
617 | $y += $oy; |
|
|
618 | |
|
|
619 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
|
|
620 | |
|
|
621 | $self->load_map ($hash, $x, $y); |
552 | } |
622 | } |
553 | |
623 | |
554 | sub conn::face_find { |
624 | sub conn::face_find { |
555 | my ($self, $facenum, $face) = @_; |
625 | my ($self, $facenum, $face) = @_; |
556 | |
626 | |
… | |
… | |
708 | |
778 | |
709 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
779 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
710 | |
780 | |
711 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
781 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
712 | |
782 | |
713 | init_screen; |
|
|
714 | |
|
|
715 | { |
783 | { |
716 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
784 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
717 | |
785 | |
718 | CFClient::add_font $_ for @fonts; |
786 | CFClient::add_font $_ for @fonts; |
719 | CFClient::set_font $fonts[0]; |
787 | CFClient::set_font $fonts[0]; |
720 | } |
788 | } |
721 | |
789 | |
|
|
790 | init_screen; |
|
|
791 | |
722 | Event::loop; |
792 | Event::loop; |
723 | |
793 | |
724 | |
794 | |