… | |
… | |
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 | |
… | |
… | |
54 | our $GAUGES; |
58 | our $GAUGES; |
55 | |
59 | |
56 | our $SDL_ACTIVE; |
60 | our $SDL_ACTIVE; |
57 | our $SDL_EV; |
61 | our $SDL_EV; |
58 | our %SDL_CB; |
62 | our %SDL_CB; |
|
|
63 | |
|
|
64 | our $SDL_MIXER; |
|
|
65 | our @SOUNDS; # event => file mapping |
|
|
66 | our %AUDIO_CHUNKS; # audio files |
59 | |
67 | |
60 | our $ALT_ENTER_MESSAGE; |
68 | our $ALT_ENTER_MESSAGE; |
61 | our $STATUS_LINE; |
69 | our $STATUS_LINE; |
62 | our $DEBUG_STATUS; |
70 | our $DEBUG_STATUS; |
63 | |
71 | |
… | |
… | |
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}; |
… | |
… | |
450 | |
459 | |
451 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
460 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
452 | $CFClient::UI::ROOT->add ($tgw); |
461 | $CFClient::UI::ROOT->add ($tgw); |
453 | } |
462 | } |
454 | |
463 | |
455 | sub destroy_screen { |
464 | sub video_shutdown { |
456 | $CFClient::UI::ROOT->{children} = []; |
465 | $CFClient::UI::ROOT->{children} = []; |
457 | undef $SDL_ACTIVE; |
466 | undef $SDL_ACTIVE; |
458 | undef $SDL_EV; |
467 | undef $SDL_EV; |
459 | 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 = (); |
460 | } |
500 | } |
461 | |
501 | |
462 | my %animate_object; |
502 | my %animate_object; |
463 | my $animate_timer; |
503 | my $animate_timer; |
464 | |
504 | |
… | |
… | |
634 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
674 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
635 | |
675 | |
636 | $self->flush_map; |
676 | $self->flush_map; |
637 | |
677 | |
638 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
678 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
639 | |
|
|
640 | warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d# |
|
|
641 | |
679 | |
642 | my $mapmapw = 250; |
680 | my $mapmapw = 250; |
643 | my $mapmaph = 250; |
681 | my $mapmaph = 250; |
644 | |
682 | |
645 | $self->flood_fill ("", $hash, $flags, |
683 | $self->flood_fill ("", $hash, $flags, |
… | |
… | |
707 | $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}}); |
708 | $MAPWIDGET->update; |
746 | $MAPWIDGET->update; |
709 | |
747 | |
710 | $tex |
748 | $tex |
711 | }; |
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# |
712 | } |
760 | } |
713 | |
761 | |
714 | sub conn::query { |
762 | sub conn::query { |
715 | my ($self, $flags, $prompt) = @_; |
763 | my ($self, $flags, $prompt) = @_; |
716 | |
764 | |
… | |
… | |
750 | refresh; |
798 | refresh; |
751 | }, |
799 | }, |
752 | SDL_KEYDOWN() => sub { |
800 | SDL_KEYDOWN() => sub { |
753 | 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) { |
754 | # alt-enter |
802 | # alt-enter |
755 | destroy_screen; |
803 | video_shutdown; |
756 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
804 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
757 | init_screen; |
805 | video_init; |
758 | } else { |
806 | } else { |
759 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
807 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
760 | } |
808 | } |
761 | }, |
809 | }, |
762 | SDL_KEYUP() => sub { |
810 | SDL_KEYUP() => sub { |
… | |
… | |
776 | }, |
824 | }, |
777 | ); |
825 | ); |
778 | |
826 | |
779 | ############################################################################# |
827 | ############################################################################# |
780 | |
828 | |
|
|
829 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
|
|
830 | |
781 | $TILECACHE = CFClient::db_table "tilecache"; |
831 | $TILECACHE = CFClient::db_table "tilecache"; |
782 | $FACEMAP = CFClient::db_table "facemap"; |
832 | $FACEMAP = CFClient::db_table "facemap"; |
783 | |
833 | |
784 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
834 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
785 | |
835 | |
… | |
… | |
818 | |
868 | |
819 | CFClient::add_font $_ for @fonts; |
869 | CFClient::add_font $_ for @fonts; |
820 | CFClient::set_font $fonts[0]; |
870 | CFClient::set_font $fonts[0]; |
821 | } |
871 | } |
822 | |
872 | |
823 | init_screen; |
873 | video_init; |
|
|
874 | audio_init; |
824 | |
875 | |
825 | Event::loop; |
876 | Event::loop; |
826 | |
877 | |
|
|
878 | END { SDL::Quit } |
827 | |
879 | |
|
|
880 | |