migrat service_menu.cpp a deltaTime

This commit is contained in:
2025-09-24 19:34:08 +02:00
parent ad39d55e79
commit c79a846b29
11 changed files with 39 additions and 37 deletions

View File

@@ -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;
}