Compare commits
2 Commits
06fc8c8579
...
0c00bf5770
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c00bf5770 | |||
| 0f17dd50db |
@@ -626,6 +626,7 @@ void Director::runInit()
|
||||
{
|
||||
Resource::get()->reload();
|
||||
}
|
||||
ServiceMenu::get()->reset();
|
||||
section::name = section::Name::LOGO;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,16 +30,15 @@ ServiceMenu::ServiceMenu()
|
||||
current_settings_group_(SettingsGroup::MAIN),
|
||||
previous_settings_group_(current_settings_group_)
|
||||
{
|
||||
initializeOptions();
|
||||
setAnchors();
|
||||
updateMenu(current_settings_group_);
|
||||
reset();
|
||||
}
|
||||
|
||||
// Alterna la visibilidad del menú de servicio
|
||||
void ServiceMenu::toggle()
|
||||
{
|
||||
enabled_ = !enabled_;
|
||||
reset();
|
||||
if (!enabled_)
|
||||
reset();
|
||||
}
|
||||
|
||||
// Dibuja el menú de servicio en pantalla
|
||||
@@ -67,18 +66,18 @@ void ServiceMenu::render()
|
||||
SDL_RenderRect(Screen::get()->getRenderer(), &rect_);
|
||||
|
||||
// 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_);
|
||||
|
||||
// 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_RenderLine(Screen::get()->getRenderer(), rect_.x + OPTIONS_HORIZONTAL_PADDING_, y, rect_.x + rect_.w - OPTIONS_HORIZONTAL_PADDING_, y);
|
||||
|
||||
// OPCIONES
|
||||
y = options_y_;
|
||||
for (size_t i = 0; i < option_pairs_.size(); ++i)
|
||||
{
|
||||
y += line_height_;
|
||||
if (getGroupAlignment(current_settings_group_) == GroupAlignment::LEFT)
|
||||
{
|
||||
// Nombre de la opción
|
||||
@@ -92,6 +91,7 @@ void ServiceMenu::render()
|
||||
// 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_);
|
||||
}
|
||||
y += options_height_ + options_padding_;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,9 +109,49 @@ void ServiceMenu::update()
|
||||
// Calcula y establece los anclajes y dimensiones del menú
|
||||
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;
|
||||
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_ = {
|
||||
(param.game.width - width_) / 2,
|
||||
(param.game.height - height_) / 2,
|
||||
@@ -206,6 +246,7 @@ void ServiceMenu::selectOption()
|
||||
current_settings_group_ = display_options_.at(selected_).target_group;
|
||||
updateMenu(current_settings_group_);
|
||||
selected_ = 0;
|
||||
setOptionsPosition();
|
||||
playMenuSound();
|
||||
return;
|
||||
}
|
||||
@@ -248,6 +289,7 @@ void ServiceMenu::moveBack()
|
||||
selected_ = 0;
|
||||
current_settings_group_ = previous_settings_group_;
|
||||
updateMenu(current_settings_group_);
|
||||
setOptionsPosition();
|
||||
playMenuSound();
|
||||
}
|
||||
}
|
||||
@@ -255,6 +297,8 @@ void ServiceMenu::moveBack()
|
||||
// Inicializa todas las opciones del menú de servicio
|
||||
void ServiceMenu::initializeOptions()
|
||||
{
|
||||
options_.clear();
|
||||
|
||||
// Video
|
||||
options_.emplace_back(lang::getText("[SERVICE_MENU] FULLSCREEN"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.video.fullscreen, ValueType::BOOL);
|
||||
options_.emplace_back(lang::getText("[SERVICE_MENU] WINDOW_SIZE"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.window.size, ValueType::INT, 1, options.window.max_size, 1);
|
||||
@@ -345,13 +389,15 @@ void ServiceMenu::reset()
|
||||
{
|
||||
selected_ = 0;
|
||||
previous_settings_group_ = current_settings_group_ = SettingsGroup::MAIN;
|
||||
initializeOptions();
|
||||
updateMenu(current_settings_group_);
|
||||
setAnchors();
|
||||
}
|
||||
|
||||
// Calcula la altura total del menú en píxeles
|
||||
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
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
void toggle(); // Muestra u oculta el menú de servicio
|
||||
void render(); // Dibuja el menú de servicio en pantalla
|
||||
void update(); // Actualiza el estado del menú de servicio
|
||||
void reset(); // Reinicia el menú al estado inicial
|
||||
|
||||
// --- Métodos de control de navegación ---
|
||||
void setSelectorUp(); // Mueve el selector hacia arriba
|
||||
@@ -160,13 +161,22 @@ private:
|
||||
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 selected_color_ = SERV_MENU_SELECTED_COLOR; // Color del elemento seleccionado
|
||||
int width_; // Ancho del menú
|
||||
int height_; // Alto del menú
|
||||
int line_height_; // Espacio entre elementos del menú
|
||||
size_t width_; // Ancho del menú
|
||||
size_t height_; // Alto 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 ---
|
||||
void setAnchors(); // Establece el valor de las variables de anclaje
|
||||
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 ---
|
||||
void initializeOptions(); // Crea todas las opciones del menú de servicio
|
||||
@@ -176,7 +186,6 @@ private:
|
||||
// --- Métodos internos: Lógica de menú ---
|
||||
void applySettings(SettingsGroup group); // Aplica la configuración de un grupo
|
||||
void updateMenu(SettingsGroup group); // Actualiza las opciones mostradas según el grupo
|
||||
void reset(); // Reinicia el menú al estado inicial
|
||||
|
||||
// --- Métodos internos: Utilidades ---
|
||||
void updateCounter(); // Actualiza el contador interno
|
||||
|
||||
Reference in New Issue
Block a user