define_buttons: modificada logica de final per a poder mostrar la animació d'eixida

This commit is contained in:
2025-08-08 17:32:30 +02:00
parent a191a296f8
commit 3b07b2e130
4 changed files with 64 additions and 28 deletions

View File

@@ -53,9 +53,27 @@ void DefineButtons::render() {
} }
void DefineButtons::update() { void DefineButtons::update() {
if (enabled_ && window_message_) { if (!enabled_) {
return;
}
// Actualizar la ventana siempre
if (window_message_) {
window_message_->update(); 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) { void DefineButtons::checkEvents(const SDL_Event &event) {
@@ -149,21 +167,33 @@ void DefineButtons::clearButtons() {
} }
void DefineButtons::checkEnd() { void DefineButtons::checkEnd() {
if (finished_) { if (finished_ && !message_shown_) {
bindButtons(options_gamepad_); bindButtons(options_gamepad_);
input_->saveGamepadConfigFromGamepad(options_gamepad_->instance); input_->saveGamepadConfigFromGamepad(options_gamepad_->instance);
input_->resetInputStates(); input_->resetInputStates();
// Mostrar mensaje de finalización brevemente // Mostrar mensaje de finalización
if (window_message_) { if (window_message_) {
window_message_->clearTexts(); window_message_->clearTexts();
window_message_->addText(Lang::getText("[DEFINE_BUTTONS] CONFIGURATION_COMPLETE")); 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() { void DefineButtons::updateWindowMessage() {
if (!window_message_ || !options_gamepad_) { if (!window_message_ || !options_gamepad_) {
return; return;

View File

@@ -9,7 +9,6 @@
#include <vector> #include <vector>
#include "input.h" #include "input.h"
#include "ui/window_message.h" #include "ui/window_message.h"
namespace Options { namespace Options {
@@ -19,12 +18,12 @@ struct Gamepad;
class DefineButtons { class DefineButtons {
public: public:
struct Button { struct Button {
std::string label; std::string label;
Input::Action action; Input::Action action;
SDL_GamepadButton button; SDL_GamepadButton button;
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) {} : label(std::move(label)), action(action), button(button) {}
}; };
DefineButtons(); DefineButtons();
@@ -35,20 +34,34 @@ class DefineButtons {
void checkEvents(const SDL_Event &event); void checkEvents(const SDL_Event &event);
auto enable(Options::Gamepad *options_gamepad) -> bool; auto enable(Options::Gamepad *options_gamepad) -> bool;
void disable(); void disable();
bool isReadyToClose() const;
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; } [[nodiscard]] auto isEnabled() const -> bool { return enabled_; }
[[nodiscard]] auto isFinished() const -> bool { return finished_; } [[nodiscard]] auto isFinished() const -> bool { return finished_; }
private: private:
Input *input_ = nullptr; // Constante para cuánto tiempo mostrar el mensaje (en frames)
std::unique_ptr<WindowMessage> window_message_; static constexpr size_t MESSAGE_DISPLAY_FRAMES = 180; // ~3 segundos a 60fps
bool enabled_ = false; // Punteros
bool finished_ = false; Input *input_ = nullptr; // Entrada del usuario
std::vector<Button> buttons_; Options::Gamepad *options_gamepad_ = nullptr; // Opciones del gamepad
size_t index_button_ = 0; std::unique_ptr<WindowMessage> window_message_; // Mensaje de ventana
std::vector<std::string> controller_names_;
Options::Gamepad *options_gamepad_ = nullptr;
// Vectores y strings
std::vector<Button> buttons_; // Lista de botones
std::vector<std::string> controller_names_; // Nombres de los controladores
// size_t
size_t index_button_ = 0; // Índice del botón seleccionado
size_t message_timer_ = 0; // Contador de frames para el mensaje
// bools
bool enabled_ = false; // Flag para indicar si está activo
bool finished_ = false; // Flag para indicar si ha terminado
bool closing_ = false; // Flag para indicar que está cerrando
bool message_shown_ = false; // Flag para indicar que ya mostró el mensaje
// Métodos
void incIndexButton(); void incIndexButton();
void doControllerButtonDown(const SDL_GamepadButtonEvent &event); void doControllerButtonDown(const SDL_GamepadButtonEvent &event);
void bindButtons(Options::Gamepad *options_gamepad); void bindButtons(Options::Gamepad *options_gamepad);

View File

@@ -86,15 +86,9 @@ void ServiceMenu::update() {
if (define_buttons_) { if (define_buttons_) {
define_buttons_->update(); define_buttons_->update();
// Si DefineButtons ha terminado, deshabilitarlo // Si DefineButtons ha terminado y está listo para cerrar completamente
if (define_buttons_->isEnabled() && define_buttons_->isFinished()) { if (define_buttons_->isEnabled() && define_buttons_->isReadyToClose()) {
// Pequeño delay antes de cerrar define_buttons_->disable();
static size_t finish_delay = 0;
finish_delay++;
if (finish_delay > DEFINE_BUTTONS_FINISH_DELAY_FRAMES) {
define_buttons_->disable();
finish_delay = 0;
}
} }
} }
} }

View File

@@ -34,7 +34,6 @@ class ServiceMenu {
static constexpr size_t MIN_WIDTH = 240; static constexpr size_t MIN_WIDTH = 240;
static constexpr size_t MIN_GAP_OPTION_VALUE = 30; static constexpr size_t MIN_GAP_OPTION_VALUE = 30;
static constexpr size_t SETTINGS_GROUP_SIZE = 6; static constexpr size_t SETTINGS_GROUP_SIZE = 6;
static constexpr size_t DEFINE_BUTTONS_FINISH_DELAY_FRAMES = 60 * 3; // 3 segundo a 60 FPS
// --- Métodos de singleton --- // --- Métodos de singleton ---
static void init(); static void init();