--- deliantra/Deliantra-Client/bin/pclient 2006/04/17 20:29:37 1.125 +++ deliantra/Deliantra-Client/bin/pclient 2006/04/18 21:31:48 1.137 @@ -10,6 +10,11 @@ use SDL::App; use SDL::Event; use SDL::Surface; + +use SDL::Mixer; +use SDL::Sound; +use SDL::Music; + use SDL::OpenGL; use Crossfire; @@ -57,20 +62,22 @@ our $SDL_EV; our %SDL_CB; +our $SDL_MIXER; +our @SOUNDS; # event => file mapping +our %AUDIO_CHUNKS; # audio files + our $ALT_ENTER_MESSAGE; our $STATUS_LINE; our $DEBUG_STATUS; sub status { $STATUS_LINE->set_text ($_[0]); - my ($w, $h) = $STATUS_LINE->size_request; - $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); + $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); } sub debug { $DEBUG_STATUS->set_text ($_[0]); - my ($w, $h) = $DEBUG_STATUS->size_request; - $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h); + $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); } sub start_game { @@ -150,6 +157,7 @@ $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { my ($self, $value) = @_; $CFG->{fow_smooth} = $value; + status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; }); $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); @@ -159,8 +167,23 @@ }); $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { - destroy_screen (); - init_screen (); + video_shutdown (); + video_init (); + }); + + $table->add (0, 8, new CFClient::UI::Label align => 1, text => "Sound"); + $table->add (1, 8, new CFClient::UI::CheckBox state => $CFG->{sound}, connect_changed => sub { + my ($self, $value) = @_; + $CFG->{sound} = $value; + }); + $table->add (0, 9, new CFClient::UI::Label align => 1, text => "Bg. Music"); + $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{bg_music_enable}, connect_changed => sub { + my ($self, $value) = @_; + $CFG->{bg_music_enable} = $value; + }); + $table->add (1, 10, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { + audio_shutdown (); + audio_init (); }); $dialog @@ -358,7 +381,7 @@ and die "SDL::Init failed!\n"; } -sub init_screen { +sub video_init { sdl_init; ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; @@ -442,22 +465,61 @@ $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup - my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 150, y => 0); - $tgw->add (my $hb = new CFClient::UI::HBox (req_w => 60, req_h => 150)); - $hb->add (my $fg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'food', expand => 1)); - $hb->add (my $mg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'mana', expand => 1)); - $hb->add (my $hg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'hp', expand => 1)); - $hb->add (my $gg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'grace', expand => 1)); + my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); + $tgw->add (my $hbox = new CFClient::UI::HBox ()); + + $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); + $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); + $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); + $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; $CFClient::UI::ROOT->add ($tgw); } -sub destroy_screen { +sub video_shutdown { $CFClient::UI::ROOT->{children} = []; undef $SDL_ACTIVE; undef $SDL_EV; - SDL::Quit; +} + +my $bgmusic;#TODO#hack#d# + +sub audio_init { + if ($CFG->{sound} || 1) { + if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { + $SDL_MIXER = new SDL::Mixer; + $SDL_MIXER->allocate_channels (8); + + if ($CFG->{bg_music_enable}) { + $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; + $SDL_MIXER->play_music ($bgmusic, -1); + } + + while (<$fh>) { + next if /^\s*#/; + next if /^\s*$/; + + my ($file, $volume, $event) = split /\s+/, $_, 3; + + push @SOUNDS, "$volume,$file"; + + $AUDIO_CHUNKS{"$volume,$file"} ||= do { + my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; + $chunk->volume ($volume * 128 / 100); + $chunk + }; + } + } else { + status "unable to open sound config: $!"; + } + } +} + +sub audio_shutdown { + undef $SDL_MIXER; + @SOUNDS = (); + %AUDIO_CHUNKS = (); } my %animate_object; @@ -638,8 +700,6 @@ my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); - warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d# - my $mapmapw = 250; my $mapmaph = 250; @@ -712,6 +772,16 @@ }; } +sub conn::sound_play { + my ($self, $x, $y, $soundnum, $type) = @_; + + my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} + or return; + + $SDL_MIXER->play_channel (-1, $chunk); + warn "sound $x,$y,$soundnum,$type\n";#d# +} + sub conn::query { my ($self, $flags, $prompt) = @_; @@ -753,9 +823,9 @@ SDL_KEYDOWN() => sub { if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { # alt-enter - destroy_screen; + video_shutdown; $CFG->{fullscreen} = !$CFG->{fullscreen}; - init_screen; + video_init; } else { CFClient::UI::feed_sdl_key_down_event ($SDL_EV); } @@ -779,6 +849,8 @@ ############################################################################# +$SIG{INT} = $SIG{TERM} = sub { exit }; + $TILECACHE = CFClient::db_table "tilecache"; $FACEMAP = CFClient::db_table "facemap"; @@ -821,8 +893,11 @@ CFClient::set_font $fonts[0]; } -init_screen; +video_init; +audio_init; Event::loop; +END { SDL::Quit } +