From 9c9cfdabc29d187f54aa2e022a8af86e28286f4f Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 27 Nov 2024 09:48:14 +0100 Subject: [PATCH] Canvi de idioma (i reinicia) amb una tecla --- README.md | 4 ++++ data/lang/es_ES.txt | 2 +- source/director.cpp | 3 ++- source/global_inputs.cpp | 42 ++++++++++++++++++++++++++++++++++++++-- source/input.h | 1 + source/lang.cpp | 8 ++++++++ source/lang.h | 3 +++ 7 files changed, 59 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a22986e..bdb7e58 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ Les tecles son les següents: - **Tecla F4**: Activa o desactiva els shaders +- **Tecla F5**: Activa o desactiva l'audio + +- **Tecla F6**: Canvia el idioma del joc i reinicia + - **Tecla F10**: Reset

diff --git a/data/lang/es_ES.txt b/data/lang/es_ES.txt index a5b82dc..5a91f79 100644 --- a/data/lang/es_ES.txt +++ b/data/lang/es_ES.txt @@ -362,7 +362,7 @@ Tiempo! Puntuacion ## 121 - CREDITS -PROGRAMADO Y DISEÑADO POR +PROGRAMADO Y DISE{ADO POR ## 122 - CREDITS GRAFICOS DIBUJADOS POR diff --git a/source/director.cpp b/source/director.cpp index c577f41..127ccc4 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -166,7 +166,8 @@ void Director::bindInputs() Input::get()->bindKey(InputType::WINDOW_FULLSCREEN, SDL_SCANCODE_F3); Input::get()->bindKey(InputType::VIDEO_SHADERS, SDL_SCANCODE_F4); Input::get()->bindKey(InputType::MUTE, SDL_SCANCODE_F5); - Input::get()->bindKey(InputType::SHOWINFO, SDL_SCANCODE_F6); + Input::get()->bindKey(InputType::CHANGE_LANG, SDL_SCANCODE_F6); + Input::get()->bindKey(InputType::SHOWINFO, SDL_SCANCODE_F7); Input::get()->bindKey(InputType::RESET, SDL_SCANCODE_F10); // Asigna botones a inputs diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index bbe035a..3736de0 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -1,6 +1,7 @@ #include "global_inputs.h" -#include // Para operator+, string -#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_REPEAT +#include // Para operator+, string +#include "input.h" // Para Input, InputType, INPUT_DO_NOT_ALLOW_REPEAT +#include "asset.h" #include "jail_audio.h" // Para JA_EnableMusic, JA_EnableSound #include "lang.h" // Para getText #include "notifier.h" // Para Notifier @@ -71,6 +72,36 @@ namespace globalInputs Notifier::get()->showText({"Audio " + boolToOnOff(options.audio.enabled)}); } + // Obtiene una fichero a partir de un lang::Code + std::string getLangFile(lang::Code code) + { + switch (code) + { + case lang::Code::ba_BA: + return Asset::get()->get("ba_BA.txt"); + break; + case lang::Code::es_ES: + return Asset::get()->get("es_ES.txt"); + break; + case lang::Code::en_UK: + return Asset::get()->get("en_UK.txt"); + break; + default: + break; + } + + return Asset::get()->get("en_UK.txt"); + } + + // Cambia el idioma + void changeLang() + { + options.game.language = lang::change(options.game.language); + lang::loadFromFile(getLangFile(static_cast(options.game.language))); + section::name = section::Name::INIT; + Notifier::get()->showText({"Reset"}); + } + // Comprueba los inputs que se pueden introducir en cualquier sección del juego void check() { @@ -125,6 +156,13 @@ namespace globalInputs return; } + // Idioma + if (Input::get()->checkInput(InputType::CHANGE_LANG, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + { + changeLang(); + return; + } + // Shaders if (Input::get()->checkInput(InputType::VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { diff --git a/source/input.h b/source/input.h index 6a9c332..107335e 100644 --- a/source/input.h +++ b/source/input.h @@ -40,6 +40,7 @@ enum class InputType : int VIDEO_SHADERS, RESET, MUTE, + CHANGE_LANG, SHOWINFO, CONFIG, SWAP_CONTROLLERS, diff --git a/source/lang.cpp b/source/lang.cpp index 7348488..b0b107b 100644 --- a/source/lang.cpp +++ b/source/lang.cpp @@ -40,4 +40,12 @@ namespace lang { return texts.at(index); } + + // Cambia el idioma seleccionado al siguiente idioma disponible + Code change(Code current_lang) + { + auto index = static_cast(current_lang); + index = (index + 1) % 3; + return static_cast(index); + } } \ No newline at end of file diff --git a/source/lang.h b/source/lang.h index 9cc414e..851d683 100644 --- a/source/lang.h +++ b/source/lang.h @@ -16,4 +16,7 @@ namespace lang // Obtiene la cadena de texto del indice std::string getText(int index); + + // Cambia el idioma seleccionado al siguiente idioma disponible + Code change(Code current_lang); } \ No newline at end of file