fix MenuRenderer: corregida la animació del cuadro del menu de servei
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
#include "menu_renderer.h"
|
||||
#include "text.h"
|
||||
#include "menu_option.h" // Necesario para acceder a las opciones
|
||||
#include "screen.h" // Para param
|
||||
#include "screen.h" // Para param
|
||||
#include <array>
|
||||
|
||||
MenuRenderer::MenuRenderer(std::shared_ptr<Text> element_text, std::shared_ptr<Text> title_text)
|
||||
: element_text_(std::move(element_text)), title_text_(std::move(title_text))
|
||||
{
|
||||
}
|
||||
: element_text_(std::move(element_text)), title_text_(std::move(title_text)) {}
|
||||
|
||||
void MenuRenderer::render(const ServiceMenu *menu_state)
|
||||
{
|
||||
@@ -77,6 +75,14 @@ void MenuRenderer::onLayoutChanged(const ServiceMenu *menu_state)
|
||||
resize(menu_state);
|
||||
}
|
||||
|
||||
void MenuRenderer::setLayout(const ServiceMenu *menu_state)
|
||||
{
|
||||
// Cuando la lógica del menú notifica un cambio, el renderer recalcula su layout
|
||||
precalculateMenuWidths(menu_state->getAllOptions(), menu_state);
|
||||
setAnchors(menu_state);
|
||||
setSize(menu_state);
|
||||
}
|
||||
|
||||
void MenuRenderer::setAnchors(const ServiceMenu *menu_state)
|
||||
{
|
||||
size_t max_entries = 0;
|
||||
@@ -99,17 +105,21 @@ void MenuRenderer::setAnchors(const ServiceMenu *menu_state)
|
||||
|
||||
width_ = ServiceMenu::MIN_WIDTH_;
|
||||
height_ = upper_height_ + lower_height_;
|
||||
|
||||
rect_ = {(param.game.width - width_) / 2.0f, (param.game.height - height_) / 2.0f, (float)width_, (float)height_};
|
||||
}
|
||||
|
||||
void MenuRenderer::resize(const ServiceMenu *menu_state)
|
||||
SDL_FRect MenuRenderer::calculateNewRect(const ServiceMenu *menu_state)
|
||||
{
|
||||
width_ = getMenuWidthForGroup(menu_state->getCurrentGroup());
|
||||
const auto &display_options = menu_state->getDisplayOptions();
|
||||
lower_height_ = ((display_options.size() > 0 ? display_options.size() - 1 : 0) * (options_height_ + options_padding_)) + options_height_ + (lower_padding_ * 2);
|
||||
height_ = upper_height_ + lower_height_;
|
||||
SDL_FRect new_rect = {(param.game.width - width_) / 2.0f, (param.game.height - height_) / 2.0f, (float)width_, (float)height_};
|
||||
|
||||
return {(param.game.width - width_) / 2.0f, (param.game.height - height_) / 2.0f, (float)width_, (float)height_};
|
||||
}
|
||||
|
||||
void MenuRenderer::resize(const ServiceMenu *menu_state)
|
||||
{
|
||||
SDL_FRect new_rect = calculateNewRect(menu_state);
|
||||
|
||||
if (rect_.x != new_rect.x || rect_.y != new_rect.y || rect_.w != new_rect.w || rect_.h != new_rect.h)
|
||||
{
|
||||
@@ -126,6 +136,14 @@ void MenuRenderer::resize(const ServiceMenu *menu_state)
|
||||
options_y_ = new_rect.y + upper_height_ + lower_padding_;
|
||||
}
|
||||
|
||||
void MenuRenderer::setSize(const ServiceMenu *menu_state)
|
||||
{
|
||||
SDL_FRect new_rect = calculateNewRect(menu_state);
|
||||
rect_ = new_rect;
|
||||
resizing_ = false;
|
||||
options_y_ = rect_.y + upper_height_ + lower_padding_;
|
||||
}
|
||||
|
||||
void MenuRenderer::updateResizeAnimation()
|
||||
{
|
||||
if (!resizing_)
|
||||
|
||||
Reference in New Issue
Block a user