RealtimeStyleTransferRuntime/Source/LyraGame/UI/LyraSettingScreen.cpp

69 lines
1.8 KiB
C++
Raw Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "LyraSettingScreen.h"
#include "Settings/LyraGameSettingRegistry.h"
#include "Player/LyraLocalPlayer.h"
#include "Input/CommonUIInputTypes.h"
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);
}
}