ServiceMenu: afegida opció per a canviar el idioma
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "lang.h"
|
||||
#include "options.h"
|
||||
|
||||
class Text;
|
||||
|
||||
@@ -68,6 +69,7 @@ private:
|
||||
{
|
||||
BOOL, // Valor booleano
|
||||
INT, // Valor entero
|
||||
LIST, // Lista de valores
|
||||
FOLDER, // Referencia a otro grupo
|
||||
NONE // Sin valor asociado
|
||||
};
|
||||
@@ -85,28 +87,35 @@ private:
|
||||
SettingsGroup group; // Categoría de la opción
|
||||
OptionBehavior behavior; // Cómo se interactúa con la opción
|
||||
void *linked_variable; // Puntero a la variable que controla la opción
|
||||
ValueType type; // Tipo de la variable (bool, int, folder, none)
|
||||
ValueType type; // Tipo de la variable
|
||||
|
||||
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)
|
||||
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)
|
||||
std::vector<std::string> value_list; // Lista de valores posibles (solo aplicable si type == LIST)
|
||||
size_t list_index; // Índice del valor seleccionado dentro de value_list
|
||||
|
||||
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
|
||||
// Constructor para opciones de tipo BOOL, NONE, FOLDER
|
||||
OptionEntry(std::string cap, SettingsGroup grp, OptionBehavior beh, void *var, ValueType 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) {}
|
||||
min_value(0), max_value(0), step_value(0), list_index(0), target_group(SettingsGroup::SYSTEM) {}
|
||||
|
||||
// Constructor para opciones de tipo INT con valores mínimos, máximos e incremento
|
||||
// Constructor para opciones de tipo INT
|
||||
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) {}
|
||||
min_value(min), max_value(max), step_value(step), list_index(0), target_group(SettingsGroup::SYSTEM) {}
|
||||
|
||||
// Constructor para opciones de tipo FOLDER que referencian otro grupo
|
||||
// Constructor para opciones de tipo LIST
|
||||
OptionEntry(std::string cap, SettingsGroup grp, OptionBehavior beh, void *var, std::vector<std::string> values)
|
||||
: caption(cap), group(grp), behavior(beh), linked_variable(var), type(ValueType::LIST),
|
||||
min_value(0), max_value(0), step_value(0), value_list(values), list_index(0), target_group(SettingsGroup::SYSTEM) {}
|
||||
|
||||
// Constructor para opciones de tipo FOLDER
|
||||
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) {}
|
||||
min_value(0), max_value(0), step_value(0), list_index(0), target_group(tgtGrp) {}
|
||||
|
||||
// Método para modificar el valor de la opción
|
||||
void adjustValue(bool adjust_up)
|
||||
@@ -124,6 +133,25 @@ private:
|
||||
bool &value = *(static_cast<bool *>(linked_variable));
|
||||
value = !value;
|
||||
}
|
||||
else if (type == ValueType::LIST && !value_list.empty())
|
||||
{
|
||||
list_index = adjust_up ? (list_index + 1) % value_list.size()
|
||||
: (list_index - 1 + value_list.size()) % value_list.size();
|
||||
|
||||
// Idioma
|
||||
if (linked_variable == &options.pending_changes.new_language)
|
||||
{
|
||||
options.pending_changes.new_language = lang::getCodeFromName(value_list[list_index]);
|
||||
options.pending_changes.has_pending_changes = true;
|
||||
}
|
||||
|
||||
// Dificultad
|
||||
if (linked_variable == &options.pending_changes.new_difficulty)
|
||||
{
|
||||
// options.pending_changes.new_difficulty =
|
||||
options.pending_changes.has_pending_changes = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +164,8 @@ private:
|
||||
return (*(static_cast<bool *>(linked_variable))) ? lang::getText("[SERVICE_MENU] ON") : lang::getText("[SERVICE_MENU] OFF");
|
||||
case ValueType::INT:
|
||||
return std::to_string(*(static_cast<int *>(linked_variable)));
|
||||
case ValueType::LIST:
|
||||
return value_list.empty() ? "" : value_list[list_index];
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
@@ -143,18 +173,18 @@ private:
|
||||
};
|
||||
|
||||
// --- Variables internas ---
|
||||
bool enabled_ = false; // Indica si el menú de servicio está activo
|
||||
SDL_FRect rect_; // Rectángulo que define el área del menú de servicio
|
||||
std::shared_ptr<Text> element_text_; // Objeto para escribir el texto de los elementos
|
||||
std::shared_ptr<Text> title_text_; // Objeto para escribir el texto del título
|
||||
size_t selected_ = 0; // Índice del 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_; // Opciones actualmente mostradas en pantalla
|
||||
OptionPairs option_pairs_; // Opciones actuales del menú (filtradas por grupo)
|
||||
SettingsGroup current_settings_group_; // Grupo de opciones actualmente activo
|
||||
SettingsGroup previous_settings_group_; // Grupo de opciones anterior
|
||||
Aspect aspect_ = Aspect::ASPECT1; // Estilo visual del menú
|
||||
bool enabled_ = false; // Indica si el menú de servicio está activo
|
||||
SDL_FRect rect_; // Rectángulo que define el área del menú de servicio
|
||||
std::shared_ptr<Text> element_text_; // Objeto para escribir el texto de los elementos
|
||||
std::shared_ptr<Text> title_text_; // Objeto para escribir el texto del título
|
||||
size_t selected_ = 0; // Índice del 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_; // Opciones actualmente mostradas en pantalla (punteros)
|
||||
OptionPairs option_pairs_; // Opciones actuales del menú (filtradas por grupo)
|
||||
SettingsGroup current_settings_group_; // Grupo de opciones actualmente activo
|
||||
SettingsGroup previous_settings_group_; // Grupo de opciones anterior
|
||||
Aspect aspect_ = Aspect::ASPECT1; // Estilo visual del menú
|
||||
|
||||
// --- Variables de aspecto ---
|
||||
Color bg_color_ = SERV_MENU_BG_COLOR; // Color de fondo
|
||||
@@ -179,19 +209,21 @@ private:
|
||||
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
|
||||
OptionPairs getOptionPairs(SettingsGroup group) const; // Devuelve las opciones como pares de strings para un grupo
|
||||
std::vector<OptionEntry> getOptionsByGroup(SettingsGroup group) const; // Devuelve las opciones de un grupo
|
||||
void initializeOptions(); // Crea todas las opciones del menú de servicio
|
||||
OptionPairs getOptionPairs(SettingsGroup group) const; // Devuelve las opciones como pares de strings para un grupo
|
||||
std::vector<OptionEntry *> getOptionsByGroup(SettingsGroup group); // Devuelve punteros a las opciones de un grupo
|
||||
|
||||
// --- 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 AdjustListValues(); // Ajusta los valores de las opciones tipo lista
|
||||
|
||||
// --- 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
|
||||
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
|
||||
OptionEntry *getOptionEntryByCaption(const std::string &caption); // Devuelve un puntero a OptionEntry a partir del caption
|
||||
|
||||
// --- Patrón Singleton ---
|
||||
ServiceMenu(); // Constructor privado
|
||||
|
||||
Reference in New Issue
Block a user