RealtimeStyleTransferRuntime/Plugins/CommonGame/Source/Public/GameUIPolicy.h

112 lines
3.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Containers/Array.h"
#include "Engine/World.h"
#include "HAL/Platform.h"
#include "Misc/AssertionMacros.h"
#include "Templates/Casts.h"
#include "Templates/SubclassOf.h"
#include "UObject/Object.h"
#include "UObject/SoftObjectPtr.h"
#include "UObject/UObjectGlobals.h"
#include "GameUIPolicy.generated.h"
class UCommonLocalPlayer;
class UGameUIManagerSubsystem;
class ULocalPlayer;
class UPrimaryGameLayout;
/**
*
*/
UENUM()
enum class ELocalMultiplayerInteractionMode : uint8
{
// Fullscreen viewport for the primary player only, regardless of the other player's existence
PrimaryOnly,
// Fullscreen viewport for one player, but players can swap control over who's is displayed and who's is dormant
SingleToggle,
// Viewports displayed simultaneously for both players
Simultaneous
};
USTRUCT()
struct FRootViewportLayoutInfo
{
GENERATED_BODY()
public:
UPROPERTY(Transient)
TObjectPtr<ULocalPlayer> LocalPlayer = nullptr;
UPROPERTY(Transient)
TObjectPtr<UPrimaryGameLayout> RootLayout = nullptr;
UPROPERTY(Transient)
bool bAddedToViewport = false;
FRootViewportLayoutInfo() {}
FRootViewportLayoutInfo(ULocalPlayer* InLocalPlayer, UPrimaryGameLayout* InRootLayout, bool bIsInViewport)
: LocalPlayer(InLocalPlayer)
, RootLayout(InRootLayout)
, bAddedToViewport(bIsInViewport)
{}
bool operator==(const ULocalPlayer* OtherLocalPlayer) const { return LocalPlayer == OtherLocalPlayer; }
};
UCLASS(Abstract, Blueprintable, Within = GameUIManagerSubsystem)
class COMMONGAME_API UGameUIPolicy : public UObject
{
GENERATED_BODY()
public:
template <typename GameUIPolicyClass = UGameUIPolicy>
static GameUIPolicyClass* GetGameUIPolicyAs(const UObject* WorldContextObject)
{
return Cast<GameUIPolicyClass>(GetGameUIPolicy(WorldContextObject));
}
static UGameUIPolicy* GetGameUIPolicy(const UObject* WorldContextObject);
public:
virtual UWorld* GetWorld() const override;
UGameUIManagerSubsystem* GetOwningUIManager() const;
UPrimaryGameLayout* GetRootLayout(const UCommonLocalPlayer* LocalPlayer) const;
ELocalMultiplayerInteractionMode GetLocalMultiplayerInteractionMode() const { return LocalMultiplayerInteractionMode; }
void RequestPrimaryControl(UPrimaryGameLayout* Layout);
protected:
void AddLayoutToViewport(UCommonLocalPlayer* LocalPlayer, UPrimaryGameLayout* Layout);
void RemoveLayoutFromViewport(UCommonLocalPlayer* LocalPlayer, UPrimaryGameLayout* Layout);
virtual void OnRootLayoutAddedToViewport(UCommonLocalPlayer* LocalPlayer, UPrimaryGameLayout* Layout);
virtual void OnRootLayoutRemovedFromViewport(UCommonLocalPlayer* LocalPlayer, UPrimaryGameLayout* Layout);
virtual void OnRootLayoutReleased(UCommonLocalPlayer* LocalPlayer, UPrimaryGameLayout* Layout);
void CreateLayoutWidget(UCommonLocalPlayer* LocalPlayer);
TSubclassOf<UPrimaryGameLayout> GetLayoutWidgetClass(UCommonLocalPlayer* LocalPlayer);
private:
ELocalMultiplayerInteractionMode LocalMultiplayerInteractionMode = ELocalMultiplayerInteractionMode::PrimaryOnly;
UPROPERTY(EditAnywhere)
TSoftClassPtr<UPrimaryGameLayout> LayoutClass;
UPROPERTY(Transient)
TArray<FRootViewportLayoutInfo> RootViewportLayouts;
private:
void NotifyPlayerAdded(UCommonLocalPlayer* LocalPlayer);
void NotifyPlayerRemoved(UCommonLocalPlayer* LocalPlayer);
void NotifyPlayerDestroyed(UCommonLocalPlayer* LocalPlayer);
friend class UGameUIManagerSubsystem;
};