From da27fde3660ec75fc8d40c07a4ff814fa0a01c53 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 1 Nov 2024 07:55:37 +0100 Subject: [PATCH] =?UTF-8?q?Millores=20en=20la=20gesti=C3=B3=20del=20"mute"?= =?UTF-8?q?=20en=20el=20joc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/director.cpp | 14 ++++++++++---- source/global_inputs.cpp | 16 ++++++++++++---- source/options.cpp | 26 +++++++++++++++++++++++--- source/options.h | 7 ++++++- 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index d321be3..a07ab95 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -241,10 +241,16 @@ void Director::bindInputs() void Director::initJailAudio() { JA_Init(48000, AUDIO_S16, 2); - JA_EnableMusic(options.audio.music.enabled); - JA_EnableSound(options.audio.sound.enabled); - JA_SetMusicVolume(options.audio.music.volume); - JA_SetSoundVolume(options.audio.sound.volume); + if (options.audio.enabled) + { + JA_SetMusicVolume(to_JA_volume(options.audio.music.volume)); + JA_SetSoundVolume(to_JA_volume(options.audio.sound.volume)); + } + else + { + JA_SetMusicVolume(0); + JA_SetSoundVolume(0); + } } // Arranca SDL y crea la ventana diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index 0d4356c..07e7c4f 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -56,10 +56,18 @@ namespace globalInputs // Activa o desactiva el audio void switchAudio() { - options.audio.sound.enabled = options.audio.music.enabled = !options.audio.music.enabled; - JA_EnableMusic(options.audio.music.enabled); - JA_EnableSound(options.audio.sound.enabled); - Notifier::get()->showText("Audio " + boolToOnOff(options.audio.music.enabled)); + options.audio.enabled = !options.audio.enabled; + if (options.audio.enabled) + { + JA_SetMusicVolume(to_JA_volume(options.audio.music.volume)); + JA_SetSoundVolume(to_JA_volume(options.audio.sound.volume)); + } + else + { + JA_SetMusicVolume(0); + JA_SetSoundVolume(0); + } + Notifier::get()->showText("Audio " + boolToOnOff(options.audio.enabled)); } // Comprueba los inputs que se pueden introducir en cualquier sección del juego diff --git a/source/options.cpp b/source/options.cpp index 2b5b76d..ec7158b 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -32,10 +32,12 @@ void initOptions() options.video.shaders = true; // Opciones de audio + options.audio.enabled = true; + options.audio.volume = 100; options.audio.music.enabled = true; - options.audio.music.volume = 128; + options.audio.music.volume = 100; options.audio.sound.enabled = true; - options.audio.sound.volume = 64; + options.audio.sound.volume = 50; // Opciones de juego options.game.difficulty = GameDifficulty::NORMAL; @@ -178,9 +180,11 @@ bool saveOptionsFile(std::string file_path) // Opciones de audio file << "\n\n## AUDIO\n"; - file << "## volume [0 .. 128]\n"; + file << "## volume [0 .. 100]\n"; file << "\n"; + file << "audio.enabled=" + boolToString(options.audio.enabled) + "\n"; + file << "audio.volume=" + std::to_string(options.audio.volume) + "\n"; file << "audio.music.enabled=" + boolToString(options.audio.music.enabled) + "\n"; file << "audio.music.volume=" + std::to_string(options.audio.music.volume) + "\n"; file << "audio.sound.enabled=" + boolToString(options.audio.sound.enabled) + "\n"; @@ -269,6 +273,15 @@ bool setOptions(const std::string &var, const std::string &value) } // Opciones de audio + else if (var == "audio.enabled") + { + options.audio.enabled = stringToBool(value); + } + + else if (var == "audio.volume") + { + options.audio.volume = std::stoi(value); + } else if (var == "audio.music.enabled") { options.audio.music.enabled = stringToBool(value); @@ -387,4 +400,11 @@ bool setOptions(const std::string &var, const std::string &value) } return success; +} + +// Convierte valores de 0 a 100 en valores de 0 a 128 +int to_JA_volume(int vol) +{ + vol = vol * 1.28f; + return std::clamp(vol, 0, 128); } \ No newline at end of file diff --git a/source/options.h b/source/options.h index e668b79..3190bed 100644 --- a/source/options.h +++ b/source/options.h @@ -57,6 +57,8 @@ struct OptionsAudio { OptionsMusic music; // Opciones para la música OptionsSound sound; // Opciones para los efectos de sonido + bool enabled; // Indica si el audio está activo o no + int volume; // Volumen al que suenan el audio }; // Estructura para las opciones del juego @@ -96,4 +98,7 @@ extern Options options; bool loadOptionsFile(std::string file_path); // Guarda el fichero de configuración -bool saveOptionsFile(std::string file_path); \ No newline at end of file +bool saveOptionsFile(std::string file_path); + +// Convierte valores de 0 a 100 en valores de 0 a 128 +int to_JA_volume(int vol); \ No newline at end of file