RealtimeStyleTransferRuntime/Source/LyraGame/UI/LyraSettingScreen.cpp

75 lines
1.9 KiB
C++
Raw Permalink Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "LyraSettingScreen.h"
2022-09-13 07:18:28 +00:00
#include "Containers/Array.h"
#include "Delegates/Delegate.h"
2022-05-23 18:41:30 +00:00
#include "Input/CommonUIInputTypes.h"
2022-09-13 07:18:28 +00:00
#include "Player/LyraLocalPlayer.h"
#include "Settings/LyraGameSettingRegistry.h"
#include "Templates/Casts.h"
class UGameSettingRegistry;
2022-05-23 18:41:30 +00:00
void ULyraSettingScreen::NativeOnInitialized()
{
Super::NativeOnInitialized();
BackHandle = RegisterUIActionBinding(FBindUIActionArgs(BackInputActionData, true, FSimpleDelegate::CreateUObject(this, &ThisClass::HandleBackAction)));
ApplyHandle = RegisterUIActionBinding(FBindUIActionArgs(ApplyInputActionData, true, FSimpleDelegate::CreateUObject(this, &ThisClass::HandleApplyAction)));
CancelChangesHandle = RegisterUIActionBinding(FBindUIActionArgs(CancelChangesInputActionData, true, FSimpleDelegate::CreateUObject(this, &ThisClass::HandleCancelChangesAction)));
}
UGameSettingRegistry* ULyraSettingScreen::CreateRegistry()
{
ULyraGameSettingRegistry* NewRegistry = NewObject<ULyraGameSettingRegistry>();
if (ULyraLocalPlayer* LocalPlayer = CastChecked<ULyraLocalPlayer>(GetOwningLocalPlayer()))
{
NewRegistry->Initialize(LocalPlayer);
}
return NewRegistry;
}
void ULyraSettingScreen::HandleBackAction()
{
if (AttemptToPopNavigation())
{
return;
}
ApplyChanges();
DeactivateWidget();
}
void ULyraSettingScreen::HandleApplyAction()
{
ApplyChanges();
}
void ULyraSettingScreen::HandleCancelChangesAction()
{
CancelChanges();
}
void ULyraSettingScreen::OnSettingsDirtyStateChanged_Implementation(bool bSettingsDirty)
{
if (bSettingsDirty)
{
if (!GetActionBindings().Contains(ApplyHandle))
{
AddActionBinding(ApplyHandle);
}
if (!GetActionBindings().Contains(CancelChangesHandle))
{
AddActionBinding(CancelChangesHandle);
}
}
else
{
RemoveActionBinding(ApplyHandle);
RemoveActionBinding(CancelChangesHandle);
}
}