Skip to content

Commit

Permalink
bugfix : Viewport doesn't adjust itself when there is a new player. F…
Browse files Browse the repository at this point in the history
…IXED
  • Loading branch information
ffreality committed Dec 16, 2024
1 parent 4df2085 commit 923221b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Source/WindowSystem/Private/Viewport/CustomViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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);
Expand All @@ -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++)
Expand All @@ -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);
Expand All @@ -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++)
Expand All @@ -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);
Expand All @@ -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++)
Expand Down
7 changes: 7 additions & 0 deletions Source/WindowSystem/Public/Viewport/CustomViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 923221b

Please sign in to comment.