RealtimeStyleTransferRuntime/Source/LyraGame/Settings/LyraGameSettingRegistry.cpp

91 lines
2.5 KiB
C++
Raw Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "LyraGameSettingRegistry.h"
2022-09-13 07:18:28 +00:00
#include "Engine/LocalPlayer.h"
2022-05-23 18:41:30 +00:00
#include "GameSettingCollection.h"
2022-09-13 07:18:28 +00:00
#include "HAL/Platform.h"
2022-05-23 18:41:30 +00:00
#include "LyraSettingsLocal.h"
#include "LyraSettingsShared.h"
2022-09-13 07:18:28 +00:00
#include "Player/LyraLocalPlayer.h"
#include "Templates/Casts.h"
2022-05-23 18:41:30 +00:00
DEFINE_LOG_CATEGORY(LogLyraGameSettingRegistry);
#define LOCTEXT_NAMESPACE "Lyra"
//--------------------------------------
// ULyraGameSettingRegistry
//--------------------------------------
ULyraGameSettingRegistry::ULyraGameSettingRegistry()
{
}
ULyraGameSettingRegistry* ULyraGameSettingRegistry::Get(ULyraLocalPlayer* InLocalPlayer)
{
ULyraGameSettingRegistry* Registry = FindObject<ULyraGameSettingRegistry>(InLocalPlayer, TEXT("LyraGameSettingRegistry"), true);
if (Registry == nullptr)
{
Registry = NewObject<ULyraGameSettingRegistry>(InLocalPlayer, TEXT("LyraGameSettingRegistry"));
Registry->Initialize(InLocalPlayer);
}
return Registry;
}
bool ULyraGameSettingRegistry::IsFinishedInitializing() const
{
if (Super::IsFinishedInitializing())
{
if (ULyraLocalPlayer* LocalPlayer = Cast<ULyraLocalPlayer>(OwningLocalPlayer))
{
if (LocalPlayer->GetSharedSettings() == nullptr)
{
return false;
}
}
return true;
}
return false;
}
void ULyraGameSettingRegistry::OnInitialize(ULocalPlayer* InLocalPlayer)
{
ULyraLocalPlayer* LyraLocalPlayer = Cast<ULyraLocalPlayer>(InLocalPlayer);
VideoSettings = InitializeVideoSettings(LyraLocalPlayer);
InitializeVideoSettings_FrameRates(VideoSettings, LyraLocalPlayer);
RegisterSetting(VideoSettings);
AudioSettings = InitializeAudioSettings(LyraLocalPlayer);
RegisterSetting(AudioSettings);
GameplaySettings = InitializeGameplaySettings(LyraLocalPlayer);
RegisterSetting(GameplaySettings);
MouseAndKeyboardSettings = InitializeMouseAndKeyboardSettings(LyraLocalPlayer);
RegisterSetting(MouseAndKeyboardSettings);
GamepadSettings = InitializeGamepadSettings(LyraLocalPlayer);
RegisterSetting(GamepadSettings);
}
void ULyraGameSettingRegistry::SaveChanges()
{
Super::SaveChanges();
if (ULyraLocalPlayer* LocalPlayer = Cast<ULyraLocalPlayer>(OwningLocalPlayer))
{
// Game user settings need to be applied to handle things like resolution, this saves indirectly
LocalPlayer->GetLocalSettings()->ApplySettings(false);
LocalPlayer->GetSharedSettings()->ApplySettings();
LocalPlayer->GetSharedSettings()->SaveSettings();
}
}
#undef LOCTEXT_NAMESPACE