… | |
… | |
8 | |
8 | |
9 | use SDL; |
9 | use SDL; |
10 | use SDL::App; |
10 | use SDL::App; |
11 | use SDL::Event; |
11 | use SDL::Event; |
12 | use SDL::Surface; |
12 | use SDL::Surface; |
|
|
13 | |
|
|
14 | use SDL::Sound; |
|
|
15 | use SDL::Mixer; |
|
|
16 | |
13 | use SDL::OpenGL; |
17 | use SDL::OpenGL; |
14 | |
18 | |
15 | use Crossfire; |
19 | use Crossfire; |
16 | use Crossfire::Protocol; |
20 | use Crossfire::Protocol; |
17 | |
21 | |
… | |
… | |
49 | our $BUTTONBAR; |
53 | our $BUTTONBAR; |
50 | our $LOGVIEW; |
54 | our $LOGVIEW; |
51 | our $CONSOLE; |
55 | our $CONSOLE; |
52 | our $METASERVER; |
56 | our $METASERVER; |
53 | |
57 | |
|
|
58 | our $GAUGES; |
|
|
59 | |
54 | our $SDL_ACTIVE; |
60 | our $SDL_ACTIVE; |
55 | our $SDL_EV; |
61 | our $SDL_EV; |
56 | our %SDL_CB; |
62 | our %SDL_CB; |
57 | |
63 | |
|
|
64 | our $SDL_MIXER; |
|
|
65 | our @SOUNDS; # event => file mapping |
|
|
66 | our %AUDIO_CHUNKS; # audio files |
|
|
67 | |
58 | our $ALT_ENTER_MESSAGE; |
68 | our $ALT_ENTER_MESSAGE; |
59 | our $STATUS_LINE; |
69 | our $STATUS_LINE; |
60 | our $DEBUG_STATUS; |
70 | our $DEBUG_STATUS; |
61 | |
71 | |
62 | sub status { |
72 | sub status { |
63 | $STATUS_LINE->set_text ($_[0]); |
73 | $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); |
74 | $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); |
66 | } |
75 | } |
67 | |
76 | |
68 | sub debug { |
77 | sub debug { |
69 | $DEBUG_STATUS->set_text ($_[0]); |
78 | $DEBUG_STATUS->set_text ($_[0]); |
70 | my ($w, $h) = $DEBUG_STATUS->size_request; |
79 | $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 | } |
80 | } |
73 | |
81 | |
74 | sub start_game { |
82 | sub start_game { |
75 | status "logging in..."; |
83 | status "logging in..."; |
76 | |
84 | |
… | |
… | |
146 | |
154 | |
147 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); |
155 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); |
148 | $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
156 | $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
149 | my ($self, $value) = @_; |
157 | my ($self, $value) = @_; |
150 | $CFG->{fow_smooth} = $value; |
158 | $CFG->{fow_smooth} = $value; |
|
|
159 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
151 | }); |
160 | }); |
152 | |
161 | |
153 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); |
162 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); |
154 | $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { |
163 | $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { |
155 | my ($self, $value) = @_; |
164 | my ($self, $value) = @_; |
156 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); |
165 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); |
157 | }); |
166 | }); |
158 | |
167 | |
159 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
168 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
160 | destroy_screen (); |
169 | video_shutdown (); |
161 | init_screen (); |
170 | video_init (); |
162 | }); |
171 | }); |
163 | |
172 | |
164 | $dialog |
173 | $dialog |
165 | } |
174 | } |
166 | |
175 | |
… | |
… | |
354 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
363 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
355 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
364 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
356 | and die "SDL::Init failed!\n"; |
365 | and die "SDL::Init failed!\n"; |
357 | } |
366 | } |
358 | |
367 | |
359 | sub init_screen { |
368 | sub video_init { |
360 | sdl_init; |
369 | sdl_init; |
361 | |
370 | |
362 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
371 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
363 | $FULLSCREEN = $CFG->{fullscreen}; |
372 | $FULLSCREEN = $CFG->{fullscreen}; |
364 | $FAST = $CFG->{fast}; |
373 | $FAST = $CFG->{fast}; |
… | |
… | |
437 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
446 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
438 | status "Configuration Saved"; |
447 | status "Configuration Saved"; |
439 | }); |
448 | }); |
440 | |
449 | |
441 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
450 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
442 | } |
|
|
443 | |
451 | |
444 | sub destroy_screen { |
452 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
|
|
453 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
|
|
454 | |
|
|
455 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); |
|
|
456 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); |
|
|
457 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); |
|
|
458 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); |
|
|
459 | |
|
|
460 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
|
|
461 | $CFClient::UI::ROOT->add ($tgw); |
|
|
462 | } |
|
|
463 | |
|
|
464 | sub video_shutdown { |
445 | $CFClient::UI::ROOT->{children} = []; |
465 | $CFClient::UI::ROOT->{children} = []; |
446 | undef $SDL_ACTIVE; |
466 | undef $SDL_ACTIVE; |
447 | undef $SDL_EV; |
467 | undef $SDL_EV; |
448 | SDL::Quit; |
468 | } |
|
|
469 | |
|
|
470 | sub audio_init { |
|
|
471 | if ($CFG->{sound} || 1) { |
|
|
472 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
|
|
473 | $SDL_MIXER = new SDL::Mixer; |
|
|
474 | $SDL_MIXER->allocate_channels (8); |
|
|
475 | |
|
|
476 | while (<$fh>) { |
|
|
477 | next if /^\s*#/; |
|
|
478 | next if /^\s*$/; |
|
|
479 | |
|
|
480 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
|
|
481 | |
|
|
482 | push @SOUNDS, "$volume,$file"; |
|
|
483 | |
|
|
484 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
|
|
485 | my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; |
|
|
486 | $chunk->volume ($volume * 128 / 100); |
|
|
487 | $chunk |
|
|
488 | }; |
|
|
489 | } |
|
|
490 | } else { |
|
|
491 | status "unable to open sound config: $!"; |
|
|
492 | } |
|
|
493 | } |
|
|
494 | } |
|
|
495 | |
|
|
496 | sub audio_shutdown { |
|
|
497 | undef $SDL_MIXER; |
|
|
498 | @SOUNDS = (); |
|
|
499 | %AUDIO_CHUNKS = (); |
449 | } |
500 | } |
450 | |
501 | |
451 | my %animate_object; |
502 | my %animate_object; |
452 | my $animate_timer; |
503 | my $animate_timer; |
453 | |
504 | |
… | |
… | |
502 | delete $animate_object{$widget}; |
553 | delete $animate_object{$widget}; |
503 | } |
554 | } |
504 | |
555 | |
505 | @conn::ISA = Crossfire::Protocol::; |
556 | @conn::ISA = Crossfire::Protocol::; |
506 | |
557 | |
|
|
558 | sub conn::stats_update { |
|
|
559 | my ($self, $stats) = @_; |
|
|
560 | |
|
|
561 | # i love text protocols!!! |
|
|
562 | # FIXME: the stats are somehow weird |
|
|
563 | my $hp = $stats->{1}; |
|
|
564 | my $hp_m = $stats->{2}; |
|
|
565 | my $sp = $stats->{3}; |
|
|
566 | my $sp_m = $stats->{4}; |
|
|
567 | my $fo = $stats->{18}; |
|
|
568 | my $fo_m = 1000; |
|
|
569 | my $gr = $stats->{23}; |
|
|
570 | my $gr_m = $stats->{24}; |
|
|
571 | |
|
|
572 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
|
|
573 | $GAUGES->{hp}->set_value ($hp, $hp_m); |
|
|
574 | $GAUGES->{mana}->set_value ($sp, $sp_m); |
|
|
575 | $GAUGES->{food}->set_value ($fo, $fo_m); |
|
|
576 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
|
|
577 | } |
|
|
578 | |
507 | sub conn::user_send { |
579 | sub conn::user_send { |
508 | my ($self, $command) = @_; |
580 | my ($self, $command) = @_; |
509 | |
581 | |
510 | $self->send_command ($command); |
582 | $self->send_command ($command); |
511 | status $command; |
583 | status $command; |
… | |
… | |
602 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
674 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
603 | |
675 | |
604 | $self->flush_map; |
676 | $self->flush_map; |
605 | |
677 | |
606 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
678 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
607 | |
|
|
608 | warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d# |
|
|
609 | |
679 | |
610 | my $mapmapw = 250; |
680 | my $mapmapw = 250; |
611 | my $mapmaph = 250; |
681 | my $mapmaph = 250; |
612 | |
682 | |
613 | $self->flood_fill ("", $hash, $flags, |
683 | $self->flood_fill ("", $hash, $flags, |
… | |
… | |
675 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
745 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
676 | $MAPWIDGET->update; |
746 | $MAPWIDGET->update; |
677 | |
747 | |
678 | $tex |
748 | $tex |
679 | }; |
749 | }; |
|
|
750 | } |
|
|
751 | |
|
|
752 | sub conn::sound_play { |
|
|
753 | my ($self, $x, $y, $soundnum, $type) = @_; |
|
|
754 | |
|
|
755 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
|
|
756 | or return; |
|
|
757 | |
|
|
758 | $SDL_MIXER->play_channel (-1, $chunk); |
|
|
759 | warn "sound $x,$y,$soundnum,$type\n";#d# |
680 | } |
760 | } |
681 | |
761 | |
682 | sub conn::query { |
762 | sub conn::query { |
683 | my ($self, $flags, $prompt) = @_; |
763 | my ($self, $flags, $prompt) = @_; |
684 | |
764 | |
… | |
… | |
718 | refresh; |
798 | refresh; |
719 | }, |
799 | }, |
720 | SDL_KEYDOWN() => sub { |
800 | SDL_KEYDOWN() => sub { |
721 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
801 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
722 | # alt-enter |
802 | # alt-enter |
723 | destroy_screen; |
803 | video_shutdown; |
724 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
804 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
725 | init_screen; |
805 | video_init; |
726 | } else { |
806 | } else { |
727 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
807 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
728 | } |
808 | } |
729 | }, |
809 | }, |
730 | SDL_KEYUP() => sub { |
810 | SDL_KEYUP() => sub { |
… | |
… | |
744 | }, |
824 | }, |
745 | ); |
825 | ); |
746 | |
826 | |
747 | ############################################################################# |
827 | ############################################################################# |
748 | |
828 | |
|
|
829 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
|
|
830 | |
749 | $TILECACHE = CFClient::db_table "tilecache"; |
831 | $TILECACHE = CFClient::db_table "tilecache"; |
750 | $FACEMAP = CFClient::db_table "facemap"; |
832 | $FACEMAP = CFClient::db_table "facemap"; |
751 | |
833 | |
752 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
834 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
753 | |
835 | |
… | |
… | |
786 | |
868 | |
787 | CFClient::add_font $_ for @fonts; |
869 | CFClient::add_font $_ for @fonts; |
788 | CFClient::set_font $fonts[0]; |
870 | CFClient::set_font $fonts[0]; |
789 | } |
871 | } |
790 | |
872 | |
791 | init_screen; |
873 | video_init; |
|
|
874 | audio_init; |
792 | |
875 | |
793 | Event::loop; |
876 | Event::loop; |
794 | |
877 | |
|
|
878 | END { SDL::Quit } |
795 | |
879 | |
|
|
880 | |