From 60397ea2611af799f856a1e3a6b5721f7bfc6ef2 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Tue, 21 Mar 2023 13:17:28 +0100 Subject: [PATCH] some improvements for the settings module --- .../Private/SenseGloveSettingsModule.cpp | 43 ++++++++++++++++--- .../Private/SenseGloveSettingsModule.h | 3 ++ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Source/SenseGloveSettings/Private/SenseGloveSettingsModule.cpp b/Source/SenseGloveSettings/Private/SenseGloveSettingsModule.cpp index 5d5bd9a3..8f62e44d 100644 --- a/Source/SenseGloveSettings/Private/SenseGloveSettingsModule.cpp +++ b/Source/SenseGloveSettings/Private/SenseGloveSettingsModule.cpp @@ -36,6 +36,7 @@ #include "SenseGloveSettingsModule.h" #include "ISettingsModule.h" +#include "ISettingsSection.h" #include "SGLog/SGLog.h" #include "SGSettings/SGSettings.h" @@ -53,14 +54,25 @@ void FSenseGloveSettingsModule::StartupModule() { SGLOG("Registering the SenseGlove settings manager through the Unreal Engine's Settings module..."); - SettingModule->RegisterSettings( - "Project", "Plugins", "SenseGloveSettings", - LOCTEXT("RuntimeSettingsName", "SenseGlove"), - LOCTEXT("RuntimeSettingsDescription", "Configure the SenseGlove settings"), - GetMutableDefault() - ); + ISettingsSectionPtr SenseGloveSettingsSection{ + SettingModule->RegisterSettings( + "Project", "Plugins", "SenseGloveSettings", + LOCTEXT("RuntimeSettingsName", "SenseGlove"), + LOCTEXT("RuntimeSettingsDescription", "Configure the SenseGlove settings"), + GetMutableDefault() + ) + }; - SGLOG("Successfully registered the SenseGlove settings manager!"); + if (SenseGloveSettingsSection.IsValid()) + { + SenseGloveSettingsSection->OnModified().BindRaw(this, &FSenseGloveSettingsModule::OnSettingsSaved); + + SGLOG("Successfully registered the SenseGlove settings manager!"); + } + else + { + SGLOG_ERROR("Failed to register the SenseGlove settings manager!"); + } } else { @@ -99,4 +111,21 @@ void FSenseGloveSettingsModule::ShutdownModule() } } +bool FSenseGloveSettingsModule::OnSettingsSaved() const +{ + USGSettings* Settings = GetMutableDefault(); + bool bResaveConfig = false; + + /// TODO + /// Validate settings here in case of invalid values. + /// In that case, we have to set bResaveConfig to true. + + if (bResaveConfig) + { + Settings->SaveConfig(); + } + + return true; +} + #undef LOCTEXT_NAMESPACE \ No newline at end of file diff --git a/Source/SenseGloveSettings/Private/SenseGloveSettingsModule.h b/Source/SenseGloveSettings/Private/SenseGloveSettingsModule.h index d4d8b000..622caf54 100644 --- a/Source/SenseGloveSettings/Private/SenseGloveSettingsModule.h +++ b/Source/SenseGloveSettings/Private/SenseGloveSettingsModule.h @@ -46,6 +46,9 @@ public: virtual void PreUnloadCallback() override; virtual void PostLoadCallback() override; virtual void ShutdownModule() override; + +private: + bool OnSettingsSaved() const; }; #undef LOCTEXT_NAMESPACE \ No newline at end of file