ServiceMenu: arreglos de colorets
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
#include "ui/service_menu.h"
|
||||
#include "menu_renderer.h"
|
||||
#include "menu_renderer.h"
|
||||
#include "menu_option.h"
|
||||
#include "resource.h"
|
||||
#include "audio.h"
|
||||
#include "section.h"
|
||||
#include "screen.h"
|
||||
#include "screen.h"
|
||||
#include "asset.h"
|
||||
|
||||
// Singleton
|
||||
ServiceMenu* ServiceMenu::instance_ = nullptr;
|
||||
ServiceMenu *ServiceMenu::instance_ = nullptr;
|
||||
void ServiceMenu::init() { ServiceMenu::instance_ = new ServiceMenu(); }
|
||||
void ServiceMenu::destroy() { delete ServiceMenu::instance_; }
|
||||
ServiceMenu* ServiceMenu::get() { return ServiceMenu::instance_; }
|
||||
ServiceMenu *ServiceMenu::get() { return ServiceMenu::instance_; }
|
||||
|
||||
// Constructor
|
||||
ServiceMenu::ServiceMenu()
|
||||
@@ -21,23 +21,27 @@ ServiceMenu::ServiceMenu()
|
||||
auto element_text = Resource::get()->getText("04b_25_flat");
|
||||
auto title_text = Resource::get()->getText("04b_25_flat_2x");
|
||||
|
||||
renderer_ = std::make_unique<MenuRenderer>(element_text, title_text);
|
||||
renderer_ = std::make_unique<MenuRenderer>(this, element_text, title_text);
|
||||
restart_message_ui_ = std::make_unique<UIMessage>(element_text, Lang::getText("[SERVICE_MENU] NEED_RESTART_MESSAGE"), SERV_MENU_TITLE_COLOR);
|
||||
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
void ServiceMenu::toggle() {
|
||||
void ServiceMenu::toggle()
|
||||
{
|
||||
enabled_ = !enabled_;
|
||||
if (!enabled_) {
|
||||
if (!enabled_)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceMenu::render() {
|
||||
if (!enabled_) return;
|
||||
void ServiceMenu::render()
|
||||
{
|
||||
if (!enabled_)
|
||||
return;
|
||||
renderer_->render(this);
|
||||
|
||||
|
||||
// El mensaje de reinicio se dibuja por encima, así que lo gestionamos aquí
|
||||
const float MSG_X = param.game.game_area.center_x;
|
||||
const float MSG_Y = renderer_->getRect().y + 39.0f;
|
||||
@@ -45,20 +49,24 @@ void ServiceMenu::render() {
|
||||
restart_message_ui_->render();
|
||||
}
|
||||
|
||||
void ServiceMenu::update() {
|
||||
if (!enabled_) return;
|
||||
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;
|
||||
@@ -69,45 +77,60 @@ void ServiceMenu::reset() {
|
||||
}
|
||||
|
||||
// --- Lógica de Navegación ---
|
||||
void ServiceMenu::setSelectorUp() {
|
||||
if (display_options_.empty()) return;
|
||||
void ServiceMenu::setSelectorUp()
|
||||
{
|
||||
if (display_options_.empty())
|
||||
return;
|
||||
selected_ = (selected_ > 0) ? selected_ - 1 : display_options_.size() - 1;
|
||||
playMenuSound();
|
||||
}
|
||||
|
||||
void ServiceMenu::setSelectorDown() {
|
||||
if (display_options_.empty()) return;
|
||||
void ServiceMenu::setSelectorDown()
|
||||
{
|
||||
if (display_options_.empty())
|
||||
return;
|
||||
selected_ = (selected_ + 1) % display_options_.size();
|
||||
playMenuSound();
|
||||
}
|
||||
|
||||
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) {
|
||||
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)
|
||||
{
|
||||
selected_option->adjustValue(adjust_up);
|
||||
applySettings();
|
||||
playMenuSound();
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
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))
|
||||
{
|
||||
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();
|
||||
}
|
||||
playMenuSound();
|
||||
}
|
||||
|
||||
void ServiceMenu::moveBack() {
|
||||
if (current_settings_group_ == SettingsGroup::MAIN) {
|
||||
void ServiceMenu::moveBack()
|
||||
{
|
||||
if (current_settings_group_ == SettingsGroup::MAIN)
|
||||
{
|
||||
enabled_ = false;
|
||||
return;
|
||||
}
|
||||
@@ -119,21 +142,25 @@ void ServiceMenu::moveBack() {
|
||||
|
||||
// --- Lógica Interna ---
|
||||
|
||||
void ServiceMenu::updateMenu() {
|
||||
void ServiceMenu::updateMenu()
|
||||
{
|
||||
title_ = settingsGroupToString(current_settings_group_);
|
||||
AdjustListValues();
|
||||
|
||||
// Actualiza las opciones visibles
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Actualiza los pares de strings para el renderer
|
||||
option_pairs_.clear();
|
||||
for (const auto& option : display_options_) {
|
||||
for (const auto &option : display_options_)
|
||||
{
|
||||
option_pairs_.emplace_back(option->getCaption(), option->getValueAsString());
|
||||
}
|
||||
|
||||
@@ -141,12 +168,18 @@ void ServiceMenu::updateMenu() {
|
||||
renderer_->onLayoutChanged(this);
|
||||
}
|
||||
|
||||
void ServiceMenu::applySettings() {
|
||||
if (current_settings_group_ == SettingsGroup::VIDEO) Screen::get()->applySettings();
|
||||
if (current_settings_group_ == SettingsGroup::AUDIO) Audio::get()->applySettings();
|
||||
if (current_settings_group_ == SettingsGroup::SETTINGS) {
|
||||
for(auto& option : options_){
|
||||
if(option->getCaption() == Lang::getText("[SERVICE_MENU] SHUTDOWN]")){
|
||||
void ServiceMenu::applySettings()
|
||||
{
|
||||
if (current_settings_group_ == SettingsGroup::VIDEO)
|
||||
Screen::get()->applySettings();
|
||||
if (current_settings_group_ == SettingsGroup::AUDIO)
|
||||
Audio::get()->applySettings();
|
||||
if (current_settings_group_ == SettingsGroup::SETTINGS)
|
||||
{
|
||||
for (auto &option : options_)
|
||||
{
|
||||
if (option->getCaption() == Lang::getText("[SERVICE_MENU] SHUTDOWN]"))
|
||||
{
|
||||
option->setHidden(!Options::settings.shutdown_enabled);
|
||||
updateMenu(); // El menú debe refrescarse si algo se oculta
|
||||
break;
|
||||
@@ -155,28 +188,34 @@ void ServiceMenu::applySettings() {
|
||||
}
|
||||
// Refresca los pares de strings por si un valor cambió
|
||||
option_pairs_.clear();
|
||||
for (const auto& option : display_options_) {
|
||||
for (const auto &option : display_options_)
|
||||
{
|
||||
option_pairs_.emplace_back(option->getCaption(), option->getValueAsString());
|
||||
}
|
||||
}
|
||||
|
||||
// --- 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++;
|
||||
}
|
||||
}
|
||||
@@ -225,7 +264,7 @@ void ServiceMenu::initializeOptions()
|
||||
options_.push_back(std::make_unique<FolderOption>(Lang::getText("[SERVICE_MENU] SETTINGS"), SettingsGroup::MAIN, SettingsGroup::SETTINGS));
|
||||
options_.push_back(std::make_unique<FolderOption>(Lang::getText("[SERVICE_MENU] SYSTEM"), SettingsGroup::MAIN, SettingsGroup::SYSTEM));
|
||||
|
||||
//precalculateMenuWidths();
|
||||
// precalculateMenuWidths();
|
||||
}
|
||||
|
||||
// Sincroniza los valores de las opciones tipo lista
|
||||
@@ -240,7 +279,6 @@ void ServiceMenu::AdjustListValues()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Reproduce el sonido de navegación del menú
|
||||
void ServiceMenu::playMenuSound() { Audio::get()->playSound("clock.wav"); }
|
||||
|
||||
@@ -263,4 +301,3 @@ std::string ServiceMenu::settingsGroupToString(SettingsGroup group) const
|
||||
return Lang::getText("[SERVICE_MENU] TITLE");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user