|
|
|
|
| #pragma once
|
|
|
| #include "CommonActivatableWidget.h"
|
| #include "CommonUIExtensions.h"
|
| #include "Engine/AssetManager.h"
|
| #include "Engine/StreamableManager.h"
|
| #include "GameplayTagContainer.h"
|
| #include "Widgets/CommonActivatableWidgetContainer.h"
|
|
|
| #include "PrimaryGameLayout.generated.h"
|
|
|
| #define UE_API COMMONGAME_API
|
|
|
| class APlayerController;
|
| class UClass;
|
| class UCommonActivatableWidgetContainerBase;
|
| class ULocalPlayer;
|
| class UObject;
|
| struct FFrame;
|
|
|
| |
| |
|
|
| enum class EAsyncWidgetLayerState : uint8
|
| {
|
| Canceled,
|
| Initialize,
|
| AfterPush
|
| };
|
|
|
| |
| |
| |
|
|
| UCLASS(MinimalAPI, Abstract, meta = (DisableNativeTick))
|
| class UPrimaryGameLayout : public UCommonUserWidget
|
| {
|
| GENERATED_BODY()
|
|
|
| public:
|
| static UE_API UPrimaryGameLayout* GetPrimaryGameLayoutForPrimaryPlayer(const UObject* WorldContextObject);
|
| static UE_API UPrimaryGameLayout* GetPrimaryGameLayout(APlayerController* PlayerController);
|
| static UE_API UPrimaryGameLayout* GetPrimaryGameLayout(ULocalPlayer* LocalPlayer);
|
|
|
| public:
|
| UE_API UPrimaryGameLayout(const FObjectInitializer& ObjectInitializer);
|
|
|
|
|
| UE_API void SetIsDormant(bool Dormant);
|
| bool IsDormant() const { return bIsDormant; }
|
|
|
| public:
|
| template <typename ActivatableWidgetT = UCommonActivatableWidget>
|
| TSharedPtr<FStreamableHandle> PushWidgetToLayerStackAsync(FGameplayTag LayerName, bool bSuspendInputUntilComplete, TSoftClassPtr<UCommonActivatableWidget> ActivatableWidgetClass)
|
| {
|
| return PushWidgetToLayerStackAsync<ActivatableWidgetT>(LayerName, bSuspendInputUntilComplete, ActivatableWidgetClass, [](EAsyncWidgetLayerState, ActivatableWidgetT*) {});
|
| }
|
|
|
| template <typename ActivatableWidgetT = UCommonActivatableWidget>
|
| TSharedPtr<FStreamableHandle> PushWidgetToLayerStackAsync(FGameplayTag LayerName, bool bSuspendInputUntilComplete, TSoftClassPtr<UCommonActivatableWidget> ActivatableWidgetClass, TFunction<void(EAsyncWidgetLayerState, ActivatableWidgetT*)> StateFunc)
|
| {
|
| static_assert(TIsDerivedFrom<ActivatableWidgetT, UCommonActivatableWidget>::IsDerived, "Only CommonActivatableWidgets can be used here");
|
|
|
| static FName NAME_PushingWidgetToLayer("PushingWidgetToLayer");
|
| const FName SuspendInputToken = bSuspendInputUntilComplete ? UCommonUIExtensions::SuspendInputForPlayer(GetOwningPlayer(), NAME_PushingWidgetToLayer) : NAME_None;
|
|
|
| FStreamableManager& StreamableManager = UAssetManager::Get().GetStreamableManager();
|
| TSharedPtr<FStreamableHandle> StreamingHandle = StreamableManager.RequestAsyncLoad(ActivatableWidgetClass.ToSoftObjectPath(), FStreamableDelegate::CreateWeakLambda(this,
|
| [this, LayerName, ActivatableWidgetClass, StateFunc, SuspendInputToken]()
|
| {
|
| UCommonUIExtensions::ResumeInputForPlayer(GetOwningPlayer(), SuspendInputToken);
|
|
|
| ActivatableWidgetT* Widget = PushWidgetToLayerStack<ActivatableWidgetT>(LayerName, ActivatableWidgetClass.Get(), [StateFunc](ActivatableWidgetT& WidgetToInit) {
|
| StateFunc(EAsyncWidgetLayerState::Initialize, &WidgetToInit);
|
| });
|
|
|
| StateFunc(EAsyncWidgetLayerState::AfterPush, Widget);
|
| })
|
| );
|
|
|
|
|
| StreamingHandle->BindCancelDelegate(FStreamableDelegate::CreateWeakLambda(this,
|
| [this, StateFunc, SuspendInputToken]()
|
| {
|
| UCommonUIExtensions::ResumeInputForPlayer(GetOwningPlayer(), SuspendInputToken);
|
| StateFunc(EAsyncWidgetLayerState::Canceled, nullptr);
|
| })
|
| );
|
|
|
| return StreamingHandle;
|
| }
|
|
|
| template <typename ActivatableWidgetT = UCommonActivatableWidget>
|
| ActivatableWidgetT* PushWidgetToLayerStack(FGameplayTag LayerName, UClass* ActivatableWidgetClass)
|
| {
|
| return PushWidgetToLayerStack<ActivatableWidgetT>(LayerName, ActivatableWidgetClass, [](ActivatableWidgetT&) {});
|
| }
|
|
|
| template <typename ActivatableWidgetT = UCommonActivatableWidget>
|
| ActivatableWidgetT* PushWidgetToLayerStack(FGameplayTag LayerName, UClass* ActivatableWidgetClass, TFunctionRef<void(ActivatableWidgetT&)> InitInstanceFunc)
|
| {
|
| static_assert(TIsDerivedFrom<ActivatableWidgetT, UCommonActivatableWidget>::IsDerived, "Only CommonActivatableWidgets can be used here");
|
|
|
| if (UCommonActivatableWidgetContainerBase* Layer = GetLayerWidget(LayerName))
|
| {
|
| return Layer->AddWidget<ActivatableWidgetT>(ActivatableWidgetClass, InitInstanceFunc);
|
| }
|
|
|
| return nullptr;
|
| }
|
|
|
|
|
| UE_API void FindAndRemoveWidgetFromLayer(UCommonActivatableWidget* ActivatableWidget);
|
|
|
|
|
| UE_API UCommonActivatableWidgetContainerBase* GetLayerWidget(FGameplayTag LayerName);
|
|
|
| protected:
|
|
|
| UFUNCTION(BlueprintCallable, Category="Layer")
|
| UE_API void RegisterLayer(UPARAM(meta = (Categories = "UI.Layer")) FGameplayTag LayerTag, UCommonActivatableWidgetContainerBase* LayerWidget);
|
|
|
| UE_API virtual void OnIsDormantChanged();
|
|
|
| UE_API void OnWidgetStackTransitioning(UCommonActivatableWidgetContainerBase* Widget, bool bIsTransitioning);
|
|
|
| private:
|
| bool bIsDormant = false;
|
|
|
|
|
|
|
| TArray<FName> SuspendInputTokens;
|
|
|
|
|
| UPROPERTY(Transient, meta = (Categories = "UI.Layer"))
|
| TMap<FGameplayTag, TObjectPtr<UCommonActivatableWidgetContainerBase>> Layers;
|
| };
|
|
|
| #undef UE_API
|
|
|