canvi de pc
This commit is contained in:
@@ -4,146 +4,86 @@
|
||||
#include <utility>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <SDL3/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "UIMessage.h"
|
||||
|
||||
// --- Forward Declarations ---
|
||||
// Forward Declarations
|
||||
class Text;
|
||||
class MenuOption; // <-- Añadido
|
||||
class MenuOption;
|
||||
class MenuRenderer; // <-- Nuevo
|
||||
|
||||
class ServiceMenu
|
||||
{
|
||||
class ServiceMenu {
|
||||
public:
|
||||
// Enums públicas para que MenuOption.h pueda usarlas.
|
||||
enum class Aspect
|
||||
{
|
||||
ASPECT1,
|
||||
ASPECT2
|
||||
};
|
||||
enum class SettingsGroup
|
||||
{
|
||||
VIDEO,
|
||||
AUDIO,
|
||||
SETTINGS,
|
||||
SYSTEM,
|
||||
MAIN
|
||||
};
|
||||
enum class GroupAlignment
|
||||
{
|
||||
CENTERED,
|
||||
LEFT
|
||||
};
|
||||
enum class Aspect { ASPECT1, ASPECT2 };
|
||||
enum class SettingsGroup { VIDEO, AUDIO, SETTINGS, SYSTEM, MAIN };
|
||||
enum class GroupAlignment { CENTERED, LEFT };
|
||||
|
||||
// --- Constantes públicas que el Renderer podría necesitar ---
|
||||
static constexpr size_t OPTIONS_HORIZONTAL_PADDING_ = 20;
|
||||
static constexpr size_t MIN_WIDTH_ = 240;
|
||||
static constexpr size_t MIN_GAP_OPTION_VALUE_ = 30;
|
||||
|
||||
static void init();
|
||||
static void destroy();
|
||||
static ServiceMenu *get();
|
||||
static ServiceMenu* get();
|
||||
|
||||
void toggle();
|
||||
void render();
|
||||
void update();
|
||||
void render(); // Ahora solo delega
|
||||
void update(); // Ahora delega la parte visual
|
||||
void reset();
|
||||
|
||||
// --- Lógica de navegación ---
|
||||
void setSelectorUp();
|
||||
void setSelectorDown();
|
||||
void adjustOption(bool adjust_up);
|
||||
void selectOption();
|
||||
void moveBack();
|
||||
|
||||
// --- Getters para que el Renderer pueda leer el estado ---
|
||||
bool isEnabled() const { return enabled_; }
|
||||
void setResizeAnimationSteps(int steps) { resize_anim_steps_ = steps; }
|
||||
const std::string& getTitle() const { return title_; }
|
||||
SettingsGroup getCurrentGroup() const { return current_settings_group_; }
|
||||
GroupAlignment getCurrentGroupAlignment() const;
|
||||
const std::vector<MenuOption*>& getDisplayOptions() const { return display_options_; }
|
||||
const std::vector<std::unique_ptr<MenuOption>>& getAllOptions() const { return options_; }
|
||||
size_t getSelectedIndex() const { return selected_; }
|
||||
const std::vector<std::pair<std::string, std::string>>& getOptionPairs() const { return option_pairs_; }
|
||||
size_t countOptionsInGroup(SettingsGroup group) const;
|
||||
Aspect getAspect() const { return aspect_; }
|
||||
|
||||
private:
|
||||
// Definición de las constantes estáticas
|
||||
static constexpr const char *MENU_SOUND_ = "clock.wav";
|
||||
static constexpr size_t OPTIONS_HORIZONTAL_PADDING_ = 20;
|
||||
static constexpr size_t MIN_WIDTH_ = 220;
|
||||
static constexpr size_t MIN_GAP_OPTION_VALUE_ = 20;
|
||||
static constexpr float RESET_TEXT_POS_Y_ = 39.0f;
|
||||
|
||||
// --- Tipos internos ---
|
||||
using OptionPairs = std::vector<std::pair<std::string, std::string>>;
|
||||
|
||||
// --- Variables internas ---
|
||||
// --- Lógica de estado del menú (Modelo) ---
|
||||
bool enabled_ = false;
|
||||
SDL_FRect rect_;
|
||||
std::shared_ptr<Text> element_text_;
|
||||
std::shared_ptr<Text> title_text_;
|
||||
size_t selected_ = 0;
|
||||
Uint32 counter_ = 0;
|
||||
|
||||
// Usamos punteros únicos para gestionar la vida de los objetos polimórficos.
|
||||
std::vector<std::unique_ptr<MenuOption>> options_;
|
||||
// Mostramos punteros raw (no propietarios) de las opciones filtradas.
|
||||
std::vector<MenuOption *> display_options_;
|
||||
|
||||
OptionPairs option_pairs_;
|
||||
std::vector<MenuOption*> display_options_;
|
||||
std::vector<std::pair<std::string, std::string>> option_pairs_;
|
||||
|
||||
SettingsGroup current_settings_group_;
|
||||
SettingsGroup previous_settings_group_;
|
||||
Aspect aspect_ = Aspect::ASPECT1;
|
||||
std::string title_;
|
||||
size_t selected_ = 0;
|
||||
size_t main_menu_selected_ = 0;
|
||||
|
||||
// Variables de aspecto y layout...
|
||||
Color bg_color_ = SERV_MENU_BG_COLOR;
|
||||
Color title_color_ = SERV_MENU_TITLE_COLOR;
|
||||
Color text_color_ = SERV_MENU_TEXT_COLOR;
|
||||
Color selected_color_ = SERV_MENU_SELECTED_COLOR;
|
||||
size_t width_;
|
||||
size_t height_;
|
||||
size_t options_height_;
|
||||
size_t options_padding_;
|
||||
size_t options_y_;
|
||||
size_t title_height_;
|
||||
size_t title_padding_;
|
||||
size_t upper_height_;
|
||||
size_t lower_height_;
|
||||
size_t lower_padding_;
|
||||
|
||||
// Variables de animación de resize...
|
||||
SDL_FRect rect_anim_from_{};
|
||||
SDL_FRect rect_anim_to_{};
|
||||
int resize_anim_step_ = 0;
|
||||
int resize_anim_steps_ = 8;
|
||||
bool resizing_ = false;
|
||||
|
||||
// Mensaje de reinicio
|
||||
// --- Mensaje de reinicio ---
|
||||
std::unique_ptr<UIMessage> restart_message_ui_;
|
||||
bool last_pending_changes_ = false;
|
||||
|
||||
// Anchos precalculados
|
||||
int group_menu_widths_[5];
|
||||
// --- La Vista ---
|
||||
std::unique_ptr<MenuRenderer> renderer_;
|
||||
|
||||
// --- Métodos internos ---
|
||||
|
||||
// Anclaje y aspecto
|
||||
void setAnchors();
|
||||
Color getSelectedColor() const;
|
||||
void setOptionsPosition();
|
||||
void resize();
|
||||
void updateResizeAnimation();
|
||||
|
||||
// Gestión de opciones
|
||||
// --- Métodos de lógica interna ---
|
||||
void initializeOptions();
|
||||
OptionPairs getOptionPairs(SettingsGroup group) const;
|
||||
std::vector<MenuOption *> getOptionsByGroup(SettingsGroup group);
|
||||
MenuOption *getOptionByCaption(const std::string &caption);
|
||||
|
||||
// Lógica de menú
|
||||
void applySettings(SettingsGroup group);
|
||||
void updateMenu(SettingsGroup group);
|
||||
void updateMenu();
|
||||
void applySettings();
|
||||
void AdjustListValues();
|
||||
|
||||
// Utilidades
|
||||
void updateCounter();
|
||||
int findLargestGroupSize() const;
|
||||
GroupAlignment getGroupAlignment(SettingsGroup group) const;
|
||||
std::string settingsGroupToString(SettingsGroup group) const;
|
||||
void precalculateMenuWidths();
|
||||
int getMenuWidthForGroup(SettingsGroup group) const;
|
||||
void playMenuSound();
|
||||
std::string settingsGroupToString(SettingsGroup group) const;
|
||||
|
||||
// --- Patrón Singleton ---
|
||||
// --- Singleton ---
|
||||
ServiceMenu();
|
||||
~ServiceMenu() = default;
|
||||
ServiceMenu(const ServiceMenu &) = delete;
|
||||
ServiceMenu &operator=(const ServiceMenu &) = delete;
|
||||
static ServiceMenu *instance_;
|
||||
ServiceMenu(const ServiceMenu&) = delete;
|
||||
ServiceMenu& operator=(const ServiceMenu&) = delete;
|
||||
static ServiceMenu* instance_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user