ServiceMenu: treballant en les animacions
This commit is contained in:
@@ -67,6 +67,9 @@ void ServiceMenu::render()
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), title_color_.r, title_color_.g, title_color_.b, 255);
|
||||
SDL_RenderRect(Screen::get()->getRenderer(), &rect_);
|
||||
|
||||
// Si está animando el resize, no pintar el contenido
|
||||
//if (resizing_) return;
|
||||
|
||||
// TITULO
|
||||
y += title_padding_;
|
||||
title_text_->writeDX(TEXT_COLOR | TEXT_CENTER, param.game.game_area.center_x, y, lang::getText("[SERVICE_MENU] TITLE"), -4, title_color_);
|
||||
@@ -101,6 +104,11 @@ void ServiceMenu::render()
|
||||
// Actualiza el estado del menú de servicio (colores, animaciones, etc.)
|
||||
void ServiceMenu::update()
|
||||
{
|
||||
if (resizing_) {
|
||||
updateResizeAnimation();
|
||||
// No actualizar colores ni animaciones mientras se redimensiona
|
||||
return;
|
||||
}
|
||||
if (enabled_)
|
||||
{
|
||||
updateCounter();
|
||||
@@ -138,21 +146,57 @@ void ServiceMenu::setAnchors()
|
||||
void ServiceMenu::setOptionsPosition()
|
||||
{
|
||||
resize();
|
||||
options_y_ = rect_.y + upper_height_ + lower_padding_;
|
||||
//options_y_ = rect_.y + upper_height_ + lower_padding_;
|
||||
|
||||
SDL_FRect new_rect = {
|
||||
(param.game.width - width_) / 2,
|
||||
(param.game.height - height_) / 2,
|
||||
static_cast<float>(width_),
|
||||
static_cast<float>(height_)};
|
||||
options_y_ = new_rect.y + upper_height_ + lower_padding_;
|
||||
|
||||
}
|
||||
|
||||
// Cambia el tamaño de la ventana de menu
|
||||
void ServiceMenu::resize()
|
||||
{
|
||||
lower_height_ = ((display_options_.size() - 1) * (options_height_ + options_padding_)) + options_height_ + (lower_padding_ * 2);
|
||||
|
||||
width_ = 240;
|
||||
height_ = upper_height_ + lower_height_;
|
||||
rect_ = {
|
||||
SDL_FRect new_rect = {
|
||||
(param.game.width - width_) / 2,
|
||||
(param.game.height - height_) / 2,
|
||||
static_cast<float>(width_),
|
||||
static_cast<float>(height_)};
|
||||
|
||||
// Si el rect actual es diferente al nuevo, inicia animación
|
||||
if (rect_.x != new_rect.x || rect_.y != new_rect.y || rect_.w != new_rect.w || rect_.h != new_rect.h) {
|
||||
rect_anim_from_ = rect_;
|
||||
rect_anim_to_ = new_rect;
|
||||
resize_anim_step_ = 0;
|
||||
resizing_ = true;
|
||||
} else {
|
||||
rect_ = new_rect;
|
||||
resizing_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceMenu::updateResizeAnimation()
|
||||
{
|
||||
if (!resizing_) return;
|
||||
++resize_anim_step_;
|
||||
float t = static_cast<float>(resize_anim_step_) / resize_anim_steps_;
|
||||
if (t >= 1.0f) {
|
||||
rect_ = rect_anim_to_;
|
||||
resizing_ = false;
|
||||
return;
|
||||
}
|
||||
// EaseOutQuad
|
||||
float ease = 1 - (1 - t) * (1 - t);
|
||||
rect_.x = rect_anim_from_.x + (rect_anim_to_.x - rect_anim_from_.x) * ease;
|
||||
rect_.y = rect_anim_from_.y + (rect_anim_to_.y - rect_anim_from_.y) * ease;
|
||||
rect_.w = rect_anim_from_.w + (rect_anim_to_.w - rect_anim_from_.w) * ease;
|
||||
rect_.h = rect_anim_from_.h + (rect_anim_to_.h - rect_anim_from_.h) * ease;
|
||||
}
|
||||
|
||||
// Actualiza el contador interno para animaciones o efectos visuales
|
||||
@@ -462,4 +506,5 @@ void ServiceMenu::AdjustListValues()
|
||||
option->list_index = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user