2021-05-03 15:49:00 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# include "SceneOutlinerPinnedColumn.h"
# include "Widgets/Images/SImage.h"
# include "Widgets/Views/STreeView.h"
2022-08-31 12:30:19 -04:00
# include "IDocumentation.h"
# include "Widgets/SToolTip.h"
2021-05-03 15:49:00 -04:00
# define LOCTEXT_NAMESPACE "SceneOutlinerPinnedActorColumn"
bool FSceneOutlinerPinnedColumn : : FSceneOutlinerPinnedStateCache : : CheckChildren ( const ISceneOutlinerTreeItem & Item ) const
{
if ( const bool * const State = PinnedStateInfo . Find ( & Item ) )
{
return * State ;
}
bool bIsPinned = false ;
for ( const auto & ChildPtr : Item . GetChildren ( ) )
{
FSceneOutlinerTreeItemPtr Child = ChildPtr . Pin ( ) ;
if ( Child . IsValid ( ) & & GetPinnedState ( * Child ) )
{
bIsPinned = true ;
break ;
}
}
PinnedStateInfo . Add ( & Item , bIsPinned ) ;
return bIsPinned ;
}
bool FSceneOutlinerPinnedColumn : : FSceneOutlinerPinnedStateCache : : GetPinnedState ( const ISceneOutlinerTreeItem & Item ) const
{
if ( Item . HasPinnedStateInfo ( ) )
{
if ( const bool * const State = PinnedStateInfo . Find ( & Item ) )
{
return * State ;
}
const bool bIsPinned = Item . GetPinnedState ( ) ;
PinnedStateInfo . Add ( & Item , bIsPinned ) ;
return bIsPinned ;
}
return CheckChildren ( Item ) ;
}
void FSceneOutlinerPinnedColumn : : FSceneOutlinerPinnedStateCache : : Empty ( )
{
PinnedStateInfo . Empty ( ) ;
}
class SPinnedWidget : public SImage
{
public :
SLATE_BEGIN_ARGS ( SPinnedWidget ) { }
SLATE_END_ARGS ( )
/** Construct this widget */
void Construct ( const FArguments & InArgs , TWeakPtr < ISceneOutliner > InWeakOutliner , TWeakPtr < ISceneOutlinerTreeItem > InWeakTreeItem , const TWeakPtr < FSceneOutlinerPinnedColumn > & InWeakColumn , const STableRow < FSceneOutlinerTreeItemPtr > * InRow )
{
WeakTreeItem = InWeakTreeItem ;
WeakOutliner = InWeakOutliner ;
WeakColumn = InWeakColumn ;
Row = InRow ;
SImage : : Construct (
SImage : : FArguments ( )
. ColorAndOpacity ( this , & SPinnedWidget : : GetForegroundColor )
. Image ( this , & SPinnedWidget : : GetBrush )
) ;
2021-11-22 15:55:34 -05:00
static const FName NAME_PinnedBrush = TEXT ( " Icons.Pinned " ) ;
static const FName NAME_UnpinnedBrush = TEXT ( " Icons.Unpinned " ) ;
2021-05-03 15:49:00 -04:00
2021-11-13 12:24:47 -05:00
PinnedBrush = FAppStyle : : Get ( ) . GetBrush ( NAME_PinnedBrush ) ;
UnpinnedBrush = FAppStyle : : Get ( ) . GetBrush ( NAME_UnpinnedBrush ) ;
2021-05-03 15:49:00 -04:00
}
private :
bool IsPinned ( ) const
{
return WeakTreeItem . IsValid ( ) & & WeakColumn . IsValid ( ) ? WeakColumn . Pin ( ) - > IsItemPinned ( * WeakTreeItem . Pin ( ) ) : false ;
}
FReply HandleClick ( ) const
{
if ( ! WeakTreeItem . IsValid ( ) | | ! WeakOutliner . IsValid ( ) )
{
return FReply : : Unhandled ( ) ;
}
const auto Outliner = WeakOutliner . Pin ( ) ;
const auto TreeItem = WeakTreeItem . Pin ( ) ;
const auto & Tree = Outliner - > GetTree ( ) ;
if ( ! IsPinned ( ) )
{
if ( Tree . IsItemSelected ( TreeItem . ToSharedRef ( ) ) )
{
Outliner - > PinSelectedItems ( ) ;
}
else
{
2022-05-27 07:18:07 -04:00
Outliner - > PinItems ( { TreeItem } ) ;
2021-05-03 15:49:00 -04:00
}
}
else
{
if ( Tree . IsItemSelected ( TreeItem . ToSharedRef ( ) ) )
{
Outliner - > UnpinSelectedItems ( ) ;
}
else
{
2022-05-27 07:18:07 -04:00
Outliner - > UnpinItems ( { TreeItem } ) ;
2021-05-03 15:49:00 -04:00
}
}
return FReply : : Handled ( ) ;
}
virtual FReply OnMouseButtonDoubleClick ( const FGeometry & InMyGeometry , const FPointerEvent & InMouseEvent ) override
{
return HandleClick ( ) ;
}
virtual FReply OnMouseButtonDown ( const FGeometry & MyGeometry , const FPointerEvent & MouseEvent ) override
{
if ( MouseEvent . GetEffectingButton ( ) = = EKeys : : LeftMouseButton )
{
2021-08-31 10:58:54 -04:00
FReply Reply = HandleClick ( ) ;
return Reply . PreventThrottling ( ) ;
2021-05-03 15:49:00 -04:00
}
return FReply : : Unhandled ( ) ;
}
const FSlateBrush * GetBrush ( ) const
{
2021-11-07 23:43:01 -05:00
return IsPinned ( ) ? PinnedBrush : UnpinnedBrush ;
2021-05-03 15:49:00 -04:00
}
virtual FSlateColor GetForegroundColor ( ) const override
{
const auto Outliner = WeakOutliner . Pin ( ) ;
const auto TreeItem = WeakTreeItem . Pin ( ) ;
const bool bIsSelected = Outliner - > GetTree ( ) . IsItemSelected ( TreeItem . ToSharedRef ( ) ) ;
if ( ! IsPinned ( ) )
{
if ( ! Row - > IsHovered ( ) & & ! bIsSelected )
{
return FLinearColor : : Transparent ;
}
}
return IsHovered ( ) ? FSlateColor : : UseForeground ( ) : FSlateColor : : UseSubduedForeground ( ) ;
}
/** The tree item we relate to */
TWeakPtr < ISceneOutlinerTreeItem > WeakTreeItem ;
/** Weak pointer back to the outliner */
TWeakPtr < ISceneOutliner > WeakOutliner ;
/** Weak pointer back to the column to check cached pinned state */
TWeakPtr < FSceneOutlinerPinnedColumn > WeakColumn ;
/** Weak pointer back to the row */
const STableRow < FSceneOutlinerTreeItemPtr > * Row = nullptr ;
2021-11-07 23:43:01 -05:00
const FSlateBrush * PinnedBrush = nullptr ;
const FSlateBrush * UnpinnedBrush = nullptr ;
2021-05-03 15:49:00 -04:00
} ;
FName FSceneOutlinerPinnedColumn : : GetColumnID ( )
{
return GetID ( ) ;
}
SHeaderRow : : FColumn : : FArguments FSceneOutlinerPinnedColumn : : ConstructHeaderRowColumn ( )
{
return SHeaderRow : : Column ( GetColumnID ( ) )
. FixedWidth ( 24.f )
. HAlignHeader ( HAlign_Center )
. VAlignHeader ( VAlign_Center )
. HAlignCell ( HAlign_Center )
. VAlignCell ( VAlign_Center )
2022-08-31 12:30:19 -04:00
. ToolTip ( IDocumentation : : Get ( ) - > CreateToolTip ( LOCTEXT ( " SceneOutlinerPinnedColumnToolTip " , " Pinned: always loaded in editor " ) , nullptr , " Shared/MenuEntries/SceneOutliner_ActorBrowsingMode " , " PinTooltip " ) )
2021-05-03 15:49:00 -04:00
[
SNew ( SImage )
. ColorAndOpacity ( FSlateColor : : UseForeground ( ) )
. Image ( this , & FSceneOutlinerPinnedColumn : : GetHeaderIcon )
] ;
}
const TSharedRef < SWidget > FSceneOutlinerPinnedColumn : : ConstructRowWidget ( FSceneOutlinerTreeItemRef TreeItem , const STableRow < FSceneOutlinerTreeItemPtr > & Row )
{
if ( TreeItem - > ShouldShowPinnedState ( ) )
{
return SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. VAlign ( VAlign_Center )
[
SNew ( SPinnedWidget , WeakSceneOutliner , TreeItem , SharedThis ( this ) , & Row )
2023-05-05 21:37:40 -04:00
. ToolTip ( IDocumentation : : Get ( ) - > CreateToolTip ( LOCTEXT ( " SceneOutlinerPinnedWidgetTooltip " , " Toggles whether this object is pinned (always loaded) in the editor. " ) , nullptr , " Shared/MenuEntries/SceneOutliner_ActorBrowsingMode " , " PinTooltip " ) )
2021-05-03 15:49:00 -04:00
] ;
}
return SNullWidget : : NullWidget ;
}
void FSceneOutlinerPinnedColumn : : Tick ( double InCurrentTime , float InDeltaTime )
{
PinnedStateCache . Empty ( ) ;
}
bool FSceneOutlinerPinnedColumn : : IsItemPinned ( const ISceneOutlinerTreeItem & Item ) const
{
return PinnedStateCache . GetPinnedState ( Item ) ;
}
const FSlateBrush * FSceneOutlinerPinnedColumn : : GetHeaderIcon ( ) const
{
2021-11-22 15:55:34 -05:00
return FAppStyle : : Get ( ) . GetBrush ( " Icons.Unpinned " ) ;
2021-05-03 15:49:00 -04:00
}
# undef LOCTEXT_NAMESPACE