migrat service_menu.cpp a deltaTime
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Button> buttons_; // Lista de botones
|
||||
std::vector<std::string> controller_names_; // Nombres de los controladores
|
||||
size_t index_button_ = 0; // Índice del botón seleccionado
|
||||
size_t message_timer_ = 0; // Contador de frames para el mensaje
|
||||
float message_timer_ = 0.0f; // Timer en segundos para el mensaje
|
||||
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
|
||||
|
||||
@@ -161,7 +161,7 @@ void Screen::update(float delta_time) {
|
||||
shake_effect_.update(src_rect_, dst_rect_, delta_time);
|
||||
flash_effect_.update(delta_time);
|
||||
if (service_menu_ != nullptr) {
|
||||
service_menu_->update();
|
||||
service_menu_->update(delta_time);
|
||||
}
|
||||
if (notifier_ != nullptr) {
|
||||
notifier_->update(delta_time);
|
||||
|
||||
@@ -107,8 +107,7 @@ void MenuRenderer::render(const ServiceMenu *menu_state) {
|
||||
}
|
||||
}
|
||||
|
||||
void MenuRenderer::update(const ServiceMenu *menu_state) {
|
||||
float delta_time = 1.0F / 60.0F; // Asumiendo 60 FPS
|
||||
void MenuRenderer::update(const ServiceMenu *menu_state, float delta_time) {
|
||||
updateAnimations(delta_time);
|
||||
|
||||
if (visible_) {
|
||||
|
||||
@@ -26,7 +26,7 @@ class MenuRenderer {
|
||||
|
||||
// --- Métodos principales de la vista ---
|
||||
void render(const ServiceMenu *menu_state);
|
||||
void update(const ServiceMenu *menu_state);
|
||||
void update(const ServiceMenu *menu_state, float delta_time);
|
||||
|
||||
// --- Nuevos: Métodos de control de visibilidad y animación ---
|
||||
void show(const ServiceMenu *menu_state);
|
||||
|
||||
@@ -84,9 +84,9 @@ void ServiceMenu::render() {
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceMenu::update() {
|
||||
void ServiceMenu::update(float delta_time) {
|
||||
// El renderer siempre se actualiza para manejar sus animaciones
|
||||
renderer_->update(this);
|
||||
renderer_->update(this, delta_time);
|
||||
|
||||
if (!enabled_) {
|
||||
return;
|
||||
@@ -98,10 +98,10 @@ void ServiceMenu::update() {
|
||||
now_pending ? restart_message_ui_->show() : restart_message_ui_->hide();
|
||||
last_pending_changes_ = now_pending;
|
||||
}
|
||||
restart_message_ui_->update();
|
||||
restart_message_ui_->update(delta_time);
|
||||
|
||||
if (define_buttons_) {
|
||||
define_buttons_->update();
|
||||
define_buttons_->update(delta_time);
|
||||
if (define_buttons_->isEnabled() && define_buttons_->isReadyToClose()) {
|
||||
define_buttons_->disable();
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class ServiceMenu {
|
||||
// --- Métodos principales ---
|
||||
void toggle();
|
||||
void render();
|
||||
void update();
|
||||
void update(float delta_time);
|
||||
void reset();
|
||||
|
||||
// --- Lógica de navegación ---
|
||||
|
||||
@@ -20,7 +20,7 @@ void UIMessage::show() {
|
||||
start_y_ = DESP; // Empieza 8 píxeles arriba de la posición base
|
||||
target_y_ = 0.0F; // La posición final es la base
|
||||
y_offset_ = start_y_;
|
||||
anim_step_ = 0;
|
||||
animation_timer_ = 0.0f;
|
||||
animating_ = true;
|
||||
visible_ = true;
|
||||
}
|
||||
@@ -33,21 +33,26 @@ void UIMessage::hide() {
|
||||
|
||||
start_y_ = y_offset_; // Comienza desde la posición actual
|
||||
target_y_ = DESP; // Termina 8 píxeles arriba de la base
|
||||
anim_step_ = 0;
|
||||
animation_timer_ = 0.0f;
|
||||
animating_ = true;
|
||||
}
|
||||
|
||||
// Actualiza el estado de la animación (debe llamarse cada frame)
|
||||
void UIMessage::update() {
|
||||
void UIMessage::update(float delta_time) {
|
||||
if (animating_) {
|
||||
updateAnimation();
|
||||
updateAnimation(delta_time);
|
||||
}
|
||||
}
|
||||
|
||||
// Interpola la posición vertical del mensaje usando ease out cubic
|
||||
void UIMessage::updateAnimation() {
|
||||
anim_step_++;
|
||||
float t = static_cast<float>(anim_step_) / ANIMATION_STEPS;
|
||||
void UIMessage::updateAnimation(float delta_time) {
|
||||
animation_timer_ += delta_time;
|
||||
float t = animation_timer_ / ANIMATION_DURATION_S;
|
||||
|
||||
// Clamp t entre 0 y 1
|
||||
if (t > 1.0f) {
|
||||
t = 1.0f;
|
||||
}
|
||||
|
||||
if (target_y_ > start_y_) {
|
||||
// Animación de entrada (ease out cubic)
|
||||
@@ -59,9 +64,10 @@ void UIMessage::updateAnimation() {
|
||||
|
||||
y_offset_ = start_y_ + (target_y_ - start_y_) * t;
|
||||
|
||||
if (anim_step_ >= ANIMATION_STEPS) {
|
||||
if (animation_timer_ >= ANIMATION_DURATION_S) {
|
||||
y_offset_ = target_y_;
|
||||
animating_ = false;
|
||||
animation_timer_ = 0.0f; // Reset timer
|
||||
if (target_y_ < 0.0F) {
|
||||
visible_ = false;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class UIMessage {
|
||||
void hide();
|
||||
|
||||
// Actualiza el estado de la animación (debe llamarse cada frame)
|
||||
void update();
|
||||
void update(float delta_time);
|
||||
|
||||
// Dibuja el mensaje en pantalla si está visible
|
||||
void render();
|
||||
@@ -47,10 +47,10 @@ class UIMessage {
|
||||
// --- Animación ---
|
||||
float start_y_ = 0.0F; // Posición Y inicial de la animación
|
||||
float target_y_ = 0.0F; // Posición Y objetivo de la animación
|
||||
int anim_step_ = 0; // Paso actual de la animación
|
||||
static constexpr int ANIMATION_STEPS = 8; // Número total de pasos de la animación
|
||||
float animation_timer_ = 0.0F; // Timer actual de la animación en segundos
|
||||
static constexpr float ANIMATION_DURATION_S = 0.133f; // Duración total de la animación (8 frames @ 60fps)
|
||||
static constexpr float DESP = -8.0F; // Distancia a desplazarse
|
||||
|
||||
// Actualiza la interpolación de la animación (ease out/in cubic)
|
||||
void updateAnimation();
|
||||
void updateAnimation(float delta_time);
|
||||
};
|
||||
@@ -76,12 +76,9 @@ void WindowMessage::render() {
|
||||
}
|
||||
}
|
||||
|
||||
void WindowMessage::update() {
|
||||
void WindowMessage::update(float delta_time) {
|
||||
// Actualizar animaciones
|
||||
if (show_hide_animation_.active || resize_animation_.active) {
|
||||
// Aquí necesitarías el delta_time del game loop
|
||||
// Por ahora usamos un valor fijo, pero idealmente se pasaría como parámetro
|
||||
float delta_time = 1.0F / 60.0F; // Asumiendo 60 FPS
|
||||
updateAnimation(delta_time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ class WindowMessage {
|
||||
|
||||
// Métodos principales
|
||||
void render();
|
||||
void update();
|
||||
void update(float delta_time);
|
||||
|
||||
// Control de visibilidad
|
||||
void show();
|
||||
|
||||
Reference in New Issue
Block a user