2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-05-16 11:52:57 -04:00
# include "PersonaPrivatePCH.h"
# include "Editor/PropertyEditor/Public/IDetailsView.h"
# include "Editor/PropertyEditor/Public/PropertyEditing.h"
# include "Editor/PropertyEditor/Public/PropertyEditorModule.h"
# include "AnimGraphNode_Base.h"
# include "ScopedTransaction.h"
# include "AnimGraphNodeSlotDetails.h"
2014-05-16 13:18:18 -04:00
# include "Persona.h"
2014-10-14 22:50:06 -04:00
# include "STextComboBox.h"
# include "STextEntryPopup.h"
2014-05-16 11:52:57 -04:00
# define LOCTEXT_NAMESPACE "AnimNodeSlotDetails"
////////////////////////////////////////////////////////////////
2014-05-29 17:16:26 -04:00
FAnimGraphNodeSlotDetails : : FAnimGraphNodeSlotDetails ( TWeakPtr < class FPersona > InPersonalEditor )
2014-05-16 11:52:57 -04:00
: PersonaEditor ( InPersonalEditor )
{
}
void FAnimGraphNodeSlotDetails : : CustomizeDetails ( class IDetailLayoutBuilder & DetailBuilder )
{
SlotNodeNamePropertyHandle = DetailBuilder . GetProperty ( TEXT ( " Node.SlotName " ) ) ;
DetailBuilder . HideProperty ( SlotNodeNamePropertyHandle ) ;
TArray < UObject * > OuterObjects ;
SlotNodeNamePropertyHandle - > GetOuterObjects ( OuterObjects ) ;
check ( SlotNodeNamePropertyHandle . IsValid ( ) ) ;
Skeleton = NULL ;
// only support one object, it doesn't make sense to have same slot node name in multiple nodes
for ( auto Object : OuterObjects )
{
// if not this object, we have problem
2014-10-01 14:45:23 -04:00
const UAnimGraphNode_Base * Node = CastChecked < UAnimGraphNode_Base > ( Object ) ;
const UAnimBlueprint * AnimBlueprint = Node - > GetAnimBlueprint ( ) ;
2014-05-16 11:52:57 -04:00
if ( AnimBlueprint )
{
// if skeleton is already set and it's not same as target skeleton, we have some problem ,return
if ( Skeleton ! = NULL & & Skeleton = = AnimBlueprint - > TargetSkeleton )
{
// abort
return ;
}
Skeleton = AnimBlueprint - > TargetSkeleton ;
}
}
check ( Skeleton ) ;
// this is used for 2 things, to create name, but also for another pop-up box to show off, it's a bit hacky to use this, but I need widget to parent on
TSharedRef < SWidget > SlotNodePropertyNameWidget = SlotNodeNamePropertyHandle - > CreatePropertyNameWidget ( ) ;
2014-10-24 15:46:54 -04:00
// fill combo with groups and slots
RefreshComboLists ( ) ;
2014-05-16 11:52:57 -04:00
2014-10-24 15:46:54 -04:00
int32 FoundIndex = SlotNameList . Find ( SlotNameComboSelectedName ) ;
TSharedPtr < FString > ComboBoxSelectedItem = SlotNameComboListItems [ FoundIndex ] ;
2014-05-16 11:52:57 -04:00
// create combo box
IDetailCategoryBuilder & SlotNameGroup = DetailBuilder . EditCategory ( TEXT ( " Settings " ) ) ;
2014-12-01 11:19:41 -05:00
SlotNameGroup . AddCustomRow ( LOCTEXT ( " SlotNameTitleLabel " , " Slot Name " ) )
2014-05-16 11:52:57 -04:00
. NameContent ( )
[
SlotNodePropertyNameWidget
]
. ValueContent ( )
2014-10-24 15:46:54 -04:00
. MinDesiredWidth ( 125.f * 3.f )
. MaxDesiredWidth ( 125.f * 3.f )
2014-05-16 11:52:57 -04:00
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
2014-10-24 15:46:54 -04:00
. AutoWidth ( )
2014-05-16 11:52:57 -04:00
[
SAssignNew ( SlotNameComboBox , STextComboBox )
2014-10-24 15:46:54 -04:00
. OptionsSource ( & SlotNameComboListItems )
2014-05-16 11:52:57 -04:00
. OnSelectionChanged ( this , & FAnimGraphNodeSlotDetails : : OnSlotNameChanged )
2014-10-24 15:46:54 -04:00
. OnComboBoxOpening ( this , & FAnimGraphNodeSlotDetails : : OnSlotListOpening )
. InitiallySelectedItem ( ComboBoxSelectedItem )
2014-05-16 11:52:57 -04:00
. ContentPadding ( 2 )
2014-10-24 15:46:54 -04:00
. ToolTipText ( FText : : FromString ( * ComboBoxSelectedItem ) )
2014-05-16 11:52:57 -04:00
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
[
SNew ( SButton )
2014-10-24 15:46:54 -04:00
. Text ( LOCTEXT ( " AnimSlotNode_DetailPanelManageButtonLabel " , " Anim Slot Manager " ) )
. ToolTipText ( LOCTEXT ( " AnimSlotNode_DetailPanelManageButtonToolTipText " , " Open Anim Slot Manager to edit Slots and Groups. " ) )
. OnClicked ( this , & FAnimGraphNodeSlotDetails : : OnOpenAnimSlotManager )
2014-05-16 11:52:57 -04:00
. Content ( )
[
SNew ( SImage )
. Image ( FEditorStyle : : GetBrush ( " MeshPaint.FindInCB " ) )
]
]
] ;
}
2014-10-24 15:46:54 -04:00
void FAnimGraphNodeSlotDetails : : RefreshComboLists ( bool bOnlyRefreshIfDifferent /*= false*/ )
2014-05-16 11:52:57 -04:00
{
2014-10-24 15:46:54 -04:00
SlotNodeNamePropertyHandle - > GetValue ( SlotNameComboSelectedName ) ;
2014-05-16 11:52:57 -04:00
2014-10-24 15:46:54 -04:00
// Make sure slot node exists in our skeleton.
Skeleton - > RegisterSlotNode ( SlotNameComboSelectedName ) ;
2014-05-16 11:52:57 -04:00
2014-10-24 15:46:54 -04:00
// Refresh Slot Names
2014-05-16 11:52:57 -04:00
{
2014-10-24 15:46:54 -04:00
TArray < TSharedPtr < FString > > NewSlotNameComboListItems ;
TArray < FName > NewSlotNameList ;
bool bIsSlotNameListDifferent = false ;
2014-05-16 11:52:57 -04:00
2014-10-24 15:46:54 -04:00
const TArray < FAnimSlotGroup > & SlotGroups = Skeleton - > GetSlotGroups ( ) ;
for ( auto SlotGroup : SlotGroups )
2014-05-16 11:52:57 -04:00
{
2014-10-24 15:46:54 -04:00
int32 Index = 0 ;
for ( auto SlotName : SlotGroup . SlotNames )
{
NewSlotNameList . Add ( SlotName ) ;
FString ComboItemString = FString : : Printf ( TEXT ( " %s.%s " ) , * SlotGroup . GroupName . ToString ( ) , * SlotName . ToString ( ) ) ;
NewSlotNameComboListItems . Add ( MakeShareable ( new FString ( ComboItemString ) ) ) ;
bIsSlotNameListDifferent = bIsSlotNameListDifferent | | ( ! SlotNameComboListItems . IsValidIndex ( Index ) | | ( SlotNameComboListItems [ Index ] ! = NewSlotNameComboListItems [ Index ] ) ) ;
Index + + ;
}
}
// Refresh if needed
if ( bIsSlotNameListDifferent | | ! bOnlyRefreshIfDifferent | | ( NewSlotNameComboListItems . Num ( ) = = 0 ) )
{
SlotNameComboListItems = NewSlotNameComboListItems ;
SlotNameList = NewSlotNameList ;
if ( SlotNameComboBox . IsValid ( ) )
{
if ( Skeleton - > ContainsSlotName ( SlotNameComboSelectedName ) )
{
int32 FoundIndex = SlotNameList . Find ( SlotNameComboSelectedName ) ;
TSharedPtr < FString > ComboItem = SlotNameComboListItems [ FoundIndex ] ;
SlotNameComboBox - > SetSelectedItem ( ComboItem ) ;
SlotNameComboBox - > SetToolTipText ( FText : : FromString ( * ComboItem ) ) ;
}
SlotNameComboBox - > RefreshOptions ( ) ;
}
2014-05-16 11:52:57 -04:00
}
}
}
2014-10-24 15:46:54 -04:00
2014-05-16 11:52:57 -04:00
////////////////////////////////////////////////////////////////
void FAnimGraphNodeSlotDetails : : OnSlotNameChanged ( TSharedPtr < FString > NewSelection , ESelectInfo : : Type SelectInfo )
{
// if it's set from code, we did that on purpose
if ( SelectInfo ! = ESelectInfo : : Direct )
{
2014-10-24 15:46:54 -04:00
int32 ItemIndex = SlotNameComboListItems . Find ( NewSelection ) ;
if ( ItemIndex ! = INDEX_NONE )
2014-05-16 11:52:57 -04:00
{
2014-10-24 15:46:54 -04:00
SlotNameComboSelectedName = SlotNameList [ ItemIndex ] ;
if ( SlotNameComboBox . IsValid ( ) )
2014-05-16 11:52:57 -04:00
{
2014-10-24 15:46:54 -04:00
SlotNameComboBox - > SetToolTipText ( FText : : FromString ( * NewSelection ) ) ;
}
if ( Skeleton - > ContainsSlotName ( SlotNameComboSelectedName ) )
{
// trigger transaction
2014-05-16 11:52:57 -04:00
//const FScopedTransaction Transaction(LOCTEXT("ChangeSlotNodeName", "Change Collision Profile"));
// set profile set up
2014-10-24 15:46:54 -04:00
ensure ( SlotNodeNamePropertyHandle - > SetValue ( SlotNameComboSelectedName . ToString ( ) ) = = FPropertyAccess : : Result : : Success ) ;
2014-05-16 11:52:57 -04:00
}
}
}
}
2014-10-24 15:46:54 -04:00
void FAnimGraphNodeSlotDetails : : OnSlotListOpening ( )
2014-05-16 11:52:57 -04:00
{
2014-10-24 15:46:54 -04:00
// Refresh Slot Names, in case we used the Anim Slot Manager to make changes.
RefreshComboLists ( true ) ;
2014-05-16 11:52:57 -04:00
}
2014-10-24 15:46:54 -04:00
FReply FAnimGraphNodeSlotDetails : : OnOpenAnimSlotManager ( )
2014-05-16 11:52:57 -04:00
{
if ( PersonaEditor . IsValid ( ) )
{
PersonaEditor . Pin ( ) - > GetTabManager ( ) - > InvokeTab ( FPersonaTabs : : SkeletonSlotNamesID ) ;
}
return FReply : : Handled ( ) ;
}
# undef LOCTEXT_NAMESPACE