From 3b07b2e1301f0f7eb1c16a555e448bd4ee73a14d Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 8 Aug 2025 17:32:30 +0200 Subject: [PATCH] =?UTF-8?q?define=5Fbuttons:=20modificada=20logica=20de=20?= =?UTF-8?q?final=20per=20a=20poder=20mostrar=20la=20animaci=C3=B3=20d'eixi?= =?UTF-8?q?da?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/define_buttons.cpp | 38 +++++++++++++++++++++++++++++++---- source/define_buttons.h | 41 +++++++++++++++++++++++++------------- source/ui/service_menu.cpp | 12 +++-------- source/ui/service_menu.h | 1 - 4 files changed, 64 insertions(+), 28 deletions(-) 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