some improvements for the settings module

This commit is contained in:
Mamadou Babaei
2023-03-28 10:39:11 +02:00
parent 2b1dc99d26
commit 9bbb1fcedb
2 changed files with 39 additions and 7 deletions
@@ -36,6 +36,7 @@
#include "SenseGloveSettingsModule.h" #include "SenseGloveSettingsModule.h"
#include "ISettingsModule.h" #include "ISettingsModule.h"
#include "ISettingsSection.h"
#include "SGLog/SGLog.h" #include "SGLog/SGLog.h"
#include "SGSettings/SGSettings.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..."); SGLOG("Registering the SenseGlove settings manager through the Unreal Engine's Settings module...");
SettingModule->RegisterSettings( ISettingsSectionPtr SenseGloveSettingsSection{
"Project", "Plugins", "SenseGloveSettings", SettingModule->RegisterSettings(
LOCTEXT("RuntimeSettingsName", "SenseGlove"), "Project", "Plugins", "SenseGloveSettings",
LOCTEXT("RuntimeSettingsDescription", "Configure the SenseGlove settings"), LOCTEXT("RuntimeSettingsName", "SenseGlove"),
GetMutableDefault<USGSettings>() LOCTEXT("RuntimeSettingsDescription", "Configure the SenseGlove settings"),
); GetMutableDefault<USGSettings>()
)
};
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 else
{ {
@@ -99,4 +111,21 @@ void FSenseGloveSettingsModule::ShutdownModule()
} }
} }
bool FSenseGloveSettingsModule::OnSettingsSaved() const
{
USGSettings* Settings = GetMutableDefault<USGSettings>();
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 #undef LOCTEXT_NAMESPACE
@@ -46,6 +46,9 @@ public:
virtual void PreUnloadCallback() override; virtual void PreUnloadCallback() override;
virtual void PostLoadCallback() override; virtual void PostLoadCallback() override;
virtual void ShutdownModule() override; virtual void ShutdownModule() override;
private:
bool OnSettingsSaved() const;
}; };
#undef LOCTEXT_NAMESPACE #undef LOCTEXT_NAMESPACE