ja guarda la configuració del mando amb els boto-triggers
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,9 @@ const std::unordered_map<SDL_GamepadButton, std::string> 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<SDL_GamepadButton>(100), "L2_AS_BUTTON"},
|
||||
{static_cast<SDL_GamepadButton>(101), "R2_AS_BUTTON"}};
|
||||
|
||||
const std::unordered_map<std::string, SDL_GamepadButton> STRING_TO_BUTTON = {
|
||||
{"WEST", SDL_GAMEPAD_BUTTON_WEST},
|
||||
@@ -87,7 +89,9 @@ const std::unordered_map<std::string, SDL_GamepadButton> 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<SDL_GamepadButton>(100)},
|
||||
{"R2_AS_BUTTON", static_cast<SDL_GamepadButton>(101)}};
|
||||
|
||||
const std::unordered_map<InputAction, InputAction> ACTION_TO_ACTION = {
|
||||
{InputAction::SM_SELECT, InputAction::FIRE_LEFT},
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user