ServiceMenu: trastejant cosetes
This commit is contained in:
@@ -1,37 +1,40 @@
|
||||
#include "UIMessage.h"
|
||||
#include <cmath> // Para pow
|
||||
#include <cmath> // Para pow
|
||||
#include "screen.h" // Para param y TEXT_CENTER
|
||||
|
||||
// Constructor
|
||||
UIMessage::UIMessage(std::shared_ptr<Text> text_renderer, const std::string& message_text, const Color& color)
|
||||
: text_renderer_(text_renderer), text_(message_text), color_(color)
|
||||
{
|
||||
}
|
||||
// Constructor: inicializa el renderizador, el texto y el color del mensaje
|
||||
UIMessage::UIMessage(std::shared_ptr<Text> text_renderer, const std::string &message_text, const Color &color)
|
||||
: text_renderer_(text_renderer), text_(message_text), color_(color) {}
|
||||
|
||||
// Muestra el mensaje en la posición base_x, base_y con animación de entrada desde arriba
|
||||
void UIMessage::show(float base_x, float base_y)
|
||||
{
|
||||
if (visible_ && target_y_ == 0.0f) return; // Ya está visible y quieto
|
||||
if (visible_ && target_y_ == 0.0f)
|
||||
return; // Ya está visible y quieto
|
||||
|
||||
base_x_ = base_x;
|
||||
base_y_ = base_y;
|
||||
start_y_ = -8.0f; // Empieza 8 píxeles arriba
|
||||
target_y_ = 0.0f; // La posición final es el base_y
|
||||
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;
|
||||
animating_ = true;
|
||||
visible_ = true;
|
||||
}
|
||||
|
||||
// Oculta el mensaje con animación de salida hacia arriba
|
||||
void UIMessage::hide()
|
||||
{
|
||||
if (!visible_) return;
|
||||
if (!visible_)
|
||||
return;
|
||||
|
||||
start_y_ = y_offset_;
|
||||
target_y_ = -8.0f; // Sube 8 píxeles para desaparecer
|
||||
start_y_ = y_offset_; // Comienza desde la posición actual
|
||||
target_y_ = DESP_; // Termina 8 píxeles arriba de la base
|
||||
anim_step_ = 0;
|
||||
animating_ = true;
|
||||
}
|
||||
|
||||
// Actualiza el estado de la animación (debe llamarse cada frame)
|
||||
void UIMessage::update()
|
||||
{
|
||||
if (animating_)
|
||||
@@ -40,27 +43,35 @@ void UIMessage::update()
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
// Ease Out Cubic para una animación más suave
|
||||
t = 1 - pow(1 - t, 3);
|
||||
|
||||
if (target_y_ > start_y_)
|
||||
{
|
||||
// Animación de entrada (ease out cubic)
|
||||
t = 1 - pow(1 - t, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Animación de salida (ease in cubic)
|
||||
t = pow(t, 3);
|
||||
}
|
||||
|
||||
y_offset_ = start_y_ + (target_y_ - start_y_) * t;
|
||||
|
||||
if (anim_step_ >= ANIMATION_STEPS)
|
||||
{
|
||||
y_offset_ = target_y_;
|
||||
animating_ = false;
|
||||
|
||||
// Si el objetivo era ocultarlo (target_y negativo), lo marcamos como no visible
|
||||
if (target_y_ < 0.0f) {
|
||||
if (target_y_ < 0.0f)
|
||||
visible_ = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el mensaje en pantalla si está visible
|
||||
void UIMessage::render()
|
||||
{
|
||||
if (visible_)
|
||||
@@ -75,7 +86,14 @@ void UIMessage::render()
|
||||
}
|
||||
}
|
||||
|
||||
// Devuelve true si el mensaje está visible actualmente
|
||||
bool UIMessage::isVisible() const
|
||||
{
|
||||
return visible_;
|
||||
}
|
||||
|
||||
// Permite actualizar la posición base Y del mensaje (por ejemplo, si el menú se mueve)
|
||||
void UIMessage::setBaseY(float new_base_y)
|
||||
{
|
||||
base_y_ = new_base_y;
|
||||
}
|
||||
Reference in New Issue
Block a user