150 lines
4.1 KiB
C++
150 lines
4.1 KiB
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include <utility>
|
|
#include <string>
|
|
#include <memory>
|
|
#include <SDL3/SDL.h>
|
|
#include "utils.h"
|
|
#include "UIMessage.h"
|
|
|
|
// --- Forward Declarations ---
|
|
class Text;
|
|
class MenuOption; // <-- Añadido
|
|
|
|
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
|
|
};
|
|
|
|
static void init();
|
|
static void destroy();
|
|
static ServiceMenu *get();
|
|
void toggle();
|
|
void render();
|
|
void update();
|
|
void reset();
|
|
void setSelectorUp();
|
|
void setSelectorDown();
|
|
void adjustOption(bool adjust_up);
|
|
void selectOption();
|
|
void moveBack();
|
|
bool isEnabled() const { return enabled_; }
|
|
void setResizeAnimationSteps(int steps) { resize_anim_steps_ = steps; }
|
|
|
|
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 ---
|
|
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_;
|
|
SettingsGroup current_settings_group_;
|
|
SettingsGroup previous_settings_group_;
|
|
Aspect aspect_ = Aspect::ASPECT1;
|
|
std::string title_;
|
|
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
|
|
std::unique_ptr<UIMessage> restart_message_ui_;
|
|
bool last_pending_changes_ = false;
|
|
|
|
// Anchos precalculados
|
|
int group_menu_widths_[5];
|
|
|
|
// --- Métodos internos ---
|
|
|
|
// Anclaje y aspecto
|
|
void setAnchors();
|
|
Color getSelectedColor() const;
|
|
void setOptionsPosition();
|
|
void resize();
|
|
void updateResizeAnimation();
|
|
|
|
// Gestión de opciones
|
|
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 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();
|
|
|
|
// --- Patrón Singleton ---
|
|
ServiceMenu();
|
|
~ServiceMenu() = default;
|
|
ServiceMenu(const ServiceMenu &) = delete;
|
|
ServiceMenu &operator=(const ServiceMenu &) = delete;
|
|
static ServiceMenu *instance_;
|
|
};
|