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 ---
|
||||
|
||||
void ServiceMenu::updateMenu()
|
||||
void ServiceMenu::updateDisplayOptions()
|
||||
{
|
||||
title_ = settingsGroupToString(current_settings_group_);
|
||||
AdjustListValues();
|
||||
|
||||
// Actualiza las opciones visibles
|
||||
display_options_.clear();
|
||||
for (auto &option : options_)
|
||||
{
|
||||
@@ -156,13 +152,25 @@ void ServiceMenu::updateMenu()
|
||||
display_options_.push_back(option.get());
|
||||
}
|
||||
}
|
||||
updateOptionPairs();
|
||||
}
|
||||
|
||||
// Actualiza los pares de strings para el renderer
|
||||
void ServiceMenu::updateOptionPairs()
|
||||
{
|
||||
option_pairs_.clear();
|
||||
for (const auto &option : display_options_)
|
||||
{
|
||||
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
|
||||
renderer_->onLayoutChanged(this);
|
||||
@@ -171,27 +179,48 @@ void ServiceMenu::updateMenu()
|
||||
void ServiceMenu::applySettings()
|
||||
{
|
||||
if (current_settings_group_ == SettingsGroup::VIDEO)
|
||||
Screen::get()->applySettings();
|
||||
applyVideoSettings();
|
||||
if (current_settings_group_ == SettingsGroup::AUDIO)
|
||||
Audio::get()->applySettings();
|
||||
applyAudioSettings();
|
||||
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]"))
|
||||
{
|
||||
option->setHidden(!Options::settings.shutdown_enabled);
|
||||
updateMenu(); // El menú debe refrescarse si algo se oculta
|
||||
break;
|
||||
}
|
||||
return option.get();
|
||||
}
|
||||
}
|
||||
// Refresca los pares de strings por si un valor cambió
|
||||
option_pairs_.clear();
|
||||
for (const auto &option : display_options_)
|
||||
{
|
||||
option_pairs_.emplace_back(option->getCaption(), option->getValueAsString());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// --- Getters y otros ---
|
||||
|
||||
@@ -12,11 +12,27 @@ class Text;
|
||||
class MenuOption;
|
||||
class MenuRenderer; // <-- Nuevo
|
||||
|
||||
class ServiceMenu {
|
||||
class ServiceMenu
|
||||
{
|
||||
public:
|
||||
enum class Aspect { SHADOW, ALPHA };
|
||||
enum class SettingsGroup { VIDEO, AUDIO, SETTINGS, SYSTEM, MAIN };
|
||||
enum class GroupAlignment { CENTERED, LEFT };
|
||||
enum class Aspect
|
||||
{
|
||||
SHADOW,
|
||||
ALPHA
|
||||
};
|
||||
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;
|
||||
@@ -25,11 +41,11 @@ public:
|
||||
|
||||
static void init();
|
||||
static void destroy();
|
||||
static ServiceMenu* get();
|
||||
static ServiceMenu *get();
|
||||
|
||||
void toggle();
|
||||
void render();
|
||||
void update();
|
||||
void render();
|
||||
void update();
|
||||
void reset();
|
||||
|
||||
// --- Lógica de navegación ---
|
||||
@@ -38,16 +54,16 @@ public:
|
||||
void adjustOption(bool adjust_up);
|
||||
void selectOption();
|
||||
void moveBack();
|
||||
|
||||
|
||||
// --- Getters para que el Renderer pueda leer el estado ---
|
||||
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_; }
|
||||
GroupAlignment getCurrentGroupAlignment() const;
|
||||
const std::vector<MenuOption*>& getDisplayOptions() const { return display_options_; }
|
||||
const std::vector<std::unique_ptr<MenuOption>>& getAllOptions() const { return options_; }
|
||||
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_; }
|
||||
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_; }
|
||||
|
||||
@@ -55,9 +71,9 @@ private:
|
||||
// --- Lógica de estado del menú (Modelo) ---
|
||||
bool enabled_ = false;
|
||||
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_;
|
||||
|
||||
|
||||
SettingsGroup current_settings_group_;
|
||||
SettingsGroup previous_settings_group_;
|
||||
Aspect aspect_ = Aspect::ALPHA;
|
||||
@@ -73,9 +89,15 @@ private:
|
||||
std::unique_ptr<MenuRenderer> renderer_;
|
||||
|
||||
// --- Métodos de lógica interna ---
|
||||
void updateDisplayOptions();
|
||||
void updateOptionPairs();
|
||||
void initializeOptions();
|
||||
void updateMenu();
|
||||
void applySettings();
|
||||
void applyVideoSettings();
|
||||
void applyAudioSettings();
|
||||
void applySettingsSettings();
|
||||
MenuOption *getOptionByCaption(const std::string &caption) const;
|
||||
void AdjustListValues();
|
||||
void playMenuSound();
|
||||
std::string settingsGroupToString(SettingsGroup group) const;
|
||||
@@ -83,7 +105,7 @@ private:
|
||||
// --- 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