2022-05-23 18:41:30 +00:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
#include "Actions/AsyncAction_PushContentToLayerForPlayer.h"
|
2022-09-13 07:18:28 +00:00
|
|
|
|
|
|
|
#include "CommonActivatableWidget.h"
|
2022-05-23 18:41:30 +00:00
|
|
|
#include "Engine/Engine.h"
|
2022-09-13 07:18:28 +00:00
|
|
|
#include "Engine/StreamableManager.h"
|
|
|
|
#include "Engine/World.h"
|
|
|
|
#include "GameFramework/PlayerController.h"
|
|
|
|
#include "HAL/Platform.h"
|
|
|
|
#include "Logging/LogVerbosity.h"
|
2022-05-23 18:41:30 +00:00
|
|
|
#include "PrimaryGameLayout.h"
|
2022-09-13 07:18:28 +00:00
|
|
|
#include "Templates/Casts.h"
|
|
|
|
#include "UObject/Stack.h"
|
|
|
|
#include "UObject/WeakObjectPtr.h"
|
|
|
|
#include "Widgets/CommonActivatableWidgetContainer.h"
|
2022-05-23 18:41:30 +00:00
|
|
|
|
|
|
|
UAsyncAction_PushContentToLayerForPlayer::UAsyncAction_PushContentToLayerForPlayer(const FObjectInitializer& ObjectInitializer)
|
|
|
|
: Super(ObjectInitializer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UAsyncAction_PushContentToLayerForPlayer* UAsyncAction_PushContentToLayerForPlayer::PushContentToLayerForPlayer(APlayerController* InOwningPlayer, TSoftClassPtr<UCommonActivatableWidget> InWidgetClass, FGameplayTag InLayerName, bool bSuspendInputUntilComplete)
|
|
|
|
{
|
|
|
|
if (InWidgetClass.IsNull())
|
|
|
|
{
|
|
|
|
FFrame::KismetExecutionMessage(TEXT("PushContentToLayerForPlayer was passed a null WidgetClass"), ELogVerbosity::Error);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UWorld* World = GEngine->GetWorldFromContextObject(InOwningPlayer, EGetWorldErrorMode::LogAndReturnNull))
|
|
|
|
{
|
|
|
|
UAsyncAction_PushContentToLayerForPlayer* Action = NewObject<UAsyncAction_PushContentToLayerForPlayer>();
|
|
|
|
Action->WidgetClass = InWidgetClass;
|
|
|
|
Action->OwningPlayerPtr = InOwningPlayer;
|
|
|
|
Action->LayerName = InLayerName;
|
|
|
|
Action->bSuspendInputUntilComplete = bSuspendInputUntilComplete;
|
|
|
|
Action->RegisterWithGameInstance(World);
|
|
|
|
|
|
|
|
return Action;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UAsyncAction_PushContentToLayerForPlayer::Cancel()
|
|
|
|
{
|
|
|
|
Super::Cancel();
|
|
|
|
|
|
|
|
if (StreamingHandle.IsValid())
|
|
|
|
{
|
|
|
|
StreamingHandle->CancelHandle();
|
|
|
|
StreamingHandle.Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UAsyncAction_PushContentToLayerForPlayer::Activate()
|
|
|
|
{
|
|
|
|
if (UPrimaryGameLayout* RootLayout = UPrimaryGameLayout::GetPrimaryGameLayout(OwningPlayerPtr.Get()))
|
|
|
|
{
|
|
|
|
TWeakObjectPtr<UAsyncAction_PushContentToLayerForPlayer> WeakThis = this;
|
|
|
|
StreamingHandle = RootLayout->PushWidgetToLayerStackAsync<UCommonActivatableWidget>(LayerName, bSuspendInputUntilComplete, WidgetClass, [this, WeakThis](EAsyncWidgetLayerState State, UCommonActivatableWidget* Widget) {
|
|
|
|
if (WeakThis.IsValid())
|
|
|
|
{
|
|
|
|
switch (State)
|
|
|
|
{
|
|
|
|
case EAsyncWidgetLayerState::Initialize:
|
|
|
|
BeforePush.Broadcast(Widget);
|
|
|
|
break;
|
|
|
|
case EAsyncWidgetLayerState::AfterPush:
|
|
|
|
AfterPush.Broadcast(Widget);
|
|
|
|
SetReadyToDestroy();
|
|
|
|
break;
|
|
|
|
case EAsyncWidgetLayerState::Canceled:
|
|
|
|
SetReadyToDestroy();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetReadyToDestroy();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetReadyToDestroy();
|
|
|
|
}
|
|
|
|
}
|