Fixing submenus
This commit is contained in:
@@ -213,7 +213,16 @@ void SettingsActivity::toggleCurrentSetting() {
|
||||
if (setting.isSeparator) return;
|
||||
|
||||
if (setting.type == SettingType::ACTION) {
|
||||
auto resultHandler = [this](const ActivityResult&) { SETTINGS.saveToFile(); };
|
||||
auto resultHandler = [this](const ActivityResult& result) {
|
||||
SETTINGS.saveToFile();
|
||||
const auto* menuResult = std::get_if<MenuResult>(&result.data);
|
||||
if (menuResult && menuResult->action != -1) {
|
||||
auto activity = createActivityForAction(static_cast<SettingAction>(menuResult->action), renderer, mappedInput);
|
||||
if (activity) {
|
||||
startActivityForResult(std::move(activity), [this](const ActivityResult&) { SETTINGS.saveToFile(); });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (setting.action == SettingAction::Submenu) {
|
||||
auto it = std::find_if(submenuData.begin(), submenuData.end(),
|
||||
|
||||
@@ -17,10 +17,32 @@ void SettingsSubmenuActivity::onEnter() {
|
||||
|
||||
void SettingsSubmenuActivity::onActionSelected(int index) {
|
||||
const auto& setting = menuItems[index];
|
||||
auto resultHandler = [this](const ActivityResult&) { SETTINGS.saveToFile(); };
|
||||
if (setting.isSeparator) return;
|
||||
|
||||
auto activity = createActivityForAction(setting.action, renderer, mappedInput);
|
||||
if (activity) startActivityForResult(std::move(activity), resultHandler);
|
||||
if (setting.type == SettingType::ACTION) {
|
||||
MenuResult menuResult;
|
||||
if (setting.action != SettingAction::None) {
|
||||
menuResult.action = static_cast<int>(setting.action);
|
||||
} else {
|
||||
menuResult.nameId = static_cast<int>(setting.nameId);
|
||||
}
|
||||
setResult(ActivityResult(menuResult));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
onSettingToggled(index);
|
||||
}
|
||||
|
||||
std::string SettingsSubmenuActivity::getItemValueString(int index) const {
|
||||
const auto& item = menuItems[index];
|
||||
if (item.type == SettingType::ACTION && item.action != SettingAction::Submenu) {
|
||||
return {};
|
||||
}
|
||||
if (itemValueStringOverride) {
|
||||
return itemValueStringOverride(item);
|
||||
}
|
||||
return MenuListActivity::getItemValueString(index);
|
||||
}
|
||||
|
||||
void SettingsSubmenuActivity::onSettingToggled(int /*index*/) { SETTINGS.saveToFile(); }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <I18n.h>
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "SettingInfo.h"
|
||||
@@ -10,16 +11,21 @@
|
||||
// Supports subcategory separators (withSubcategory) exactly as the parent settings tabs do.
|
||||
class SettingsSubmenuActivity final : public MenuListActivity {
|
||||
StrId titleId;
|
||||
std::function<std::string(const SettingInfo&)> itemValueStringOverride;
|
||||
|
||||
// MenuListActivity overrides
|
||||
void onEnter() override;
|
||||
void onActionSelected(int index) override;
|
||||
void onSettingToggled(int index) override;
|
||||
std::string getItemValueString(int index) const override;
|
||||
|
||||
public:
|
||||
explicit SettingsSubmenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, StrId titleId,
|
||||
std::vector<SettingInfo> items)
|
||||
: MenuListActivity("SettingsSubmenu", renderer, mappedInput), titleId(titleId) {
|
||||
std::vector<SettingInfo> items,
|
||||
std::function<std::string(const SettingInfo&)> itemValueStringOverride = {})
|
||||
: MenuListActivity("SettingsSubmenu", renderer, mappedInput),
|
||||
titleId(titleId),
|
||||
itemValueStringOverride(std::move(itemValueStringOverride)) {
|
||||
menuItems = std::move(items);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user