2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-03-14 14:13:41 -04:00
# include "AnimGraphPrivatePCH.h"
2014-04-24 14:34:01 -04:00
# include "AnimGraphNode_RotationOffsetBlendSpace.h"
2014-03-14 14:13:41 -04:00
# include "GraphEditorActions.h"
# include "CompilerResultsLog.h"
2014-08-21 18:50:33 -04:00
# include "BlueprintNodeSpawner.h"
2014-08-23 20:16:29 -04:00
# include "BlueprintActionDatabaseRegistrar.h"
2014-03-14 14:13:41 -04:00
/////////////////////////////////////////////////////
// UAnimGraphNode_RotationOffsetBlendSpace
2014-04-23 18:30:37 -04:00
# define LOCTEXT_NAMESPACE "A3Nodes"
2014-10-14 10:29:11 -04:00
UAnimGraphNode_RotationOffsetBlendSpace : : UAnimGraphNode_RotationOffsetBlendSpace ( const FObjectInitializer & ObjectInitializer )
: Super ( ObjectInitializer )
2014-03-14 14:13:41 -04:00
{
}
2014-09-03 18:14:09 -04:00
FText UAnimGraphNode_RotationOffsetBlendSpace : : GetTooltipText ( ) const
2014-03-14 14:13:41 -04:00
{
2014-09-03 18:17:44 -04:00
// FText::Format() is slow, so we utilize the cached list title
return GetNodeTitle ( ENodeTitleType : : ListView ) ;
2014-03-14 14:13:41 -04:00
}
2014-04-23 18:30:37 -04:00
FText UAnimGraphNode_RotationOffsetBlendSpace : : GetNodeTitle ( ENodeTitleType : : Type TitleType ) const
2014-03-14 14:13:41 -04:00
{
2014-09-03 18:17:44 -04:00
if ( Node . BlendSpace = = nullptr )
2014-04-23 18:30:37 -04:00
{
2014-09-16 15:01:38 -04:00
if ( TitleType = = ENodeTitleType : : ListView | | TitleType = = ENodeTitleType : : MenuTitle )
2014-09-03 18:17:44 -04:00
{
return LOCTEXT ( " RotationOffsetBlend_NONE_ListTitle " , " AimOffset '(None) ' " ) ;
}
else
{
return LOCTEXT ( " RotationOffsetBlend_NONE_Title " , " (None) \ nAimOffset " ) ;
}
2014-04-23 18:30:37 -04:00
}
2014-09-24 14:15:13 -04:00
// @TODO: the bone can be altered in the property editor, so we have to
// choose to mark this dirty when that happens for this to properly work
2015-04-02 11:16:23 -04:00
else //if (!CachedNodeTitles.IsTitleCached(TitleType, this))
2014-04-23 18:30:37 -04:00
{
2014-09-03 18:17:44 -04:00
const FText BlendSpaceName = FText : : FromString ( Node . BlendSpace - > GetName ( ) ) ;
FFormatNamedArguments Args ;
Args . Add ( TEXT ( " BlendSpaceName " ) , BlendSpaceName ) ;
// FText::Format() is slow, so we cache this to save on performance
2014-09-16 15:01:38 -04:00
if ( TitleType = = ENodeTitleType : : ListView | | TitleType = = ENodeTitleType : : MenuTitle )
2014-09-03 18:17:44 -04:00
{
2015-04-02 11:16:23 -04:00
CachedNodeTitles . SetCachedTitle ( TitleType , FText : : Format ( LOCTEXT ( " AimOffsetListTitle " , " AimOffset '{BlendSpaceName}' " ) , Args ) , this ) ;
2014-09-03 18:17:44 -04:00
}
else
{
2015-04-02 11:16:23 -04:00
CachedNodeTitles . SetCachedTitle ( TitleType , FText : : Format ( LOCTEXT ( " AimOffsetFullTitle " , " {BlendSpaceName} \n AimOffset " ) , Args ) , this ) ;
2014-09-03 18:17:44 -04:00
}
2014-04-23 18:30:37 -04:00
}
2014-09-03 18:17:44 -04:00
return CachedNodeTitles [ TitleType ] ;
2014-04-23 18:30:37 -04:00
}
2014-08-23 20:16:29 -04:00
void UAnimGraphNode_RotationOffsetBlendSpace : : GetMenuActions ( FBlueprintActionDatabaseRegistrar & ActionRegistrar ) const
2014-08-21 18:50:33 -04:00
{
auto PostSpawnSetupLambda = [ ] ( UEdGraphNode * NewNode , bool /*bIsTemplateNode*/ , TWeakObjectPtr < UBlendSpaceBase > BlendSpace )
{
UAnimGraphNode_RotationOffsetBlendSpace * BlendSpaceNode = CastChecked < UAnimGraphNode_RotationOffsetBlendSpace > ( NewNode ) ;
BlendSpaceNode - > Node . BlendSpace = BlendSpace . Get ( ) ;
} ;
for ( TObjectIterator < UBlendSpaceBase > BlendSpaceIt ; BlendSpaceIt ; + + BlendSpaceIt )
{
UBlendSpaceBase * BlendSpace = * BlendSpaceIt ;
2014-09-10 17:09:26 -04:00
// to keep from needlessly instantiating a UBlueprintNodeSpawner, first
// check to make sure that the registrar is looking for actions of this type
// (could be regenerating actions for a specific asset, and therefore the
// registrar would only accept actions corresponding to that asset)
if ( ! ActionRegistrar . IsOpenForRegistration ( BlendSpace ) )
{
continue ;
}
2014-08-21 18:50:33 -04:00
bool const bIsAimOffset = BlendSpace - > IsA ( UAimOffsetBlendSpace : : StaticClass ( ) ) | |
BlendSpace - > IsA ( UAimOffsetBlendSpace1D : : StaticClass ( ) ) ;
if ( bIsAimOffset )
{
UBlueprintNodeSpawner * NodeSpawner = UBlueprintNodeSpawner : : Create ( GetClass ( ) ) ;
check ( NodeSpawner ! = nullptr ) ;
2014-09-10 17:09:26 -04:00
ActionRegistrar . AddBlueprintAction ( BlendSpace , NodeSpawner ) ;
2014-08-21 18:50:33 -04:00
TWeakObjectPtr < UBlendSpaceBase > BlendSpacePtr = BlendSpace ;
NodeSpawner - > CustomizeNodeDelegate = UBlueprintNodeSpawner : : FCustomizeNodeDelegate : : CreateStatic ( PostSpawnSetupLambda , BlendSpacePtr ) ;
}
}
}
2014-09-17 17:07:37 -04:00
FBlueprintNodeSignature UAnimGraphNode_RotationOffsetBlendSpace : : GetSignature ( ) const
{
FBlueprintNodeSignature NodeSignature = Super : : GetSignature ( ) ;
NodeSignature . AddSubObject ( Node . BlendSpace ) ;
return NodeSignature ;
}
2014-03-14 14:13:41 -04:00
void UAnimGraphNode_RotationOffsetBlendSpace : : ValidateAnimNodeDuringCompilation ( class USkeleton * ForSkeleton , class FCompilerResultsLog & MessageLog )
{
if ( Node . BlendSpace = = NULL )
{
MessageLog . Error ( TEXT ( " @@ references an unknown blend space " ) , this ) ;
}
else if ( Cast < UAimOffsetBlendSpace > ( Node . BlendSpace ) = = NULL & &
Cast < UAimOffsetBlendSpace1D > ( Node . BlendSpace ) = = NULL )
{
MessageLog . Error ( TEXT ( " @@ references an invalid blend space (one that is not an aim offset) " ) , this ) ;
}
else
{
2014-10-01 14:45:23 -04:00
USkeleton * BlendSpaceSkeleton = Node . BlendSpace - > GetSkeleton ( ) ;
2014-03-14 14:13:41 -04:00
if ( BlendSpaceSkeleton & & // if blend space doesn't have skeleton, it might be due to blend space not loaded yet, @todo: wait with anim blueprint compilation until all assets are loaded?
! BlendSpaceSkeleton - > IsCompatible ( ForSkeleton ) )
{
MessageLog . Error ( TEXT ( " @@ references blendspace that uses different skeleton @@ " ) , this , BlendSpaceSkeleton ) ;
}
}
}
void UAnimGraphNode_RotationOffsetBlendSpace : : GetContextMenuActions ( const FGraphNodeContextMenuBuilder & Context ) const
{
if ( ! Context . bIsDebugging )
{
// add an option to convert to single frame
Context . MenuBuilder - > BeginSection ( " AnimGraphNodeBlendSpacePlayer " , NSLOCTEXT ( " A3Nodes " , " BlendSpaceHeading " , " Blend Space " ) ) ;
{
Context . MenuBuilder - > AddMenuEntry ( FGraphEditorCommands : : Get ( ) . OpenRelatedAsset ) ;
}
Context . MenuBuilder - > EndSection ( ) ;
}
2014-04-23 18:30:37 -04:00
}
2015-03-20 18:05:34 -04:00
void UAnimGraphNode_RotationOffsetBlendSpace : : GetAllAnimationSequencesReferred ( TArray < UAnimationAsset * > & ComplexAnims , TArray < UAnimSequence * > & AnimationSequences ) const
{
if ( Node . BlendSpace )
{
HandleAnimReferenceCollection ( Node . BlendSpace , ComplexAnims , AnimationSequences ) ;
}
}
void UAnimGraphNode_RotationOffsetBlendSpace : : ReplaceReferredAnimations ( const TMap < UAnimationAsset * , UAnimationAsset * > & ComplexAnimsMap , const TMap < UAnimSequence * , UAnimSequence * > & AnimSequenceMap )
{
HandleAnimReferenceReplacement ( Node . BlendSpace , ComplexAnimsMap , AnimSequenceMap ) ;
}
2014-04-23 18:30:37 -04:00
# undef LOCTEXT_NAMESPACE