Files

108 lines
3.3 KiB
C
Raw Permalink Normal View History

2023-08-28 03:38:23 +08:00
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Engine/World.h"
#include "GameUIPolicy.generated.h"
2025-07-15 00:36:32 +08:00
#define UE_API COMMONGAME_API
2023-08-28 03:38:23 +08:00
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; }
};
2025-07-15 00:36:32 +08:00
UCLASS(MinimalAPI, Abstract, Blueprintable, Within = GameUIManagerSubsystem)
class UGameUIPolicy : public UObject
2023-08-28 03:38:23 +08:00
{
GENERATED_BODY()
public:
template <typename GameUIPolicyClass = UGameUIPolicy>
static GameUIPolicyClass* GetGameUIPolicyAs(const UObject* WorldContextObject)
{
return Cast<GameUIPolicyClass>(GetGameUIPolicy(WorldContextObject));
}
2025-07-15 00:36:32 +08:00
static UE_API UGameUIPolicy* GetGameUIPolicy(const UObject* WorldContextObject);
2023-08-28 03:38:23 +08:00
public:
2025-07-15 00:36:32 +08:00
UE_API virtual UWorld* GetWorld() const override;
UE_API UGameUIManagerSubsystem* GetOwningUIManager() const;
UE_API UPrimaryGameLayout* GetRootLayout(const UCommonLocalPlayer* LocalPlayer) const;
2023-08-28 03:38:23 +08:00
ELocalMultiplayerInteractionMode GetLocalMultiplayerInteractionMode() const { return LocalMultiplayerInteractionMode; }
2025-07-15 00:36:32 +08:00
UE_API void RequestPrimaryControl(UPrimaryGameLayout* Layout);
2023-08-28 03:38:23 +08:00
protected:
2025-07-15 00:36:32 +08:00
UE_API void AddLayoutToViewport(UCommonLocalPlayer* LocalPlayer, UPrimaryGameLayout* Layout);
UE_API void RemoveLayoutFromViewport(UCommonLocalPlayer* LocalPlayer, UPrimaryGameLayout* Layout);
2023-08-28 03:38:23 +08:00
2025-07-15 00:36:32 +08:00
UE_API virtual void OnRootLayoutAddedToViewport(UCommonLocalPlayer* LocalPlayer, UPrimaryGameLayout* Layout);
UE_API virtual void OnRootLayoutRemovedFromViewport(UCommonLocalPlayer* LocalPlayer, UPrimaryGameLayout* Layout);
UE_API virtual void OnRootLayoutReleased(UCommonLocalPlayer* LocalPlayer, UPrimaryGameLayout* Layout);
2023-08-28 03:38:23 +08:00
2025-07-15 00:36:32 +08:00
UE_API void CreateLayoutWidget(UCommonLocalPlayer* LocalPlayer);
UE_API TSubclassOf<UPrimaryGameLayout> GetLayoutWidgetClass(UCommonLocalPlayer* LocalPlayer);
2023-08-28 03:38:23 +08:00
private:
ELocalMultiplayerInteractionMode LocalMultiplayerInteractionMode = ELocalMultiplayerInteractionMode::PrimaryOnly;
UPROPERTY(EditAnywhere)
TSoftClassPtr<UPrimaryGameLayout> LayoutClass;
UPROPERTY(Transient)
TArray<FRootViewportLayoutInfo> RootViewportLayouts;
private:
2025-07-15 00:36:32 +08:00
UE_API void NotifyPlayerAdded(UCommonLocalPlayer* LocalPlayer);
UE_API void NotifyPlayerRemoved(UCommonLocalPlayer* LocalPlayer);
UE_API void NotifyPlayerDestroyed(UCommonLocalPlayer* LocalPlayer);
2023-08-28 03:38:23 +08:00
friend class UGameUIManagerSubsystem;
};
2025-07-15 00:36:32 +08:00
#undef UE_API