File size: 3,058 Bytes
7fd553e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | // Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CommonActivatableWidget.h"
#include "GameFeatureAction_WorldActionBase.h"
#include "UIExtensionSystem.h"
#include "GameFeatureAction_AddWidget.generated.h"
struct FWorldContext;
struct FComponentRequestHandle;
USTRUCT()
struct FLyraHUDLayoutRequest
{
GENERATED_BODY()
// The layout widget to spawn
UPROPERTY(EditAnywhere, Category=UI, meta=(AssetBundles="Client"))
TSoftClassPtr<UCommonActivatableWidget> LayoutClass;
// The layer to insert the widget in
UPROPERTY(EditAnywhere, Category=UI, meta=(Categories="UI.Layer"))
FGameplayTag LayerID;
};
USTRUCT()
struct FLyraHUDElementEntry
{
GENERATED_BODY()
// The widget to spawn
UPROPERTY(EditAnywhere, Category=UI, meta=(AssetBundles="Client"))
TSoftClassPtr<UUserWidget> WidgetClass;
// The slot ID where we should place this widget
UPROPERTY(EditAnywhere, Category = UI)
FGameplayTag SlotID;
};
//////////////////////////////////////////////////////////////////////
// UGameFeatureAction_AddWidget
/**
* GameFeatureAction responsible for adding widgets.
*/
UCLASS(MinimalAPI, meta = (DisplayName = "Add Widgets"))
class UGameFeatureAction_AddWidgets final : public UGameFeatureAction_WorldActionBase
{
GENERATED_BODY()
public:
//~ Begin UGameFeatureAction interface
virtual void OnGameFeatureDeactivating(FGameFeatureDeactivatingContext& Context) override;
#if WITH_EDITORONLY_DATA
virtual void AddAdditionalAssetBundleData(FAssetBundleData& AssetBundleData) override;
#endif
//~ End UGameFeatureAction interface
//~ Begin UObject interface
#if WITH_EDITOR
virtual EDataValidationResult IsDataValid(class FDataValidationContext& Context) const override;
#endif
//~ End UObject interface
private:
// Layout to add to the HUD
UPROPERTY(EditAnywhere, Category=UI, meta=(TitleProperty="{LayerID} -> {LayoutClass}"))
TArray<FLyraHUDLayoutRequest> Layout;
// Widgets to add to the HUD
UPROPERTY(EditAnywhere, Category=UI, meta=(TitleProperty="{SlotID} -> {WidgetClass}"))
TArray<FLyraHUDElementEntry> Widgets;
private:
struct FPerActorData
{
TArray<TWeakObjectPtr<UCommonActivatableWidget>> LayoutsAdded;
TArray<FUIExtensionHandle> ExtensionHandles;
};
struct FPerContextData
{
TArray<TSharedPtr<FComponentRequestHandle>> ComponentRequests;
TMap<FObjectKey, FPerActorData> ActorData;
};
TMap<FGameFeatureStateChangeContext, FPerContextData> ContextData;
//~ Begin UGameFeatureAction_WorldActionBase interface
virtual void AddToWorld(const FWorldContext& WorldContext, const FGameFeatureStateChangeContext& ChangeContext) override;
//~ End UGameFeatureAction_WorldActionBase interface
void Reset(FPerContextData& ActiveData);
void HandleActorExtension(AActor* Actor, FName EventName, FGameFeatureStateChangeContext ChangeContext);
void AddWidgets(AActor* Actor, FPerContextData& ActiveData);
void RemoveWidgets(AActor* Actor, FPerContextData& ActiveData);
};
|