ServiceMenu: animació per al missatge de reiniciar
This commit is contained in:
@@ -67,11 +67,26 @@ void ServiceMenu::render()
|
|||||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), title_color_.r, title_color_.g, title_color_.b, 255);
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), title_color_.r, title_color_.g, title_color_.b, 255);
|
||||||
SDL_RenderRect(Screen::get()->getRenderer(), &rect_);
|
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_);
|
||||||
|
}
|
||||||
|
|
||||||
// TITULO
|
// TITULO
|
||||||
y += title_padding_;
|
y += title_padding_;
|
||||||
title_text_->writeDX(TEXT_COLOR | TEXT_CENTER, param.game.game_area.center_x, y, title_, -4, title_color_);
|
title_text_->writeDX(TEXT_COLOR | TEXT_CENTER, param.game.game_area.center_x, y, title_, -4, title_color_);
|
||||||
if (Options::pending_changes.has_pending_changes)
|
// if (Options::pending_changes.has_pending_changes)
|
||||||
element_text_->writeDX(TEXT_COLOR | TEXT_CENTER, param.game.game_area.center_x, y + 25, Lang::getText("[SERVICE_MENU] NEED_RESTART_MESSAGE"), -2, title_color_);
|
// element_text_->writeDX(TEXT_COLOR | TEXT_CENTER, param.game.game_area.center_x, y + 25, Lang::getText("[SERVICE_MENU] NEED_RESTART_MESSAGE"), -2, title_color_);
|
||||||
|
|
||||||
// LINEA
|
// LINEA
|
||||||
y = rect_.y + upper_height_;
|
y = rect_.y + upper_height_;
|
||||||
@@ -114,6 +129,37 @@ void ServiceMenu::update()
|
|||||||
updateCounter();
|
updateCounter();
|
||||||
selected_color_ = getSelectedColor();
|
selected_color_ = getSelectedColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detecta cambios en el estado de pending_changes
|
||||||
|
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);
|
||||||
|
else
|
||||||
|
hideRestartMessage(y_offset);
|
||||||
|
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_;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula y establece los anclajes y dimensiones del menú
|
// Calcula y establece los anclajes y dimensiones del menú
|
||||||
@@ -451,7 +497,8 @@ void ServiceMenu::applySettings(ServiceMenu::SettingsGroup group)
|
|||||||
case SettingsGroup::SETTINGS:
|
case SettingsGroup::SETTINGS:
|
||||||
{
|
{
|
||||||
auto option = getOptionEntryByCaption(Lang::getText("[SERVICE_MENU] SHUTDOWN"));
|
auto option = getOptionEntryByCaption(Lang::getText("[SERVICE_MENU] SHUTDOWN"));
|
||||||
if (option != nullptr) {
|
if (option != nullptr)
|
||||||
|
{
|
||||||
option->hidden = !Options::settings.shutdown_enabled;
|
option->hidden = !Options::settings.shutdown_enabled;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -623,3 +670,26 @@ std::string ServiceMenu::settingsGroupToString(SettingsGroup group) const
|
|||||||
return Lang::getText("[SERVICE_MENU] TITLE");
|
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;
|
||||||
|
}
|
||||||
@@ -217,6 +217,17 @@ private:
|
|||||||
int resize_anim_steps_ = 8; // Total de pasos de la animación
|
int resize_anim_steps_ = 8; // Total de pasos de la animación
|
||||||
bool resizing_ = false; // Si está animando el resize
|
bool resizing_ = false; // Si está animando el resize
|
||||||
|
|
||||||
|
// --- Variables para el mensaje de reinicio ---
|
||||||
|
float restart_msg_y_ = 0.0f;
|
||||||
|
float restart_msg_target_y_ = 0.0f;
|
||||||
|
float restart_msg_start_y_ = 0.0f;
|
||||||
|
int restart_msg_anim_step_ = 0;
|
||||||
|
static constexpr int restart_msg_anim_steps_ = 6; // 8 pasos
|
||||||
|
bool restart_msg_animating_ = false;
|
||||||
|
bool restart_msg_visible_ = false;
|
||||||
|
|
||||||
|
float restart_msg_base_offset_ = 0.0f;
|
||||||
|
|
||||||
int group_menu_widths_[5];
|
int group_menu_widths_[5];
|
||||||
|
|
||||||
// --- Métodos internos: Anclaje y aspecto ---
|
// --- Métodos internos: Anclaje y aspecto ---
|
||||||
@@ -250,6 +261,9 @@ private:
|
|||||||
void precalculateMenuWidths();
|
void precalculateMenuWidths();
|
||||||
int getMenuWidthForGroup(SettingsGroup group) const;
|
int getMenuWidthForGroup(SettingsGroup group) const;
|
||||||
|
|
||||||
|
void showRestartMessage(float y);
|
||||||
|
void hideRestartMessage(float y);
|
||||||
|
|
||||||
// --- Patrón Singleton ---
|
// --- Patrón Singleton ---
|
||||||
ServiceMenu(); // Constructor privado
|
ServiceMenu(); // Constructor privado
|
||||||
~ServiceMenu() = default; // Destructor privado
|
~ServiceMenu() = default; // Destructor privado
|
||||||
@@ -261,4 +275,6 @@ private:
|
|||||||
|
|
||||||
// --- Método para reproducir el sonido del menú ---
|
// --- Método para reproducir el sonido del menú ---
|
||||||
void playMenuSound(); // Reproduce el sonido del menú
|
void playMenuSound(); // Reproduce el sonido del menú
|
||||||
|
|
||||||
|
bool last_pending_changes_ = false; // Último estado conocido de pending_changes
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user