diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index c6c1688..f128d29 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -152,6 +152,12 @@ void DefineButtons::doControllerAxisMotion(const SDL_GamepadAxisEvent &event) { updateWindowMessage(); } } + + // Detectar liberación del trigger para llamar checkEnd() + if (!l2_is_pressed_now && l2_was_pressed_) { + checkEnd(); + } + l2_was_pressed_ = l2_is_pressed_now; } else if (event.axis == SDL_GAMEPAD_AXIS_RIGHT_TRIGGER) { @@ -166,6 +172,12 @@ void DefineButtons::doControllerAxisMotion(const SDL_GamepadAxisEvent &event) { updateWindowMessage(); } } + + // Detectar liberación del trigger para llamar checkEnd() + if (!r2_is_pressed_now && r2_was_pressed_) { + checkEnd(); + } + r2_was_pressed_ = r2_is_pressed_now; } } diff --git a/source/input_types.cpp b/source/input_types.cpp index 48437ac..745e40c 100644 --- a/source/input_types.cpp +++ b/source/input_types.cpp @@ -73,7 +73,9 @@ const std::unordered_map BUTTON_TO_STRING = { {SDL_GAMEPAD_BUTTON_DPAD_UP, "DPAD_UP"}, {SDL_GAMEPAD_BUTTON_DPAD_DOWN, "DPAD_DOWN"}, {SDL_GAMEPAD_BUTTON_DPAD_LEFT, "DPAD_LEFT"}, - {SDL_GAMEPAD_BUTTON_DPAD_RIGHT, "DPAD_RIGHT"}}; + {SDL_GAMEPAD_BUTTON_DPAD_RIGHT, "DPAD_RIGHT"}, + {static_cast(100), "L2_AS_BUTTON"}, + {static_cast(101), "R2_AS_BUTTON"}}; const std::unordered_map STRING_TO_BUTTON = { {"WEST", SDL_GAMEPAD_BUTTON_WEST}, @@ -87,7 +89,9 @@ const std::unordered_map STRING_TO_BUTTON = { {"DPAD_UP", SDL_GAMEPAD_BUTTON_DPAD_UP}, {"DPAD_DOWN", SDL_GAMEPAD_BUTTON_DPAD_DOWN}, {"DPAD_LEFT", SDL_GAMEPAD_BUTTON_DPAD_LEFT}, - {"DPAD_RIGHT", SDL_GAMEPAD_BUTTON_DPAD_RIGHT}}; + {"DPAD_RIGHT", SDL_GAMEPAD_BUTTON_DPAD_RIGHT}, + {"L2_AS_BUTTON", static_cast(100)}, + {"R2_AS_BUTTON", static_cast(101)}}; const std::unordered_map ACTION_TO_ACTION = { {InputAction::SM_SELECT, InputAction::FIRE_LEFT}, diff --git a/test_triggers.cpp b/test_triggers.cpp deleted file mode 100644 index 9d7e7e4..0000000 --- a/test_triggers.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include - -int main() { - // Inicializar SDL - if (!SDL_Init(SDL_INIT_GAMEPAD)) { - std::cerr << "Error inicializando SDL: " << SDL_GetError() << std::endl; - return 1; - } - - std::cout << "Prueba de triggers L2/R2 como botones digitales" << std::endl; - std::cout << "Conecta un mando arcade y presiona L2 o R2" << std::endl; - std::cout << "Presiona ESC para salir" << std::endl; - - // Abrir primer gamepad disponible - SDL_Gamepad* gamepad = nullptr; - SDL_JoystickID* joysticks = SDL_GetJoysticks(nullptr); - - if (joysticks) { - for (int i = 0; joysticks[i]; i++) { - if (SDL_IsGamepad(joysticks[i])) { - gamepad = SDL_OpenGamepad(joysticks[i]); - if (gamepad) { - std::cout << "Gamepad conectado: " << SDL_GetGamepadName(gamepad) << std::endl; - break; - } - } - } - SDL_free(joysticks); - } - - if (!gamepad) { - std::cout << "No se encontró ningún gamepad compatible" << std::endl; - SDL_Quit(); - return 1; - } - - bool running = true; - SDL_Event event; - - while (running) { - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_EVENT_QUIT: - running = false; - break; - case SDL_EVENT_GAMEPAD_AXIS_MOTION: - if (event.gaxis.axis == SDL_GAMEPAD_AXIS_LEFT_TRIGGER) { - if (event.gaxis.value > 16384) { - std::cout << "L2 PRESIONADO como botón digital (valor: " << event.gaxis.value << ")" << std::endl; - } - } else if (event.gaxis.axis == SDL_GAMEPAD_AXIS_RIGHT_TRIGGER) { - if (event.gaxis.value > 16384) { - std::cout << "R2 PRESIONADO como botón digital (valor: " << event.gaxis.value << ")" << std::endl; - } - } - break; - case SDL_EVENT_GAMEPAD_BUTTON_DOWN: - std::cout << "Botón presionado: " << event.gbutton.button << std::endl; - break; - } - } - - // Verificar ESC para salir - const bool* keyboard_state = SDL_GetKeyboardState(nullptr); - if (keyboard_state[SDL_SCANCODE_ESCAPE]) { - running = false; - } - - SDL_Delay(16); // ~60 FPS - } - - if (gamepad) { - SDL_CloseGamepad(gamepad); - } - SDL_Quit(); - return 0; -} \ No newline at end of file