Skip to content

Commit c82c007

Browse files
committed
FullscreenUI: Add settings reset option to settings
1 parent 0a47006 commit c82c007

6 files changed

Lines changed: 79 additions & 9 deletions

File tree

src/core/fullscreen_ui.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ static float GetEffectiveFloatSetting(SettingsInterface* bsi, const char* sectio
322322
float default_value);
323323
static TinyString GetEffectiveTinyStringSetting(SettingsInterface* bsi, const char* section, const char* key,
324324
const char* default_value);
325+
static void BeginResetSettings();
325326
static void DoCopyGameSettings();
326327
static void DoClearGameSettings();
327328
static void CopyGlobalControllerSettingsToGame();
@@ -3465,6 +3466,20 @@ void FullscreenUI::PopulatePatchesAndCheatsList()
34653466
s_state.game_settings_interface->GetStringList(Cheats::CHEATS_CONFIG_SECTION, Cheats::PATCH_ENABLE_CONFIG_KEY);
34663467
}
34673468

3469+
void FullscreenUI::BeginResetSettings()
3470+
{
3471+
OpenConfirmMessageDialog(FSUI_STR("Restore Defaults"),
3472+
FSUI_STR("Are you sure you want to restore the default settings? Any preferences will be "
3473+
"lost.\n\nYou cannot undo this action."),
3474+
[](bool result) {
3475+
if (!result)
3476+
return;
3477+
3478+
Host::RequestResetSettings(true, false);
3479+
ShowToast(std::string(), FSUI_STR("Settings reset to default."));
3480+
});
3481+
}
3482+
34683483
void FullscreenUI::DoCopyGameSettings()
34693484
{
34703485
if (!s_state.game_settings_interface)
@@ -3966,6 +3981,15 @@ void FullscreenUI::DrawInterfaceSettingsPage()
39663981
FSUI_CSTR("Shows enhancement settings in the bottom-right corner of the screen."), "Display",
39673982
"ShowEnhancements", false);
39683983

3984+
MenuHeading(FSUI_CSTR("Operations"));
3985+
{
3986+
if (MenuButton(FSUI_ICONSTR(ICON_FA_DUMPSTER_FIRE, "Restore Defaults"),
3987+
FSUI_CSTR("Resets all settings to the defaults.")))
3988+
{
3989+
BeginResetSettings();
3990+
}
3991+
}
3992+
39693993
EndMenuButtons();
39703994
}
39713995

@@ -4413,9 +4437,7 @@ void FullscreenUI::BeginResetControllerSettings()
44134437
if (!result)
44144438
return;
44154439

