ja redefinix els botons i axis, pero el axis sempre te un comportament default. corregir

This commit is contained in:
2025-11-02 19:02:29 +01:00
parent b79f30a57b
commit 87527d01a8
2 changed files with 33 additions and 6 deletions

View File

@@ -36,7 +36,8 @@ Title::Title()
fade_accumulator_(0.0F),
exit_scene_(SceneManager::Scene::GAME),
controls_menu_state_(ControlsMenuState::MAIN),
remap_step_(0) {
remap_step_(0),
axis_cooldown_(0.0F) {
// Inicializa variables
state_ = SceneManager::options == SceneManager::Options::TITLE_WITH_LOADING_SCREEN ? State::SHOW_LOADING_SCREEN : State::MAIN_MENU;
SceneManager::current = SceneManager::Scene::TITLE;
@@ -79,6 +80,14 @@ void Title::handleEvents() {
while (SDL_PollEvent(&event)) {
GlobalEvents::handle(event);
// Manejo especial para captura de botones de gamepad
if (state_ == State::CONTROLS_MENU &&
controls_menu_state_ == ControlsMenuState::JOYSTICK_REMAP &&
(event.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN || event.type == SDL_EVENT_GAMEPAD_AXIS_MOTION)) {
handleControlsMenuJoystickRemap(event);
continue; // No procesar más este evento
}
if (event.type == SDL_EVENT_KEY_DOWN) {
switch (state_) {
case State::MAIN_MENU:
@@ -120,6 +129,7 @@ void Title::handleEvents() {
controls_menu_state_ = ControlsMenuState::JOYSTICK_REMAP;
remap_step_ = 0;
remap_error_message_.clear();
axis_cooldown_ = 0.0F; // Resetear cooldown
}
break;
@@ -129,9 +139,6 @@ void Title::handleEvents() {
} else if (controls_menu_state_ == ControlsMenuState::KEYBOARD_REMAP) {
// Captura de teclas para redefinir
handleControlsMenuKeyboardRemap(event);
} else if (controls_menu_state_ == ControlsMenuState::JOYSTICK_REMAP) {
// Captura de botones del gamepad para redefinir
handleControlsMenuJoystickRemap(event);
}
break;
@@ -333,6 +340,14 @@ void Title::updateControlsMenu(float delta_time) {
// Actualiza la marquesina (sigue visible en fondo)
updateMarquee(delta_time);
// Decrementar cooldown de ejes si estamos capturando botones
if (controls_menu_state_ == ControlsMenuState::JOYSTICK_REMAP && axis_cooldown_ > 0.0F) {
axis_cooldown_ -= delta_time;
if (axis_cooldown_ < 0.0F) {
axis_cooldown_ = 0.0F;
}
}
// Si estamos mostrando las teclas definidas, esperar antes de guardar
if (controls_menu_state_ == ControlsMenuState::KEYBOARD_REMAP_COMPLETE) {
state_time_ += delta_time;
@@ -736,21 +751,32 @@ void Title::handleControlsMenuJoystickRemap(const SDL_Event& event) {
if (event.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN) {
captured_button = static_cast<int>(event.gbutton.button);
}
// Capturar triggers como botones (usando valores especiales 100/101)
// Capturar triggers y ejes analógicos
else if (event.type == SDL_EVENT_GAMEPAD_AXIS_MOTION) {
// Si el cooldown está activo, ignorar eventos de ejes (evita múltiples capturas)
if (axis_cooldown_ > 0.0F) {
return;
}
constexpr Sint16 TRIGGER_THRESHOLD = 20000;
constexpr Sint16 AXIS_THRESHOLD = 20000;
// Capturar triggers como botones (usando valores especiales 100/101)
if (event.gaxis.axis == SDL_GAMEPAD_AXIS_LEFT_TRIGGER && event.gaxis.value > TRIGGER_THRESHOLD) {
captured_button = Input::TRIGGER_L2_AS_BUTTON; // 100
axis_cooldown_ = 0.5F; // Cooldown de medio segundo
} else if (event.gaxis.axis == SDL_GAMEPAD_AXIS_RIGHT_TRIGGER && event.gaxis.value > TRIGGER_THRESHOLD) {
captured_button = Input::TRIGGER_R2_AS_BUTTON; // 101
axis_cooldown_ = 0.5F;
}
// Capturar ejes del stick analógico (usando valores especiales 200+)
else if (event.gaxis.axis == SDL_GAMEPAD_AXIS_LEFTX) {
constexpr Sint16 AXIS_THRESHOLD = 20000;
if (event.gaxis.value < -AXIS_THRESHOLD) {
captured_button = 200; // Left stick izquierda
axis_cooldown_ = 0.5F;
} else if (event.gaxis.value > AXIS_THRESHOLD) {
captured_button = 201; // Left stick derecha
axis_cooldown_ = 0.5F;
}
}
}

View File

@@ -92,6 +92,7 @@ class Title {
SDL_Scancode temp_keys_[3]; // Almacenamiento temporal de teclas capturadas
int temp_buttons_[3]; // Almacenamiento temporal de botones de gamepad capturados
std::string remap_error_message_; // Mensaje de error si la tecla/boton es invalido
float axis_cooldown_; // Cooldown para evitar múltiples capturas de ejes
// --- Funciones ---
void update(); // Actualiza las variables