From c79a846b292d2d93a2b5aa5b7286e4aa8518f467 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 24 Sep 2025 19:34:08 +0200 Subject: [PATCH] migrat service_menu.cpp a deltaTime --- source/define_buttons.cpp | 10 +++++----- source/define_buttons.h | 6 +++--- source/screen.cpp | 2 +- source/ui/menu_renderer.cpp | 3 +-- source/ui/menu_renderer.h | 2 +- source/ui/service_menu.cpp | 8 ++++---- source/ui/service_menu.h | 2 +- source/ui/ui_message.cpp | 22 ++++++++++++++-------- source/ui/ui_message.h | 14 +++++++------- source/ui/window_message.cpp | 5 +---- source/ui/window_message.h | 2 +- 11 files changed, 39 insertions(+), 37 deletions(-) diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index a00b5a6..d25d180 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -39,22 +39,22 @@ void DefineButtons::render() { } } -void DefineButtons::update() { +void DefineButtons::update(float delta_time) { if (!enabled_) { return; } // Actualizar la ventana siempre if (window_message_) { - window_message_->update(); + window_message_->update(delta_time); } // Manejar la secuencia de cierre si ya terminamos if (finished_ && message_shown_) { - message_timer_++; + message_timer_ += delta_time; // Después del delay, iniciar animación de cierre (solo una vez) - if (message_timer_ > MESSAGE_DISPLAY_FRAMES && !closing_) { + if (message_timer_ >= MESSAGE_DISPLAY_DURATION_S && !closing_) { if (window_message_) { window_message_->hide(); // Iniciar animación de cierre } @@ -234,7 +234,7 @@ void DefineButtons::checkEnd() { // Solo marcar que ya mostramos el mensaje message_shown_ = true; - message_timer_ = 0; + message_timer_ = 0.0f; } } diff --git a/source/define_buttons.h b/source/define_buttons.h index f85d9b3..15cd719 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -36,7 +36,7 @@ class DefineButtons { // --- Métodos principales --- void render(); - void update(); + void update(float delta_time); void handleEvents(const SDL_Event &event); auto enable(Options::Gamepad *options_gamepad) -> bool; void disable(); @@ -48,7 +48,7 @@ class DefineButtons { private: // --- Constantes --- - static constexpr size_t MESSAGE_DISPLAY_FRAMES = 120; // Cuánto tiempo mostrar el mensaje (en frames) ~2 segundos a 60fps + static constexpr float MESSAGE_DISPLAY_DURATION_S = 2.0f; // Cuánto tiempo mostrar el mensaje en segundos // --- Objetos y punteros --- Input *input_ = nullptr; // Entrada del usuario @@ -59,7 +59,7 @@ class DefineButtons { std::vector