… | |
… | |
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::Mixer; |
|
|
15 | use SDL::Sound; |
|
|
16 | use SDL::Music; |
|
|
17 | |
13 | use SDL::OpenGL; |
18 | use SDL::OpenGL; |
14 | |
19 | |
15 | use Crossfire; |
20 | use Crossfire; |
16 | use Crossfire::Protocol; |
21 | use Crossfire::Protocol; |
17 | |
22 | |
… | |
… | |
54 | our $GAUGES; |
59 | our $GAUGES; |
55 | |
60 | |
56 | our $SDL_ACTIVE; |
61 | our $SDL_ACTIVE; |
57 | our $SDL_EV; |
62 | our $SDL_EV; |
58 | our %SDL_CB; |
63 | our %SDL_CB; |
|
|
64 | |
|
|
65 | our $SDL_MIXER; |
|
|
66 | our @SOUNDS; # event => file mapping |
|
|
67 | our %AUDIO_CHUNKS; # audio files |
59 | |
68 | |
60 | our $ALT_ENTER_MESSAGE; |
69 | our $ALT_ENTER_MESSAGE; |
61 | our $STATUS_LINE; |
70 | our $STATUS_LINE; |
62 | our $DEBUG_STATUS; |
71 | our $DEBUG_STATUS; |
63 | |
72 | |
… | |
… | |
146 | |
155 | |
147 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); |
156 | $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 { |
157 | $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
149 | my ($self, $value) = @_; |
158 | my ($self, $value) = @_; |
150 | $CFG->{fow_smooth} = $value; |
159 | $CFG->{fow_smooth} = $value; |
|
|
160 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
151 | }); |
161 | }); |
152 | |
162 | |
153 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); |
163 | $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 { |
164 | $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { |
155 | my ($self, $value) = @_; |
165 | my ($self, $value) = @_; |
156 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); |
166 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); |
157 | }); |
167 | }); |
158 | |
168 | |
159 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
169 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
160 | destroy_screen (); |
170 | video_shutdown (); |
161 | init_screen (); |
171 | video_init (); |
|
|
172 | }); |
|
|
173 | |
|
|
174 | $table->add (0, 8, new CFClient::UI::Label align => 1, text => "Sound"); |
|
|
175 | $table->add (1, 8, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub { |
|
|
176 | my ($self, $value) = @_; |
|
|
177 | $CFG->{audio_enable} = $value; |
|
|
178 | }); |
|
|
179 | $table->add (0, 9, new CFClient::UI::Label align => 1, text => "Bg. Music"); |
|
|
180 | $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{bgm_enable}, connect_changed => sub { |
|
|
181 | my ($self, $value) = @_; |
|
|
182 | $CFG->{bgm_enable} = $value; |
|
|
183 | }); |
|
|
184 | $table->add (1, 10, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
|
|
185 | audio_shutdown (); |
|
|
186 | audio_init (); |
162 | }); |
187 | }); |
163 | |
188 | |
164 | $dialog |
189 | $dialog |
165 | } |
190 | } |
166 | |
191 | |
… | |
… | |
349 | |
374 | |
350 | $window |
375 | $window |
351 | } |
376 | } |
352 | |
377 | |
353 | sub sdl_init { |
378 | sub sdl_init { |
354 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
379 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
355 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
380 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
356 | and die "SDL::Init failed!\n"; |
381 | and die "SDL::Init failed!\n"; |
357 | } |
382 | } |
358 | |
383 | |
359 | sub init_screen { |
384 | sub video_init { |
360 | sdl_init; |
385 | sdl_init; |
361 | |
386 | |
362 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
387 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
363 | $FULLSCREEN = $CFG->{fullscreen}; |
388 | $FULLSCREEN = $CFG->{fullscreen}; |
364 | $FAST = $CFG->{fast}; |
389 | $FAST = $CFG->{fast}; |
… | |
… | |
450 | |
475 | |
451 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
476 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
452 | $CFClient::UI::ROOT->add ($tgw); |
477 | $CFClient::UI::ROOT->add ($tgw); |
453 | } |
478 | } |
454 | |
479 | |
455 | sub destroy_screen { |
480 | sub video_shutdown { |
456 | $CFClient::UI::ROOT->{children} = []; |
481 | $CFClient::UI::ROOT->{children} = []; |
457 | undef $SDL_ACTIVE; |
482 | undef $SDL_ACTIVE; |
458 | undef $SDL_EV; |
483 | undef $SDL_EV; |
459 | SDL::Quit; |
484 | } |
|
|
485 | |
|
|
486 | my $bgmusic;#TODO#hack#d# |
|
|
487 | |
|
|
488 | sub audio_init { |
|
|
489 | if ($CFG->{audio_enable}) { |
|
|
490 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
|
|
491 | $SDL_MIXER = new SDL::Mixer; |
|
|
492 | $SDL_MIXER->allocate_channels (8); |
|
|
493 | |
|
|
494 | # TODO: hack, do play loop and mood music |
|
|
495 | if ($CFG->{bgm_enable}) { |
|
|
496 | $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; |
|
|
497 | $SDL_MIXER->play_music ($bgmusic, -1); |
|
|
498 | } |
|
|
499 | |
|
|
500 | while (<$fh>) { |
|
|
501 | next if /^\s*#/; |
|
|
502 | next if /^\s*$/; |
|
|
503 | |
|
|
504 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
|
|
505 | |
|
|
506 | push @SOUNDS, "$volume,$file"; |
|
|
507 | |
|
|
508 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
|
|
509 | my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; |
|
|
510 | $chunk->volume ($volume * 128 / 100); |
|
|
511 | $chunk |
|
|
512 | }; |
|
|
513 | } |
|
|
514 | } else { |
|
|
515 | status "unable to open sound config: $!"; |
|
|
516 | } |
|
|
517 | } |
|
|
518 | } |
|
|
519 | |
|
|
520 | sub audio_shutdown { |
|
|
521 | undef $SDL_MIXER; |
|
|
522 | @SOUNDS = (); |
|
|
523 | %AUDIO_CHUNKS = (); |
460 | } |
524 | } |
461 | |
525 | |
462 | my %animate_object; |
526 | my %animate_object; |
463 | my $animate_timer; |
527 | my $animate_timer; |
464 | |
528 | |
… | |
… | |
705 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
769 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
706 | $MAPWIDGET->update; |
770 | $MAPWIDGET->update; |
707 | |
771 | |
708 | $tex |
772 | $tex |
709 | }; |
773 | }; |
|
|
774 | } |
|
|
775 | |
|
|
776 | sub conn::sound_play { |
|
|
777 | my ($self, $x, $y, $soundnum, $type) = @_; |
|
|
778 | |
|
|
779 | $SDL_MIXER |
|
|
780 | or return; |
|
|
781 | |
|
|
782 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
|
|
783 | or return; |
|
|
784 | |
|
|
785 | $SDL_MIXER->play_channel (-1, $chunk); |
|
|
786 | warn "sound $x,$y,$soundnum,$type\n";#d# |
710 | } |
787 | } |
711 | |
788 | |
712 | sub conn::query { |
789 | sub conn::query { |
713 | my ($self, $flags, $prompt) = @_; |
790 | my ($self, $flags, $prompt) = @_; |
714 | |
791 | |
… | |
… | |
748 | refresh; |
825 | refresh; |
749 | }, |
826 | }, |
750 | SDL_KEYDOWN() => sub { |
827 | SDL_KEYDOWN() => sub { |
751 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
828 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
752 | # alt-enter |
829 | # alt-enter |
753 | destroy_screen; |
830 | video_shutdown; |
754 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
831 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
755 | init_screen; |
832 | video_init; |
756 | } else { |
833 | } else { |
757 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
834 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
758 | } |
835 | } |
759 | }, |
836 | }, |
760 | SDL_KEYUP() => sub { |
837 | SDL_KEYUP() => sub { |
… | |
… | |
794 | fow_smooth => 0, |
871 | fow_smooth => 0, |
795 | log_fontsize => 14, |
872 | log_fontsize => 14, |
796 | mapsize => 100, |
873 | mapsize => 100, |
797 | host => "crossfire.schmorp.de", |
874 | host => "crossfire.schmorp.de", |
798 | say_command => 'say', |
875 | say_command => 'say', |
|
|
876 | audio_enable => 1, |
|
|
877 | bgm_enable => 1, |
799 | ); |
878 | ); |
800 | |
879 | |
801 | while (my ($k, $v) = each %DEF_CFG) { |
880 | while (my ($k, $v) = each %DEF_CFG) { |
802 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
881 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
803 | } |
882 | } |
… | |
… | |
818 | |
897 | |
819 | CFClient::add_font $_ for @fonts; |
898 | CFClient::add_font $_ for @fonts; |
820 | CFClient::set_font $fonts[0]; |
899 | CFClient::set_font $fonts[0]; |
821 | } |
900 | } |
822 | |
901 | |
823 | init_screen; |
902 | video_init; |
|
|
903 | audio_init; |
824 | |
904 | |
825 | Event::loop; |
905 | Event::loop; |
826 | |
906 | |
827 | END { SDL::Quit } |
907 | END { SDL::Quit } |
828 | |
908 | |