diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index 256f833..7ce47b3 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -53,9 +53,27 @@ void DefineButtons::render() { } void DefineButtons::update() { - if (enabled_ && window_message_) { + if (!enabled_) { + return; + } + + // Actualizar la ventana siempre + if (window_message_) { window_message_->update(); } + + // Manejar la secuencia de cierre si ya terminamos + if (finished_ && message_shown_) { + message_timer_++; + + // Después del delay, iniciar animación de cierre (solo una vez) + if (message_timer_ > MESSAGE_DISPLAY_FRAMES && !closing_) { + if (window_message_) { + window_message_->hide(); // Iniciar animación de cierre + } + closing_ = true; + } + } } void DefineButtons::checkEvents(const SDL_Event &event) { @@ -149,21 +167,33 @@ void DefineButtons::clearButtons() { } void DefineButtons::checkEnd() { - if (finished_) { + if (finished_ && !message_shown_) { bindButtons(options_gamepad_); input_->saveGamepadConfigFromGamepad(options_gamepad_->instance); input_->resetInputStates(); - // Mostrar mensaje de finalización brevemente + // Mostrar mensaje de finalización if (window_message_) { window_message_->clearTexts(); window_message_->addText(Lang::getText("[DEFINE_BUTTONS] CONFIGURATION_COMPLETE")); } - // Se deshabilitará desde el ServiceMenu después de un breve delay + // Solo marcar que ya mostramos el mensaje + message_shown_ = true; + message_timer_ = 0; } } +bool DefineButtons::isReadyToClose() const { + // Solo está listo para cerrar si: + // 1. Terminó + // 2. Ya mostró el mensaje + // 3. Está cerrando + // 4. La ventana ya no está visible (animación terminada) + return finished_ && message_shown_ && closing_ && + (!window_message_ || !window_message_->isVisible()); +} + void DefineButtons::updateWindowMessage() { if (!window_message_ || !options_gamepad_) { return; diff --git a/source/define_buttons.h b/source/define_buttons.h index 2b1989a..c1fdae8 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -9,7 +9,6 @@ #include #include "input.h" - #include "ui/window_message.h" namespace Options { @@ -19,12 +18,12 @@ struct Gamepad; class DefineButtons { public: struct Button { - std::string label; - Input::Action action; - SDL_GamepadButton button; + std::string label; + Input::Action action; + SDL_GamepadButton button; - Button(std::string label, Input::Action action, SDL_GamepadButton button) - : label(std::move(label)), action(action), button(button) {} + Button(std::string label, Input::Action action, SDL_GamepadButton button) + : label(std::move(label)), action(action), button(button) {} }; DefineButtons(); @@ -35,20 +34,34 @@ class DefineButtons { void checkEvents(const SDL_Event &event); auto enable(Options::Gamepad *options_gamepad) -> bool; void disable(); + bool isReadyToClose() const; [[nodiscard]] auto isEnabled() const -> bool { return enabled_; } [[nodiscard]] auto isFinished() const -> bool { return finished_; } private: - Input *input_ = nullptr; - std::unique_ptr window_message_; + // Constante para cuánto tiempo mostrar el mensaje (en frames) + static constexpr size_t MESSAGE_DISPLAY_FRAMES = 180; // ~3 segundos a 60fps - bool enabled_ = false; - bool finished_ = false; - std::vector