FullscreenUI: Add settings reset option to settings

This commit is contained in:
Stenzek 2025-03-15 14:33:51 +10:00
parent 0a470067f5
commit c82c007a75
No known key found for this signature in database
6 changed files with 79 additions and 9 deletions

View File

@ -322,6 +322,7 @@ static float GetEffectiveFloatSetting(SettingsInterface* bsi, const char* sectio
float default_value);
static TinyString GetEffectiveTinyStringSetting(SettingsInterface* bsi, const char* section, const char* key,
const char* default_value);
static void BeginResetSettings();
static void DoCopyGameSettings();
static void DoClearGameSettings();
static void CopyGlobalControllerSettingsToGame();
@ -3465,6 +3466,20 @@ void FullscreenUI::PopulatePatchesAndCheatsList()
s_state.game_settings_interface->GetStringList(Cheats::CHEATS_CONFIG_SECTION, Cheats::PATCH_ENABLE_CONFIG_KEY);
}
void FullscreenUI::BeginResetSettings()
{
OpenConfirmMessageDialog(FSUI_STR("Restore Defaults"),
FSUI_STR("Are you sure you want to restore the default settings? Any preferences will be "
"lost.\n\nYou cannot undo this action."),
[](bool result) {
if (!result)
return;
Host::RequestResetSettings(true, false);
ShowToast(std::string(), FSUI_STR("Settings reset to default."));
});
}
void FullscreenUI::DoCopyGameSettings()
{
if (!s_state.game_settings_interface)
@ -3966,6 +3981,15 @@ void FullscreenUI::DrawInterfaceSettingsPage()
FSUI_CSTR("Shows enhancement settings in the bottom-right corner of the screen."), "Display",
"ShowEnhancements", false);
MenuHeading(FSUI_CSTR("Operations"));
{
if (MenuButton(FSUI_ICONSTR(ICON_FA_DUMPSTER_FIRE, "Restore Defaults"),
FSUI_CSTR("Resets all settings to the defaults.")))
{
BeginResetSettings();
}
}
EndMenuButtons();
}
@ -4413,9 +4437,7 @@ void FullscreenUI::BeginResetControllerSettings()
if (!result)
return;
SettingsInterface* dsi = GetEditingSettingsInterface();
Settings::SetDefaultControllerConfig(*dsi);
Host::RequestResetSettings(false, true);
ShowToast(std::string(), FSUI_STR("Controller settings reset to default."));
});
}
@ -8824,6 +8846,7 @@ TRANSLATE_NOOP("FullscreenUI", "Apply Image Patches");
TRANSLATE_NOOP("FullscreenUI", "Are you sure you want to clear all mappings for this controller?\n\nYou cannot undo this action.");
TRANSLATE_NOOP("FullscreenUI", "Are you sure you want to clear the current post-processing chain? All configuration will be lost.");
TRANSLATE_NOOP("FullscreenUI", "Are you sure you want to restore the default controller configuration?\n\nAll bindings and configuration will be lost. You cannot undo this action.");
TRANSLATE_NOOP("FullscreenUI", "Are you sure you want to restore the default settings? Any preferences will be lost.\n\nYou cannot undo this action.");
TRANSLATE_NOOP("FullscreenUI", "Aspect Ratio");
TRANSLATE_NOOP("FullscreenUI", "Attempts to detect one pixel high/wide lines that rely on non-upscaled rasterization behavior, filling in gaps introduced by upscaling.");
TRANSLATE_NOOP("FullscreenUI", "Attempts to map the selected port to a chosen controller.");
@ -8916,6 +8939,7 @@ TRANSLATE_NOOP("FullscreenUI", "Culling Correction");
TRANSLATE_NOOP("FullscreenUI", "Current Game");
TRANSLATE_NOOP("FullscreenUI", "Custom");
TRANSLATE_NOOP("FullscreenUI", "Dark");
TRANSLATE_NOOP("FullscreenUI", "Dark Ruby");
TRANSLATE_NOOP("FullscreenUI", "Deadzone");
TRANSLATE_NOOP("FullscreenUI", "Debugging Settings");
TRANSLATE_NOOP("FullscreenUI", "Default");
@ -9256,8 +9280,10 @@ TRANSLATE_NOOP("FullscreenUI", "Reset Play Time");
TRANSLATE_NOOP("FullscreenUI", "Reset Settings");
TRANSLATE_NOOP("FullscreenUI", "Reset System");
TRANSLATE_NOOP("FullscreenUI", "Resets all configuration to defaults (including bindings).");
TRANSLATE_NOOP("FullscreenUI", "Resets all settings to the defaults.");
TRANSLATE_NOOP("FullscreenUI", "Resets memory card directory to default (user directory).");
TRANSLATE_NOOP("FullscreenUI", "Resolution change will be applied after restarting.");
TRANSLATE_NOOP("FullscreenUI", "Restore Defaults");
TRANSLATE_NOOP("FullscreenUI", "Restores the state of the system prior to the last state loaded.");
TRANSLATE_NOOP("FullscreenUI", "Resume Game");
TRANSLATE_NOOP("FullscreenUI", "Resume Last Session");
@ -9334,6 +9360,7 @@ TRANSLATE_NOOP("FullscreenUI", "Sets which sort of memory card image will be use
TRANSLATE_NOOP("FullscreenUI", "Setting {} binding {}.");
TRANSLATE_NOOP("FullscreenUI", "Settings");
TRANSLATE_NOOP("FullscreenUI", "Settings and Operations");
TRANSLATE_NOOP("FullscreenUI", "Settings reset to default.");
TRANSLATE_NOOP("FullscreenUI", "Shader {} added as stage {}.");
TRANSLATE_NOOP("FullscreenUI", "Shared Card Name");
TRANSLATE_NOOP("FullscreenUI", "Show Achievement Trophy Icons");

View File

@ -121,6 +121,9 @@ namespace Host {
#ifndef __ANDROID__
/// Requests settings reset.
void RequestResetSettings(bool system, bool controller);
/// Requests shut down and exit of the hosting application. This may not actually exit,
/// if the user cancels the shutdown confirmation.
void RequestExitApplication(bool allow_confirm);

View File

@ -1251,6 +1251,32 @@ std::optional<WindowInfo> Host::GetTopLevelWindowInfo()
return MiniHost::TranslateSDLWindowInfo(MiniHost::s_state.sdl_window, nullptr);
}
void Host::RequestResetSettings(bool system, bool controller)
{
using namespace MiniHost;
auto lock = Host::GetSettingsLock();
{
SettingsInterface& si = *s_state.base_settings_interface.get();
if (system)
{
System::SetDefaultSettings(si);
EmuFolders::SetDefaults();
EmuFolders::Save(si);
}
if (controller)
{
InputManager::SetDefaultSourceConfig(si);
Settings::SetDefaultControllerConfig(si);
Settings::SetDefaultHotkeyConfig(si);
}
}
System::ApplySettings(false);
}
void Host::RequestExitApplication(bool allow_confirm)
{
Host::RunOnCPUThread([]() {

View File

@ -646,15 +646,18 @@ void Host::CheckForSettingsChanges(const Settings& old_settings)
void EmuThread::setDefaultSettings(bool system /* = true */, bool controller /* = true */)
{
if (isCurrentThread())
if (!isCurrentThread())
{
QMetaObject::invokeMethod(this, "setDefaultSettings", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "setDefaultSettings", Qt::QueuedConnection, Q_ARG(bool, system),
Q_ARG(bool, controller));
return;
}
auto lock = Host::GetSettingsLock();
QtHost::SetDefaultSettings(*s_base_settings_interface, system, controller);
QtHost::QueueSettingsSave();
{
auto lock = Host::GetSettingsLock();
QtHost::SetDefaultSettings(*s_base_settings_interface, system, controller);
QtHost::QueueSettingsSave();
}
applySettings(false);
@ -2558,6 +2561,11 @@ void Host::RequestSystemShutdown(bool allow_confirm, bool save_state)
Q_ARG(bool, true), Q_ARG(bool, save_state));
}
void Host::RequestResetSettings(bool system, bool controller)
{
g_emu_thread->setDefaultSettings(system, controller);
}
void Host::RequestExitApplication(bool allow_confirm)
{
QMetaObject::invokeMethod(g_main_window, "requestExit", Qt::QueuedConnection, Q_ARG(bool, allow_confirm));

View File

@ -307,7 +307,8 @@ void SettingsWindow::onCategoryCurrentRowChanged(int row)
void SettingsWindow::onRestoreDefaultsClicked()
{
if (QMessageBox::question(this, tr("Confirm Restore Defaults"),
tr("Are you sure you want to restore the default settings? Any preferences will be lost."),
tr("Are you sure you want to restore the default settings? Any preferences will be "
"lost.\n\nYou cannot undo this action."),
QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes)
{
return;

View File

@ -345,6 +345,11 @@ void Host::RequestResizeHostDisplay(s32 width, s32 height)
//
}
void Host::RequestResetSettings(bool system, bool controller)
{
//
}
void Host::RequestExitApplication(bool save_state_if_running)
{
//