linter
This commit is contained in:
@@ -91,53 +91,13 @@ void Title::handleEvents() {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN) {
|
||||
switch (state_) {
|
||||
case State::MAIN_MENU:
|
||||
switch (event.key.key) {
|
||||
case SDLK_1:
|
||||
exit_scene_ = SceneManager::Scene::GAME;
|
||||
transitionToState(State::FADE_MENU);
|
||||
Audio::get()->fadeOutMusic(1000);
|
||||
break;
|
||||
|
||||
case SDLK_2:
|
||||
transitionToState(State::CONTROLS_MENU);
|
||||
controls_menu_state_ = ControlsMenuState::MAIN;
|
||||
break;
|
||||
|
||||
case SDLK_3:
|
||||
transitionToState(State::CHEEVOS_MENU);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
handleMainMenuKeyPress(event.key.key);
|
||||
break;
|
||||
|
||||
case State::CONTROLS_MENU:
|
||||
if (controls_menu_state_ == ControlsMenuState::MAIN) {
|
||||
// Menu principal de controles
|
||||
switch (event.key.key) {
|
||||
case SDLK_1:
|
||||
// Iniciar redefinicion de teclado
|
||||
controls_menu_state_ = ControlsMenuState::KEYBOARD_REMAP;
|
||||
remap_step_ = 0;
|
||||
remap_error_message_.clear();
|
||||
break;
|
||||
|
||||
case SDLK_2:
|
||||
// Redefinir joystick - solo si hay gamepads conectados
|
||||
if (Input::get()->gameControllerFound()) {
|
||||
controls_menu_state_ = ControlsMenuState::JOYSTICK_REMAP;
|
||||
remap_step_ = 0;
|
||||
remap_error_message_.clear();
|
||||
axis_cooldown_ = 0.0F; // Resetear cooldown
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
handleControlsMenuKeyPress(event.key.key);
|
||||
} else if (controls_menu_state_ == ControlsMenuState::KEYBOARD_REMAP) {
|
||||
// Captura de teclas para redefinir
|
||||
handleControlsMenuKeyboardRemap(event);
|
||||
}
|
||||
break;
|
||||
@@ -149,6 +109,54 @@ void Title::handleEvents() {
|
||||
}
|
||||
}
|
||||
|
||||
// Maneja las teclas del menu principal
|
||||
void Title::handleMainMenuKeyPress(SDL_Keycode key) {
|
||||
switch (key) {
|
||||
case SDLK_1:
|
||||
exit_scene_ = SceneManager::Scene::GAME;
|
||||
transitionToState(State::FADE_MENU);
|
||||
Audio::get()->fadeOutMusic(1000);
|
||||
break;
|
||||
|
||||
case SDLK_2:
|
||||
transitionToState(State::CONTROLS_MENU);
|
||||
controls_menu_state_ = ControlsMenuState::MAIN;
|
||||
break;
|
||||
|
||||
case SDLK_3:
|
||||
transitionToState(State::CHEEVOS_MENU);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Maneja las teclas del menu de controles
|
||||
void Title::handleControlsMenuKeyPress(SDL_Keycode key) {
|
||||
switch (key) {
|
||||
case SDLK_1:
|
||||
// Iniciar redefinicion de teclado
|
||||
controls_menu_state_ = ControlsMenuState::KEYBOARD_REMAP;
|
||||
remap_step_ = 0;
|
||||
remap_error_message_.clear();
|
||||
break;
|
||||
|
||||
case SDLK_2:
|
||||
// Redefinir joystick - solo si hay gamepads conectados
|
||||
if (Input::get()->gameControllerFound()) {
|
||||
controls_menu_state_ = ControlsMenuState::JOYSTICK_REMAP;
|
||||
remap_step_ = 0;
|
||||
remap_error_message_.clear();
|
||||
axis_cooldown_ = 0.0F; // Resetear cooldown
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Title::handleInput(float delta_time) {
|
||||
Input::get()->update();
|
||||
@@ -247,7 +255,7 @@ void Title::update() {
|
||||
|
||||
updateState(DELTA_TIME); // Actualiza el estado actual
|
||||
|
||||
Audio::get()->update(); // Actualiza el objeto Audio
|
||||
Audio::update(); // Actualiza el objeto Audio
|
||||
Screen::get()->update(DELTA_TIME); // Actualiza el objeto Screen
|
||||
}
|
||||
|
||||
@@ -343,9 +351,7 @@ void Title::updateControlsMenu(float 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;
|
||||
}
|
||||
axis_cooldown_ = std::max(axis_cooldown_, 0.0F);
|
||||
}
|
||||
|
||||
// Si estamos mostrando las teclas definidas, esperar antes de guardar
|
||||
@@ -517,7 +523,7 @@ void Title::renderControlsMenu() {
|
||||
controls_menu_state_ == ControlsMenuState::KEYBOARD_REMAP_COMPLETE) {
|
||||
renderKeyboardRemap();
|
||||
} else if (controls_menu_state_ == ControlsMenuState::JOYSTICK_REMAP ||
|
||||
controls_menu_state_ == ControlsMenuState::JOYSTICK_REMAP_COMPLETE) {
|
||||
controls_menu_state_ == ControlsMenuState::JOYSTICK_REMAP_COMPLETE) {
|
||||
renderJoystickRemap();
|
||||
} else {
|
||||
// Menu principal de controles
|
||||
@@ -527,9 +533,8 @@ void Title::renderControlsMenu() {
|
||||
menu_text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 11 * TEXT_SIZE, "1. REDEFINE KEYBOARD", 1, COLOR);
|
||||
|
||||
// Deshabilitar opcion de joystick si no hay gamepads conectados
|
||||
const bool gamepad_available = Input::get()->gameControllerFound();
|
||||
menu_text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 13 * TEXT_SIZE,
|
||||
"2. REDEFINE JOYSTICK", 1, gamepad_available ? COLOR : DISABLED_COLOR);
|
||||
const bool GAMEPAD_AVAILABLE = Input::get()->gameControllerFound();
|
||||
menu_text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 13 * TEXT_SIZE, "2. REDEFINE JOYSTICK", 1, GAMEPAD_AVAILABLE ? COLOR : DISABLED_COLOR);
|
||||
|
||||
menu_text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 17 * TEXT_SIZE, "ENTER TO GO BACK", 1, COLOR);
|
||||
}
|
||||
@@ -607,7 +612,7 @@ void Title::handleControlsMenuKeyboardRemap(const SDL_Event& event) {
|
||||
}
|
||||
|
||||
// Valida si una tecla es permitida
|
||||
bool Title::isKeyValid(SDL_Scancode scancode) {
|
||||
auto Title::isKeyValid(SDL_Scancode scancode) -> bool {
|
||||
// Prohibir ESC (reservado para cancelar)
|
||||
if (scancode == SDL_SCANCODE_ESCAPE) {
|
||||
return false;
|
||||
@@ -627,7 +632,7 @@ bool Title::isKeyValid(SDL_Scancode scancode) {
|
||||
}
|
||||
|
||||
// Verifica si una tecla ya fue usada en pasos anteriores
|
||||
bool Title::isKeyDuplicate(SDL_Scancode scancode, int current_step) {
|
||||
auto Title::isKeyDuplicate(SDL_Scancode scancode, int current_step) -> bool {
|
||||
for (int i = 0; i < current_step; i++) {
|
||||
if (temp_keys_[i] == scancode) {
|
||||
return true;
|
||||
@@ -637,7 +642,7 @@ bool Title::isKeyDuplicate(SDL_Scancode scancode, int current_step) {
|
||||
}
|
||||
|
||||
// Retorna el nombre de la accion para el paso actual
|
||||
std::string Title::getActionName(int step) {
|
||||
auto Title::getActionName(int step) -> std::string {
|
||||
switch (step) {
|
||||
case 0:
|
||||
return "LEFT";
|
||||
@@ -671,7 +676,7 @@ void Title::renderKeyboardRemap() {
|
||||
const int TEXT_SIZE = menu_text_->getCharacterSize();
|
||||
|
||||
// Titulo
|
||||
//menu_text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 9 * TEXT_SIZE, "REDEFINE KEYBOARD", 1, COLOR);
|
||||
// menu_text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 9 * TEXT_SIZE, "REDEFINE KEYBOARD", 1, COLOR);
|
||||
|
||||
// Mensaje principal: "PRESS KEY FOR [ACTION]" o "KEYS DEFINED" si completado
|
||||
if (remap_step_ >= 3) {
|
||||
@@ -764,7 +769,7 @@ void Title::handleControlsMenuJoystickRemap(const SDL_Event& event) {
|
||||
// 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
|
||||
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;
|
||||
@@ -805,7 +810,7 @@ void Title::handleControlsMenuJoystickRemap(const SDL_Event& event) {
|
||||
}
|
||||
|
||||
// Valida si un botón está duplicado
|
||||
bool Title::isButtonDuplicate(int button, int current_step) {
|
||||
auto Title::isButtonDuplicate(int button, int current_step) -> bool {
|
||||
for (int i = 0; i < current_step; ++i) {
|
||||
if (temp_buttons_[i] == button) {
|
||||
return true;
|
||||
@@ -829,7 +834,7 @@ void Title::applyJoystickRemap() {
|
||||
}
|
||||
|
||||
// Retorna el nombre amigable del botón del gamepad
|
||||
std::string Title::getButtonName(int button) {
|
||||
auto Title::getButtonName(int button) -> std::string {
|
||||
// Triggers especiales
|
||||
if (button == Input::TRIGGER_L2_AS_BUTTON) {
|
||||
return "L2";
|
||||
@@ -847,7 +852,7 @@ std::string Title::getButtonName(int button) {
|
||||
}
|
||||
|
||||
// Botones estándar SDL
|
||||
const auto sdl_button = static_cast<SDL_GamepadButton>(button);
|
||||
const char* button_name = SDL_GetGamepadStringForButton(sdl_button);
|
||||
return button_name ? std::string(button_name) : "UNKNOWN";
|
||||
const auto GAMEPAD_BUTTON = static_cast<SDL_GamepadButton>(button);
|
||||
const char* button_name = SDL_GetGamepadStringForButton(GAMEPAD_BUTTON);
|
||||
return (button_name != nullptr) ? std::string(button_name) : "UNKNOWN";
|
||||
}
|
||||
Reference in New Issue
Block a user