From d26ecec04f0c9f68655dc6f742ea806301a27069 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 1 May 2026 09:07:22 +0200 Subject: [PATCH] =?UTF-8?q?feat(menu):=20acceptar=20amb=20ATTACK=20i=20can?= =?UTF-8?q?cel=C2=B7lar=20amb=20JUMP=20del=20mando?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/game/ui/service_menu.cpp | 43 ++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/source/game/ui/service_menu.cpp b/source/game/ui/service_menu.cpp index 0327906..36b08f0 100644 --- a/source/game/ui/service_menu.cpp +++ b/source/game/ui/service_menu.cpp @@ -445,14 +445,14 @@ void ServiceMenu::activateCurrent(int direction) { namespace { - // Resol el botó SERVICE configurat per al mando que ha emès aquest - // event. -1 si no troba cap match (mando desconegut o desconnectat - // mentrestant). - auto serviceButtonForEvent(SDL_JoystickID jid) -> int { + // Resol el botó configurat per a una acció concreta (SERVICE / ATTACK + // / JUMP) al mando que ha emès aquest event. -1 si no troba cap match + // (mando desconegut o desconnectat mentrestant). + auto actionButtonForEvent(SDL_JoystickID jid, GamepadBindings::Action action) -> int { for (const auto& info : GamepadManager::get().getAll()) { if (info.pad == nullptr) { continue; } if (SDL_GetJoystickID(SDL_GetGamepadJoystick(info.pad)) != jid) { continue; } - return GamepadBindings::get().getButton(info.name, info.path, GamepadBindings::Action::SERVICE); + return GamepadBindings::get().getButton(info.name, info.path, action); } return -1; } @@ -525,15 +525,31 @@ void ServiceMenu::handleGamepadAxisMotion(const SDL_GamepadAxisEvent& ev) { } void ServiceMenu::handleGamepadButtonDown(const SDL_GamepadButtonEvent& ev) { - // El botó SERVICE (per defecte BACK; remapejable per dispositiu via - // `GamepadBindings`) tanca el menú sencer. Cada mando pot tenir el - // seu propi mapeig — resolem-lo a partir del joystick instance ID. - const int SERVICE_BTN = serviceButtonForEvent(ev.which); - if (SERVICE_BTN >= 0 && static_cast(ev.button) == SERVICE_BTN) { + // Tots tres botons rellevants (SERVICE/ATTACK/JUMP) són remapejables per + // dispositiu via `GamepadBindings`. Resolem-los una sola vegada a partir + // del joystick instance ID i comparem; els defaults (WEST=ATTACK, + // SOUTH=JUMP, BACK=SERVICE) preserven el comportament històric. + const int SERVICE_BTN = actionButtonForEvent(ev.which, GamepadBindings::Action::SERVICE); + const int ACCEPT_BTN = actionButtonForEvent(ev.which, GamepadBindings::Action::ATTACK); + const int CANCEL_BTN = actionButtonForEvent(ev.which, GamepadBindings::Action::JUMP); + const int BTN = static_cast(ev.button); + + if (SERVICE_BTN >= 0 && BTN == SERVICE_BTN) { close(); playSelectSound(); return; } + if (ACCEPT_BTN >= 0 && BTN == ACCEPT_BTN) { + activateCurrent(+1); + playAcceptSound(); + return; + } + if (CANCEL_BTN >= 0 && BTN == CANCEL_BTN) { + popPage(); + playSelectSound(); + return; + } + switch (ev.button) { case SDL_GAMEPAD_BUTTON_DPAD_UP: moveCursor(-1); @@ -548,16 +564,9 @@ void ServiceMenu::handleGamepadButtonDown(const SDL_GamepadButtonEvent& ev) { playAcceptSound(); break; case SDL_GAMEPAD_BUTTON_DPAD_RIGHT: - case SDL_GAMEPAD_BUTTON_EAST: - case SDL_GAMEPAD_BUTTON_NORTH: activateCurrent(+1); playAcceptSound(); break; - case SDL_GAMEPAD_BUTTON_WEST: - case SDL_GAMEPAD_BUTTON_SOUTH: - popPage(); - playSelectSound(); - break; default: break; }