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() {
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;

View File

@@ -9,7 +9,6 @@
#include <vector>
#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<WindowMessage> 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<Button> buttons_;
size_t index_button_ = 0;
std::vector<std::string> controller_names_;
Options::Gamepad *options_gamepad_ = nullptr;
// Punteros
Input *input_ = nullptr; // Entrada del usuario
Options::Gamepad *options_gamepad_ = nullptr; // Opciones del gamepad
std::unique_ptr<WindowMessage> window_message_; // Mensaje de ventana
// 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 doControllerButtonDown(const SDL_GamepadButtonEvent &event);
void bindButtons(Options::Gamepad *options_gamepad);

View File

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

View File

@@ -34,7 +34,6 @@ class ServiceMenu {
static constexpr size_t MIN_WIDTH = 240;
static constexpr size_t MIN_GAP_OPTION_VALUE = 30;
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 ---
static void init();