some improvements for the settings module

This commit is contained in:
Mamadou Babaei
2023-03-28 10:39:55 +02:00
parent 5b3ed4ffe8
commit 60397ea261
2 changed files with 39 additions and 7 deletions
@@ -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<USGSettings>()
);
ISettingsSectionPtr SenseGloveSettingsSection{
SettingModule->RegisterSettings(
"Project", "Plugins", "SenseGloveSettings",
LOCTEXT("RuntimeSettingsName", "SenseGlove"),
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
{
@@ -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
@@ -46,6 +46,9 @@ public:
virtual void PreUnloadCallback() override;
virtual void PostLoadCallback() override;
virtual void ShutdownModule() override;
private:
bool OnSettingsSaved() const;
};
#undef LOCTEXT_NAMESPACE