ServiceMenu: refactorització d'alguns métodes
ServiceMenu: en Video, amaga tamany de finestra quan está en fullscreen
This commit is contained in:
@@ -142,12 +142,8 @@ void ServiceMenu::moveBack()
|
|||||||
|
|
||||||
// --- Lógica Interna ---
|
// --- Lógica Interna ---
|
||||||
|
|
||||||
void ServiceMenu::updateMenu()
|
void ServiceMenu::updateDisplayOptions()
|
||||||
{
|
{
|
||||||
title_ = settingsGroupToString(current_settings_group_);
|
|
||||||
AdjustListValues();
|
|
||||||
|
|
||||||
// Actualiza las opciones visibles
|
|
||||||
display_options_.clear();
|
display_options_.clear();
|
||||||
for (auto &option : options_)
|
for (auto &option : options_)
|
||||||
{
|
{
|
||||||
@@ -156,13 +152,25 @@ void ServiceMenu::updateMenu()
|
|||||||
display_options_.push_back(option.get());
|
display_options_.push_back(option.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateOptionPairs();
|
||||||
|
}
|
||||||
|
|
||||||
// Actualiza los pares de strings para el renderer
|
void ServiceMenu::updateOptionPairs()
|
||||||
|
{
|
||||||
option_pairs_.clear();
|
option_pairs_.clear();
|
||||||
for (const auto &option : display_options_)
|
for (const auto &option : display_options_)
|
||||||
{
|
{
|
||||||
option_pairs_.emplace_back(option->getCaption(), option->getValueAsString());
|
option_pairs_.emplace_back(option->getCaption(), option->getValueAsString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceMenu::updateMenu()
|
||||||
|
{
|
||||||
|
title_ = settingsGroupToString(current_settings_group_);
|
||||||
|
AdjustListValues();
|
||||||
|
|
||||||
|
// Actualiza las opciones visibles
|
||||||
|
updateDisplayOptions();
|
||||||
|
|
||||||
// Notifica al renderer del cambio de layout
|
// Notifica al renderer del cambio de layout
|
||||||
renderer_->onLayoutChanged(this);
|
renderer_->onLayoutChanged(this);
|
||||||
@@ -171,27 +179,48 @@ void ServiceMenu::updateMenu()
|
|||||||
void ServiceMenu::applySettings()
|
void ServiceMenu::applySettings()
|
||||||
{
|
{
|
||||||
if (current_settings_group_ == SettingsGroup::VIDEO)
|
if (current_settings_group_ == SettingsGroup::VIDEO)
|
||||||
Screen::get()->applySettings();
|
applyVideoSettings();
|
||||||
if (current_settings_group_ == SettingsGroup::AUDIO)
|
if (current_settings_group_ == SettingsGroup::AUDIO)
|
||||||
Audio::get()->applySettings();
|
applyAudioSettings();
|
||||||
if (current_settings_group_ == SettingsGroup::SETTINGS)
|
if (current_settings_group_ == SettingsGroup::SETTINGS)
|
||||||
|
applySettingsSettings();
|
||||||
|
|
||||||
|
// Actualiza los valores de las opciones
|
||||||
|
updateOptionPairs();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceMenu::applyVideoSettings()
|
||||||
|
{
|
||||||
|
Screen::get()->applySettings();
|
||||||
|
auto option = getOptionByCaption(Lang::getText("[SERVICE_MENU] WINDOW_SIZE"));
|
||||||
|
if (option)
|
||||||
|
option->setHidden(Options::video.fullscreen);
|
||||||
|
updateMenu(); // El menú debe refrescarse si algo se oculta
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceMenu::applyAudioSettings()
|
||||||
|
{
|
||||||
|
Audio::get()->applySettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServiceMenu::applySettingsSettings()
|
||||||
|
{
|
||||||
|
auto option = getOptionByCaption(Lang::getText("[SERVICE_MENU] SHUTDOWN"));
|
||||||
|
if (option)
|
||||||
|
option->setHidden(!Options::settings.shutdown_enabled);
|
||||||
|
updateMenu(); // El menú debe refrescarse si algo se oculta
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuOption *ServiceMenu::getOptionByCaption(const std::string &caption) const
|
||||||
|
{
|
||||||
|
for (const auto &option : options_)
|
||||||
{
|
{
|
||||||
for (auto &option : options_)
|
if (option->getCaption() == caption)
|
||||||
{
|
{
|
||||||
if (option->getCaption() == Lang::getText("[SERVICE_MENU] SHUTDOWN]"))
|
return option.get();
|
||||||
{
|
|
||||||
option->setHidden(!Options::settings.shutdown_enabled);
|
|
||||||
updateMenu(); // El menú debe refrescarse si algo se oculta
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Refresca los pares de strings por si un valor cambió
|
return nullptr;
|
||||||
option_pairs_.clear();
|
|
||||||
for (const auto &option : display_options_)
|
|
||||||
{
|
|
||||||
option_pairs_.emplace_back(option->getCaption(), option->getValueAsString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Getters y otros ---
|
// --- Getters y otros ---
|
||||||
|
|||||||
@@ -12,11 +12,27 @@ class Text;
|
|||||||
class MenuOption;
|
class MenuOption;
|
||||||
class MenuRenderer; // <-- Nuevo
|
class MenuRenderer; // <-- Nuevo
|
||||||
|
|
||||||
class ServiceMenu {
|
class ServiceMenu
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
enum class Aspect { SHADOW, ALPHA };
|
enum class Aspect
|
||||||
enum class SettingsGroup { VIDEO, AUDIO, SETTINGS, SYSTEM, MAIN };
|
{
|
||||||
enum class GroupAlignment { CENTERED, LEFT };
|
SHADOW,
|
||||||
|
ALPHA
|
||||||
|
};
|
||||||
|
enum class SettingsGroup
|
||||||
|
{
|
||||||
|
VIDEO,
|
||||||
|
AUDIO,
|
||||||
|
SETTINGS,
|
||||||
|
SYSTEM,
|
||||||
|
MAIN
|
||||||
|
};
|
||||||
|
enum class GroupAlignment
|
||||||
|
{
|
||||||
|
CENTERED,
|
||||||
|
LEFT
|
||||||
|
};
|
||||||
|
|
||||||
// --- Constantes públicas que el Renderer podría necesitar ---
|
// --- Constantes públicas que el Renderer podría necesitar ---
|
||||||
static constexpr size_t OPTIONS_HORIZONTAL_PADDING_ = 20;
|
static constexpr size_t OPTIONS_HORIZONTAL_PADDING_ = 20;
|
||||||
@@ -25,11 +41,11 @@ public:
|
|||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
static void destroy();
|
static void destroy();
|
||||||
static ServiceMenu* get();
|
static ServiceMenu *get();
|
||||||
|
|
||||||
void toggle();
|
void toggle();
|
||||||
void render();
|
void render();
|
||||||
void update();
|
void update();
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
// --- Lógica de navegación ---
|
// --- Lógica de navegación ---
|
||||||
@@ -38,16 +54,16 @@ public:
|
|||||||
void adjustOption(bool adjust_up);
|
void adjustOption(bool adjust_up);
|
||||||
void selectOption();
|
void selectOption();
|
||||||
void moveBack();
|
void moveBack();
|
||||||
|
|
||||||
// --- Getters para que el Renderer pueda leer el estado ---
|
// --- Getters para que el Renderer pueda leer el estado ---
|
||||||
bool isEnabled() const { return enabled_; }
|
bool isEnabled() const { return enabled_; }
|
||||||
const std::string& getTitle() const { return title_; }
|
const std::string &getTitle() const { return title_; }
|
||||||
SettingsGroup getCurrentGroup() const { return current_settings_group_; }
|
SettingsGroup getCurrentGroup() const { return current_settings_group_; }
|
||||||
GroupAlignment getCurrentGroupAlignment() const;
|
GroupAlignment getCurrentGroupAlignment() const;
|
||||||
const std::vector<MenuOption*>& getDisplayOptions() const { return display_options_; }
|
const std::vector<MenuOption *> &getDisplayOptions() const { return display_options_; }
|
||||||
const std::vector<std::unique_ptr<MenuOption>>& getAllOptions() const { return options_; }
|
const std::vector<std::unique_ptr<MenuOption>> &getAllOptions() const { return options_; }
|
||||||
size_t getSelectedIndex() const { return selected_; }
|
size_t getSelectedIndex() const { return selected_; }
|
||||||
const std::vector<std::pair<std::string, std::string>>& getOptionPairs() const { return option_pairs_; }
|
const std::vector<std::pair<std::string, std::string>> &getOptionPairs() const { return option_pairs_; }
|
||||||
size_t countOptionsInGroup(SettingsGroup group) const;
|
size_t countOptionsInGroup(SettingsGroup group) const;
|
||||||
Aspect getAspect() const { return aspect_; }
|
Aspect getAspect() const { return aspect_; }
|
||||||
|
|
||||||
@@ -55,9 +71,9 @@ private:
|
|||||||
// --- Lógica de estado del menú (Modelo) ---
|
// --- Lógica de estado del menú (Modelo) ---
|
||||||
bool enabled_ = false;
|
bool enabled_ = false;
|
||||||
std::vector<std::unique_ptr<MenuOption>> options_;
|
std::vector<std::unique_ptr<MenuOption>> options_;
|
||||||
std::vector<MenuOption*> display_options_;
|
std::vector<MenuOption *> display_options_;
|
||||||
std::vector<std::pair<std::string, std::string>> option_pairs_;
|
std::vector<std::pair<std::string, std::string>> option_pairs_;
|
||||||
|
|
||||||
SettingsGroup current_settings_group_;
|
SettingsGroup current_settings_group_;
|
||||||
SettingsGroup previous_settings_group_;
|
SettingsGroup previous_settings_group_;
|
||||||
Aspect aspect_ = Aspect::ALPHA;
|
Aspect aspect_ = Aspect::ALPHA;
|
||||||
@@ -73,9 +89,15 @@ private:
|
|||||||
std::unique_ptr<MenuRenderer> renderer_;
|
std::unique_ptr<MenuRenderer> renderer_;
|
||||||
|
|
||||||
// --- Métodos de lógica interna ---
|
// --- Métodos de lógica interna ---
|
||||||
|
void updateDisplayOptions();
|
||||||
|
void updateOptionPairs();
|
||||||
void initializeOptions();
|
void initializeOptions();
|
||||||
void updateMenu();
|
void updateMenu();
|
||||||
void applySettings();
|
void applySettings();
|
||||||
|
void applyVideoSettings();
|
||||||
|
void applyAudioSettings();
|
||||||
|
void applySettingsSettings();
|
||||||
|
MenuOption *getOptionByCaption(const std::string &caption) const;
|
||||||
void AdjustListValues();
|
void AdjustListValues();
|
||||||
void playMenuSound();
|
void playMenuSound();
|
||||||
std::string settingsGroupToString(SettingsGroup group) const;
|
std::string settingsGroupToString(SettingsGroup group) const;
|
||||||
@@ -83,7 +105,7 @@ private:
|
|||||||
// --- Singleton ---
|
// --- Singleton ---
|
||||||
ServiceMenu();
|
ServiceMenu();
|
||||||
~ServiceMenu() = default;
|
~ServiceMenu() = default;
|
||||||
ServiceMenu(const ServiceMenu&) = delete;
|
ServiceMenu(const ServiceMenu &) = delete;
|
||||||
ServiceMenu& operator=(const ServiceMenu&) = delete;
|
ServiceMenu &operator=(const ServiceMenu &) = delete;
|
||||||
static ServiceMenu* instance_;
|
static ServiceMenu *instance_;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user