2020-10-28 06:51:40 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# include "SDataLayerTreeLabel.h"
# include "DataLayer/DataLayerEditorSubsystem.h"
# include "DataLayerTreeItem.h"
# include "Widgets/Text/SInlineEditableTextBlock.h"
2021-01-28 11:19:30 -04:00
# include "WorldPartition/DataLayer/DataLayerSubsystem.h"
# include "Math/ColorList.h"
2020-10-28 06:51:40 -04:00
# include "ISceneOutliner.h"
# include "ISceneOutlinerMode.h"
2022-05-16 08:48:27 -04:00
# include "ScopedTransaction.h"
2020-10-28 06:51:40 -04:00
# include "Editor.h"
# define LOCTEXT_NAMESPACE "DataLayer"
void SDataLayerTreeLabel : : Construct ( const FArguments & InArgs , FDataLayerTreeItem & DataLayerItem , ISceneOutliner & SceneOutliner , const STableRow < FSceneOutlinerTreeItemPtr > & InRow )
{
WeakSceneOutliner = StaticCastSharedRef < ISceneOutliner > ( SceneOutliner . AsShared ( ) ) ;
TreeItemPtr = StaticCastSharedRef < FDataLayerTreeItem > ( DataLayerItem . AsShared ( ) ) ;
DataLayerPtr = DataLayerItem . GetDataLayer ( ) ;
HighlightText = SceneOutliner . GetFilterHighlightText ( ) ;
2022-05-02 11:00:12 -04:00
bInEditingMode = false ;
2020-10-28 06:51:40 -04:00
TSharedPtr < SInlineEditableTextBlock > InlineTextBlock ;
auto MainContent = SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. VAlign ( VAlign_Center )
[
SAssignNew ( InlineTextBlock , SInlineEditableTextBlock )
2021-11-25 13:51:47 -05:00
. Font ( this , & SDataLayerTreeLabel : : GetDisplayNameFont )
2020-10-28 06:51:40 -04:00
. Text ( this , & SDataLayerTreeLabel : : GetDisplayText )
. ToolTipText ( this , & SDataLayerTreeLabel : : GetTooltipText )
. HighlightText ( HighlightText )
. ColorAndOpacity ( this , & SDataLayerTreeLabel : : GetForegroundColor )
. OnTextCommitted ( this , & SDataLayerTreeLabel : : OnLabelCommitted )
. OnVerifyTextChanged ( this , & SDataLayerTreeLabel : : OnVerifyItemLabelChanged )
2022-05-02 11:00:12 -04:00
. OnEnterEditingMode ( this , & SDataLayerTreeLabel : : OnEnterEditingMode )
. OnExitEditingMode ( this , & SDataLayerTreeLabel : : OnExitEditingMode )
2020-10-28 06:51:40 -04:00
. IsSelected ( FIsSelected : : CreateSP ( & InRow , & STableRow < FSceneOutlinerTreeItemPtr > : : IsSelectedExclusively ) )
. IsReadOnly_Lambda ( [ Item = DataLayerItem . AsShared ( ) , this ] ( )
{
2022-03-15 13:52:28 -04:00
return DataLayerPtr = = nullptr | | ! DataLayerPtr - > SupportRelabeling ( ) | | ! CanExecuteRenameRequest ( Item . Get ( ) ) ;
2020-10-28 06:51:40 -04:00
} )
]
+ SHorizontalBox : : Slot ( )
. VAlign ( VAlign_Center )
. AutoWidth ( )
. Padding ( 0.0f , 0.f , 3.0f , 0.0f )
[
SNew ( STextBlock )
. Text ( this , & SDataLayerTreeLabel : : GetTypeText )
. Visibility ( this , & SDataLayerTreeLabel : : GetTypeTextVisibility )
. HighlightText ( HighlightText )
] ;
if ( WeakSceneOutliner . Pin ( ) - > GetMode ( ) - > IsInteractive ( ) )
{
DataLayerItem . RenameRequestEvent . BindSP ( InlineTextBlock . Get ( ) , & SInlineEditableTextBlock : : EnterEditingMode ) ;
}
ChildSlot
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. VAlign ( VAlign_Center )
. Padding ( FSceneOutlinerDefaultTreeItemMetrics : : IconPadding ( ) )
[
SNew ( SBox )
. WidthOverride ( FSceneOutlinerDefaultTreeItemMetrics : : IconSize ( ) )
. HeightOverride ( FSceneOutlinerDefaultTreeItemMetrics : : IconSize ( ) )
[
SNew ( SImage )
. Image ( this , & SDataLayerTreeLabel : : GetIcon )
. ToolTipText ( this , & SDataLayerTreeLabel : : GetIconTooltip )
. ColorAndOpacity ( FSlateColor : : UseForeground ( ) )
]
]
+ SHorizontalBox : : Slot ( )
. FillWidth ( 1.0f )
. VAlign ( VAlign_Center )
. Padding ( 0.0f , 0.0f )
[
MainContent
]
2021-11-07 23:43:01 -05:00
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. HAlign ( HAlign_Right )
. VAlign ( VAlign_Center )
[
SNew ( SImage )
2022-05-10 10:22:54 -04:00
. Visibility_Lambda ( [ this ] { return ( DataLayerPtr . IsValid ( ) & & DataLayerPtr - > IsLocked ( ) & & ! DataLayerPtr - > IsReadOnly ( ) & & ! DataLayerPtr - > GetWorld ( ) - > IsPlayInEditor ( ) ) ? EVisibility : : Visible : EVisibility : : Collapsed ; } )
2021-11-07 23:43:01 -05:00
. ColorAndOpacity ( FSlateColor : : UseForeground ( ) )
2022-05-09 13:12:28 -04:00
. Image ( FAppStyle : : GetBrush ( TEXT ( " PropertyWindow.Locked " ) ) )
2021-11-07 23:43:01 -05:00
. ToolTipText ( LOCTEXT ( " LockedRuntimeDataLayerEditing " , " Locked editing. (To allow editing, in Data Layer Outliner, go to Advanced -> Allow Runtime Data Layer Editing) " ) )
]
2020-10-28 06:51:40 -04:00
] ;
}
2021-11-25 13:51:47 -05:00
bool SDataLayerTreeLabel : : ShouldBeHighlighted ( ) const
{
const FSceneOutlinerTreeItemPtr TreeItem = TreeItemPtr . Pin ( ) ;
FDataLayerTreeItem * DataLayerTreeItem = TreeItem ? TreeItem - > CastTo < FDataLayerTreeItem > ( ) : nullptr ;
return DataLayerTreeItem & & DataLayerTreeItem - > ShouldBeHighlighted ( ) ;
}
2022-03-08 09:40:27 -05:00
bool SDataLayerTreeLabel : : IsInActorEditorContext ( ) const
{
2022-03-15 13:52:28 -04:00
const UDataLayerInstance * DataLayer = DataLayerPtr . Get ( ) ;
2022-03-08 09:40:27 -05:00
return DataLayer & & DataLayer - > IsInActorEditorContext ( ) ;
}
2021-11-25 13:51:47 -05:00
FSlateFontInfo SDataLayerTreeLabel : : GetDisplayNameFont ( ) const
{
if ( ShouldBeHighlighted ( ) )
{
return FAppStyle : : Get ( ) . GetFontStyle ( " DataLayerBrowser.LabelFontBold " ) ;
}
else
{
return FAppStyle : : Get ( ) . GetFontStyle ( " DataLayerBrowser.LabelFont " ) ;
}
}
2020-10-28 06:51:40 -04:00
FText SDataLayerTreeLabel : : GetDisplayText ( ) const
{
2022-03-15 13:52:28 -04:00
const UDataLayerInstance * DataLayer = DataLayerPtr . Get ( ) ;
2021-01-28 11:19:30 -04:00
bool bIsDataLayerActive = false ;
2022-05-02 11:00:12 -04:00
FText SuffixText = FText : : GetEmpty ( ) ;
if ( ! bInEditingMode )
2021-01-28 11:19:30 -04:00
{
2022-05-02 11:00:12 -04:00
if ( DataLayer & & DataLayer - > IsRuntime ( ) & & DataLayer - > GetWorld ( ) - > IsPlayInEditor ( ) )
{
const UDataLayerSubsystem * DataLayerSubsystem = DataLayer - > GetWorld ( ) - > GetSubsystem < UDataLayerSubsystem > ( ) ;
SuffixText = FText : : Format ( LOCTEXT ( " DataLayerRuntimeState " , " ({0}) " ) , FTextStringHelper : : CreateFromBuffer ( GetDataLayerRuntimeStateName ( DataLayerSubsystem - > GetDataLayerEffectiveRuntimeState ( DataLayer ) ) ) ) ;
}
else if ( IsInActorEditorContext ( ) )
{
SuffixText = FText ( LOCTEXT ( " IsCurrentSuffix " , " (Current) " ) ) ;
}
2021-01-28 11:19:30 -04:00
}
2022-05-02 11:00:12 -04:00
2021-01-28 11:19:30 -04:00
static const FText DataLayerDeleted = LOCTEXT ( " DataLayerLabelForMissingDataLayer " , " (Deleted Data Layer) " ) ;
2022-05-02 11:00:12 -04:00
return DataLayer ? FText : : Format ( LOCTEXT ( " DataLayerDisplayText " , " {0}{1} " ) , FText : : FromString ( DataLayer - > GetDataLayerShortName ( ) ) , SuffixText ) : DataLayerDeleted ;
2020-10-28 06:51:40 -04:00
}
FText SDataLayerTreeLabel : : GetTooltipText ( ) const
{
2021-11-07 23:43:01 -05:00
if ( const FSceneOutlinerTreeItemPtr TreeItem = TreeItemPtr . Pin ( ) )
2020-10-28 06:51:40 -04:00
{
2022-05-02 11:00:12 -04:00
FText Description = IsInActorEditorContext ( ) ? LOCTEXT ( " DataLayerIsCurrentDescription " , " This Data Layer is part of Current Data Layers. New actors will attempt to be added to this Data Layer. " ) : FText : : GetEmpty ( ) ;
return FText : : Format ( LOCTEXT ( " DataLayerTooltipText " , " {0} \n {1} " ) , FText : : FromString ( TreeItem - > GetDisplayString ( ) ) , Description ) ;
2020-10-28 06:51:40 -04:00
}
2021-11-07 23:43:01 -05:00
2020-10-28 06:51:40 -04:00
return FText ( ) ;
}
FText SDataLayerTreeLabel : : GetTypeText ( ) const
{
2022-03-15 13:52:28 -04:00
const UDataLayerInstance * DataLayer = DataLayerPtr . Get ( ) ;
2020-10-28 06:51:40 -04:00
return DataLayer ? FText : : FromName ( DataLayer - > GetClass ( ) - > GetFName ( ) ) : FText ( ) ;
}
EVisibility SDataLayerTreeLabel : : GetTypeTextVisibility ( ) const
{
return HighlightText . Get ( ) . IsEmpty ( ) ? EVisibility : : Collapsed : EVisibility : : Visible ;
}
const FSlateBrush * SDataLayerTreeLabel : : GetIcon ( ) const
{
2022-03-15 13:52:28 -04:00
const UDataLayerInstance * DataLayer = DataLayerPtr . Get ( ) ;
2020-10-28 06:51:40 -04:00
if ( DataLayer & & WeakSceneOutliner . IsValid ( ) )
{
2021-11-07 23:43:01 -05:00
const TCHAR * IconName = DataLayer - > GetDataLayerIconName ( ) ;
2020-10-28 06:51:40 -04:00
if ( const FSlateBrush * CachedBrush = WeakSceneOutliner . Pin ( ) - > GetCachedIconForClass ( IconName ) )
{
return CachedBrush ;
}
2022-05-09 13:12:28 -04:00
const FSlateBrush * FoundSlateBrush = FAppStyle : : GetBrush ( IconName ) ;
2020-10-28 06:51:40 -04:00
WeakSceneOutliner . Pin ( ) - > CacheIconForClass ( IconName , FoundSlateBrush ) ;
return FoundSlateBrush ;
}
return nullptr ;
}
FText SDataLayerTreeLabel : : GetIconTooltip ( ) const
{
2022-03-15 13:52:28 -04:00
const UDataLayerInstance * DataLayer = DataLayerPtr . Get ( ) ;
2021-11-07 23:43:01 -05:00
return DataLayer ? ( DataLayer - > IsRuntime ( ) ? FText ( LOCTEXT ( " RuntimeDataLayer " , " Runtime Data Layer " ) ) : FText ( LOCTEXT ( " EditorDataLayer " , " Editor Data Layer " ) ) ) : FText ( ) ;
2020-10-28 06:51:40 -04:00
}
FSlateColor SDataLayerTreeLabel : : GetForegroundColor ( ) const
{
if ( TOptional < FLinearColor > BaseColor = FSceneOutlinerCommonLabelData : : GetForegroundColor ( * TreeItemPtr . Pin ( ) ) )
{
return BaseColor . GetValue ( ) ;
}
2022-03-15 13:52:28 -04:00
const UDataLayerInstance * DataLayer = DataLayerPtr . Get ( ) ;
2021-02-09 15:01:37 -04:00
if ( DataLayer )
2021-01-28 11:19:30 -04:00
{
2021-11-07 23:43:01 -05:00
if ( DataLayer - > GetWorld ( ) - > IsPlayInEditor ( ) )
2021-01-28 11:19:30 -04:00
{
2021-11-07 23:43:01 -05:00
if ( DataLayer - > IsRuntime ( ) )
{
const UDataLayerSubsystem * DataLayerSubsystem = DataLayer - > GetWorld ( ) - > GetSubsystem < UDataLayerSubsystem > ( ) ;
EDataLayerRuntimeState State = DataLayerSubsystem - > GetDataLayerEffectiveRuntimeState ( DataLayer ) ;
switch ( State )
{
case EDataLayerRuntimeState : : Activated :
return FColorList : : LimeGreen ;
case EDataLayerRuntimeState : : Loaded :
return FColorList : : NeonBlue ;
case EDataLayerRuntimeState : : Unloaded :
2021-12-07 13:48:13 -05:00
return FColorList : : DarkSlateGrey ;
2021-11-07 23:43:01 -05:00
}
}
else
{
return FSceneOutlinerCommonLabelData : : DarkColor ;
}
2021-02-09 15:01:37 -04:00
}
2021-11-07 23:43:01 -05:00
else if ( DataLayer - > IsLocked ( ) )
2021-02-09 15:01:37 -04:00
{
2021-11-07 23:43:01 -05:00
return FSceneOutlinerCommonLabelData : : DarkColor ;
2021-01-28 11:19:30 -04:00
}
}
2021-11-25 13:51:47 -05:00
if ( ! DataLayer | | ! DataLayer - > GetWorld ( ) )
{
return FLinearColor ( 0.2f , 0.2f , 0.25f ) ;
}
if ( ShouldBeHighlighted ( ) )
{
return FAppStyle : : Get ( ) . GetSlateColor ( " Colors.AccentBlue " ) ;
}
2022-05-02 11:00:12 -04:00
else if ( IsInActorEditorContext ( ) )
{
return FAppStyle : : Get ( ) . GetSlateColor ( " Colors.AccentGreen " ) ;
}
2021-11-25 13:51:47 -05:00
return FSlateColor : : UseForeground ( ) ;
2020-10-28 06:51:40 -04:00
}
bool SDataLayerTreeLabel : : OnVerifyItemLabelChanged ( const FText & InLabel , FText & OutErrorMessage )
{
if ( InLabel . IsEmptyOrWhitespace ( ) )
{
2021-03-17 15:17:35 -04:00
OutErrorMessage = LOCTEXT ( " EmptyDataLayerLabel " , " Data Layer must be given a name " ) ;
2020-10-28 06:51:40 -04:00
return false ;
}
2022-03-15 13:52:28 -04:00
UDataLayerInstance * FoundDataLayerInstance ;
PRAGMA_DISABLE_DEPRECATION_WARNINGS
if ( UDataLayerEditorSubsystem : : Get ( ) - > TryGetDataLayerFromLabel ( * InLabel . ToString ( ) , FoundDataLayerInstance ) & & FoundDataLayerInstance ! = DataLayerPtr . Get ( ) )
2020-10-28 06:51:40 -04:00
{
2021-03-17 15:17:35 -04:00
OutErrorMessage = LOCTEXT ( " RenameFailed_AlreadyExists " , " This Data Layer already exists " ) ;
2020-10-28 06:51:40 -04:00
return false ;
}
2022-03-15 13:52:28 -04:00
PRAGMA_ENABLE_DEPRECATION_WARNINGS
if ( FoundDataLayerInstance ! = nullptr & & ! FoundDataLayerInstance - > SupportRelabeling ( ) )
{
OutErrorMessage = LOCTEXT ( " RenameFailed_NotPermittedOnDataLayer " , " This Data Layer does not support renaming " ) ;
return false ;
}
2020-10-28 06:51:40 -04:00
return true ;
}
void SDataLayerTreeLabel : : OnLabelCommitted ( const FText & InLabel , ETextCommit : : Type InCommitInfo )
{
2022-03-15 13:52:28 -04:00
UDataLayerInstance * DataLayerInstance = DataLayerPtr . Get ( ) ;
check ( DataLayerInstance - > SupportRelabeling ( ) ) ;
if ( ! InLabel . ToString ( ) . Equals ( DataLayerInstance - > GetDataLayerShortName ( ) , ESearchCase : : CaseSensitive ) )
2020-10-28 06:51:40 -04:00
{
2022-05-16 08:48:27 -04:00
const FScopedTransaction Transaction ( LOCTEXT ( " SceneOutlinerRenameDataLayerTransaction " , " Rename Data Layer " ) ) ;
2022-03-15 13:52:28 -04:00
PRAGMA_DISABLE_DEPRECATION_WARNINGS
UDataLayerEditorSubsystem : : Get ( ) - > RenameDataLayer ( DataLayerInstance , * InLabel . ToString ( ) ) ;
PRAGMA_ENABLE_DEPRECATION_WARNINGS
2020-10-28 06:51:40 -04:00
if ( WeakSceneOutliner . IsValid ( ) )
{
WeakSceneOutliner . Pin ( ) - > SetKeyboardFocus ( ) ;
}
}
}
2022-05-02 11:00:12 -04:00
void SDataLayerTreeLabel : : OnEnterEditingMode ( )
{
bInEditingMode = true ;
}
void SDataLayerTreeLabel : : OnExitEditingMode ( )
{
bInEditingMode = false ;
}
2020-10-28 06:51:40 -04:00
# undef LOCTEXT_NAMESPACE