pasaeta loca de clang-format (despres m'arrepentiré pero bueno)
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
#include "ui/service_menu.h"
|
||||
|
||||
#include "audio.h" // Para Audio
|
||||
#include "lang.h" // Para getText, getCodeFromName, getNameFromCode
|
||||
#include "menu_option.h" // Para MenuOption, BoolOption, ActionOption, Int...
|
||||
#include "menu_renderer.h" // Para MenuRenderer
|
||||
#include "options.h" // Para PendingChanges, VideoOptions, pending_cha...
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamServiceMenu
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.h" // Para Name, name, Options, options
|
||||
#include "ui/ui_message.h" // Para UIMessage
|
||||
#include "utils.h" // Para Zone
|
||||
#include "audio.h" // Para Audio
|
||||
#include "lang.h" // Para getText, getCodeFromName, getNameFromCode
|
||||
#include "menu_option.h" // Para MenuOption, BoolOption, ActionOption, Int...
|
||||
#include "menu_renderer.h" // Para MenuRenderer
|
||||
#include "options.h" // Para PendingChanges, VideoOptions, pending_cha...
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamServiceMenu
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.h" // Para Name, name, Options, options
|
||||
#include "ui/ui_message.h" // Para UIMessage
|
||||
#include "utils.h" // Para Zone
|
||||
|
||||
// Singleton
|
||||
ServiceMenu *ServiceMenu::instance_ = nullptr;
|
||||
@@ -21,8 +21,7 @@ ServiceMenu *ServiceMenu::get() { return ServiceMenu::instance_; }
|
||||
// Constructor
|
||||
ServiceMenu::ServiceMenu()
|
||||
: current_settings_group_(SettingsGroup::MAIN),
|
||||
previous_settings_group_(current_settings_group_)
|
||||
{
|
||||
previous_settings_group_(current_settings_group_) {
|
||||
auto element_text = Resource::get()->getText("04b_25_flat");
|
||||
auto title_text = Resource::get()->getText("04b_25_flat_2x");
|
||||
|
||||
@@ -32,18 +31,15 @@ ServiceMenu::ServiceMenu()
|
||||
reset();
|
||||
}
|
||||
|
||||
void ServiceMenu::toggle()
|
||||
{
|
||||
void ServiceMenu::toggle() {
|
||||
playBackSound();
|
||||
enabled_ = !enabled_;
|
||||
if (!enabled_)
|
||||
{
|
||||
if (!enabled_) {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceMenu::render()
|
||||
{
|
||||
void ServiceMenu::render() {
|
||||
if (!enabled_)
|
||||
return;
|
||||
renderer_->render(this);
|
||||
@@ -55,89 +51,76 @@ void ServiceMenu::render()
|
||||
restart_message_ui_->render();
|
||||
}
|
||||
|
||||
void ServiceMenu::update()
|
||||
{
|
||||
void ServiceMenu::update() {
|
||||
if (!enabled_)
|
||||
return;
|
||||
|
||||
renderer_->update(this);
|
||||
|
||||
bool now_pending = Options::pending_changes.has_pending_changes;
|
||||
if (now_pending != last_pending_changes_)
|
||||
{
|
||||
if (now_pending != last_pending_changes_) {
|
||||
now_pending ? restart_message_ui_->show() : restart_message_ui_->hide();
|
||||
last_pending_changes_ = now_pending;
|
||||
}
|
||||
restart_message_ui_->update();
|
||||
}
|
||||
|
||||
void ServiceMenu::reset()
|
||||
{
|
||||
void ServiceMenu::reset() {
|
||||
selected_ = 0;
|
||||
main_menu_selected_ = 0;
|
||||
current_settings_group_ = SettingsGroup::MAIN;
|
||||
previous_settings_group_ = SettingsGroup::MAIN;
|
||||
initializeOptions();
|
||||
updateMenu();
|
||||
renderer_->setLayout(this); // Notifica al renderer para que calcule el layout inicial
|
||||
renderer_->setLayout(this); // Notifica al renderer para que calcule el layout inicial
|
||||
}
|
||||
|
||||
// --- Lógica de Navegación ---
|
||||
void ServiceMenu::setSelectorUp()
|
||||
{
|
||||
void ServiceMenu::setSelectorUp() {
|
||||
if (display_options_.empty())
|
||||
return;
|
||||
selected_ = (selected_ > 0) ? selected_ - 1 : display_options_.size() - 1;
|
||||
playMoveSound();
|
||||
}
|
||||
|
||||
void ServiceMenu::setSelectorDown()
|
||||
{
|
||||
void ServiceMenu::setSelectorDown() {
|
||||
if (display_options_.empty())
|
||||
return;
|
||||
selected_ = (selected_ + 1) % display_options_.size();
|
||||
playMoveSound();
|
||||
}
|
||||
|
||||
void ServiceMenu::adjustOption(bool adjust_up)
|
||||
{
|
||||
void ServiceMenu::adjustOption(bool adjust_up) {
|
||||
if (display_options_.empty())
|
||||
return;
|
||||
auto &selected_option = display_options_.at(selected_);
|
||||
if (selected_option->getBehavior() == MenuOption::Behavior::ADJUST)
|
||||
{
|
||||
if (selected_option->getBehavior() == MenuOption::Behavior::ADJUST) {
|
||||
selected_option->adjustValue(adjust_up);
|
||||
applySettings();
|
||||
playAdjustSound();
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceMenu::selectOption()
|
||||
{
|
||||
void ServiceMenu::selectOption() {
|
||||
if (display_options_.empty())
|
||||
return;
|
||||
if (current_settings_group_ == SettingsGroup::MAIN)
|
||||
main_menu_selected_ = selected_;
|
||||
auto &selected_option = display_options_.at(selected_);
|
||||
if (auto folder = dynamic_cast<FolderOption *>(selected_option))
|
||||
{
|
||||
if (auto folder = dynamic_cast<FolderOption *>(selected_option)) {
|
||||
previous_settings_group_ = current_settings_group_;
|
||||
current_settings_group_ = folder->getTargetGroup();
|
||||
selected_ = 0;
|
||||
updateMenu();
|
||||
}
|
||||
else if (selected_option->getBehavior() == MenuOption::Behavior::SELECT)
|
||||
{
|
||||
} else if (selected_option->getBehavior() == MenuOption::Behavior::SELECT) {
|
||||
selected_option->executeAction();
|
||||
}
|
||||
playSelectSound();
|
||||
}
|
||||
|
||||
void ServiceMenu::moveBack()
|
||||
{
|
||||
void ServiceMenu::moveBack() {
|
||||
playBackSound();
|
||||
if (current_settings_group_ == SettingsGroup::MAIN)
|
||||
{
|
||||
if (current_settings_group_ == SettingsGroup::MAIN) {
|
||||
enabled_ = false;
|
||||
return;
|
||||
}
|
||||
@@ -148,30 +131,24 @@ void ServiceMenu::moveBack()
|
||||
|
||||
// --- Lógica Interna ---
|
||||
|
||||
void ServiceMenu::updateDisplayOptions()
|
||||
{
|
||||
void ServiceMenu::updateDisplayOptions() {
|
||||
display_options_.clear();
|
||||
for (auto &option : options_)
|
||||
{
|
||||
if (option->getGroup() == current_settings_group_ && !option->isHidden())
|
||||
{
|
||||
for (auto &option : options_) {
|
||||
if (option->getGroup() == current_settings_group_ && !option->isHidden()) {
|
||||
display_options_.push_back(option.get());
|
||||
}
|
||||
}
|
||||
updateOptionPairs();
|
||||
}
|
||||
|
||||
void ServiceMenu::updateOptionPairs()
|
||||
{
|
||||
void ServiceMenu::updateOptionPairs() {
|
||||
option_pairs_.clear();
|
||||
for (const auto &option : display_options_)
|
||||
{
|
||||
for (const auto &option : display_options_) {
|
||||
option_pairs_.emplace_back(option->getCaption(), option->getValueAsString());
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceMenu::updateMenu()
|
||||
{
|
||||
void ServiceMenu::updateMenu() {
|
||||
title_ = settingsGroupToString(current_settings_group_);
|
||||
AdjustListValues();
|
||||
|
||||
@@ -182,8 +159,7 @@ void ServiceMenu::updateMenu()
|
||||
renderer_->onLayoutChanged(this);
|
||||
}
|
||||
|
||||
void ServiceMenu::applySettings()
|
||||
{
|
||||
void ServiceMenu::applySettings() {
|
||||
if (current_settings_group_ == SettingsGroup::VIDEO)
|
||||
applyVideoSettings();
|
||||
if (current_settings_group_ == SettingsGroup::AUDIO)
|
||||
@@ -195,28 +171,22 @@ void ServiceMenu::applySettings()
|
||||
updateOptionPairs();
|
||||
}
|
||||
|
||||
void ServiceMenu::applyVideoSettings()
|
||||
{
|
||||
void ServiceMenu::applyVideoSettings() {
|
||||
Screen::get()->applySettings();
|
||||
setHiddenOptions();
|
||||
}
|
||||
|
||||
void ServiceMenu::applyAudioSettings()
|
||||
{
|
||||
void ServiceMenu::applyAudioSettings() {
|
||||
Audio::get()->applySettings();
|
||||
}
|
||||
|
||||
void ServiceMenu::applySettingsSettings()
|
||||
{
|
||||
void ServiceMenu::applySettingsSettings() {
|
||||
setHiddenOptions();
|
||||
}
|
||||
|
||||
MenuOption *ServiceMenu::getOptionByCaption(const std::string &caption) const
|
||||
{
|
||||
for (const auto &option : options_)
|
||||
{
|
||||
if (option->getCaption() == caption)
|
||||
{
|
||||
MenuOption *ServiceMenu::getOptionByCaption(const std::string &caption) const {
|
||||
for (const auto &option : options_) {
|
||||
if (option->getCaption() == caption) {
|
||||
return option.get();
|
||||
}
|
||||
}
|
||||
@@ -225,26 +195,21 @@ MenuOption *ServiceMenu::getOptionByCaption(const std::string &caption) const
|
||||
|
||||
// --- Getters y otros ---
|
||||
|
||||
ServiceMenu::GroupAlignment ServiceMenu::getCurrentGroupAlignment() const
|
||||
{
|
||||
switch (current_settings_group_)
|
||||
{
|
||||
case SettingsGroup::VIDEO:
|
||||
case SettingsGroup::AUDIO:
|
||||
case SettingsGroup::SETTINGS:
|
||||
return GroupAlignment::LEFT;
|
||||
default:
|
||||
return GroupAlignment::CENTERED;
|
||||
ServiceMenu::GroupAlignment ServiceMenu::getCurrentGroupAlignment() const {
|
||||
switch (current_settings_group_) {
|
||||
case SettingsGroup::VIDEO:
|
||||
case SettingsGroup::AUDIO:
|
||||
case SettingsGroup::SETTINGS:
|
||||
return GroupAlignment::LEFT;
|
||||
default:
|
||||
return GroupAlignment::CENTERED;
|
||||
}
|
||||
}
|
||||
|
||||
size_t ServiceMenu::countOptionsInGroup(SettingsGroup group) const
|
||||
{
|
||||
size_t ServiceMenu::countOptionsInGroup(SettingsGroup group) const {
|
||||
size_t count = 0;
|
||||
for (const auto &option : options_)
|
||||
{
|
||||
if (option->getGroup() == group && !option->isHidden())
|
||||
{
|
||||
for (const auto &option : options_) {
|
||||
if (option->getGroup() == group && !option->isHidden()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@@ -252,8 +217,7 @@ size_t ServiceMenu::countOptionsInGroup(SettingsGroup group) const
|
||||
}
|
||||
|
||||
// Inicializa todas las opciones del menú
|
||||
void ServiceMenu::initializeOptions()
|
||||
{
|
||||
void ServiceMenu::initializeOptions() {
|
||||
options_.clear();
|
||||
|
||||
// --- Video ---
|
||||
@@ -271,21 +235,14 @@ void ServiceMenu::initializeOptions()
|
||||
|
||||
// --- Settings ---
|
||||
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] AUTOFIRE"), SettingsGroup::SETTINGS, &Options::settings.autofire));
|
||||
options_.push_back(std::make_unique<ListOption>(Lang::getText("[SERVICE_MENU] LANGUAGE"), SettingsGroup::SETTINGS, std::vector<std::string>{Lang::getText("[SERVICE_MENU] LANG_ES"), Lang::getText("[SERVICE_MENU] LANG_BA"), Lang::getText("[SERVICE_MENU] LANG_EN")}, []()
|
||||
{ return Lang::getNameFromCode(Options::pending_changes.new_language); }, [](const std::string &val)
|
||||
{ Options::pending_changes.new_language = Lang::getCodeFromName(val); Options::checkPendingChanges(); }));
|
||||
options_.push_back(std::make_unique<ListOption>(Lang::getText("[SERVICE_MENU] DIFFICULTY"), SettingsGroup::SETTINGS, std::vector<std::string>{Lang::getText("[SERVICE_MENU] EASY"), Lang::getText("[SERVICE_MENU] NORMAL"), Lang::getText("[SERVICE_MENU] HARD")}, []()
|
||||
{ return Options::getDifficultyNameFromCode(Options::pending_changes.new_difficulty); }, [](const std::string &val)
|
||||
{ Options::pending_changes.new_difficulty = Options::getDifficultyCodeFromName(val); Options::checkPendingChanges(); }));
|
||||
options_.push_back(std::make_unique<ListOption>(Lang::getText("[SERVICE_MENU] LANGUAGE"), SettingsGroup::SETTINGS, std::vector<std::string>{Lang::getText("[SERVICE_MENU] LANG_ES"), Lang::getText("[SERVICE_MENU] LANG_BA"), Lang::getText("[SERVICE_MENU] LANG_EN")}, []() { return Lang::getNameFromCode(Options::pending_changes.new_language); }, [](const std::string &val) { Options::pending_changes.new_language = Lang::getCodeFromName(val); Options::checkPendingChanges(); }));
|
||||
options_.push_back(std::make_unique<ListOption>(Lang::getText("[SERVICE_MENU] DIFFICULTY"), SettingsGroup::SETTINGS, std::vector<std::string>{Lang::getText("[SERVICE_MENU] EASY"), Lang::getText("[SERVICE_MENU] NORMAL"), Lang::getText("[SERVICE_MENU] HARD")}, []() { return Options::getDifficultyNameFromCode(Options::pending_changes.new_difficulty); }, [](const std::string &val) { Options::pending_changes.new_difficulty = Options::getDifficultyCodeFromName(val); Options::checkPendingChanges(); }));
|
||||
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] ENABLE_SHUTDOWN"), SettingsGroup::SETTINGS, &Options::settings.shutdown_enabled));
|
||||
|
||||
// --- System ---
|
||||
options_.push_back(std::make_unique<ActionOption>(Lang::getText("[SERVICE_MENU] RESET"), SettingsGroup::SYSTEM, [this]()
|
||||
{ Section::name = Section::Name::RESET; toggle(); }));
|
||||
options_.push_back(std::make_unique<ActionOption>(Lang::getText("[SERVICE_MENU] QUIT"), SettingsGroup::SYSTEM, []()
|
||||
{ Section::name = Section::Name::QUIT; Section::options = Section::Options::NONE; }));
|
||||
options_.push_back(std::make_unique<ActionOption>(Lang::getText("[SERVICE_MENU] SHUTDOWN"), SettingsGroup::SYSTEM, []()
|
||||
{ Section::name = Section::Name::QUIT; Section::options = Section::Options::SHUTDOWN; }, !Options::settings.shutdown_enabled));
|
||||
options_.push_back(std::make_unique<ActionOption>(Lang::getText("[SERVICE_MENU] RESET"), SettingsGroup::SYSTEM, [this]() { Section::name = Section::Name::RESET; toggle(); }));
|
||||
options_.push_back(std::make_unique<ActionOption>(Lang::getText("[SERVICE_MENU] QUIT"), SettingsGroup::SYSTEM, []() { Section::name = Section::Name::QUIT; Section::options = Section::Options::NONE; }));
|
||||
options_.push_back(std::make_unique<ActionOption>(Lang::getText("[SERVICE_MENU] SHUTDOWN"), SettingsGroup::SYSTEM, []() { Section::name = Section::Name::QUIT; Section::options = Section::Options::SHUTDOWN; }, !Options::settings.shutdown_enabled));
|
||||
|
||||
// --- Main Menu ---
|
||||
options_.push_back(std::make_unique<FolderOption>(Lang::getText("[SERVICE_MENU] VIDEO"), SettingsGroup::MAIN, SettingsGroup::VIDEO));
|
||||
@@ -297,12 +254,9 @@ void ServiceMenu::initializeOptions()
|
||||
}
|
||||
|
||||
// Sincroniza los valores de las opciones tipo lista
|
||||
void ServiceMenu::AdjustListValues()
|
||||
{
|
||||
for (auto &option : options_)
|
||||
{
|
||||
if (auto list_option = dynamic_cast<ListOption *>(option.get()))
|
||||
{
|
||||
void ServiceMenu::AdjustListValues() {
|
||||
for (auto &option : options_) {
|
||||
if (auto list_option = dynamic_cast<ListOption *>(option.get())) {
|
||||
list_option->sync();
|
||||
}
|
||||
}
|
||||
@@ -315,28 +269,25 @@ void ServiceMenu::playSelectSound() { Audio::get()->playSound("service_menu_sele
|
||||
void ServiceMenu::playBackSound() { Audio::get()->playSound("service_menu_select.wav", Audio::Group::INTERFACE); }
|
||||
|
||||
// Devuelve el nombre del grupo como string para el título
|
||||
std::string ServiceMenu::settingsGroupToString(SettingsGroup group) const
|
||||
{
|
||||
switch (group)
|
||||
{
|
||||
case SettingsGroup::MAIN:
|
||||
return Lang::getText("[SERVICE_MENU] TITLE");
|
||||
case SettingsGroup::VIDEO:
|
||||
return Lang::getText("[SERVICE_MENU] VIDEO");
|
||||
case SettingsGroup::AUDIO:
|
||||
return Lang::getText("[SERVICE_MENU] AUDIO");
|
||||
case SettingsGroup::SETTINGS:
|
||||
return Lang::getText("[SERVICE_MENU] SETTINGS");
|
||||
case SettingsGroup::SYSTEM:
|
||||
return Lang::getText("[SERVICE_MENU] SYSTEM");
|
||||
default:
|
||||
return Lang::getText("[SERVICE_MENU] TITLE");
|
||||
std::string ServiceMenu::settingsGroupToString(SettingsGroup group) const {
|
||||
switch (group) {
|
||||
case SettingsGroup::MAIN:
|
||||
return Lang::getText("[SERVICE_MENU] TITLE");
|
||||
case SettingsGroup::VIDEO:
|
||||
return Lang::getText("[SERVICE_MENU] VIDEO");
|
||||
case SettingsGroup::AUDIO:
|
||||
return Lang::getText("[SERVICE_MENU] AUDIO");
|
||||
case SettingsGroup::SETTINGS:
|
||||
return Lang::getText("[SERVICE_MENU] SETTINGS");
|
||||
case SettingsGroup::SYSTEM:
|
||||
return Lang::getText("[SERVICE_MENU] SYSTEM");
|
||||
default:
|
||||
return Lang::getText("[SERVICE_MENU] TITLE");
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el estado de oculto de ciertas opciones
|
||||
void ServiceMenu::setHiddenOptions()
|
||||
{
|
||||
void ServiceMenu::setHiddenOptions() {
|
||||
{
|
||||
auto option = getOptionByCaption(Lang::getText("[SERVICE_MENU] WINDOW_SIZE"));
|
||||
if (option)
|
||||
@@ -349,5 +300,5 @@ void ServiceMenu::setHiddenOptions()
|
||||
option->setHidden(!Options::settings.shutdown_enabled);
|
||||
}
|
||||
|
||||
updateMenu(); // El menú debe refrescarse si algo se oculta
|
||||
updateMenu(); // El menú debe refrescarse si algo se oculta
|
||||
}
|
||||
Reference in New Issue
Block a user