4416-
SettingsInterface* dsi = GetEditingSettingsInterface();
4417-
4418-
Settings::SetDefaultControllerConfig(*dsi);
4440+
Host::RequestResetSettings(false, true);
44194441
ShowToast(std::string(), FSUI_STR("Controller settings reset to default."));
44204442
});
44214443
}
@@ -8824,6 +8846,7 @@ TRANSLATE_NOOP("FullscreenUI", "Apply Image Patches");
88248846
TRANSLATE_NOOP("FullscreenUI", "Are you sure you want to clear all mappings for this controller?\n\nYou cannot undo this action.");
88258847
TRANSLATE_NOOP("FullscreenUI", "Are you sure you want to clear the current post-processing chain? All configuration will be lost.");
88268848
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.");
8849+
TRANSLATE_NOOP("FullscreenUI", "Are you sure you want to restore the default settings? Any preferences will be lost.\n\nYou cannot undo this action.");
88278850
TRANSLATE_NOOP("FullscreenUI", "Aspect Ratio");
88288851
TRANSLATE_NOOP("FullscreenUI", "Attempts to detect one pixel high/wide lines that rely on non-upscaled rasterization behavior, filling in gaps introduced by upscaling.");
88298852
TRANSLATE_NOOP("FullscreenUI", "Attempts to map the selected port to a chosen controller.");
@@ -8916,6 +8939,7 @@ TRANSLATE_NOOP("FullscreenUI", "Culling Correction");
89168939
TRANSLATE_NOOP("FullscreenUI", "Current Game");
89178940
TRANSLATE_NOOP("FullscreenUI", "Custom");
89188941
TRANSLATE_NOOP("FullscreenUI", "Dark");
8942+
TRANSLATE_NOOP("FullscreenUI", "Dark Ruby");
89198943
TRANSLATE_NOOP("FullscreenUI", "Deadzone");
89208944
TRANSLATE_NOOP("FullscreenUI", "Debugging Settings");
89218945
TRANSLATE_NOOP("FullscreenUI", "Default");
@@ -9256,8 +9280,10 @@ TRANSLATE_NOOP("FullscreenUI", "Reset Play Time");
92569280
TRANSLATE_NOOP("FullscreenUI", "Reset Settings");
92579281
TRANSLATE_NOOP("FullscreenUI", "Reset System");
92589282
TRANSLATE_NOOP("FullscreenUI", "Resets all configuration to defaults (including bindings).");
9283+
TRANSLATE_NOOP("FullscreenUI", "Resets all settings to the defaults.");
92599284
TRANSLATE_NOOP("FullscreenUI", "Resets memory card directory to default (user directory).");
92609285
TRANSLATE_NOOP("FullscreenUI", "Resolution change will be applied after restarting.");
9286+
TRANSLATE_NOOP("FullscreenUI", "Restore Defaults");
92619287
TRANSLATE_NOOP("FullscreenUI", "Restores the state of the system prior to the last state loaded.");
92629288
TRANSLATE_NOOP("FullscreenUI", "Resume Game");
92639289
TRANSLATE_NOOP("FullscreenUI", "Resume Last Session");
@@ -9334,6 +9360,7 @@ TRANSLATE_NOOP("FullscreenUI", "Sets which sort of memory card image will be use
93349360
TRANSLATE_NOOP("FullscreenUI", "Setting {} binding {}.");
93359361
TRANSLATE_NOOP("FullscreenUI", "Settings");
93369362
TRANSLATE_NOOP("FullscreenUI", "Settings and Operations");
9363+
TRANSLATE_NOOP("FullscreenUI", "Settings reset to default.");
93379364
TRANSLATE_NOOP("FullscreenUI", "Shader {} added as stage {}.");
93389365
TRANSLATE_NOOP("FullscreenUI", "Shared Card Name");
93399366
TRANSLATE_NOOP("FullscreenUI", "Show Achievement Trophy Icons");

src/core/fullscreen_ui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ namespace Host {
121121

122122
#ifndef __ANDROID__
123123

124+
/// Requests settings reset.
125+
void RequestResetSettings(bool system, bool controller);
126+
124127
/// Requests shut down and exit of the hosting application. This may not actually exit,
125128
/// if the user cancels the shutdown confirmation.
126129
void RequestExitApplication(bool allow_confirm);

src/duckstation-mini/mini_host.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,32 @@ std::optional<WindowInfo> Host::GetTopLevelWindowInfo()
12511251
return MiniHost::TranslateSDLWindowInfo(MiniHost::s_state.sdl_window, nullptr);
12521252
}
12531253

1254+
void Host::RequestResetSettings(bool system, bool controller)
1255+
{
1256+
using namespace MiniHost;
1257+
1258+
auto lock = Host::GetSettingsLock();
1259+
{
1260+
SettingsInterface& si = *s_state.base_settings_interface.get();
1261+
1262+
if (system)
1263+
{
1264+
System::SetDefaultSettings(si);
1265+
EmuFolders::SetDefaults();
1266+
EmuFolders::Save(si);
1267+
}
1268+
1269+
if (controller)
1270+
{
1271+
InputManager::SetDefaultSourceConfig(si);
1272+
Settings::SetDefaultControllerConfig(si);
1273+
Settings::SetDefaultHotkeyConfig(si);
1274+
}
1275+
}
1276+
1277+
System::ApplySettings(false);
1278+
}
1279+
12541280
void Host::RequestExitApplication(bool allow_confirm)
12551281
{
12561282
Host::RunOnCPUThread([]() {

src/duckstation-qt/qthost.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,15 +646,18 @@ void Host::CheckForSettingsChanges(const Settings& old_settings)
646646

647647
void EmuThread::setDefaultSettings(bool system /* = true */, bool controller /* = true */)
648648
{
649-
if (isCurrentThread())
649+
if (!isCurrentThread())
650650
{
651-
QMetaObject::invokeMethod(this, "setDefaultSettings", Qt::QueuedConnection);
651+
QMetaObject::invokeMethod(this, "setDefaultSettings", Qt::QueuedConnection, Q_ARG(bool, system),
652+
Q_ARG(bool, controller));
652653
return;
653654
}
654655

655-
auto lock = Host::GetSettingsLock();
656-
QtHost::SetDefaultSettings(*s_base_settings_interface, system, controller);
657-
QtHost::QueueSettingsSave();
656+
{
657+
auto lock = Host::GetSettingsLock();
658+
QtHost::SetDefaultSettings(*s_base_settings_interface, system, controller);
659+
QtHost::QueueSettingsSave();
660+
}
658661

659662
applySettings(false);
660663

@@ -2558,6 +2561,11 @@ void Host::RequestSystemShutdown(bool allow_confirm, bool save_state)
25582561
Q_ARG(bool, true), Q_ARG(bool, save_state));
25592562
}
25602563

2564+
void Host::RequestResetSettings(bool system, bool controller)
2565+
{
2566+
g_emu_thread->setDefaultSettings(system, controller);
2567+
}
2568+
25612569
void Host::RequestExitApplication(bool allow_confirm)
25622570
{
25632571
QMetaObject::invokeMethod(g_main_window, "requestExit", Qt::QueuedConnection, Q_ARG(bool, allow_confirm));

src/duckstation-qt/settingswindow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ void SettingsWindow::onCategoryCurrentRowChanged(int row)
307307
void SettingsWindow::onRestoreDefaultsClicked()
308308
{
309309
if (QMessageBox::question(this, tr("Confirm Restore Defaults"),
310-
tr("Are you sure you want to restore the default settings? Any preferences will be lost."),
310+
tr("Are you sure you want to restore the default settings? Any preferences will be "
311+
"lost.\n\nYou cannot undo this action."),
311312
QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes)
312313
{
313314
return;

src/duckstation-regtest/regtest_host.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ void Host::RequestResizeHostDisplay(s32 width, s32 height)
345345
//
346346
}
347347

348+
void Host::RequestResetSettings(bool system, bool controller)
349+
{
350+
//
351+
}
352+
348353
void Host::RequestExitApplication(bool save_state_if_running)
349354
{
350355
//

0 commit comments

Comments
 (0)