From 923221baa9c98c96a71752d1b10a2f81a93683a3 Mon Sep 17 00:00:00 2001 From: Frozen Forest Reality Technologies Date: Mon, 16 Dec 2024 15:33:03 +0300 Subject: [PATCH] bugfix : Viewport doesn't adjust itself when there is a new player. FIXED --- .../Private/Viewport/CustomViewport.cpp | 21 +++++++++++++++---- .../Public/Viewport/CustomViewport.h | 7 +++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Source/WindowSystem/Private/Viewport/CustomViewport.cpp b/Source/WindowSystem/Private/Viewport/CustomViewport.cpp index 76d9694..008f63d 100644 --- a/Source/WindowSystem/Private/Viewport/CustomViewport.cpp +++ b/Source/WindowSystem/Private/Viewport/CustomViewport.cpp @@ -38,11 +38,15 @@ void UCustomViewport::LayoutPlayers() if (Player_Count == 1) { - if (!this->bIsInitialsLoaded) + if (!this->bIsInitialsLoaded || this->LastPlayerCount != Player_Count) { + this->bIsInitialsLoaded = false; + PlayerList[0]->Size = FVector2D(0.9f); PlayerList[0]->Origin = FVector2D(0.05); + this->bIsInitialsLoaded = true; + this->LastPlayerCount = Player_Count; } for (int32 PlayerIdx = 0; PlayerIdx < Player_Count; PlayerIdx++) @@ -59,8 +63,10 @@ void UCustomViewport::LayoutPlayers() else if (Player_Count == 2) { - if (!this->bIsInitialsLoaded) + if (!this->bIsInitialsLoaded || this->LastPlayerCount != Player_Count) { + this->bIsInitialsLoaded = false; + // Player 1 = Right PlayerList[0]->Size = FVector2D(0.425, 0.9); @@ -72,6 +78,7 @@ void UCustomViewport::LayoutPlayers() PlayerList[1]->Origin = FVector2D(0.05); this->bIsInitialsLoaded = true; + this->LastPlayerCount = Player_Count; } for (int32 PlayerIdx = 0; PlayerIdx < Player_Count; PlayerIdx++) @@ -88,8 +95,10 @@ void UCustomViewport::LayoutPlayers() else if (Player_Count == 3) { - if (!this->bIsInitialsLoaded) + if (!this->bIsInitialsLoaded || this->LastPlayerCount != Player_Count) { + this->bIsInitialsLoaded = false; + // Player 1 = Right PlayerList[0]->Size = FVector2D(0.425, 0.9); @@ -106,6 +115,7 @@ void UCustomViewport::LayoutPlayers() PlayerList[2]->Origin = FVector2D(0.05, 0.525); this->bIsInitialsLoaded = true; + this->LastPlayerCount = Player_Count; } for (int32 PlayerIdx = 0; PlayerIdx < Player_Count; PlayerIdx++) @@ -122,8 +132,10 @@ void UCustomViewport::LayoutPlayers() else if (Player_Count == 4) { - if (!this->bIsInitialsLoaded) + if (!this->bIsInitialsLoaded || this->LastPlayerCount != Player_Count) { + this->bIsInitialsLoaded = false; + // Player 1 = Bottom Right PlayerList[0]->Size = FVector2D(0.425); @@ -145,6 +157,7 @@ void UCustomViewport::LayoutPlayers() PlayerList[3]->Origin = FVector2D(0.05, 0.525); this->bIsInitialsLoaded = true; + this->LastPlayerCount = Player_Count; } for (int32 PlayerIdx = 0; PlayerIdx < Player_Count; PlayerIdx++) diff --git a/Source/WindowSystem/Public/Viewport/CustomViewport.h b/Source/WindowSystem/Public/Viewport/CustomViewport.h index f5ad862..6a901b0 100644 --- a/Source/WindowSystem/Public/Viewport/CustomViewport.h +++ b/Source/WindowSystem/Public/Viewport/CustomViewport.h @@ -32,8 +32,15 @@ class WINDOWSYSTEM_API UCustomViewport : public UGameViewportClient protected: + // If there is a new player, we need to reset views. + int32 LastPlayerCount = 0; + + // Views shouldn't reset to defaults if there is no change. bool bIsInitialsLoaded = false; + + // We use this to forcefully stop background rendering. For example there is only one view and it is in full screen state. bool bStopBackground = false; + UMaterialInterface* BG_Material = nullptr; public: