… | |
… | |
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 | |
53 | |
|
|
54 | our $GAUGES; |
|
|
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 | |
58 | our $ALT_ENTER_MESSAGE; |
60 | our $ALT_ENTER_MESSAGE; |
59 | our $STATUS_LINE; |
61 | our $STATUS_LINE; |
60 | our $DEBUG_STATUS; |
62 | our $DEBUG_STATUS; |
61 | |
63 | |
62 | sub status { |
64 | sub status { |
63 | $STATUS_LINE->set_text ($_[0]); |
65 | $STATUS_LINE->set_text ($_[0]); |
64 | my ($w, $h) = $STATUS_LINE->size_request; |
|
|
65 | $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); |
66 | $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); |
66 | } |
67 | } |
67 | |
68 | |
68 | sub debug { |
69 | sub debug { |
69 | $DEBUG_STATUS->set_text ($_[0]); |
70 | $DEBUG_STATUS->set_text ($_[0]); |
70 | my ($w, $h) = $DEBUG_STATUS->size_request; |
71 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); |
71 | $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h); |
|
|
72 | } |
72 | } |
73 | |
73 | |
74 | sub start_game { |
74 | sub start_game { |
75 | status "logging in..."; |
75 | status "logging in..."; |
76 | |
76 | |
… | |
… | |
300 | |
300 | |
301 | sub message_window { |
301 | sub message_window { |
302 | my $window = new CFClient::UI::FancyFrame |
302 | my $window = new CFClient::UI::FancyFrame |
303 | border_bg => [1, 1, 1, 0.5], |
303 | border_bg => [1, 1, 1, 0.5], |
304 | bg => [0.3, 0.3, 0.3, 0.8], |
304 | bg => [0.3, 0.3, 0.3, 0.8], |
305 | user_w => $::WIDTH/4, |
305 | user_w => int $::WIDTH / 3, |
306 | user_h => $::HEIGHT, |
306 | user_h => int $::HEIGHT / 5, |
307 | child => (my $vbox = new CFClient::UI::VBox); |
307 | child => (my $vbox = new CFClient::UI::VBox); |
308 | |
308 | |
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 { |
315 | connect_focus_in => sub { |
316 | my ($input, $prev_focus) = @_; |
316 | my ($input, $prev_focus) = @_; |
317 | |
317 | |
318 | delete $input->{refocus_map}; |
318 | delete $input->{refocus_map}; |
319 | |
319 | |
… | |
… | |
325 | connect_activate => sub { |
325 | connect_activate => sub { |
326 | my ($input, $text) = @_; |
326 | my ($input, $text) = @_; |
327 | $input->set_text (''); |
327 | $input->set_text (''); |
328 | |
328 | |
329 | if ($text =~ /^\/(.*)/) { |
329 | if ($text =~ /^\/(.*)/) { |
330 | $::CONN->user_send ("command $1"); |
330 | $::CONN->user_send ($1); |
331 | } else { |
331 | } else { |
332 | my $say_cmd = $::CFG->{say_command} || 'say'; |
332 | my $say_cmd = $::CFG->{say_command} || 'say'; |
333 | $::CONN->user_send ("command $say_cmd $text"); |
333 | $::CONN->user_send ("$say_cmd $text"); |
334 | } |
334 | } |
335 | if ($input->{refocus_map}) { |
335 | if ($input->{refocus_map}) { |
336 | delete $input->{refocus_map}; |
336 | delete $input->{refocus_map}; |
337 | $MAPWIDGET->focus_in |
337 | $MAPWIDGET->focus_in |
338 | } |
338 | } |
… | |
… | |
404 | padding => 0, |
404 | padding => 0, |
405 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
405 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
406 | $CFClient::UI::ROOT->add ($STATUS_LINE); |
406 | $CFClient::UI::ROOT->add ($STATUS_LINE); |
407 | |
407 | |
408 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
408 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
409 | padding => 0, |
409 | padding => 0, |
410 | y => $HEIGHT * 44 / 45, |
410 | y => $HEIGHT * 44 / 45, |
411 | height => $HEIGHT / 45, |
411 | fontsize => $HEIGHT / 45, |
412 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
412 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
413 | $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); |
413 | $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); |
414 | |
414 | |
415 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
415 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
416 | $MAPWIDGET->focus_in; |
416 | $MAPWIDGET->focus_in; |
417 | $MAPWIDGET->connect (activate_console => sub { |
417 | $MAPWIDGET->connect (activate_console => sub { |
… | |
… | |
437 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
437 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
438 | status "Configuration Saved"; |
438 | status "Configuration Saved"; |
439 | }); |
439 | }); |
440 | |
440 | |
441 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
441 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
|
|
442 | |
|
|
443 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
|
|
444 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
|
|
445 | |
|
|
446 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); |
|
|
447 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); |
|
|
448 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); |
|
|
449 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); |
|
|
450 | |
|
|
451 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
|
|
452 | $CFClient::UI::ROOT->add ($tgw); |
442 | } |
453 | } |
443 | |
454 | |
444 | sub destroy_screen { |
455 | sub destroy_screen { |
445 | $CFClient::UI::ROOT->{children} = []; |
456 | $CFClient::UI::ROOT->{children} = []; |
446 | undef $SDL_ACTIVE; |
457 | undef $SDL_ACTIVE; |
… | |
… | |
502 | delete $animate_object{$widget}; |
513 | delete $animate_object{$widget}; |
503 | } |
514 | } |
504 | |
515 | |
505 | @conn::ISA = Crossfire::Protocol::; |
516 | @conn::ISA = Crossfire::Protocol::; |
506 | |
517 | |
|
|
518 | sub conn::stats_update { |
|
|
519 | my ($self, $stats) = @_; |
|
|
520 | |
|
|
521 | # i love text protocols!!! |
|
|
522 | # FIXME: the stats are somehow weird |
|
|
523 | my $hp = $stats->{1}; |
|
|
524 | my $hp_m = $stats->{2}; |
|
|
525 | my $sp = $stats->{3}; |
|
|
526 | my $sp_m = $stats->{4}; |
|
|
527 | my $fo = $stats->{18}; |
|
|
528 | my $fo_m = 1000; |
|
|
529 | my $gr = $stats->{23}; |
|
|
530 | my $gr_m = $stats->{24}; |
|
|
531 | |
|
|
532 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
|
|
533 | $GAUGES->{hp}->set_value ($hp, $hp_m); |
|
|
534 | $GAUGES->{mana}->set_value ($sp, $sp_m); |
|
|
535 | $GAUGES->{food}->set_value ($fo, $fo_m); |
|
|
536 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
|
|
537 | } |
|
|
538 | |
507 | sub conn::user_send { |
539 | sub conn::user_send { |
508 | my ($self, $command) = @_; |
540 | my ($self, $command) = @_; |
509 | |
541 | |
510 | $self->send ($command); |
542 | $self->send_command ($command); |
511 | status $command; |
543 | status $command; |
512 | } |
544 | } |
513 | |
545 | |
514 | sub conn::map_scroll { |
546 | sub conn::map_scroll { |
515 | my ($self, $dx, $dy) = @_; |
547 | my ($self, $dx, $dy) = @_; |
… | |
… | |
567 | } |
599 | } |
568 | |
600 | |
569 | sub conn::flood_fill { |
601 | sub conn::flood_fill { |
570 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
602 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
571 | |
603 | |
|
|
604 | # the server does not allow map paths > 6 |
|
|
605 | return if 6 <= length $path; |
|
|
606 | |
572 | for my $tile (1..4) { |
607 | for my $tile (1..4) { |
573 | next if $self->{neigh}{$hash}[$tile]; |
608 | next if $self->{neigh}{$hash}[$tile]; |
574 | next unless $flags & (1 << ($tile - 1)); |
609 | next unless $flags & (1 << ($tile - 1)); |
575 | |
610 | |
576 | my $neigh = $self->{neigh}{$hash} ||= []; |
611 | my $neigh = $self->{neigh}{$hash} ||= []; |
577 | |
612 | |
578 | $self->send_mapinfo ("spatial $path$tile", sub { |
613 | $self->send_mapinfo ("spatial $path$tile", sub { |
579 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
614 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
580 | |
615 | |
581 | warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
616 | #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
582 | return if $mode ne "spatial"; |
617 | return if $mode ne "spatial"; |
583 | |
618 | |
584 | $x += $MAP->ox; |
619 | $x += $MAP->ox; |
585 | $y += $MAP->oy; |
620 | $y += $MAP->oy; |
586 | |
621 | |
587 | $self->load_map ($hash, $x, $y); |
622 | $self->load_map ($hash, $x, $y) |
|
|
623 | unless $self->{neigh}{$hash}[5]++;#d# |
588 | |
624 | |
589 | $neigh->[$tile] = [$x, $y, $w, $h]; |
625 | $neigh->[$tile] = [$x, $y, $w, $h]; |
590 | |
626 | |
591 | $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) |
627 | $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) |
592 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
628 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
… | |
… | |
775 | |
811 | |
776 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
812 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
777 | |
813 | |
778 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
814 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
779 | |
815 | |
780 | init_screen; |
|
|
781 | |
|
|
782 | { |
816 | { |
783 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
817 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
784 | |
818 | |
785 | CFClient::add_font $_ for @fonts; |
819 | CFClient::add_font $_ for @fonts; |
786 | CFClient::set_font $fonts[0]; |
820 | CFClient::set_font $fonts[0]; |
787 | } |
821 | } |
788 | |
822 | |
|
|
823 | init_screen; |
|
|
824 | |
789 | Event::loop; |
825 | Event::loop; |
790 | |
826 | |
791 | |
827 | |