ServiceMenu: adapta el tamany de la finestra al contingut
This commit is contained in:
@@ -66,18 +66,18 @@ void ServiceMenu::render()
|
|||||||
SDL_RenderRect(Screen::get()->getRenderer(), &rect_);
|
SDL_RenderRect(Screen::get()->getRenderer(), &rect_);
|
||||||
|
|
||||||
// TITULO
|
// TITULO
|
||||||
y += line_height_;
|
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_);
|
title_text_->writeDX(TEXT_COLOR | TEXT_CENTER, param.game.game_area.center_x, y, lang::getText("[SERVICE_MENU] TITLE"), -4, title_color_);
|
||||||
|
|
||||||
// LINEA
|
// LINEA
|
||||||
y += line_height_ * 2;
|
y = rect_.y + upper_height_;
|
||||||
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_RenderLine(Screen::get()->getRenderer(), rect_.x + OPTIONS_HORIZONTAL_PADDING_, y, rect_.x + rect_.w - OPTIONS_HORIZONTAL_PADDING_, y);
|
SDL_RenderLine(Screen::get()->getRenderer(), rect_.x + OPTIONS_HORIZONTAL_PADDING_, y, rect_.x + rect_.w - OPTIONS_HORIZONTAL_PADDING_, y);
|
||||||
|
|
||||||
// OPCIONES
|
// OPCIONES
|
||||||
|
y = options_y_;
|
||||||
for (size_t i = 0; i < option_pairs_.size(); ++i)
|
for (size_t i = 0; i < option_pairs_.size(); ++i)
|
||||||
{
|
{
|
||||||
y += line_height_;
|
|
||||||
if (getGroupAlignment(current_settings_group_) == GroupAlignment::LEFT)
|
if (getGroupAlignment(current_settings_group_) == GroupAlignment::LEFT)
|
||||||
{
|
{
|
||||||
// Nombre de la opción
|
// Nombre de la opción
|
||||||
@@ -91,6 +91,7 @@ void ServiceMenu::render()
|
|||||||
// Nombre de la opción
|
// Nombre de la opción
|
||||||
element_text_->writeDX(TEXT_CENTER | TEXT_COLOR, rect_.x + rect_.w / 2, y, option_pairs_.at(i).first, -2, i == selected_ ? selected_color_ : text_color_);
|
element_text_->writeDX(TEXT_CENTER | TEXT_COLOR, rect_.x + rect_.w / 2, y, option_pairs_.at(i).first, -2, i == selected_ ? selected_color_ : text_color_);
|
||||||
}
|
}
|
||||||
|
y += options_height_ + options_padding_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,9 +109,49 @@ void ServiceMenu::update()
|
|||||||
// Calcula y establece los anclajes y dimensiones del menú
|
// Calcula y establece los anclajes y dimensiones del menú
|
||||||
void ServiceMenu::setAnchors()
|
void ServiceMenu::setAnchors()
|
||||||
{
|
{
|
||||||
line_height_ = element_text_->getCharacterSize() + 5;
|
const size_t MAX_ENTRIES = findLargestGroupSize();
|
||||||
|
|
||||||
|
options_height_ = element_text_->getCharacterSize();
|
||||||
|
options_padding_ = 5;
|
||||||
|
|
||||||
|
title_height_ = title_text_->getCharacterSize();
|
||||||
|
title_padding_ = title_height_ / 2;
|
||||||
|
|
||||||
|
upper_height_ = (title_padding_ * 2) + title_height_;
|
||||||
|
lower_padding_ = (options_padding_ * 3);
|
||||||
|
lower_height_ = ((MAX_ENTRIES - 1) * (options_height_ + options_padding_)) + options_height_ + (lower_padding_ * 2);
|
||||||
|
|
||||||
width_ = 240;
|
width_ = 240;
|
||||||
height_ = calculateMenuHeight();
|
height_ = upper_height_ + lower_height_;
|
||||||
|
rect_ = {
|
||||||
|
(param.game.width - width_) / 2,
|
||||||
|
(param.game.height - height_) / 2,
|
||||||
|
static_cast<float>(width_),
|
||||||
|
static_cast<float>(height_)};
|
||||||
|
|
||||||
|
setOptionsPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establce la posición donde empezar a escribir las opciones del menu
|
||||||
|
void ServiceMenu::setOptionsPosition()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
const size_t MAX_ENTRIES = findLargestGroupSize();
|
||||||
|
const size_t CURRENT_ENTRIES = display_options_.size();
|
||||||
|
const size_t ADDED_SPACE = ((MAX_ENTRIES - CURRENT_ENTRIES) * (options_height_ + options_padding_)) / 2;
|
||||||
|
options_y_ = rect_.y + upper_height_ + lower_padding_ + ADDED_SPACE;
|
||||||
|
*/
|
||||||
|
resize();
|
||||||
|
options_y_ = 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_ = {
|
rect_ = {
|
||||||
(param.game.width - width_) / 2,
|
(param.game.width - width_) / 2,
|
||||||
(param.game.height - height_) / 2,
|
(param.game.height - height_) / 2,
|
||||||
@@ -205,6 +246,7 @@ void ServiceMenu::selectOption()
|
|||||||
current_settings_group_ = display_options_.at(selected_).target_group;
|
current_settings_group_ = display_options_.at(selected_).target_group;
|
||||||
updateMenu(current_settings_group_);
|
updateMenu(current_settings_group_);
|
||||||
selected_ = 0;
|
selected_ = 0;
|
||||||
|
setOptionsPosition();
|
||||||
playMenuSound();
|
playMenuSound();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -247,6 +289,7 @@ void ServiceMenu::moveBack()
|
|||||||
selected_ = 0;
|
selected_ = 0;
|
||||||
current_settings_group_ = previous_settings_group_;
|
current_settings_group_ = previous_settings_group_;
|
||||||
updateMenu(current_settings_group_);
|
updateMenu(current_settings_group_);
|
||||||
|
setOptionsPosition();
|
||||||
playMenuSound();
|
playMenuSound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -347,14 +390,14 @@ void ServiceMenu::reset()
|
|||||||
selected_ = 0;
|
selected_ = 0;
|
||||||
previous_settings_group_ = current_settings_group_ = SettingsGroup::MAIN;
|
previous_settings_group_ = current_settings_group_ = SettingsGroup::MAIN;
|
||||||
initializeOptions();
|
initializeOptions();
|
||||||
setAnchors();
|
|
||||||
updateMenu(current_settings_group_);
|
updateMenu(current_settings_group_);
|
||||||
|
setAnchors();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula la altura total del menú en píxeles
|
// Calcula la altura total del menú en píxeles
|
||||||
int ServiceMenu::calculateMenuHeight() const
|
int ServiceMenu::calculateMenuHeight() const
|
||||||
{
|
{
|
||||||
return ((4 + findLargestGroupSize() + 1) * line_height_) - 5;
|
return ((4 + findLargestGroupSize() + 1) * options_padding_) - 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el tamaño (número de opciones) del grupo más grande
|
// Devuelve el tamaño (número de opciones) del grupo más grande
|
||||||
|
|||||||
@@ -161,13 +161,22 @@ private:
|
|||||||
Color title_color_ = SERV_MENU_TITLE_COLOR; // Color del título del menú
|
Color title_color_ = SERV_MENU_TITLE_COLOR; // Color del título del menú
|
||||||
Color text_color_ = SERV_MENU_TEXT_COLOR; // Color del texto de los elementos
|
Color text_color_ = SERV_MENU_TEXT_COLOR; // Color del texto de los elementos
|
||||||
Color selected_color_ = SERV_MENU_SELECTED_COLOR; // Color del elemento seleccionado
|
Color selected_color_ = SERV_MENU_SELECTED_COLOR; // Color del elemento seleccionado
|
||||||
int width_; // Ancho del menú
|
size_t width_; // Ancho del menú
|
||||||
int height_; // Alto del menú
|
size_t height_; // Alto del menú
|
||||||
int line_height_; // Espacio entre elementos del menú
|
size_t options_height_; // Altura de cada elemento del menu
|
||||||
|
size_t options_padding_; // Espaciado vertical alrededor de cada elemento del menu
|
||||||
|
size_t options_y_; // Posicion del primer elemento del menu
|
||||||
|
size_t title_height_; // Altura del texto de titulo del menu
|
||||||
|
size_t title_padding_; // Espaciado vertical alrededor del titulo
|
||||||
|
size_t upper_height_; // Altura de la parte de arriba del menu: la del titulo
|
||||||
|
size_t lower_height_; // Altira de la parte baja del menu: la que tiene las opciones
|
||||||
|
size_t lower_padding_; // Espaciado vertical mínimo entre los bordes y el contenido de la zona inferior
|
||||||
|
|
||||||
// --- Métodos internos: Anclaje y aspecto ---
|
// --- Métodos internos: Anclaje y aspecto ---
|
||||||
void setAnchors(); // Establece el valor de las variables de anclaje
|
void setAnchors(); // Establece el valor de las variables de anclaje
|
||||||
Color getSelectedColor() const; // Devuelve el color del elemento seleccionado
|
Color getSelectedColor() const; // Devuelve el color del elemento seleccionado
|
||||||
|
void setOptionsPosition(); // Establce la posición donde empezar a escribir las opciones del menu
|
||||||
|
void resize(); // Cambia el tamaño de la ventana de menu
|
||||||
|
|
||||||
// --- Métodos internos: Gestión de opciones ---
|
// --- Métodos internos: Gestión de opciones ---
|
||||||
void initializeOptions(); // Crea todas las opciones del menú de servicio
|
void initializeOptions(); // Crea todas las opciones del menú de servicio
|
||||||
|
|||||||
Reference in New Issue
Block a user