Files
UnrealEngineUWP/Engine/Source/Editor/LevelEditor/Private/SLevelEditorToolBox.cpp

193 lines
6.1 KiB
C++
Raw Normal View History

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "SLevelEditorToolBox.h"
#include "Framework/MultiBox/MultiBoxDefs.h"
#include "Widgets/Text/STextBlock.h"
#include "Framework/MultiBox/MultiBoxBuilder.h"
#include "Framework/Commands/InputBindingManager.h"
#include "EditorModeRegistry.h"
#include "Modules/ModuleManager.h"
#include "Widgets/Layout/SBorder.h"
#include "EditorStyleSet.h"
#include "Editor/EditorPerProjectUserSettings.h"
#include "LevelEditor.h"
#include "LevelEditorActions.h"
#include "LevelEditorModesActions.h"
#define LOCTEXT_NAMESPACE "SLevelEditorToolBox"
SLevelEditorToolBox::~SLevelEditorToolBox()
{
GetMutableDefault<UEditorPerProjectUserSettings>()->OnUserSettingChanged().RemoveAll( this );
}
void SLevelEditorToolBox::Construct( const FArguments& InArgs, const TSharedRef< class ILevelEditor >& OwningLevelEditor )
{
LevelEditor = OwningLevelEditor;
// Important: We use a raw binding here because we are releasing our binding in our destructor (where a weak pointer would be invalid)
// It's imperative that our delegate is removed in the destructor for the level editor module to play nicely with reloading.
GetMutableDefault<UEditorPerProjectUserSettings>()->OnUserSettingChanged().AddRaw( this, &SLevelEditorToolBox::HandleUserSettingsChange );
ChildSlot
[
SNew( SVerticalBox )
+ SVerticalBox::Slot()
.AutoHeight()
.HAlign( HAlign_Left )
.Padding(0, 0, 0, 0)
[
SAssignNew( ModeToolBarContainer, SBorder )
.BorderImage( FEditorStyle::GetBrush( "NoBorder" ) )
.Padding( FMargin(4, 0, 0, 0) )
]
+ SVerticalBox::Slot()
.FillHeight( 1.0f )
.Padding( 2, 0, 0, 0 )
[
SNew( SVerticalBox )
+ SVerticalBox::Slot()
[
SAssignNew(InlineContentHolder, SBorder)
.BorderImage( FEditorStyle::GetBrush( "ToolPanel.GroupBorder" ) )
.Padding(0.f)
.Visibility( this, &SLevelEditorToolBox::GetInlineContentHolderVisibility )
]
+ SVerticalBox::Slot()
.AutoHeight()
.HAlign( HAlign_Center )
.Padding( 2.0f, 14.0f, 2.0f, 2.0f )
[
SNew( STextBlock )
.Text( LOCTEXT("NoToolSelected", "Select a tool to display its options.") )
.Visibility( this, &SLevelEditorToolBox::GetNoToolSelectedTextVisibility )
]
]
];
UpdateModeToolBar();
}
void SLevelEditorToolBox::HandleUserSettingsChange( FName PropertyName )
{
UpdateModeToolBar();
}
void SLevelEditorToolBox::OnEditorModeCommandsChanged()
{
UpdateModeToolBar();
}
void SLevelEditorToolBox::UpdateModeToolBar()
{
FLevelEditorModule& LevelEditorModule = FModuleManager::GetModuleChecked<FLevelEditorModule>( "LevelEditor");
const TSharedPtr< const FUICommandList > CommandList = LevelEditorModule.GetGlobalLevelEditorActions();
const TSharedPtr<FExtender> ModeBarExtenders = LevelEditorModule.GetModeBarExtensibilityManager()->GetAllExtenders();
FToolBarBuilder EditorModeTools( CommandList, FMultiBoxCustomization::None, ModeBarExtenders );
{
EditorModeTools.SetStyle(&FEditorStyle::Get(), "EditorModesToolbar");
EditorModeTools.SetLabelVisibility( EVisibility::Collapsed );
const FLevelEditorModesCommands& Commands = LevelEditorModule.GetLevelEditorModesCommands();
for ( const FEditorModeInfo& Mode : FEditorModeRegistry::Get().GetSortedModeInfo() )
{
// If the mode isn't visible don't create a menu option for it.
if ( !Mode.bVisible )
{
continue;
}
FName EditorModeCommandName = FName( *( FString( "EditorMode." ) + Mode.ID.ToString() ) );
TSharedPtr<FUICommandInfo> EditorModeCommand =
FInputBindingManager::Get().FindCommandInContext( Commands.GetContextName(), EditorModeCommandName );
// If a command isn't yet registered for this mode, we need to register one.
if ( !EditorModeCommand.IsValid() )
{
continue;
}
const FUIAction* UIAction = EditorModeTools.GetTopCommandList()->GetActionForCommand( EditorModeCommand );
if ( ensure( UIAction ) )
{
EditorModeTools.AddToolBarButton( EditorModeCommand, Mode.ID, Mode.Name, Mode.Name, Mode.IconBrush, Mode.ID );// , EUserInterfaceActionType::ToggleButton );
}
}
}
ModeToolBarContainer->SetContent( EditorModeTools.MakeWidget() );
const TArray< TSharedPtr< IToolkit > >& HostedToolkits = LevelEditor.Pin()->GetHostedToolkits();
for( auto HostedToolkitIt = HostedToolkits.CreateConstIterator(); HostedToolkitIt; ++HostedToolkitIt )
{
UpdateInlineContent( ( *HostedToolkitIt )->GetInlineContent() );
break;
}
}
EVisibility SLevelEditorToolBox::GetInlineContentHolderVisibility() const
{
return InlineContentHolder->GetContent() == SNullWidget::NullWidget ? EVisibility::Collapsed : EVisibility::Visible;
}
EVisibility SLevelEditorToolBox::GetNoToolSelectedTextVisibility() const
{
return InlineContentHolder->GetContent() == SNullWidget::NullWidget ? EVisibility::Visible : EVisibility::Collapsed;
}
void SLevelEditorToolBox::UpdateInlineContent(TSharedPtr<SWidget> InlineContent) const
{
if (InlineContent.IsValid() && InlineContentHolder.IsValid())
{
InlineContentHolder->SetContent(InlineContent.ToSharedRef());
}
}
void SLevelEditorToolBox::OnToolkitHostingStarted( const TSharedRef< class IToolkit >& Toolkit )
{
UpdateInlineContent( Toolkit->GetInlineContent() );
}
void SLevelEditorToolBox::OnToolkitHostingFinished( const TSharedRef< class IToolkit >& Toolkit )
{
bool FoundAnotherToolkit = false;
const TArray< TSharedPtr< IToolkit > >& HostedToolkits = LevelEditor.Pin()->GetHostedToolkits();
for( auto HostedToolkitIt = HostedToolkits.CreateConstIterator(); HostedToolkitIt; ++HostedToolkitIt )
{
if ( ( *HostedToolkitIt ) != Toolkit )
{
UpdateInlineContent( ( *HostedToolkitIt )->GetInlineContent() );
FoundAnotherToolkit = true;
break;
}
}
if ( !FoundAnotherToolkit )
{
UpdateInlineContent( SNullWidget::NullWidget );
}
}
FSlateIcon SLevelEditorToolBox::GetEditorModeIcon(TSharedPtr< FUICommandInfo > EditorModeUICommand, FEditorModeID EditorMode )
{
const FSlateIcon& Icon = EditorModeUICommand->GetIcon();
FName IconName = Icon.GetStyleName();
if( FLevelEditorActionCallbacks::IsEditorModeActive(EditorMode) )
{
IconName = FEditorStyle::Join(IconName, ".Selected");
}
return FSlateIcon(Icon.GetStyleSetName(), IconName);
}
#undef LOCTEXT_NAMESPACE