--- deliantra/Deliantra-Client/bin/pclient 2006/04/18 01:36:13 1.130 +++ deliantra/Deliantra-Client/bin/pclient 2006/04/19 07:30:33 1.142 @@ -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; @@ -19,6 +24,7 @@ use CFClient; use CFClient::UI; +use CFClient::MapWidget; our $VERSION = '0.1'; @@ -57,6 +63,10 @@ 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; @@ -103,14 +113,14 @@ sub client_setup { my $dialog = new CFClient::UI::FancyFrame child => (my $vbox = new CFClient::UI::VBox); - $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); + $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Client Setup"); $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); - $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); + $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); $table->add (1, 0, my $hbox = new CFClient::UI::HBox); $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); - $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); + $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8); $mode_slider->connect (changed => sub { my ($self, $value) = @_; @@ -120,45 +130,74 @@ }); $mode_slider->emit (changed => $mode_slider->{range}[0]); - $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); + $table->add (0, 1, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen"); $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; }); - $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); + $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; }); - $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); + $table->add (0, 3, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War"); $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { my ($self, $value) = @_; $CFG->{fow_enable} = $value; }); - $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); + $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity"); $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { my ($self, $value) = @_; $CFG->{fow_intensity} = $value; }); - $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); + $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth"); $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"); - $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { - my ($self, $value) = @_; - $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); + $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); + $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { + $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10; +# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; }); - $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { - destroy_screen (); - init_screen (); + $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize"); + $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { + $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); + }); + + $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { + video_shutdown (); + video_init (); + }); + + $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable"); + $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub { + $CFG->{audio_enable} = $_[1]; + }); +# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); +# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub { +# $CFG->{effects_volume} = $_[1]; +# }); + $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); + $table->add (1, 10, my $hbox = new CFClient::UI::HBox); + $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { + $CFG->{bgm_enable} = $_[1]; + }); + $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 128, 1], connect_changed => sub { + $CFG->{bgm_volume} = $_[1]; + $SDL_MIXER->music_volume ($_[1]); + }); + + $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { + audio_shutdown (); + audio_init (); }); $dialog @@ -232,7 +271,7 @@ (new CFClient::UI::Empty expand => 1), ]); - $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) + $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8) for 0 .. $#$m; } } @@ -243,44 +282,44 @@ my $dialog = new CFClient::UI::FancyFrame child => (my $vbox = new CFClient::UI::VBox); - $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); + $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Server Setup"); $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); - $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); + $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); { $table->add (1, 2, my $vbox = new CFClient::UI::VBox); - $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { + $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub { my ($self, $value) = @_; $CFG->{host} = $value; }); $METASERVER = metaserver_dialog; - $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { + $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub { update_metaserver $HOST; }); } - $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); + $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username"); $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { my ($self, $value) = @_; $CFG->{user} = $value; }); - $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); + $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password"); $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { my ($self, $value) = @_; $CFG->{password} = $value; }); - $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); + $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd"); $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { my ($self, $value) = @_; $CFG->{say_command} = $value; }); - $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); + $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); $table->add (1, 7, new CFClient::UI::Slider req_w => 100, range => [$CFG->{mapsize}, 10, 100 + 1, 1], @@ -351,12 +390,12 @@ } sub sdl_init { - SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE - #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO + #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE + SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO and die "SDL::Init failed!\n"; } -sub init_screen { +sub video_init { sdl_init; ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; @@ -393,26 +432,26 @@ CFClient::gl_init; - $FONTSIZE = int $HEIGHT / 40; + $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; ############################################################################# $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; - $CFClient::UI::ROOT->add ($DEBUG_STATUS); + $DEBUG_STATUS->show; $STATUS_LINE = new CFClient::UI::Label padding => 0, - y => $HEIGHT * 44 / 45 - $FONTSIZE; - $CFClient::UI::ROOT->add ($STATUS_LINE); + y => $HEIGHT - $FONTSIZE * 1.8; + $STATUS_LINE->show; $ALT_ENTER_MESSAGE = new CFClient::UI::Label padding => 0, - y => $HEIGHT * 44 / 45, - fontsize => $HEIGHT / 45, + fontsize => 0.8, markup => "Use Alt-Enter to toggle fullscreen mode"; - $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); + $ALT_ENTER_MESSAGE->show; + $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); - $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); + $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); $MAPWIDGET->focus_in; $MAPWIDGET->connect (activate_console => sub { my ($mapwidget, $preset) = @_; @@ -452,11 +491,56 @@ $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->{audio_enable}) { + if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { + + $SDL_MIXER = new SDL::Mixer + -rate => 22050, + -channels => 1, # mono + -size => 512; + + $SDL_MIXER->allocate_channels (8); + + # TODO: hack, do play loop and mood music + if ($CFG->{bgm_enable}) { + $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; + $SDL_MIXER->play_music ($bgmusic, -1); + $SDL_MIXER->music_volume ($CFG->{bgm_volume}); + } + + 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; @@ -637,8 +721,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; @@ -711,6 +793,19 @@ }; } +sub conn::sound_play { + my ($self, $x, $y, $soundnum, $type) = @_; + + $SDL_MIXER + or return; + + my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} + or return; + + $SDL_MIXER->play_channel (-1, $chunk, 0, -1); + warn "sound $x,$y,$soundnum,$type\n";#d# +} + sub conn::query { my ($self, $flags, $prompt) = @_; @@ -752,9 +847,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); } @@ -778,6 +873,8 @@ ############################################################################# +$SIG{INT} = $SIG{TERM} = sub { exit }; + $TILECACHE = CFClient::db_table "tilecache"; $FACEMAP = CFClient::db_table "facemap"; @@ -792,10 +889,14 @@ fow_enable => 1, fow_intensity => 0.45, fow_smooth => 0, + gui_fontsize => 1, log_fontsize => 14, mapsize => 100, host => "crossfire.schmorp.de", say_command => 'say', + audio_enable => 1, + bgm_enable => 1, + bgm_volume => 64, ); while (my ($k, $v) = each %DEF_CFG) { @@ -820,8 +921,11 @@ CFClient::set_font $fonts[0]; } -init_screen; +video_init; +audio_init; Event::loop; +END { SDL::Quit } +