From 98f34c0a09ea801193dc0460232153a4ce3ee813 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 8 Aug 2025 19:14:34 +0200 Subject: [PATCH] arreglos en globalInputs i Lang --- source/global_inputs.cpp | 49 +++++++++------------------------------- source/lang.cpp | 36 ++++++++++++++++++++++++++--- source/lang.h | 42 ++++++++++++---------------------- 3 files changed, 58 insertions(+), 69 deletions(-) diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index fc9a682..6359c9f 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -66,48 +66,21 @@ void toggleShaders() { Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 13") + " " + boolToOnOff(Options::video.shaders)}); } -// Obtiene una fichero a partir de un lang::Code -auto getLangFile(Lang::Code code) -> std::string { - switch (code) { - case Lang::Code::VALENCIAN: - return Asset::get()->get("ba_BA.json"); - break; - case Lang::Code::SPANISH: - return Asset::get()->get("es_ES.json"); - break; - default: - return Asset::get()->get("en_UK.json"); - break; - } -} - -// Obtiene una cadena a partir de un lang::Code -auto getLangName(Lang::Code code) -> std::string { - switch (code) { - case Lang::Code::VALENCIAN: - return " \"ba_BA\""; - break; - case Lang::Code::SPANISH: - return " \"es_ES\""; - break; - default: - return " \"en_UK\""; - break; - } -} - -// Cambia el idioma -void changeLang() { +// Cambia al siguiente idioma +void setNextLang() { const std::string CODE = "LANG"; + const auto NEXT_LANG_CODE = Lang::getNextLangCode(Options::settings.language); + const auto NEXT_LANG_NAME = Lang::getLangName(NEXT_LANG_CODE); if (Notifier::get()->checkCode(CODE)) { - Options::settings.language = Lang::getNextLangCode(Options::settings.language); - Lang::loadFromFile(getLangFile(Options::settings.language)); + // Si la notificación de cambiar idioma está activa, cambia de de idioma + Options::settings.language = NEXT_LANG_CODE; + Lang::loadFromFile(Lang::getLangFile(NEXT_LANG_CODE)); Section::name = Section::Name::RESET; Section::options = Section::Options::RELOAD; - Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 05") + getLangName(Options::settings.language)}); + Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 05") + NEXT_LANG_NAME}); } else { - const auto NEXT = Lang::getNextLangCode(Options::settings.language); - Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 04") + getLangName(NEXT), std::string()}, -1, CODE); + // Si la notificación de cambiar idioma no está activa, muestra la notificación + Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 04") + NEXT_LANG_NAME, std::string()}, -1, CODE); } } @@ -193,7 +166,7 @@ auto checkSystemInputs() -> bool { {Action::RESET, reset}, {Action::TOGGLE_AUDIO, toggleAudio}, {Action::TOGGLE_AUTO_FIRE, toggleFireMode}, - {Action::CHANGE_LANG, changeLang}, + {Action::CHANGE_LANG, setNextLang}, {Action::TOGGLE_VIDEO_SHADERS, toggleShaders}, {Action::TOGGLE_VIDEO_INTEGER_SCALE, toggleIntegerScale}, {Action::TOGGLE_VIDEO_VSYNC, toggleVSync}, diff --git a/source/lang.cpp b/source/lang.cpp index fc2b35c..92e26ac 100644 --- a/source/lang.cpp +++ b/source/lang.cpp @@ -154,10 +154,40 @@ auto getLanguageFileName(Lang::Code code) -> std::string { } // Establece el idioma -void setLanguage(Code lang) { - Options::settings.language = lang; - loadFromFile(Asset::get()->get(getLanguage(lang).file_name)); +void setLanguage(Code code) { + Options::settings.language = code; + loadFromFile(Asset::get()->get(getLanguage(code).file_name)); updateLanguageNames(); updateDifficultyNames(); } + +// Obtiene una fichero a partir de un Code +auto getLangFile(Code code) -> std::string { + switch (code) { + case Code::VALENCIAN: + return Asset::get()->get("ba_BA.json"); + break; + case Code::SPANISH: + return Asset::get()->get("es_ES.json"); + break; + default: + return Asset::get()->get("en_UK.json"); + break; + } +} + +// Obtiene una cadena a partir de un Code +auto getLangName(Code code) -> std::string { + switch (code) { + case Code::VALENCIAN: + return " \"ba_BA\""; + break; + case Code::SPANISH: + return " \"es_ES\""; + break; + default: + return " \"en_UK\""; + break; + } +} } // namespace Lang diff --git a/source/lang.h b/source/lang.h index 34323cd..338a6ed 100644 --- a/source/lang.h +++ b/source/lang.h @@ -11,7 +11,7 @@ enum class Code : int { ENGLISH = 2 }; -// Estructura que representa un idioma +// --- Estructura que representa un idioma --- struct Language { Code code; // Código que identifica al idioma std::string name; // Nombre que identifica el idioma @@ -21,30 +21,16 @@ struct Language { : code(c), name(std::move(n)), file_name(std::move(fn)) {} }; -// Carga los textos desde el fichero JSON especificado -auto loadFromFile(const std::string &file_path) -> bool; - -// Obtiene el texto por clave -auto getText(const std::string &key) -> std::string; - -// Obtiene el código del siguiente idioma (circular) -auto getNextLangCode(Code current_lang) -> Code; - -// Obtiene el idioma correspondiente al código proporcionado -auto getLanguage(Code code) -> Language; - -// Devuelve el código de un idioma a partir de un nombre -auto getCodeFromName(const std::string &name) -> Code; - -// Devuelve el nombre de un idioma a partir de un código -auto getNameFromCode(Code code) -> std::string; - -// Actualiza los nombres de los idiomas -void updateLanguageNames(); - -// Obtiene el nombre del fichero de textos asociado a un código de idioma -auto getLanguageFileName(Code code) -> std::string; - -// Establece el idioma actual -void setLanguage(Code lang); -} // namespace Lang +// --- Métodos --- +auto loadFromFile(const std::string &file_path) -> bool; // Carga los textos desde el fichero JSON especificado +auto getText(const std::string &key) -> std::string; // Obtiene el texto por clave +auto getNextLangCode(Code current_lang) -> Code; // Obtiene el código del siguiente idioma (circular) +auto getLanguage(Code code) -> Language; // Obtiene el idioma correspondiente al código proporcionado +auto getCodeFromName(const std::string &name) -> Code; // Devuelve el código de un idioma a partir de un nombre +auto getNameFromCode(Code code) -> std::string; // Devuelve el nombre de un idioma a partir de un código +void updateLanguageNames(); // Actualiza los nombres de los idiomas +auto getLanguageFileName(Code code) -> std::string; // Obtiene el nombre del fichero de textos asociado a un código de idioma +void setLanguage(Code code); // Establece el idioma actual +auto getLangFile(Code code) -> std::string; // Obtiene una fichero a partir de un Code +auto getLangName(Code code) -> std::string; // Obtiene una cadena a partir de un Code +} // namespace Lang \ No newline at end of file