Files
UnrealEngineUWP/Engine/Source/Editor/LevelEditor/Private/LevelViewportLayout2x2.cpp
matt kuhlenschmidt 0f072073f6 Reworked how realtime is overriden in the editor. This fixes issues where a temporarily set realtime state is saved between editor sessions causing users to be unaware that their viewport is not realtime. Shutting down the editor during PIE or remote desktop were two such cases.
Now there is a separate api on editor viewports to set and remove a temporary override state.  Deprecated existing methods and fixed up use cases.



#ROBOMERGE-OWNER: matt.kuhlenschmidt
#ROBOMERGE-AUTHOR: matt.kuhlenschmidt
#ROBOMERGE-SOURCE: CL 11498109 via CL 11498156 via CL 11498165
#ROBOMERGE-BOT: (v654-11333218)
#rb none

[CL 11498464 by matt kuhlenschmidt in Main branch]
2020-02-18 09:38:41 -05:00

179 lines
5.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "LevelViewportLayout2x2.h"
#include "Framework/Docking/LayoutService.h"
#include "Editor.h"
#include "Misc/ConfigCacheIni.h"
#include "Modules/ModuleManager.h"
#include "Framework/Application/SlateApplication.h"
#include "LevelEditor.h"
namespace ViewportLayout2x2Defs
{
/** Default 2x2 splitters to equal 50/50 splits */
static const FVector2D DefaultSplitterPercentages(0.5f, 0.5f);
}
// FLevelViewportLayout2x2 //////////////////////////////////////////
TSharedRef<SWidget> FLevelViewportLayout2x2::MakeViewportLayout(const FString& LayoutString)
{
FString SpecificLayoutString = GetTypeSpecificLayoutString(LayoutString);
FString TopLeftKey, BottomLeftKey, TopRightKey, BottomRightKey;
FString TopLeftType = TEXT("Default"), BottomLeftType = TEXT("Default"), TopRightType = TEXT("Default"), BottomRightType = TEXT("Default");
TArray<FVector2D> SplitterPercentages;
if (!SpecificLayoutString.IsEmpty())
{
// The Layout String only holds the unique ID of the Additional Layout Configs to use
const FString& IniSection = FLayoutSaveRestore::GetAdditionalLayoutConfigIni();
TopLeftKey = SpecificLayoutString + TEXT(".Viewport0");
BottomLeftKey = SpecificLayoutString + TEXT(".Viewport1");
TopRightKey = SpecificLayoutString + TEXT(".Viewport2");
BottomRightKey = SpecificLayoutString + TEXT(".Viewport3");
GConfig->GetString(*IniSection, *(TopLeftKey + TEXT(".TypeWithinLayout")), TopLeftType, GEditorPerProjectIni);
GConfig->GetString(*IniSection, *(TopRightKey + TEXT(".TypeWithinLayout")), TopRightType, GEditorPerProjectIni);
GConfig->GetString(*IniSection, *(BottomLeftKey + TEXT(".TypeWithinLayout")), BottomLeftType, GEditorPerProjectIni);
GConfig->GetString(*IniSection, *(BottomRightKey + TEXT(".TypeWithinLayout")), BottomRightType, GEditorPerProjectIni);
for (int32 i = 0; i < 4; ++i)
{
FString PercentageString;
FVector2D NewPercentage = ViewportLayout2x2Defs::DefaultSplitterPercentages;
if(GConfig->GetString(*IniSection, *(SpecificLayoutString + FString::Printf(TEXT(".Percentages%i"), i)), PercentageString, GEditorPerProjectIni))
{
NewPercentage.InitFromString(PercentageString);
}
SplitterPercentages.Add(NewPercentage);
}
}
FLevelEditorModule& LevelEditor = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
// Set up the viewports
FViewportConstructionArgs Args;
Args.ParentLayout = AsShared();
Args.ParentLevelEditor = ParentLevelEditor;
Args.IsEnabled = FSlateApplication::Get().GetNormalExecutionAttribute();
// Left viewport
Args.bRealtime = false;
Args.ConfigKey = *TopLeftKey;
Args.ViewportType = LVT_OrthoYZ;
TSharedPtr< ILevelViewportLayoutEntity > ViewportTL = LevelEditor.FactoryViewport(*TopLeftType, Args);
// Persp viewport
Args.bRealtime = true;
Args.ConfigKey = *BottomLeftKey;
Args.ViewportType = LVT_Perspective;
TSharedPtr< ILevelViewportLayoutEntity > ViewportBL = LevelEditor.FactoryViewport(*BottomLeftType, Args);
// Front viewport
Args.bRealtime = false;
Args.ConfigKey = *TopRightKey;
Args.ViewportType = LVT_OrthoXZ;
TSharedPtr< ILevelViewportLayoutEntity > ViewportTR = LevelEditor.FactoryViewport(*TopRightType, Args);
// Top Viewport
Args.bRealtime = false;
Args.ConfigKey = *BottomRightKey;
Args.ViewportType = LVT_OrthoXY;
TSharedPtr< ILevelViewportLayoutEntity > ViewportBR = LevelEditor.FactoryViewport(*BottomRightType, Args);
Viewports.Add( *TopLeftKey, ViewportTL );
Viewports.Add( *BottomLeftKey, ViewportBL );
Viewports.Add( *TopRightKey, ViewportTR );
Viewports.Add( *BottomRightKey, ViewportBR );
// Set up the splitter
SplitterWidget =
SNew( SSplitter2x2 )
.TopLeft()
[
ViewportTL->AsWidget()
]
.BottomLeft()
[
ViewportBL->AsWidget()
]
.TopRight()
[
ViewportTR->AsWidget()
]
.BottomRight()
[
ViewportBR->AsWidget()
];
// Make newly-created perspective viewports active by default
GCurrentLevelEditingViewportClient = &ViewportBL->GetLevelViewportClient();
if (SplitterPercentages.Num() > 0)
{
SplitterWidget->SetSplitterPercentages(SplitterPercentages);
}
InitCommonLayoutFromString(SpecificLayoutString, *BottomLeftKey);
return SplitterWidget.ToSharedRef();
}
void FLevelViewportLayout2x2::SaveLayoutString(const FString& LayoutString) const
{
if (!bIsTransitioning)
{
FString SpecificLayoutString = GetTypeSpecificLayoutString(LayoutString);
const FString& IniSection = FLayoutSaveRestore::GetAdditionalLayoutConfigIni();
TArray<FVector2D> Percentages;
SplitterWidget->GetSplitterPercentages(Percentages);
for (int32 i = 0; i < Percentages.Num(); ++i)
{
GConfig->SetString(*IniSection, *(SpecificLayoutString + FString::Printf(TEXT(".Percentages%i"), i)), *Percentages[i].ToString(), GEditorPerProjectIni);
}
SaveCommonLayoutString(SpecificLayoutString);
}
}
void FLevelViewportLayout2x2::ReplaceWidget( TSharedRef< SWidget > Source, TSharedRef< SWidget > Replacement )
{
bool bWasFound = false;
if( SplitterWidget->GetTopLeftContent() == Source )
{
SplitterWidget->SetTopLeftContent( Replacement );
bWasFound = true;
}
else if( SplitterWidget->GetBottomLeftContent() == Source )
{
SplitterWidget->SetBottomLeftContent( Replacement );
bWasFound = true;
}
else if( SplitterWidget->GetTopRightContent() == Source )
{
SplitterWidget->SetTopRightContent( Replacement );
bWasFound = true;
}
else if( SplitterWidget->GetBottomRightContent() == Source )
{
SplitterWidget->SetBottomRightContent( Replacement );
bWasFound = true;
}
// Source widget should have already been a content widget for the splitter
check( bWasFound );
}