ja navega pels menus en ServiceMenu

Ja aplica les opcions de video de ServiceMenu
This commit is contained in:
2025-06-05 14:06:42 +02:00
parent 1a84f1b1b0
commit f1c576beef
7 changed files with 246 additions and 86 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include <vector>
#include <utility>
#include <string>
#include <memory>
#include <SDL3/SDL.h>
@@ -24,19 +25,24 @@ public:
// --- Métodos de control ---
void setSelectorUp();
void setSelectorDown();
void setSelectorRight();
void setSelectorLeft();
void acceptSelection();
void cancelSelection();
void moveBack();
// --- Getters ---
bool isEnabled() const { return enabled_; }
private:
using OptionPairs = std::vector<std::pair<std::string, std::string>>;
enum class SettingsGroup
{
VIDEO, // Configuraciones relacionadas con la calidad y resolución de imagen
AUDIO, // Opciones de sonido y volumen
GAME, // Ajustes de jugabilidad y mecánicas
SYSTEM // Preferencias generales y configuraciones del sistema
VIDEO, // Configuraciones relacionadas con la calidad y resolución de imagen
AUDIO, // Opciones de sonido y volumen
GAME, // Ajustes de jugabilidad y mecánicas
SYSTEM, // Preferencias generales y configuraciones del sistema
MAIN // Raíz
};
enum class OptionBehavior
@@ -49,6 +55,7 @@ private:
{
BOOL,
INT,
FOLDER,
NONE
};
@@ -57,48 +64,98 @@ private:
std::string caption; // Texto visible en el menú
SettingsGroup group; // Categoría de la opción
OptionBehavior behavior; // Cómo se interactúa con la opción
void *linkedVariable; // Puntero a la variable que controla la opción
ValueType type; // Tipo de la variable (bool o int)
void *linked_variable; // Puntero a la variable que controla la opción
ValueType type; // Tipo de la variable (bool, int, folder, none)
// Constructor para inicializar los valores fácilmente
int min_value; // Valor mínimo (solo aplicable si type == INT)
int max_value; // Valor máximo (solo aplicable si type == INT)
int step_value; // Incremento al modificar la opción (solo aplicable si type == INT)
SettingsGroup target_group; // Grupo al que hace referencia la opción si es de tipo FOLDER
// Constructor para opciones de tipo BOOL, NONE o FOLDER
OptionEntry(std::string cap, SettingsGroup grp, OptionBehavior beh, void *var, ValueType t)
: caption(cap), group(grp), behavior(beh), linkedVariable(var), type(t) {}
: caption(cap), group(grp), behavior(beh), linked_variable(var), type(t),
min_value(0), max_value(0), step_value(0), target_group(SettingsGroup::SYSTEM) {}
// Constructor para opciones de tipo INT con valores mínimos, máximos e incremento
OptionEntry(std::string cap, SettingsGroup grp, OptionBehavior beh, void *var, ValueType t, int min, int max, int step)
: caption(cap), group(grp), behavior(beh), linked_variable(var), type(t),
min_value(min), max_value(max), step_value(step), target_group(SettingsGroup::SYSTEM) {}
// Constructor para opciones de tipo FOLDER que referencian otro grupo
OptionEntry(std::string cap, SettingsGroup grp, OptionBehavior beh, SettingsGroup tgtGrp)
: caption(cap), group(grp), behavior(beh), linked_variable(nullptr), type(ValueType::FOLDER),
min_value(0), max_value(0), step_value(0), target_group(tgtGrp) {}
// Método para modificar el valor
void adjustValue(bool increase)
{
if (linked_variable)
{
if (type == ValueType::INT)
{
int &value = *(static_cast<int *>(linked_variable));
int newValue = increase ? 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);
}
else if (type == ValueType::BOOL)
{
bool &value = *(static_cast<bool *>(linked_variable));
value = !value; // Invierte el valor booleano
}
}
}
// Método para obtener el valor como string
std::string getValueAsString() const
{
if (type == ValueType::BOOL)
return (*(static_cast<bool *>(linkedVariable))) ? "ON" : "OFF";
else if (type == ValueType::INT)
return std::to_string(*(static_cast<int *>(linkedVariable)));
return "Unknown";
switch (type)
{
case ValueType::BOOL:
return (*(static_cast<bool *>(linked_variable))) ? "ON" : "OFF";
case ValueType::INT:
return std::to_string(*(static_cast<int *>(linked_variable)));
default:
return "";
}
}
};
// -- Variables internas ---
bool enabled_ = false; // Indica si el menú de servicio está activo
SDL_FRect rect_; // Rectangulo para definir el area del menú de servicio
std::shared_ptr<Text> elementText_; // Objeto para escribir texto;
std::shared_ptr<Text> titleText_; // Objeto para escribir texto;
size_t selected_ = 2; // Elemento del menú seleccionado
Uint32 counter_ = 0; // Contador interno
std::vector<OptionEntry> options_; // Listado con todas las opciones del menú de servicio
bool enabled_ = false; // Indica si el menú de servicio está activo
SDL_FRect rect_; // Rectangulo para definir el area del menú de servicio
std::shared_ptr<Text> element_text_; // Objeto para escribir texto;
std::shared_ptr<Text> title_text_; // Objeto para escribir texto;
size_t selected_ = 0; // Elemento del menú seleccionado
Uint32 counter_ = 0; // Contador interno
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
OptionPairs option_pairs_; // Listado con las opciones de menu actuales (filtradas por grupo)
SettingsGroup current_settings_group_; // Grupo actual
SettingsGroup previous_settings_group_; // Grupo anterior
// -- Aspecto --
Color bgColor_ = SERV_MENU_BG_COLOR; // Color de fondo
Color titleColor_ = SERV_MENU_TITLE_COLOR; // Color del título del menu
Color textColor_ = SERV_MENU_TEXT_COLOR; // Color para el texto de los elementos
Color selectedColor_ = SERV_MENU_SELECTED_COLOR; // Color para el elemento seleccionado
int width_; // Ancho del menú
int height_; // Alto del menu
int lineHeight_; // Espacio entre elementos del menu
Color bg_color_ = SERV_MENU_BG_COLOR; // Color de fondo
Color title_color_ = SERV_MENU_TITLE_COLOR; // Color del título del menu
Color text_color_ = SERV_MENU_TEXT_COLOR; // Color para el texto de los elementos
Color selected_color_ = SERV_MENU_SELECTED_COLOR; // Color para el elemento seleccionado
int width_; // Ancho del menú
int height_; // Alto del menu
int line_height_; // Espacio entre elementos del menu
// -- Métodos internos ---
void setAnchors(); // Establece el valor de las variables de anclaje
void updateCounter(); // Actualiza el contador interno
Color getSelectedColor(); // Devuelve el color del elemento seleccionado
void initializeOptions(); // Crea todas las opciones del menú de servicio
OptionPairs getOptionPairs(SettingsGroup group) const;
std::vector<OptionEntry> getOptionsByGroup(SettingsGroup group) const;
void applySettings(SettingsGroup group);
void updateMenu(SettingsGroup group);
void reset();
// --- Patrón Singleton ---
ServiceMenu(); // Constructor privado