From 0fc83cf9c14467c99d992352c388cfb82da17342 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 8 Aug 2025 21:06:28 +0200 Subject: [PATCH] merdes varies --- data/lang/ba_BA.json | 2 +- data/lang/en_UK.json | 2 +- data/lang/es_ES.json | 2 +- source/define_buttons.cpp | 2 +- source/define_buttons.h | 2 +- source/global_events.cpp | 11 +++++++---- source/input.cpp | 7 ++++--- source/input.h | 2 +- source/options.cpp | 2 +- source/options.h | 2 ++ source/ui/service_menu.cpp | 26 ++++++++++++++------------ 11 files changed, 34 insertions(+), 26 deletions(-) diff --git a/data/lang/ba_BA.json b/data/lang/ba_BA.json index 0779d74..76ba1a9 100644 --- a/data/lang/ba_BA.json +++ b/data/lang/ba_BA.json @@ -105,7 +105,7 @@ "[SERVICE_MENU] CONTROLLER2": "Mando 2", "[SERVICE_MENU] CONFIGURE1": "Configurar Mando 1", "[SERVICE_MENU] CONFIGURE2": "Configurar Mando 2", - "[SERVICE_MENU] NO_CONTROLLER": "Cap", + "[SERVICE_MENU] NO_CONTROLLER": "[ Desconectat ]", "[SERVICE_MENU] SWAP_CONTROLLERS": "Intercanvia mandos", "[SCOREBOARD] 1": "Jugador 1", diff --git a/data/lang/en_UK.json b/data/lang/en_UK.json index 540f56d..48ab655 100644 --- a/data/lang/en_UK.json +++ b/data/lang/en_UK.json @@ -104,7 +104,7 @@ "[SERVICE_MENU] CONTROLLER2": "Controller 2", "[SERVICE_MENU] CONFIGURE1": "Configure Controller 1", "[SERVICE_MENU] CONFIGURE2": "Configure Controller 2", - "[SERVICE_MENU] NO_CONTROLLER": "None", + "[SERVICE_MENU] NO_CONTROLLER": "[No controller]", "[SERVICE_MENU] SWAP_CONTROLLERS": "Swap Controllers", "[SCOREBOARD] 1" : "Player 1", diff --git a/data/lang/es_ES.json b/data/lang/es_ES.json index a468c66..1e3dbd7 100644 --- a/data/lang/es_ES.json +++ b/data/lang/es_ES.json @@ -104,7 +104,7 @@ "[SERVICE_MENU] CONTROLLER2": "Mando 2", "[SERVICE_MENU] CONFIGURE1": "Configurar Mando 1", "[SERVICE_MENU] CONFIGURE2": "Configurar Mando 2", - "[SERVICE_MENU] NO_CONTROLLER": "Ninguno", + "[SERVICE_MENU] NO_CONTROLLER": "[Desconectat]", "[SERVICE_MENU] SWAP_CONTROLLERS": "Intercambia mandos", "[SCOREBOARD] 1": "Jugador 1", diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index 79f9f2b..4b39226 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -75,7 +75,7 @@ void DefineButtons::update() { } } -void DefineButtons::checkEvents(const SDL_Event &event) { +void DefineButtons::handleEvents(const SDL_Event &event) { if (enabled_) { switch (event.type) { case SDL_EVENT_GAMEPAD_BUTTON_DOWN: diff --git a/source/define_buttons.h b/source/define_buttons.h index 75fb0a7..ce5adcf 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -31,7 +31,7 @@ class DefineButtons { void render(); void update(); - void checkEvents(const SDL_Event &event); + void handleEvents(const SDL_Event &event); auto enable(Options::Gamepad *options_gamepad) -> bool; void disable(); bool isReadyToClose() const; diff --git a/source/global_events.cpp b/source/global_events.cpp index 3bc9af9..5d01d5a 100644 --- a/source/global_events.cpp +++ b/source/global_events.cpp @@ -2,9 +2,10 @@ #include // Para SDL_LogInfo, SDL_LogCategory -#include "input.h" -#include "mouse.h" // Para handleEvent -#include "screen.h" +#include "input.h" // Para Input +#include "mouse.h" // Para handleEvent +#include "options.h" // Para Options +#include "screen.h" // Para Screen #include "section.hpp" // Para Name, Options, name, options #include "ui/service_menu.h" // Para ServiceMenu @@ -34,6 +35,8 @@ void check(const SDL_Event &event) { Mouse::handleEvent(event); static auto *input_ = Input::get(); - input_->handleEvent(event); + if (input_->handleEvent(event)) { + Options::gamepad_manager.assignAndLinkGamepads(); + } } } // namespace GlobalEvents \ No newline at end of file diff --git a/source/input.cpp b/source/input.cpp index a86a8d2..0710fd0 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -308,15 +308,16 @@ void Input::update() { } } -void Input::handleEvent(const SDL_Event &event) { +auto Input::handleEvent(const SDL_Event &event) -> bool { switch (event.type) { case SDL_EVENT_GAMEPAD_ADDED: addGamepad(event.gdevice.which); - break; + return true; case SDL_EVENT_GAMEPAD_REMOVED: removeGamepad(event.gdevice.which); - break; + return true; } + return false; } void Input::addGamepad(int device_index) { diff --git a/source/input.h b/source/input.h index 4c8dd2a..85e276a 100644 --- a/source/input.h +++ b/source/input.h @@ -168,7 +168,7 @@ class Input { void resetInputStates(); // --- Eventos --- - void handleEvent(const SDL_Event &event); + auto handleEvent(const SDL_Event &event) -> bool; void printConnectedGamepads() const; diff --git a/source/options.cpp b/source/options.cpp index a7ec589..438e93c 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -386,7 +386,7 @@ void GamepadManager::clearUnassignedGamepadSlots() { if (gamepad_config.instance == nullptr) { // Limpiamos sus datos de configuración para no mostrar información // de un mando que ya no está conectado. - gamepad_config.name = ""; + gamepad_config.name = Lang::getText("[SERVICE_MENU] NO_CONTROLLER"); gamepad_config.path = ""; } } diff --git a/source/options.h b/source/options.h index 522accb..1c9422f 100644 --- a/source/options.h +++ b/source/options.h @@ -10,6 +10,7 @@ #include // Para shared_ptr, swap #include // Para out_of_range, invalid_argument #include // Para char_traits, string, allocator, operator==, swap, operator<<, basic_string, stoi +#include // Para string_view #include // Para vector #include "difficulty.h" // Para Code @@ -216,6 +217,7 @@ class GamepadManager { [[nodiscard]] static auto size() -> size_t { return MAX_PLAYERS; } private: + static constexpr std::string_view UNASSIGNED_TEXT = "---"; static constexpr size_t MAX_PLAYERS = 2; std::array gamepads_; diff --git a/source/ui/service_menu.cpp b/source/ui/service_menu.cpp index 05440d8..5592f84 100644 --- a/source/ui/service_menu.cpp +++ b/source/ui/service_menu.cpp @@ -40,12 +40,14 @@ ServiceMenu::ServiceMenu() void ServiceMenu::toggle() { if (define_buttons_ && define_buttons_->isEnabled()) { - return; // No se puede mostrar u ocultar el menu de servicio si se estan definiendo los botones + return; // No se puede mostrar u ocultar el menu de servicio si se estan definiendo los botones } playBackSound(); enabled_ = !enabled_; - if (!enabled_) { + if (enabled_) { + Options::gamepad_manager.assignAndLinkGamepads(); + } else { reset(); } } @@ -546,8 +548,8 @@ void ServiceMenu::handleEvent(const SDL_Event &event) { // Si DefineButtons está activo, que maneje todos los eventos if (define_buttons_ && define_buttons_->isEnabled()) { - define_buttons_->checkEvents(event); - //return; // No procesar otros eventos mientras DefineButtons está activo + define_buttons_->handleEvents(event); + // return; // No procesar otros eventos mientras DefineButtons está activo } } @@ -565,16 +567,16 @@ bool ServiceMenu::checkInput() { using Action = Input::Action; const std::vector>> actions = { - { Action::UP, [this]() { setSelectorUp(); } }, - { Action::DOWN, [this]() { setSelectorDown(); } }, - { Action::RIGHT, [this]() { adjustOption(true); } }, - { Action::LEFT, [this]() { adjustOption(false); } }, - { Action::SM_SELECT, [this]() { selectOption(); } }, - { Action::SM_BACK, [this]() { moveBack(); } }, + {Action::UP, [this]() { setSelectorUp(); }}, + {Action::DOWN, [this]() { setSelectorDown(); }}, + {Action::RIGHT, [this]() { adjustOption(true); }}, + {Action::LEFT, [this]() { adjustOption(false); }}, + {Action::SM_SELECT, [this]() { selectOption(); }}, + {Action::SM_BACK, [this]() { moveBack(); }}, }; // Teclado - for (const auto& [action, func] : actions) { + for (const auto &[action, func] : actions) { if (input->checkAction(action, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) { func(); return true; @@ -583,7 +585,7 @@ bool ServiceMenu::checkInput() { // Mandos for (auto gamepad : input->getGamepads()) { - for (const auto& [action, func] : actions) { + for (const auto &[action, func] : actions) { if (input->checkAction(action, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) { func(); return true;