… | |
… | |
48 | our $MAPWIDGET; |
48 | our $MAPWIDGET; |
49 | our $BUTTONBAR; |
49 | our $BUTTONBAR; |
50 | our $LOGVIEW; |
50 | our $LOGVIEW; |
51 | our $CONSOLE; |
51 | our $CONSOLE; |
52 | our $METASERVER; |
52 | our $METASERVER; |
|
|
53 | |
|
|
54 | our $GAUGES; |
53 | |
55 | |
54 | our $SDL_ACTIVE; |
56 | our $SDL_ACTIVE; |
55 | our $SDL_EV; |
57 | our $SDL_EV; |
56 | our %SDL_CB; |
58 | our %SDL_CB; |
57 | |
59 | |
… | |
… | |
300 | |
302 | |
301 | sub message_window { |
303 | sub message_window { |
302 | my $window = new CFClient::UI::FancyFrame |
304 | my $window = new CFClient::UI::FancyFrame |
303 | border_bg => [1, 1, 1, 0.5], |
305 | border_bg => [1, 1, 1, 0.5], |
304 | bg => [0.3, 0.3, 0.3, 0.8], |
306 | bg => [0.3, 0.3, 0.3, 0.8], |
305 | user_w => $::WIDTH/4, |
307 | user_w => int $::WIDTH / 3, |
306 | user_h => $::HEIGHT, |
308 | user_h => int $::HEIGHT / 5, |
307 | child => (my $vbox = new CFClient::UI::VBox); |
309 | child => (my $vbox = new CFClient::UI::VBox); |
308 | |
310 | |
309 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
311 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
310 | expand => 1, |
312 | expand => 1, |
311 | fontsize => $::CFG->{log_fontsize}, |
313 | fontsize => $::CFG->{log_fontsize}, |
312 | ); |
314 | ); |
313 | |
315 | |
314 | $vbox->add (my $input = new CFClient::UI::LineEntry |
316 | $vbox->add (my $input = new CFClient::UI::Entry |
|
|
317 | connect_focus_in => sub { |
|
|
318 | my ($input, $prev_focus) = @_; |
|
|
319 | |
|
|
320 | delete $input->{refocus_map}; |
|
|
321 | |
|
|
322 | if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) { |
|
|
323 | $input->{refocus_map} = 1; |
|
|
324 | } |
|
|
325 | delete $input->{auto_activated}; |
|
|
326 | }, |
315 | connect_activate => sub { |
327 | connect_activate => sub { |
316 | my ($input, $text) = @_; |
328 | my ($input, $text) = @_; |
317 | $input->set_text (''); |
329 | $input->set_text (''); |
318 | |
330 | |
319 | if ($text =~ /^\/(.*)/) { |
331 | if ($text =~ /^\/(.*)/) { |
320 | $::CONN->user_send ("command $1"); |
332 | $::CONN->user_send ($1); |
321 | } else { |
333 | } else { |
322 | my $say_cmd = $::CFG->{say_command} || 'say'; |
334 | my $say_cmd = $::CFG->{say_command} || 'say'; |
323 | $::CONN->user_send ("command $say_cmd $text"); |
335 | $::CONN->user_send ("$say_cmd $text"); |
|
|
336 | } |
|
|
337 | if ($input->{refocus_map}) { |
|
|
338 | delete $input->{refocus_map}; |
|
|
339 | $MAPWIDGET->focus_in |
324 | } |
340 | } |
325 | }, |
341 | }, |
326 | connect_escape => sub { |
342 | connect_escape => sub { |
327 | $MAPWIDGET->focus_in |
343 | $MAPWIDGET->focus_in |
328 | }, |
344 | }, |
… | |
… | |
390 | padding => 0, |
406 | padding => 0, |
391 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
407 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
392 | $CFClient::UI::ROOT->add ($STATUS_LINE); |
408 | $CFClient::UI::ROOT->add ($STATUS_LINE); |
393 | |
409 | |
394 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
410 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
395 | padding => 0, |
411 | padding => 0, |
396 | y => $HEIGHT * 44 / 45, |
412 | y => $HEIGHT * 44 / 45, |
397 | height => $HEIGHT / 45, |
413 | fontsize => $HEIGHT / 45, |
398 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
414 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
399 | $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); |
415 | $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); |
400 | |
416 | |
401 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
417 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
402 | $MAPWIDGET->focus_in; |
418 | $MAPWIDGET->focus_in; |
403 | $MAPWIDGET->connect (activate_console => sub { |
419 | $MAPWIDGET->connect (activate_console => sub { |
404 | my ($mapwidget, $preset) = @_; |
420 | my ($mapwidget, $preset) = @_; |
405 | |
421 | |
406 | if ($CONSOLE) { |
422 | if ($CONSOLE) { |
|
|
423 | $CONSOLE->{input}->{auto_activated} = 1; |
407 | $CONSOLE->{input}->focus_in; |
424 | $CONSOLE->{input}->focus_in; |
408 | |
425 | |
409 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
426 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
410 | $CONSOLE->{input}->set_text ($preset); |
427 | $CONSOLE->{input}->set_text ($preset); |
411 | } |
428 | } |
… | |
… | |
421 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
438 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
422 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
439 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
423 | status "Configuration Saved"; |
440 | status "Configuration Saved"; |
424 | }); |
441 | }); |
425 | |
442 | |
426 | $BUTTONBAR->{children}[0]->emit ("activate"); |
443 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
|
|
444 | |
|
|
445 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 150, y => 0); |
|
|
446 | $tgw->add (my $hbox = new CFClient::UI::HBox (req_w => 60, req_h => 150)); |
|
|
447 | |
|
|
448 | $hbox->add (my $fg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'food', expand => 1)); |
|
|
449 | $hbox->add (my $mg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'mana', expand => 1)); |
|
|
450 | $hbox->add (my $hg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'hp', expand => 1)); |
|
|
451 | $hbox->add (my $gg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'grace', expand => 1)); |
|
|
452 | |
|
|
453 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
|
|
454 | $CFClient::UI::ROOT->add ($tgw); |
427 | } |
455 | } |
428 | |
456 | |
429 | sub destroy_screen { |
457 | sub destroy_screen { |
430 | $CFClient::UI::ROOT->{children} = []; |
458 | $CFClient::UI::ROOT->{children} = []; |
431 | undef $SDL_ACTIVE; |
459 | undef $SDL_ACTIVE; |
… | |
… | |
487 | delete $animate_object{$widget}; |
515 | delete $animate_object{$widget}; |
488 | } |
516 | } |
489 | |
517 | |
490 | @conn::ISA = Crossfire::Protocol::; |
518 | @conn::ISA = Crossfire::Protocol::; |
491 | |
519 | |
|
|
520 | sub conn::stats_update { |
|
|
521 | my ($self, $stats) = @_; |
|
|
522 | |
|
|
523 | # i love text protocols!!! |
|
|
524 | # FIXME: the stats are somehow weird |
|
|
525 | my $hp = $stats->{1}; |
|
|
526 | my $hp_m = $stats->{2}; |
|
|
527 | my $sp = $stats->{3}; |
|
|
528 | my $sp_m = $stats->{4}; |
|
|
529 | my $fo = $stats->{18}; |
|
|
530 | my $fo_m = 1000; |
|
|
531 | my $gr = $stats->{23}; |
|
|
532 | my $gr_m = $stats->{24}; |
|
|
533 | |
|
|
534 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
|
|
535 | $GAUGES->{hp}->set_value ($hp, $hp_m); |
|
|
536 | $GAUGES->{mana}->set_value ($sp, $sp_m); |
|
|
537 | $GAUGES->{food}->set_value ($fo, $fo_m); |
|
|
538 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
|
|
539 | } |
|
|
540 | |
492 | sub conn::user_send { |
541 | sub conn::user_send { |
493 | my ($self, $command) = @_; |
542 | my ($self, $command) = @_; |
494 | |
543 | |
495 | $self->send ($command); |
544 | $self->send_command ($command); |
496 | status $command; |
545 | status $command; |
|
|
546 | } |
|
|
547 | |
|
|
548 | sub conn::map_scroll { |
|
|
549 | my ($self, $dx, $dy) = @_; |
|
|
550 | |
|
|
551 | $MAP->scroll ($dx, $dy); |
497 | } |
552 | } |
498 | |
553 | |
499 | sub conn::feed_map1a { |
554 | sub conn::feed_map1a { |
500 | my ($self, $data) = @_; |
555 | my ($self, $data) = @_; |
501 | |
556 | |
502 | # $self->Crossfire::Protocol::feed_map1a ($data); |
557 | # $self->Crossfire::Protocol::feed_map1a ($data); |
503 | |
558 | |
504 | $MAP->scroll (delete $self->{delayed_scroll_x}, delete $self->{delayed_scroll_y}); |
|
|
505 | $MAP->map1a_update ($data); |
559 | $MAP->map1a_update ($data); |
506 | $MAPWIDGET->update; |
560 | $MAPWIDGET->update; |
507 | } |
561 | } |
508 | |
562 | |
509 | sub conn::flush_map { |
563 | sub conn::flush_map { |
… | |
… | |
523 | |
577 | |
524 | sub conn::map_clear { |
578 | sub conn::map_clear { |
525 | my ($self) = @_; |
579 | my ($self) = @_; |
526 | |
580 | |
527 | $self->flush_map; |
581 | $self->flush_map; |
|
|
582 | delete $self->{neigh}; |
528 | |
583 | |
529 | $MAP->clear; |
584 | $MAP->clear; |
530 | } |
585 | } |
531 | |
586 | |
532 | sub conn::map_info { |
|
|
533 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
534 | |
587 | |
535 | $self->flush_map; |
588 | sub conn::load_map($$$) { |
536 | |
589 | 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 | |
590 | |
542 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
591 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
543 | $data = Compress::LZF::decompress $data; |
592 | $data = Compress::LZF::decompress $data; |
544 | warn sprintf "LOADmap[%s] length %d\n", $hash, length $data;#d# |
593 | 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)) { |
594 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
546 | my $data = $TILECACHE->get ($id) |
595 | my $data = $TILECACHE->get ($id) |
547 | or next; |
596 | or next; |
548 | |
597 | |
549 | $self->set_texture ($id => $data); |
598 | $self->set_texture ($id => $data); |
550 | } |
599 | } |
551 | } |
600 | } |
|
|
601 | } |
|
|
602 | |
|
|
603 | sub conn::flood_fill { |
|
|
604 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
|
|
605 | |
|
|
606 | # the server does not allow map paths > 6 |
|
|
607 | return if 6 <= length $path; |
|
|
608 | |
|
|
609 | for my $tile (1..4) { |
|
|
610 | next if $self->{neigh}{$hash}[$tile]; |
|
|
611 | next unless $flags & (1 << ($tile - 1)); |
|
|
612 | |
|
|
613 | my $neigh = $self->{neigh}{$hash} ||= []; |
|
|
614 | |
|
|
615 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
616 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
617 | |
|
|
618 | #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
|
|
619 | return if $mode ne "spatial"; |
|
|
620 | |
|
|
621 | $x += $MAP->ox; |
|
|
622 | $y += $MAP->oy; |
|
|
623 | |
|
|
624 | $self->load_map ($hash, $x, $y) |
|
|
625 | unless $self->{neigh}{$hash}[5]++;#d# |
|
|
626 | |
|
|
627 | $neigh->[$tile] = [$x, $y, $w, $h]; |
|
|
628 | |
|
|
629 | $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) |
|
|
630 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
631 | }); |
|
|
632 | } |
|
|
633 | } |
|
|
634 | |
|
|
635 | sub conn::map_change { |
|
|
636 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
637 | |
|
|
638 | $self->flush_map; |
|
|
639 | |
|
|
640 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
|
|
641 | |
|
|
642 | warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d# |
|
|
643 | |
|
|
644 | my $mapmapw = 250; |
|
|
645 | my $mapmaph = 250; |
|
|
646 | |
|
|
647 | $self->flood_fill ("", $hash, $flags, |
|
|
648 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
649 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5); |
|
|
650 | |
|
|
651 | $x += $ox; |
|
|
652 | $y += $oy; |
|
|
653 | |
|
|
654 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
|
|
655 | |
|
|
656 | $self->load_map ($hash, $x, $y); |
552 | } |
657 | } |
553 | |
658 | |
554 | sub conn::face_find { |
659 | sub conn::face_find { |
555 | my ($self, $facenum, $face) = @_; |
660 | my ($self, $facenum, $face) = @_; |
556 | |
661 | |
… | |
… | |
619 | my ($self, $color, $text) = @_; |
724 | my ($self, $color, $text) = @_; |
620 | |
725 | |
621 | my @color = ( |
726 | my @color = ( |
622 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
727 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
623 | [1.00, 1.00, 1.00], |
728 | [1.00, 1.00, 1.00], |
624 | [0.50, 0.50, 1.00], # changed |
729 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
625 | [1.00, 0.00, 0.00], |
730 | [1.00, 0.00, 0.00], |
626 | [1.00, 0.54, 0.00], |
731 | [1.00, 0.54, 0.00], |
627 | [0.11, 0.56, 1.00], |
732 | [0.11, 0.56, 1.00], |
628 | [0.93, 0.46, 0.00], |
733 | [0.93, 0.46, 0.00], |
629 | [0.18, 0.54, 0.34], |
734 | [0.18, 0.54, 0.34], |
… | |
… | |
708 | |
813 | |
709 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
814 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
710 | |
815 | |
711 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
816 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
712 | |
817 | |
713 | init_screen; |
|
|
714 | |
|
|
715 | { |
818 | { |
716 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
819 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
717 | |
820 | |
718 | CFClient::add_font $_ for @fonts; |
821 | CFClient::add_font $_ for @fonts; |
719 | CFClient::set_font $fonts[0]; |
822 | CFClient::set_font $fonts[0]; |
720 | } |
823 | } |
721 | |
824 | |
|
|
825 | init_screen; |
|
|
826 | |
722 | Event::loop; |
827 | Event::loop; |
723 | |
828 | |
724 | |
829 | |