feat(menu): acceptar amb ATTACK i cancel·lar amb JUMP del mando
This commit is contained in:
1 parent
fddea0c449
commit
d26ecec04f
1 file changed
+26
-17
@@ -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<int>(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<int>(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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user