RealtimeStyleTransferRuntime/Source/LyraGame/UI/Subsystem/LyraUIManagerSubsystem.cpp

73 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 "LyraUIManagerSubsystem.h"
#include "CommonLocalPlayer.h"
2022-09-13 07:18:28 +00:00
#include "Components/SlateWrapperTypes.h"
#include "Containers/Array.h"
#include "Delegates/Delegate.h"
#include "Engine/GameInstance.h"
#include "Engine/LocalPlayer.h"
#include "Equipment/LyraEquipmentDefinition.h"
#include "GameFramework/HUD.h"
#include "GameFramework/PlayerController.h"
2022-05-23 18:41:30 +00:00
#include "GameUIPolicy.h"
#include "PrimaryGameLayout.h"
2022-09-13 07:18:28 +00:00
#include "Templates/Casts.h"
class FSubsystemCollectionBase;
2022-05-23 18:41:30 +00:00
ULyraUIManagerSubsystem::ULyraUIManagerSubsystem()
{
}
void ULyraUIManagerSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
TickHandle = FTSTicker::GetCoreTicker().AddTicker(FTickerDelegate::CreateUObject(this, &ULyraUIManagerSubsystem::Tick), 0.0f);
}
void ULyraUIManagerSubsystem::Deinitialize()
{
Super::Deinitialize();
FTSTicker::GetCoreTicker().RemoveTicker(TickHandle);
}
bool ULyraUIManagerSubsystem::Tick(float DeltaTime)
{
SyncRootLayoutVisibilityToShowHUD();
return true;
}
void ULyraUIManagerSubsystem::SyncRootLayoutVisibilityToShowHUD()
{
if (const UGameUIPolicy* Policy = GetCurrentUIPolicy())
{
for (const ULocalPlayer* LocalPlayer : GetGameInstance()->GetLocalPlayers())
{
bool bShouldShowUI = true;
if (const APlayerController* PC = LocalPlayer->GetPlayerController(GetWorld()))
{
const AHUD* HUD = PC->GetHUD();
if (HUD && !HUD->bShowHUD)
{
bShouldShowUI = false;
}
}
if (UPrimaryGameLayout* RootLayout = Policy->GetRootLayout(CastChecked<UCommonLocalPlayer>(LocalPlayer)))
{
const ESlateVisibility DesiredVisibility = bShouldShowUI ? ESlateVisibility::SelfHitTestInvisible : ESlateVisibility::Collapsed;
if (DesiredVisibility != RootLayout->GetVisibility())
{
RootLayout->SetVisibility(DesiredVisibility);
}
}
}
}
}