111 lines
4.1 KiB
C++
111 lines
4.1 KiB
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
#include <memory>
|
|
#include <SDL3/SDL.h>
|
|
#include "utils.h"
|
|
|
|
class Text;
|
|
|
|
class ServiceMenu
|
|
{
|
|
public:
|
|
// --- Métodos de singleton ---
|
|
static void init(); // Inicializa el objeto ServiceMenu
|
|
static void destroy(); // Libera el objeto ServiceMenu
|
|
static ServiceMenu *get(); // Obtiene el puntero al objeto ServiceMenu
|
|
|
|
// -- Métodos ---
|
|
void toggle();
|
|
void render();
|
|
void update();
|
|
|
|
// --- Métodos de control ---
|
|
void setSelectorUp();
|
|
void setSelectorDown();
|
|
void acceptSelection();
|
|
void cancelSelection();
|
|
|
|
// --- Getters ---
|
|
bool isEnabled() const { return enabled_; }
|
|
|
|
private:
|
|
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
|
|
};
|
|
|
|
enum class OptionBehavior
|
|
{
|
|
ADJUST, // Modificable con izquierda/derecha
|
|
SELECT // Activable con ENTER
|
|
};
|
|
|
|
enum class ValueType
|
|
{
|
|
BOOL,
|
|
INT,
|
|
NONE
|
|
};
|
|
|
|
struct OptionEntry
|
|
{
|
|
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)
|
|
|
|
// Constructor para inicializar los valores fácilmente
|
|
OptionEntry(std::string cap, SettingsGroup grp, OptionBehavior beh, void *var, ValueType t)
|
|
: caption(cap), group(grp), behavior(beh), linkedVariable(var), type(t) {}
|
|
|
|
// 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";
|
|
}
|
|
};
|
|
|
|
// -- 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
|
|
|
|
// -- 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
|
|
|
|
// -- 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
|
|
|
|
// --- Patrón Singleton ---
|
|
ServiceMenu(); // Constructor privado
|
|
~ServiceMenu() = default; // Destructor privado
|
|
ServiceMenu(const ServiceMenu &) = delete; // Evitar copia
|
|
ServiceMenu &operator=(const ServiceMenu &) = delete; // Evitar asignación
|
|
|
|
// --- Singleton ---
|
|
static ServiceMenu *instance_;
|
|
}; |