114 lines
3.1 KiB
C++
114 lines
3.1 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "Game/PHYHUD.h"
|
|
|
|
#include UE_INLINE_GENERATED_CPP_BY_NAME(PHYHUD)
|
|
|
|
#include "CommonActivatableWidget.h"
|
|
#include "Engine/GameInstance.h"
|
|
#include "GameplayTags/PHYGameplayTags_UI.h"
|
|
#include "PHYConfigSettings.h"
|
|
#include "UI/GUIS_GameUILayout.h"
|
|
#include "UI/GUIS_GameUIPolicy.h"
|
|
#include "UI/GUIS_GameUISubsystem.h"
|
|
#include "UI/PHYHUDStatusWidget.h"
|
|
#include "UI/PHYPlayerUIContext.h"
|
|
|
|
APHYHUD::APHYHUD(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
}
|
|
|
|
void APHYHUD::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
InitializeHUDForPlayer(GetOwningPlayerController());
|
|
}
|
|
|
|
void APHYHUD::InitializeHUDForPlayer(APlayerController* OwningPlayerController)
|
|
{
|
|
if (!OwningPlayerController || bHUDInitialized)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (InitializeGenericUIForPlayer(OwningPlayerController))
|
|
{
|
|
DefaultHUDWidget = PushDefaultHUDWidget(OwningPlayerController);
|
|
bHUDInitialized = true;
|
|
}
|
|
}
|
|
|
|
bool APHYHUD::InitializeGenericUIForPlayer(APlayerController* OwningPlayerController)
|
|
{
|
|
if (!OwningPlayerController || !OwningPlayerController->IsLocalController())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
const UPHYUISettings* UISettings = GetDefault<UPHYUISettings>();
|
|
if (!UISettings || !UISettings->bUseCommonUI || !UISettings->bUseGenericUISystem)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
ULocalPlayer* LocalPlayer = OwningPlayerController->GetLocalPlayer();
|
|
if (!LocalPlayer)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
UGameInstance* GameInstance = OwningPlayerController->GetGameInstance();
|
|
UGUIS_GameUISubsystem* GameUISubsystem = GameInstance ? GameInstance->GetSubsystem<UGUIS_GameUISubsystem>() : nullptr;
|
|
if (!GameUISubsystem)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
GameUISubsystem->AddPlayer(LocalPlayer);
|
|
|
|
if (!PlayerUIContext)
|
|
{
|
|
PlayerUIContext = NewObject<UPHYPlayerUIContext>(this);
|
|
}
|
|
PlayerUIContext->InitializeForPlayer(OwningPlayerController);
|
|
|
|
GameUISubsystem->RegisterUIContextForPlayer(LocalPlayer, PlayerUIContext, PlayerUIContextBindingHandle);
|
|
return true;
|
|
}
|
|
|
|
UCommonActivatableWidget* APHYHUD::PushDefaultHUDWidget(APlayerController* OwningPlayerController)
|
|
{
|
|
if (!OwningPlayerController || DefaultHUDWidget)
|
|
{
|
|
return DefaultHUDWidget;
|
|
}
|
|
|
|
const UPHYUISettings* UISettings = GetDefault<UPHYUISettings>();
|
|
TSubclassOf<UCommonActivatableWidget> HUDWidgetClass = UPHYHUDStatusWidget::StaticClass();
|
|
if (UISettings && !UISettings->DefaultHUDWidgetClass.IsNull())
|
|
{
|
|
if (UClass* LoadedHUDWidgetClass = UISettings->DefaultHUDWidgetClass.LoadSynchronous())
|
|
{
|
|
HUDWidgetClass = LoadedHUDWidgetClass;
|
|
}
|
|
}
|
|
|
|
ULocalPlayer* LocalPlayer = OwningPlayerController->GetLocalPlayer();
|
|
if (!LocalPlayer)
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
UGUIS_GameUIPolicy* UIPolicy = UGUIS_GameUIPolicy::GetGameUIPolicy(OwningPlayerController);
|
|
UGUIS_GameUILayout* RootLayout = UIPolicy ? UIPolicy->GetRootLayout(LocalPlayer) : nullptr;
|
|
if (!RootLayout)
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
const FGameplayTag HUDLayerTag = (UISettings && UISettings->HUDLayerTag.IsValid()) ? UISettings->HUDLayerTag : PHYGameplayTags::UI_Layer_HUD;
|
|
return RootLayout->PushWidgetToLayerStack<UCommonActivatableWidget>(HUDLayerTag, HUDWidgetClass);
|
|
}
|