621 lines
22 KiB
C++
621 lines
22 KiB
C++
#include "service_menu.h"
|
|
#include "screen.h"
|
|
#include <SDL3/SDL.h>
|
|
#include <array>
|
|
#include <string>
|
|
#include "text.h"
|
|
#include "resource.h"
|
|
#include "options.h"
|
|
#include "section.h" // Para Name, name, Options, options, AttractMode
|
|
#include "audio.h"
|
|
#include <unordered_map>
|
|
#include "lang.h"
|
|
|
|
// Singleton
|
|
ServiceMenu *ServiceMenu::instance_ = nullptr;
|
|
|
|
// Inicializa la instancia única del singleton
|
|
void ServiceMenu::init() { ServiceMenu::instance_ = new ServiceMenu(); }
|
|
|
|
// Libera la instancia única del singleton
|
|
void ServiceMenu::destroy() { delete ServiceMenu::instance_; }
|
|
|
|
// Devuelve la instancia única del singleton
|
|
ServiceMenu *ServiceMenu::get() { return ServiceMenu::instance_; }
|
|
|
|
// Constructor de ServiceMenu
|
|
ServiceMenu::ServiceMenu()
|
|
: element_text_(Resource::get()->getText("04b_25_flat")),
|
|
title_text_(Resource::get()->getText("04b_25_flat_2x")),
|
|
current_settings_group_(SettingsGroup::MAIN),
|
|
previous_settings_group_(current_settings_group_)
|
|
{
|
|
reset();
|
|
}
|
|
|
|
// Alterna la visibilidad del menú de servicio
|
|
void ServiceMenu::toggle()
|
|
{
|
|
enabled_ = !enabled_;
|
|
if (!enabled_)
|
|
{
|
|
reset();
|
|
}
|
|
}
|
|
|
|
// Dibuja el menú de servicio en pantalla
|
|
void ServiceMenu::render()
|
|
{
|
|
if (enabled_)
|
|
{
|
|
int y = rect_.y;
|
|
|
|
// SOMBRA
|
|
if (aspect_ == Aspect::ASPECT1)
|
|
{
|
|
SDL_FRect shadowRect = {rect_.x + 5, rect_.y + 5, rect_.w, rect_.h};
|
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 64);
|
|
SDL_RenderFillRect(Screen::get()->getRenderer(), &shadowRect);
|
|
}
|
|
|
|
// FONDO
|
|
const Uint8 ALPHA = aspect_ == Aspect::ASPECT1 ? 255 : 255;
|
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), bg_color_.r, bg_color_.g, bg_color_.b, ALPHA);
|
|
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect_);
|
|
|
|
// BORDE
|
|
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, title_, -4, title_color_);
|
|
|
|
// LINEA
|
|
y = rect_.y + upper_height_;
|
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), Options::pending_changes.has_pending_changes ? 0 : 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)
|
|
{
|
|
if (getGroupAlignment(current_settings_group_) == GroupAlignment::LEFT)
|
|
{
|
|
// Nombre de la opción
|
|
element_text_->writeColored(rect_.x + OPTIONS_HORIZONTAL_PADDING_, y, option_pairs_.at(i).first, i == selected_ ? selected_color_ : text_color_, -2);
|
|
// Valor de la opción
|
|
const int X = rect_.x + rect_.w - OPTIONS_HORIZONTAL_PADDING_ - element_text_->lenght(std::string(option_pairs_.at(i).second), -2);
|
|
element_text_->writeColored(X, y, std::string(option_pairs_.at(i).second), i == selected_ ? selected_color_ : text_color_, -2);
|
|
}
|
|
else
|
|
{
|
|
// 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_;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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();
|
|
selected_color_ = getSelectedColor();
|
|
}
|
|
}
|
|
|
|
// Calcula y establece los anclajes y dimensiones del menú
|
|
void ServiceMenu::setAnchors()
|
|
{
|
|
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_ = 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()
|
|
{
|
|
resize();
|
|
// 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()
|
|
{
|
|
// Usa el ancho precalculado para el grupo actual
|
|
int menu_width = getMenuWidthForGroup(current_settings_group_);
|
|
width_ = menu_width;
|
|
lower_height_ = ((display_options_.size() - 1) * (options_height_ + options_padding_)) + options_height_ + (lower_padding_ * 2);
|
|
height_ = upper_height_ + lower_height_;
|
|
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
|
|
void ServiceMenu::updateCounter()
|
|
{
|
|
static Uint64 lastUpdate = SDL_GetTicks();
|
|
Uint64 currentTicks = SDL_GetTicks();
|
|
if (currentTicks - lastUpdate >= 50)
|
|
{
|
|
counter_++;
|
|
lastUpdate = currentTicks;
|
|
}
|
|
}
|
|
|
|
// Devuelve el color actual del elemento seleccionado (animado)
|
|
Color ServiceMenu::getSelectedColor() const
|
|
{
|
|
static std::array<Color, 12> colors = {
|
|
Color(0xFF, 0xFB, 0x8A), // Amarillo suave
|
|
Color(0xFF, 0xE4, 0x5D), // Dorado medio
|
|
Color(0xFF, 0xD1, 0x3C), // Amarillo pastel intenso
|
|
Color(0xFF, 0xBF, 0x23), // Amarillo anaranjado
|
|
Color(0xFF, 0xAA, 0x12), // Amarillo cálido
|
|
Color(0xE6, 0x9A, 0x08), // Mostaza oscuro
|
|
Color(0xE6, 0x9A, 0x08), // Mostaza oscuro (regreso, cierre)
|
|
Color(0xFF, 0xAA, 0x12), // Amarillo cálido (regreso)
|
|
Color(0xFF, 0xBF, 0x23), // Amarillo anaranjado (regreso)
|
|
Color(0xFF, 0xD1, 0x3C), // Amarillo pastel intenso (regreso)
|
|
Color(0xFF, 0xE4, 0x5D), // Dorado medio (regreso)
|
|
Color(0xFF, 0xFB, 0x8A) // Amarillo suave (regreso)
|
|
};
|
|
|
|
const size_t index = counter_ % colors.size();
|
|
|
|
return colors.at(index);
|
|
}
|
|
|
|
// Método privado para reproducir el sonido del menú
|
|
void ServiceMenu::playMenuSound()
|
|
{
|
|
Audio::get()->playSound(MENU_SOUND_);
|
|
}
|
|
|
|
// Mueve el selector hacia arriba en la lista de opciones
|
|
void ServiceMenu::setSelectorUp()
|
|
{
|
|
if (display_options_.empty())
|
|
return;
|
|
selected_ = (selected_ > 0) ? selected_ - 1 : display_options_.size() - 1;
|
|
playMenuSound();
|
|
}
|
|
|
|
// Mueve el selector hacia abajo en la lista de opciones
|
|
void ServiceMenu::setSelectorDown()
|
|
{
|
|
if (display_options_.empty())
|
|
return;
|
|
selected_ = (selected_ + 1) % display_options_.size();
|
|
playMenuSound();
|
|
}
|
|
|
|
// Ajusta el valor de la opción seleccionada (si es ajustable)
|
|
void ServiceMenu::adjustOption(bool adjust_up)
|
|
{
|
|
if (display_options_.empty() || selected_ >= display_options_.size())
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (display_options_.at(selected_)->behavior == OptionBehavior::ADJUST)
|
|
{
|
|
display_options_.at(selected_)->adjustValue(adjust_up);
|
|
option_pairs_ = getOptionPairs(current_settings_group_);
|
|
applySettings(current_settings_group_);
|
|
playMenuSound();
|
|
}
|
|
}
|
|
|
|
// Ejecuta la acción de la opción seleccionada o navega a un submenú
|
|
void ServiceMenu::selectOption()
|
|
{
|
|
if (display_options_.empty() || selected_ >= display_options_.size())
|
|
return;
|
|
|
|
// Si estamos en el menú principal, guarda la selección actual
|
|
if (current_settings_group_ == SettingsGroup::MAIN)
|
|
main_menu_selected_ = selected_;
|
|
|
|
// Carpeta
|
|
if (display_options_.at(selected_)->type == ValueType::FOLDER)
|
|
{
|
|
previous_settings_group_ = current_settings_group_;
|
|
current_settings_group_ = display_options_.at(selected_)->target_group;
|
|
title_ = settingsGroupToString(current_settings_group_);
|
|
updateMenu(current_settings_group_);
|
|
selected_ = 0;
|
|
setOptionsPosition();
|
|
playMenuSound();
|
|
return;
|
|
}
|
|
|
|
// Opción
|
|
if (display_options_.at(selected_)->behavior == OptionBehavior::SELECT)
|
|
{
|
|
if (display_options_.at(selected_)->caption == Lang::getText("[SERVICE_MENU] RESET"))
|
|
{
|
|
Section::name = Section::Name::RESET;
|
|
toggle();
|
|
return;
|
|
}
|
|
else if (display_options_.at(selected_)->caption == Lang::getText("[SERVICE_MENU] QUIT"))
|
|
{
|
|
Section::name = Section::Name::QUIT;
|
|
Section::options = Section::Options::NONE;
|
|
return;
|
|
}
|
|
else if (display_options_.at(selected_)->caption == Lang::getText("[SERVICE_MENU] SHUTDOWN"))
|
|
{
|
|
Section::name = Section::Name::QUIT;
|
|
Section::options = Section::Options::SHUTDOWN;
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Vuelve al grupo de opciones anterior o cierra el menú si está en el principal
|
|
void ServiceMenu::moveBack()
|
|
{
|
|
if (current_settings_group_ == SettingsGroup::MAIN)
|
|
{
|
|
enabled_ = false;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
// Si vamos a volver al menú principal, restaura la selección guardada
|
|
if (previous_settings_group_ == SettingsGroup::MAIN)
|
|
selected_ = main_menu_selected_;
|
|
else
|
|
selected_ = 0;
|
|
|
|
current_settings_group_ = previous_settings_group_;
|
|
updateMenu(current_settings_group_);
|
|
setOptionsPosition();
|
|
playMenuSound();
|
|
}
|
|
}
|
|
|
|
// 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);
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] SHADERS"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &Options::video.shaders, ValueType::BOOL);
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] VSYNC"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &Options::video.v_sync, ValueType::BOOL);
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] INTEGER_SCALE"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &Options::video.integer_scale, ValueType::BOOL);
|
|
|
|
// Audio
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] AUDIO"), SettingsGroup::AUDIO, OptionBehavior::ADJUST, &Options::audio.enabled, ValueType::BOOL);
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] MAIN_VOLUME"), SettingsGroup::AUDIO, OptionBehavior::ADJUST, &Options::audio.volume, ValueType::INT, 0, 100, 5);
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] MUSIC_VOLUME"), SettingsGroup::AUDIO, OptionBehavior::ADJUST, &Options::audio.music.volume, ValueType::INT, 0, 100, 5);
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] SFX_VOLUME"), SettingsGroup::AUDIO, OptionBehavior::ADJUST, &Options::audio.sound.volume, ValueType::INT, 0, 100, 5);
|
|
|
|
// Settings
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] AUTOFIRE"), SettingsGroup::SETTINGS, OptionBehavior::ADJUST, &Options::settings.autofire, ValueType::BOOL);
|
|
options_.emplace_back(
|
|
Lang::getText("[SERVICE_MENU] LANGUAGE"),
|
|
SettingsGroup::SETTINGS,
|
|
OptionBehavior::ADJUST,
|
|
&Options::pending_changes.new_language,
|
|
std::vector<std::string>{
|
|
Lang::getText("[SERVICE_MENU] LANG_ES"),
|
|
Lang::getText("[SERVICE_MENU] LANG_BA"),
|
|
Lang::getText("[SERVICE_MENU] LANG_EN")});
|
|
options_.emplace_back(
|
|
Lang::getText("[SERVICE_MENU] DIFFICULTY"),
|
|
SettingsGroup::SETTINGS,
|
|
OptionBehavior::ADJUST,
|
|
&Options::pending_changes.new_difficulty,
|
|
std::vector<std::string>{
|
|
Lang::getText("[SERVICE_MENU] EASY"),
|
|
Lang::getText("[SERVICE_MENU] NORMAL"),
|
|
Lang::getText("[SERVICE_MENU] HARD")});
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] ENABLE_SHUTDOWN"), SettingsGroup::SETTINGS, OptionBehavior::ADJUST, &Options::settings.shutdown_enabled, ValueType::BOOL);
|
|
|
|
// System
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] RESET"), SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE);
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] QUIT"), SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE);
|
|
if (Options::settings.shutdown_enabled)
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] SHUTDOWN"), SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE);
|
|
|
|
// Menu principal
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] VIDEO"), SettingsGroup::MAIN, OptionBehavior::SELECT, SettingsGroup::VIDEO);
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] AUDIO"), SettingsGroup::MAIN, OptionBehavior::SELECT, SettingsGroup::AUDIO);
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] SETTINGS"), SettingsGroup::MAIN, OptionBehavior::SELECT, SettingsGroup::SETTINGS);
|
|
options_.emplace_back(Lang::getText("[SERVICE_MENU] SYSTEM"), SettingsGroup::MAIN, OptionBehavior::SELECT, SettingsGroup::SYSTEM);
|
|
|
|
// Al terminar de inicializar las opciones, recalcula los anchos de menú
|
|
precalculateMenuWidths();
|
|
}
|
|
|
|
// Devuelve las opciones del grupo como pares (nombre, valor)
|
|
ServiceMenu::OptionPairs ServiceMenu::getOptionPairs(ServiceMenu::SettingsGroup group) const
|
|
{
|
|
OptionPairs option_pairs;
|
|
|
|
for (const auto &option : options_)
|
|
{
|
|
if (option.group == group)
|
|
{
|
|
option_pairs.emplace_back(option.caption, option.getValueAsString());
|
|
}
|
|
}
|
|
|
|
return option_pairs;
|
|
}
|
|
|
|
// Devuelve las opciones del grupo como un vector de OptionEntry
|
|
std::vector<ServiceMenu::OptionEntry *> ServiceMenu::getOptionsByGroup(SettingsGroup group)
|
|
{
|
|
std::vector<OptionEntry *> filtered_options;
|
|
for (auto &option : options_)
|
|
{
|
|
if (option.group == group)
|
|
{
|
|
filtered_options.push_back(&option);
|
|
}
|
|
}
|
|
return filtered_options;
|
|
}
|
|
|
|
// Aplica la configuración correspondiente al grupo seleccionado
|
|
void ServiceMenu::applySettings(ServiceMenu::SettingsGroup group)
|
|
{
|
|
switch (group)
|
|
{
|
|
case SettingsGroup::VIDEO:
|
|
Screen::get()->applySettings();
|
|
break;
|
|
case SettingsGroup::AUDIO:
|
|
Audio::get()->applySettings();
|
|
break;
|
|
case SettingsGroup::SETTINGS:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Actualiza las opciones mostradas según el grupo seleccionado
|
|
void ServiceMenu::updateMenu(SettingsGroup group)
|
|
{
|
|
title_ = settingsGroupToString(group);
|
|
AdjustListValues();
|
|
option_pairs_ = getOptionPairs(group);
|
|
display_options_ = getOptionsByGroup(group);
|
|
// Recalcula el ancho del menú al cambiar de grupo
|
|
resize();
|
|
}
|
|
|
|
// Reinicia el menú al estado inicial (grupo principal y opción seleccionada)
|
|
void ServiceMenu::reset()
|
|
{
|
|
selected_ = 0;
|
|
previous_settings_group_ = current_settings_group_ = SettingsGroup::MAIN;
|
|
title_ = settingsGroupToString(current_settings_group_);
|
|
initializeOptions();
|
|
updateMenu(current_settings_group_);
|
|
setAnchors();
|
|
}
|
|
|
|
// Calcula la altura total del menú en píxeles
|
|
int ServiceMenu::calculateMenuHeight() const
|
|
{
|
|
return ((4 + findLargestGroupSize() + 1) * options_padding_) - 5;
|
|
}
|
|
|
|
// Devuelve el tamaño (número de opciones) del grupo más grande
|
|
int ServiceMenu::findLargestGroupSize() const
|
|
{
|
|
std::unordered_map<SettingsGroup, int> group_counts;
|
|
for (const auto &option : options_)
|
|
++group_counts[option.group];
|
|
|
|
int max_size = 0;
|
|
for (const auto &pair : group_counts)
|
|
if (pair.second > max_size)
|
|
max_size = pair.second;
|
|
return max_size;
|
|
}
|
|
|
|
// Devuelve la alineación de las opciones para el grupo dado
|
|
ServiceMenu::GroupAlignment ServiceMenu::getGroupAlignment(SettingsGroup group) const
|
|
{
|
|
switch (group)
|
|
{
|
|
case SettingsGroup::VIDEO:
|
|
case SettingsGroup::AUDIO:
|
|
case SettingsGroup::SETTINGS:
|
|
return GroupAlignment::LEFT;
|
|
default:
|
|
return GroupAlignment::CENTERED;
|
|
}
|
|
}
|
|
|
|
// Devuelve un puntero a OptionEntry a partir del caption, o nullptr si no se encuentra
|
|
ServiceMenu::OptionEntry *ServiceMenu::getOptionEntryByCaption(const std::string &caption)
|
|
{
|
|
for (auto &option : options_)
|
|
{
|
|
if (option.caption == caption)
|
|
{
|
|
return &option;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
// Pone el texto que corresponde al valor de la variable en las opciones de tipo lista
|
|
void ServiceMenu::AdjustListValues()
|
|
{
|
|
{ // Idioma
|
|
auto option = getOptionEntryByCaption(Lang::getText("[SERVICE_MENU] LANGUAGE"));
|
|
for (size_t i = 0; i < option->value_list.size(); ++i)
|
|
{
|
|
if (Lang::getCodeFromName(option->value_list[i]) == Options::pending_changes.new_language)
|
|
{
|
|
option->list_index = i;
|
|
}
|
|
}
|
|
}
|
|
|
|
{ // Dificultad
|
|
auto option = getOptionEntryByCaption(Lang::getText("[SERVICE_MENU] DIFFICULTY"));
|
|
for (size_t i = 0; i < option->value_list.size(); ++i)
|
|
{
|
|
if (Options::getDifficultyCodeFromName(option->value_list[i]) == Options::pending_changes.new_difficulty)
|
|
{
|
|
option->list_index = i;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void ServiceMenu::precalculateMenuWidths()
|
|
{
|
|
// Inicializa todos los anchos al mínimo
|
|
for (int &w : group_menu_widths_)
|
|
w = MIN_WIDTH_;
|
|
|
|
// Para cada grupo
|
|
for (int group = 0; group < 5; ++group)
|
|
{
|
|
SettingsGroup sg = static_cast<SettingsGroup>(group);
|
|
int max_option_width = 0;
|
|
int max_value_width = 0;
|
|
for (const auto &option : options_)
|
|
{
|
|
if (option.group != sg)
|
|
continue;
|
|
// Opción más larga
|
|
max_option_width = std::max(max_option_width, element_text_->lenght(option.caption, -2));
|
|
// Valor más largo de todos los posibles valores de todas las opciones
|
|
switch (option.type)
|
|
{
|
|
case ValueType::BOOL:
|
|
max_value_width = std::max({max_value_width,
|
|
element_text_->lenght(Lang::getText("[SERVICE_MENU] ON"), -2),
|
|
element_text_->lenght(Lang::getText("[SERVICE_MENU] OFF"), -2)});
|
|
break;
|
|
case ValueType::INT:
|
|
max_value_width = std::max({max_value_width,
|
|
element_text_->lenght(std::to_string(option.min_value), -2),
|
|
element_text_->lenght(std::to_string(option.max_value), -2)});
|
|
break;
|
|
case ValueType::LIST:
|
|
for (const auto &val : option.value_list)
|
|
max_value_width = std::max(max_value_width, element_text_->lenght(val, -2));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
size_t total_width = max_option_width + MIN_GAP_OPTION_VALUE_ + max_value_width + (OPTIONS_HORIZONTAL_PADDING_ * 2);
|
|
group_menu_widths_[group] = std::max(MIN_WIDTH_, total_width);
|
|
}
|
|
}
|
|
|
|
int ServiceMenu::getMenuWidthForGroup(SettingsGroup group) const
|
|
{
|
|
return group_menu_widths_[static_cast<int>(group)];
|
|
}
|
|
|
|
std::string ServiceMenu::settingsGroupToString(SettingsGroup group) const
|
|
{
|
|
switch (group)
|
|
{
|
|
case SettingsGroup::MAIN:
|
|
return Lang::getText("[SERVICE_MENU] TITLE");
|
|
case SettingsGroup::VIDEO:
|
|
return Lang::getText("[SERVICE_MENU] VIDEO");
|
|
case SettingsGroup::AUDIO:
|
|
return Lang::getText("[SERVICE_MENU] AUDIO");
|
|
case SettingsGroup::SETTINGS:
|
|
return Lang::getText("[SERVICE_MENU] SETTINGS");
|
|
case SettingsGroup::SYSTEM:
|
|
return Lang::getText("[SERVICE_MENU] SYSTEM");
|
|
default:
|
|
return Lang::getText("[SERVICE_MENU] TITLE");
|
|
}
|
|
} |