migrat service_menu.cpp a deltaTime
This commit is contained in:
@@ -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();
|
||||
@@ -45,12 +45,12 @@ class UIMessage {
|
||||
float y_offset_ = 0.0F; // Desplazamiento vertical actual del mensaje (para animación)
|
||||
|
||||
// --- 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
|
||||
static constexpr float DESP = -8.0F; // Distancia a desplazarse
|
||||
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
|
||||
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