UIMessage: creada
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "audio.h"
|
||||
#include <unordered_map>
|
||||
#include "lang.h"
|
||||
#include "UIMessage.h"
|
||||
|
||||
// Singleton
|
||||
ServiceMenu *ServiceMenu::instance_ = nullptr;
|
||||
@@ -30,6 +31,10 @@ ServiceMenu::ServiceMenu()
|
||||
current_settings_group_(SettingsGroup::MAIN),
|
||||
previous_settings_group_(current_settings_group_)
|
||||
{
|
||||
restart_message_ui_ = std::make_unique<UIMessage>(
|
||||
element_text_,
|
||||
Lang::getText("[SERVICE_MENU] NEED_RESTART_MESSAGE"),
|
||||
title_color_);
|
||||
reset();
|
||||
}
|
||||
|
||||
@@ -68,20 +73,8 @@ void ServiceMenu::render()
|
||||
SDL_RenderRect(Screen::get()->getRenderer(), &rect_);
|
||||
|
||||
// MENSAJE DE RESTART
|
||||
if (restart_msg_visible_ || restart_msg_animating_)
|
||||
{
|
||||
// Al pintar el mensaje, calcula la posición base en ese frame:
|
||||
float base_y = rect_.y + restart_msg_base_offset_;
|
||||
float msg_y = base_y + restart_msg_y_;
|
||||
element_text_->writeDX(
|
||||
TEXT_COLOR | TEXT_CENTER,
|
||||
param.game.game_area.center_x,
|
||||
msg_y,
|
||||
Lang::getText("[SERVICE_MENU] NEED_RESTART_MESSAGE"),
|
||||
-2,
|
||||
title_color_);
|
||||
}
|
||||
|
||||
restart_message_ui_->render();
|
||||
|
||||
// TITULO
|
||||
y += title_padding_;
|
||||
title_text_->writeDX(TEXT_COLOR | TEXT_CENTER, param.game.game_area.center_x, y, title_, -4, title_color_);
|
||||
@@ -134,32 +127,21 @@ void ServiceMenu::update()
|
||||
bool now_pending = Options::pending_changes.has_pending_changes;
|
||||
if (now_pending != last_pending_changes_)
|
||||
{
|
||||
float y_offset = 39.0f; // O el que uses
|
||||
if (now_pending)
|
||||
showRestartMessage(y_offset);
|
||||
{
|
||||
float msg_x = param.game.game_area.center_x;
|
||||
float msg_y = rect_.y + 39.0f; // Posición Y base del mensaje
|
||||
restart_message_ui_->show(msg_x, msg_y);
|
||||
}
|
||||
else
|
||||
hideRestartMessage(y_offset);
|
||||
{
|
||||
restart_message_ui_->hide();
|
||||
}
|
||||
last_pending_changes_ = now_pending;
|
||||
}
|
||||
|
||||
// Animación del mensaje de reinicio
|
||||
if (restart_msg_animating_)
|
||||
{
|
||||
++restart_msg_anim_step_;
|
||||
float t = static_cast<float>(restart_msg_anim_step_) / restart_msg_anim_steps_;
|
||||
// Ease out cubic
|
||||
t = 1 - pow(1 - t, 3);
|
||||
restart_msg_y_ = restart_msg_start_y_ + (restart_msg_target_y_ - restart_msg_start_y_) * t;
|
||||
|
||||
if (restart_msg_anim_step_ >= restart_msg_anim_steps_)
|
||||
{
|
||||
restart_msg_y_ = restart_msg_target_y_;
|
||||
restart_msg_animating_ = false;
|
||||
// Si se oculta, asegúrate de que no se pinte más
|
||||
if (!restart_msg_visible_)
|
||||
restart_msg_y_ = restart_msg_target_y_;
|
||||
}
|
||||
}
|
||||
restart_message_ui_->update();
|
||||
}
|
||||
|
||||
// Calcula y establece los anclajes y dimensiones del menú
|
||||
@@ -669,27 +651,4 @@ std::string ServiceMenu::settingsGroupToString(SettingsGroup group) const
|
||||
default:
|
||||
return Lang::getText("[SERVICE_MENU] TITLE");
|
||||
}
|
||||
}
|
||||
|
||||
// Inicia la animación para mostrar el mensaje de reinicio
|
||||
void ServiceMenu::showRestartMessage(float y_offset)
|
||||
{
|
||||
restart_msg_start_y_ = -8.0f; // Empieza 8 píxeles arriba del destino
|
||||
restart_msg_target_y_ = 0.0f; // El destino siempre es offset 0 respecto a base_y
|
||||
restart_msg_y_ = restart_msg_start_y_;
|
||||
restart_msg_anim_step_ = 0;
|
||||
restart_msg_animating_ = true;
|
||||
restart_msg_visible_ = true;
|
||||
restart_msg_base_offset_ = y_offset; // Nueva variable para recordar el offset
|
||||
}
|
||||
|
||||
// Inicia la animación para ocultar el mensaje de reinicio
|
||||
void ServiceMenu::hideRestartMessage(float y_offset)
|
||||
{
|
||||
restart_msg_start_y_ = restart_msg_y_;
|
||||
restart_msg_target_y_ = -6.0f; // Sube 8 píxeles arriba del destino
|
||||
restart_msg_anim_step_ = 0;
|
||||
restart_msg_animating_ = true;
|
||||
restart_msg_visible_ = false;
|
||||
restart_msg_base_offset_ = y_offset;
|
||||
}
|
||||
Reference in New Issue
Block a user