ServiceMenu: optimitzacions
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "section.h" // Para Name, name, Options, options, AttractMode
|
#include "section.h" // Para Name, name, Options, options, AttractMode
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
// Singleton
|
// Singleton
|
||||||
ServiceMenu *ServiceMenu::instance_ = nullptr;
|
ServiceMenu *ServiceMenu::instance_ = nullptr;
|
||||||
@@ -15,13 +16,13 @@ ServiceMenu *ServiceMenu::instance_ = nullptr;
|
|||||||
// Inicializa la instancia única del singleton
|
// Inicializa la instancia única del singleton
|
||||||
void ServiceMenu::init() { ServiceMenu::instance_ = new ServiceMenu(); }
|
void ServiceMenu::init() { ServiceMenu::instance_ = new ServiceMenu(); }
|
||||||
|
|
||||||
// Libera la instancia
|
// Libera la instancia única del singleton
|
||||||
void ServiceMenu::destroy() { delete ServiceMenu::instance_; }
|
void ServiceMenu::destroy() { delete ServiceMenu::instance_; }
|
||||||
|
|
||||||
// Obtiene la instancia
|
// Devuelve la instancia única del singleton
|
||||||
ServiceMenu *ServiceMenu::get() { return ServiceMenu::instance_; }
|
ServiceMenu *ServiceMenu::get() { return ServiceMenu::instance_; }
|
||||||
|
|
||||||
// Constructor
|
// Constructor de ServiceMenu
|
||||||
ServiceMenu::ServiceMenu()
|
ServiceMenu::ServiceMenu()
|
||||||
: element_text_(Resource::get()->getText("04b_25_flat")),
|
: element_text_(Resource::get()->getText("04b_25_flat")),
|
||||||
title_text_(Resource::get()->getText("04b_25_flat_2x")),
|
title_text_(Resource::get()->getText("04b_25_flat_2x")),
|
||||||
@@ -33,12 +34,14 @@ ServiceMenu::ServiceMenu()
|
|||||||
updateMenu(current_settings_group_);
|
updateMenu(current_settings_group_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Alterna la visibilidad del menú de servicio
|
||||||
void ServiceMenu::toggle()
|
void ServiceMenu::toggle()
|
||||||
{
|
{
|
||||||
enabled_ = !enabled_;
|
enabled_ = !enabled_;
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dibuja el menú de servicio en pantalla
|
||||||
void ServiceMenu::render()
|
void ServiceMenu::render()
|
||||||
{
|
{
|
||||||
if (enabled_)
|
if (enabled_)
|
||||||
@@ -62,7 +65,7 @@ void ServiceMenu::render()
|
|||||||
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_RenderRect(Screen::get()->getRenderer(), &rect_);
|
SDL_RenderRect(Screen::get()->getRenderer(), &rect_);
|
||||||
|
|
||||||
// SERVICE MENU
|
// TITULO
|
||||||
y += line_height_;
|
y += line_height_;
|
||||||
title_text_->writeDX(TEXT_COLOR | TEXT_CENTER, param.game.game_area.center_x, y, "SERVICE MENU", -4, title_color_);
|
title_text_->writeDX(TEXT_COLOR | TEXT_CENTER, param.game.game_area.center_x, y, "SERVICE MENU", -4, title_color_);
|
||||||
|
|
||||||
@@ -71,7 +74,7 @@ void ServiceMenu::render()
|
|||||||
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);
|
||||||
|
|
||||||
// LIST
|
// OPCIONES
|
||||||
for (size_t i = 0; i < option_pairs_.size(); ++i)
|
for (size_t i = 0; i < option_pairs_.size(); ++i)
|
||||||
{
|
{
|
||||||
y += line_height_;
|
y += line_height_;
|
||||||
@@ -99,6 +102,7 @@ void ServiceMenu::render()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualiza el estado del menú de servicio (colores, animaciones, etc.)
|
||||||
void ServiceMenu::update()
|
void ServiceMenu::update()
|
||||||
{
|
{
|
||||||
if (enabled_)
|
if (enabled_)
|
||||||
@@ -108,6 +112,7 @@ void ServiceMenu::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calcula y establece los anclajes y dimensiones del menú
|
||||||
void ServiceMenu::setAnchors()
|
void ServiceMenu::setAnchors()
|
||||||
{
|
{
|
||||||
line_height_ = element_text_->getCharacterSize() + 5;
|
line_height_ = element_text_->getCharacterSize() + 5;
|
||||||
@@ -120,6 +125,7 @@ void ServiceMenu::setAnchors()
|
|||||||
static_cast<float>(height_)};
|
static_cast<float>(height_)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualiza el contador interno para animaciones o efectos visuales
|
||||||
void ServiceMenu::updateCounter()
|
void ServiceMenu::updateCounter()
|
||||||
{
|
{
|
||||||
static Uint64 lastUpdate = SDL_GetTicks();
|
static Uint64 lastUpdate = SDL_GetTicks();
|
||||||
@@ -131,7 +137,8 @@ void ServiceMenu::updateCounter()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Color ServiceMenu::getSelectedColor()
|
// Devuelve el color actual del elemento seleccionado (animado)
|
||||||
|
Color ServiceMenu::getSelectedColor() const
|
||||||
{
|
{
|
||||||
static std::array<Color, 12> colors = {
|
static std::array<Color, 12> colors = {
|
||||||
Color(0xFF, 0xFB, 0x8A), // Amarillo suave
|
Color(0xFF, 0xFB, 0x8A), // Amarillo suave
|
||||||
@@ -153,31 +160,51 @@ Color ServiceMenu::getSelectedColor()
|
|||||||
return colors.at(index);
|
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()
|
void ServiceMenu::setSelectorUp()
|
||||||
{
|
{
|
||||||
|
if (display_options_.empty())
|
||||||
|
return;
|
||||||
selected_ = (selected_ > 0) ? --selected_ : display_options_.size() - 1;
|
selected_ = (selected_ > 0) ? --selected_ : display_options_.size() - 1;
|
||||||
Audio::get()->playSound(MENU_SOUND_);
|
playMenuSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mueve el selector hacia abajo en la lista de opciones
|
||||||
void ServiceMenu::setSelectorDown()
|
void ServiceMenu::setSelectorDown()
|
||||||
{
|
{
|
||||||
|
if (display_options_.empty())
|
||||||
|
return;
|
||||||
selected_ = (selected_ + 1) % display_options_.size();
|
selected_ = (selected_ + 1) % display_options_.size();
|
||||||
Audio::get()->playSound(MENU_SOUND_);
|
playMenuSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ajusta el valor de la opción seleccionada (si es ajustable)
|
||||||
void ServiceMenu::adjustOption(bool adjust_up)
|
void ServiceMenu::adjustOption(bool adjust_up)
|
||||||
{
|
{
|
||||||
|
if (display_options_.empty() || selected_ >= display_options_.size())
|
||||||
|
return;
|
||||||
|
|
||||||
if (display_options_.at(selected_).behavior == OptionBehavior::ADJUST)
|
if (display_options_.at(selected_).behavior == OptionBehavior::ADJUST)
|
||||||
{
|
{
|
||||||
display_options_.at(selected_).adjustValue(adjust_up);
|
display_options_.at(selected_).adjustValue(adjust_up);
|
||||||
option_pairs_ = getOptionPairs(current_settings_group_);
|
option_pairs_ = getOptionPairs(current_settings_group_);
|
||||||
applySettings(current_settings_group_);
|
applySettings(current_settings_group_);
|
||||||
Audio::get()->playSound(MENU_SOUND_);
|
playMenuSound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ejecuta la acción de la opción seleccionada o navega a un submenú
|
||||||
void ServiceMenu::selectOption()
|
void ServiceMenu::selectOption()
|
||||||
{
|
{
|
||||||
|
if (display_options_.empty() || selected_ >= display_options_.size())
|
||||||
|
return;
|
||||||
|
|
||||||
// Carpeta
|
// Carpeta
|
||||||
if (display_options_.at(selected_).type == ValueType::FOLDER)
|
if (display_options_.at(selected_).type == ValueType::FOLDER)
|
||||||
{
|
{
|
||||||
@@ -185,7 +212,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;
|
||||||
Audio::get()->playSound(MENU_SOUND_);
|
playMenuSound();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,6 +241,7 @@ void ServiceMenu::selectOption()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Vuelve al grupo de opciones anterior o cierra el menú si está en el principal
|
||||||
void ServiceMenu::moveBack()
|
void ServiceMenu::moveBack()
|
||||||
{
|
{
|
||||||
if (current_settings_group_ == SettingsGroup::MAIN)
|
if (current_settings_group_ == SettingsGroup::MAIN)
|
||||||
@@ -226,10 +254,11 @@ 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_);
|
||||||
Audio::get()->playSound(MENU_SOUND_);
|
playMenuSound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inicializa todas las opciones del menú de servicio
|
||||||
void ServiceMenu::initializeOptions()
|
void ServiceMenu::initializeOptions()
|
||||||
{
|
{
|
||||||
// Video
|
// Video
|
||||||
@@ -261,6 +290,7 @@ void ServiceMenu::initializeOptions()
|
|||||||
options_.emplace_back("SYSTEM", SettingsGroup::MAIN, OptionBehavior::SELECT, SettingsGroup::SYSTEM);
|
options_.emplace_back("SYSTEM", SettingsGroup::MAIN, OptionBehavior::SELECT, SettingsGroup::SYSTEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Devuelve las opciones del grupo como pares (nombre, valor)
|
||||||
ServiceMenu::OptionPairs ServiceMenu::getOptionPairs(ServiceMenu::SettingsGroup group) const
|
ServiceMenu::OptionPairs ServiceMenu::getOptionPairs(ServiceMenu::SettingsGroup group) const
|
||||||
{
|
{
|
||||||
OptionPairs optionPairs;
|
OptionPairs optionPairs;
|
||||||
@@ -276,6 +306,7 @@ ServiceMenu::OptionPairs ServiceMenu::getOptionPairs(ServiceMenu::SettingsGroup
|
|||||||
return optionPairs;
|
return optionPairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Devuelve las opciones del grupo como un vector de OptionEntry
|
||||||
std::vector<ServiceMenu::OptionEntry> ServiceMenu::getOptionsByGroup(SettingsGroup group) const
|
std::vector<ServiceMenu::OptionEntry> ServiceMenu::getOptionsByGroup(SettingsGroup group) const
|
||||||
{
|
{
|
||||||
std::vector<OptionEntry> filteredOptions;
|
std::vector<OptionEntry> filteredOptions;
|
||||||
@@ -291,6 +322,7 @@ std::vector<ServiceMenu::OptionEntry> ServiceMenu::getOptionsByGroup(SettingsGro
|
|||||||
return filteredOptions;
|
return filteredOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Aplica la configuración correspondiente al grupo seleccionado
|
||||||
void ServiceMenu::applySettings(ServiceMenu::SettingsGroup group)
|
void ServiceMenu::applySettings(ServiceMenu::SettingsGroup group)
|
||||||
{
|
{
|
||||||
switch (group)
|
switch (group)
|
||||||
@@ -308,12 +340,14 @@ void ServiceMenu::applySettings(ServiceMenu::SettingsGroup group)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualiza las opciones mostradas según el grupo seleccionado
|
||||||
void ServiceMenu::updateMenu(SettingsGroup group)
|
void ServiceMenu::updateMenu(SettingsGroup group)
|
||||||
{
|
{
|
||||||
option_pairs_ = getOptionPairs(group);
|
option_pairs_ = getOptionPairs(group);
|
||||||
display_options_ = getOptionsByGroup(group);
|
display_options_ = getOptionsByGroup(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reinicia el menú al estado inicial (grupo principal y opción seleccionada)
|
||||||
void ServiceMenu::reset()
|
void ServiceMenu::reset()
|
||||||
{
|
{
|
||||||
selected_ = 0;
|
selected_ = 0;
|
||||||
@@ -321,30 +355,28 @@ void ServiceMenu::reset()
|
|||||||
updateMenu(current_settings_group_);
|
updateMenu(current_settings_group_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServiceMenu::calculateMenuHeight()
|
// Calcula la altura total del menú en píxeles
|
||||||
|
int ServiceMenu::calculateMenuHeight() const
|
||||||
{
|
{
|
||||||
return ((4 + findLargestGroupSize() + 1) * line_height_) - 5;
|
return ((4 + findLargestGroupSize() + 1) * line_height_) - 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServiceMenu::findLargestGroupSize()
|
// Devuelve el tamaño (número de opciones) del grupo más grande
|
||||||
|
int ServiceMenu::findLargestGroupSize() const
|
||||||
{
|
{
|
||||||
int max_size = 0;
|
std::unordered_map<SettingsGroup, int> group_counts;
|
||||||
// Recorremos todos los posibles grupos
|
|
||||||
for (int group = static_cast<int>(SettingsGroup::VIDEO); group <= static_cast<int>(SettingsGroup::MAIN); ++group)
|
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
for (const auto &option : options_)
|
for (const auto &option : options_)
|
||||||
{
|
++group_counts[option.group];
|
||||||
if (static_cast<int>(option.group) == group)
|
|
||||||
++count;
|
int max_size = 0;
|
||||||
}
|
for (const auto &pair : group_counts)
|
||||||
if (count > max_size)
|
if (pair.second > max_size)
|
||||||
max_size = count;
|
max_size = pair.second;
|
||||||
}
|
|
||||||
return max_size;
|
return max_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceMenu::GroupAlignment ServiceMenu::getGroupAlignment(SettingsGroup group)
|
// Devuelve la alineación de las opciones para el grupo dado
|
||||||
|
ServiceMenu::GroupAlignment ServiceMenu::getGroupAlignment(SettingsGroup group) const
|
||||||
{
|
{
|
||||||
switch (group)
|
switch (group)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,45 +12,48 @@ class Text;
|
|||||||
class ServiceMenu
|
class ServiceMenu
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// --- Métodos de singleton ---
|
// --- Métodos de Singleton ---
|
||||||
static void init(); // Inicializa el objeto ServiceMenu
|
static void init(); // Inicializa la instancia única de ServiceMenu
|
||||||
static void destroy(); // Libera el objeto ServiceMenu
|
static void destroy(); // Libera la instancia única de ServiceMenu
|
||||||
static ServiceMenu *get(); // Obtiene el puntero al objeto ServiceMenu
|
static ServiceMenu *get(); // Devuelve el puntero a la instancia única
|
||||||
|
|
||||||
// -- Métodos ---
|
// --- Métodos principales ---
|
||||||
void toggle();
|
void toggle(); // Muestra u oculta el menú de servicio
|
||||||
void render();
|
void render(); // Dibuja el menú de servicio en pantalla
|
||||||
void update();
|
void update(); // Actualiza el estado del menú de servicio
|
||||||
|
|
||||||
// --- Métodos de control ---
|
// --- Métodos de control de navegación ---
|
||||||
void setSelectorUp();
|
void setSelectorUp(); // Mueve el selector hacia arriba
|
||||||
void setSelectorDown();
|
void setSelectorDown(); // Mueve el selector hacia abajo
|
||||||
void adjustOption(bool adjust_up);
|
void adjustOption(bool adjust_up); // Ajusta el valor de la opción seleccionada
|
||||||
void selectOption();
|
void selectOption(); // Selecciona la opción actual
|
||||||
void moveBack();
|
void moveBack(); // Vuelve al grupo de opciones anterior
|
||||||
|
|
||||||
// --- Getters ---
|
// --- Getters ---
|
||||||
bool isEnabled() const { return enabled_; }
|
bool isEnabled() const { return enabled_; } // Indica si el menú de servicio está activo
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// --- Tipos internos ---
|
||||||
using OptionPairs = std::vector<std::pair<std::string, std::string>>;
|
using OptionPairs = std::vector<std::pair<std::string, std::string>>;
|
||||||
|
|
||||||
static constexpr const char *MENU_SOUND_ = "clock.wav";
|
// --- Constantes ---
|
||||||
static constexpr int OPTIONS_HORIZONTAL_PADDING_ = 20;
|
static constexpr const char *MENU_SOUND_ = "clock.wav"; // Sonido al navegar por el menú
|
||||||
|
static constexpr int OPTIONS_HORIZONTAL_PADDING_ = 20; // Relleno horizontal de las opciones
|
||||||
|
|
||||||
|
// --- Enumeraciones internas ---
|
||||||
enum class Aspect
|
enum class Aspect
|
||||||
{
|
{
|
||||||
ASPECT1, // Fondo opaco y proyecta sombra
|
ASPECT1, // Fondo opaco y proyecta sombra
|
||||||
ASPECT2 // Fondo translucido
|
ASPECT2 // Fondo translúcido
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class SettingsGroup
|
enum class SettingsGroup
|
||||||
{
|
{
|
||||||
VIDEO, // Configuraciones relacionadas con la calidad y resolución de imagen
|
VIDEO, // Configuraciones de vídeo
|
||||||
AUDIO, // Opciones de sonido y volumen
|
AUDIO, // Opciones de audio
|
||||||
GAME, // Ajustes de jugabilidad y mecánicas
|
GAME, // Opciones de juego
|
||||||
SYSTEM, // Preferencias generales y configuraciones del sistema
|
SYSTEM, // Opciones del sistema
|
||||||
MAIN // Raíz
|
MAIN // Menú principal
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class OptionBehavior
|
enum class OptionBehavior
|
||||||
@@ -61,18 +64,19 @@ private:
|
|||||||
|
|
||||||
enum class ValueType
|
enum class ValueType
|
||||||
{
|
{
|
||||||
BOOL,
|
BOOL, // Valor booleano
|
||||||
INT,
|
INT, // Valor entero
|
||||||
FOLDER,
|
FOLDER, // Referencia a otro grupo
|
||||||
NONE
|
NONE // Sin valor asociado
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class GroupAlignment
|
enum class GroupAlignment
|
||||||
{
|
{
|
||||||
CENTERED,
|
CENTERED, // Opciones centradas
|
||||||
LEFT
|
LEFT // Opciones alineadas a la izquierda
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// --- Estructura de opción del menú ---
|
||||||
struct OptionEntry
|
struct OptionEntry
|
||||||
{
|
{
|
||||||
std::string caption; // Texto visible en el menú
|
std::string caption; // Texto visible en el menú
|
||||||
@@ -102,7 +106,7 @@ private:
|
|||||||
: caption(cap), group(grp), behavior(beh), linked_variable(nullptr), type(ValueType::FOLDER),
|
: caption(cap), group(grp), behavior(beh), linked_variable(nullptr), type(ValueType::FOLDER),
|
||||||
min_value(0), max_value(0), step_value(0), target_group(tgtGrp) {}
|
min_value(0), max_value(0), step_value(0), target_group(tgtGrp) {}
|
||||||
|
|
||||||
// Método para modificar el valor
|
// Método para modificar el valor de la opción
|
||||||
void adjustValue(bool adjust_up)
|
void adjustValue(bool adjust_up)
|
||||||
{
|
{
|
||||||
if (linked_variable)
|
if (linked_variable)
|
||||||
@@ -111,14 +115,12 @@ private:
|
|||||||
{
|
{
|
||||||
int &value = *(static_cast<int *>(linked_variable));
|
int &value = *(static_cast<int *>(linked_variable));
|
||||||
int newValue = adjust_up ? value + step_value : value - step_value;
|
int newValue = adjust_up ? value + step_value : value - step_value;
|
||||||
|
|
||||||
// Asegurar que el nuevo valor se mantenga dentro de los límites
|
|
||||||
value = std::clamp(newValue, min_value, max_value);
|
value = std::clamp(newValue, min_value, max_value);
|
||||||
}
|
}
|
||||||
else if (type == ValueType::BOOL)
|
else if (type == ValueType::BOOL)
|
||||||
{
|
{
|
||||||
bool &value = *(static_cast<bool *>(linked_variable));
|
bool &value = *(static_cast<bool *>(linked_variable));
|
||||||
value = !value; // Invierte el valor booleano
|
value = !value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,49 +140,58 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// -- Variables internas ---
|
// --- Variables internas ---
|
||||||
bool enabled_ = false; // Indica si el menú de servicio está activo
|
bool enabled_ = false; // Indica si el menú de servicio está activo
|
||||||
SDL_FRect rect_; // Rectangulo para definir el area del menú de servicio
|
SDL_FRect rect_; // Rectángulo que define el área del menú de servicio
|
||||||
std::shared_ptr<Text> element_text_; // Objeto para escribir texto;
|
std::shared_ptr<Text> element_text_; // Objeto para escribir el texto de los elementos
|
||||||
std::shared_ptr<Text> title_text_; // Objeto para escribir texto;
|
std::shared_ptr<Text> title_text_; // Objeto para escribir el texto del título
|
||||||
size_t selected_ = 0; // Elemento del menú seleccionado
|
size_t selected_ = 0; // Índice del elemento del menú seleccionado
|
||||||
Uint32 counter_ = 0; // Contador interno
|
Uint32 counter_ = 0; // Contador interno
|
||||||
std::vector<OptionEntry> options_; // Listado con todas las opciones del menú de servicio
|
std::vector<OptionEntry> options_; // Listado con todas las opciones del menú de servicio
|
||||||
std::vector<OptionEntry> display_options_; // Listado con todas las opciones del menú de servicio que se estan mostrando
|
std::vector<OptionEntry> display_options_; // Opciones actualmente mostradas en pantalla
|
||||||
OptionPairs option_pairs_; // Listado con las opciones de menu actuales (filtradas por grupo)
|
OptionPairs option_pairs_; // Opciones actuales del menú (filtradas por grupo)
|
||||||
SettingsGroup current_settings_group_; // Grupo actual
|
SettingsGroup current_settings_group_; // Grupo de opciones actualmente activo
|
||||||
SettingsGroup previous_settings_group_; // Grupo anterior
|
SettingsGroup previous_settings_group_; // Grupo de opciones anterior
|
||||||
Aspect aspect_ = Aspect::ASPECT2;
|
Aspect aspect_ = Aspect::ASPECT2; // Estilo visual del menú
|
||||||
|
|
||||||
// -- Aspecto --
|
// --- Variables de aspecto ---
|
||||||
Color bg_color_ = SERV_MENU_BG_COLOR; // Color de fondo
|
Color bg_color_ = SERV_MENU_BG_COLOR; // Color de fondo
|
||||||
Color title_color_ = SERV_MENU_TITLE_COLOR; // Color del título del menu
|
Color title_color_ = SERV_MENU_TITLE_COLOR; // Color del título del menú
|
||||||
Color text_color_ = SERV_MENU_TEXT_COLOR; // Color para el 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 para el elemento seleccionado
|
Color selected_color_ = SERV_MENU_SELECTED_COLOR; // Color del elemento seleccionado
|
||||||
int width_; // Ancho del menú
|
int width_; // Ancho del menú
|
||||||
int height_; // Alto del menu
|
int height_; // Alto del menú
|
||||||
int line_height_; // Espacio entre elementos del menu
|
int line_height_; // Espacio entre elementos del menú
|
||||||
|
|
||||||
// -- Métodos internos ---
|
// --- 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
|
||||||
void updateCounter(); // Actualiza el contador interno
|
Color getSelectedColor() const; // Devuelve el color del elemento seleccionado
|
||||||
Color getSelectedColor(); // Devuelve el color del elemento seleccionado
|
|
||||||
|
// --- 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
|
||||||
OptionPairs getOptionPairs(SettingsGroup group) const;
|
OptionPairs getOptionPairs(SettingsGroup group) const; // Devuelve las opciones como pares de strings para un grupo
|
||||||
std::vector<OptionEntry> getOptionsByGroup(SettingsGroup group) const;
|
std::vector<OptionEntry> getOptionsByGroup(SettingsGroup group) const; // Devuelve las opciones de un grupo
|
||||||
void applySettings(SettingsGroup group);
|
|
||||||
void updateMenu(SettingsGroup group);
|
// --- Métodos internos: Lógica de menú ---
|
||||||
void reset();
|
void applySettings(SettingsGroup group); // Aplica la configuración de un grupo
|
||||||
int calculateMenuHeight();
|
void updateMenu(SettingsGroup group); // Actualiza las opciones mostradas según el grupo
|
||||||
int findLargestGroupSize();
|
void reset(); // Reinicia el menú al estado inicial
|
||||||
GroupAlignment getGroupAlignment(SettingsGroup group);
|
|
||||||
|
// --- Métodos internos: Utilidades ---
|
||||||
|
void updateCounter(); // Actualiza el contador interno
|
||||||
|
int calculateMenuHeight() const; // Calcula la altura del menú
|
||||||
|
int findLargestGroupSize() const; // Devuelve el tamaño del grupo más grande
|
||||||
|
GroupAlignment getGroupAlignment(SettingsGroup group) const; // Devuelve la alineación del grupo
|
||||||
|
|
||||||
// --- Patrón Singleton ---
|
// --- Patrón Singleton ---
|
||||||
ServiceMenu(); // Constructor privado
|
ServiceMenu(); // Constructor privado
|
||||||
~ServiceMenu() = default; // Destructor privado
|
~ServiceMenu() = default; // Destructor privado
|
||||||
ServiceMenu(const ServiceMenu &) = delete; // Evitar copia
|
ServiceMenu(const ServiceMenu &) = delete; // Evita la copia
|
||||||
ServiceMenu &operator=(const ServiceMenu &) = delete; // Evitar asignación
|
ServiceMenu &operator=(const ServiceMenu &) = delete; // Evita la asignación
|
||||||
|
|
||||||
// --- Singleton ---
|
// --- Instancia Singleton ---
|
||||||
static ServiceMenu *instance_;
|
static ServiceMenu *instance_; // Instancia única del menú de servicio
|
||||||
|
|
||||||
|
// --- Método para reproducir el sonido del menú ---
|
||||||
|
void playMenuSound(); // Reproduce el sonido del menú
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user