feat(menu): acceptar amb ATTACK i cancel·lar amb JUMP del mando

This commit is contained in:
JailDesigner committed 2026-05-01 09:07:22 +02:00
1 parent fddea0c449
commit d26ecec04f
1 file changed
+26 -17
+26 -17
View File
@@ -445,14 +445,14 @@ void ServiceMenu::activateCurrent(int direction) {
namespace { namespace {
// Resol el botó SERVICE configurat per al mando que ha emès aquest // Resol el botó configurat per a una acció concreta (SERVICE / ATTACK
// event. -1 si no troba cap match (mando desconegut o desconnectat // / JUMP) al mando que ha emès aquest event. -1 si no troba cap match
// mentrestant). // (mando desconegut o desconnectat mentrestant).
auto serviceButtonForEvent(SDL_JoystickID jid) -> int { auto actionButtonForEvent(SDL_JoystickID jid, GamepadBindings::Action action) -> int {
for (const auto& info : GamepadManager::get().getAll()) { for (const auto& info : GamepadManager::get().getAll()) {
if (info.pad == nullptr) { continue; } if (info.pad == nullptr) { continue; }
if (SDL_GetJoystickID(SDL_GetGamepadJoystick(info.pad)) != jid) { 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; return -1;
} }
@@ -525,15 +525,31 @@ void ServiceMenu::handleGamepadAxisMotion(const SDL_GamepadAxisEvent& ev) {
} }
void ServiceMenu::handleGamepadButtonDown(const SDL_GamepadButtonEvent& ev) { void ServiceMenu::handleGamepadButtonDown(const SDL_GamepadButtonEvent& ev) {
// El botó SERVICE (per defecte BACK; remapejable per dispositiu via // Tots tres botons rellevants (SERVICE/ATTACK/JUMP) són remapejables per
// `GamepadBindings`) tanca el menú sencer. Cada mando pot tenir el // dispositiu via `GamepadBindings`. Resolem-los una sola vegada a partir
// seu propi mapeig — resolem-lo a partir del joystick instance ID. // del joystick instance ID i comparem; els defaults (WEST=ATTACK,
const int SERVICE_BTN = serviceButtonForEvent(ev.which); // SOUTH=JUMP, BACK=SERVICE) preserven el comportament històric.
if (SERVICE_BTN >= 0 && static_cast<int>(ev.button) == SERVICE_BTN) { 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<int>(ev.button);
if (SERVICE_BTN >= 0 && BTN == SERVICE_BTN) {
close(); close();
playSelectSound(); playSelectSound();
return; 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) { switch (ev.button) {
case SDL_GAMEPAD_BUTTON_DPAD_UP: case SDL_GAMEPAD_BUTTON_DPAD_UP:
moveCursor(-1); moveCursor(-1);
@@ -548,16 +564,9 @@ void ServiceMenu::handleGamepadButtonDown(const SDL_GamepadButtonEvent& ev) {
playAcceptSound(); playAcceptSound();
break; break;
case SDL_GAMEPAD_BUTTON_DPAD_RIGHT: case SDL_GAMEPAD_BUTTON_DPAD_RIGHT:
case SDL_GAMEPAD_BUTTON_EAST:
case SDL_GAMEPAD_BUTTON_NORTH:
activateCurrent(+1); activateCurrent(+1);
playAcceptSound(); playAcceptSound();
break; break;
case SDL_GAMEPAD_BUTTON_WEST:
case SDL_GAMEPAD_BUTTON_SOUTH:
popPage();
playSelectSound();
break;
default: default:
break; break;
} }