2014-03-14 14:13:41 -04:00
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
# include "BlueprintGraphPrivatePCH.h"
# include "KismetCompiler.h"
2014-07-14 16:30:29 -04:00
# include "BlueprintNodeSpawner.h"
2014-07-14 14:20:04 -04:00
# include "EditorCategoryUtils.h"
2014-08-23 20:16:29 -04:00
# include "BlueprintActionDatabaseRegistrar.h"
2014-03-14 14:13:41 -04:00
class FKCHandler_TemporaryVariable : public FNodeHandlingFunctor
{
public :
FKCHandler_TemporaryVariable ( FKismetCompilerContext & InCompilerContext )
: FNodeHandlingFunctor ( InCompilerContext )
{
}
2014-06-13 06:14:46 -04:00
virtual void RegisterNet ( FKismetFunctionContext & Context , UEdGraphPin * Net ) override
2014-03-14 14:13:41 -04:00
{
// This net is an anonymous temporary variable
2014-09-26 11:32:41 -04:00
FBPTerminal * Term = Context . CreateLocalTerminal ( Context . IsEventGraph ( ) ? ETerminalSpecification : : TS_ForcedShared : ETerminalSpecification : : TS_Unspecified ) ;
2014-03-14 14:13:41 -04:00
FString NetName = Context . NetNameMap - > MakeValidName ( Net ) ;
Term - > CopyFromPin ( Net , NetName ) ;
UK2Node_TemporaryVariable * TempVarNode = CastChecked < UK2Node_TemporaryVariable > ( Net - > GetOwningNode ( ) ) ;
Term - > bIsSavePersistent = TempVarNode - > bIsPersistent ;
Context . NetMap . Add ( Net , Term ) ;
}
} ;
UK2Node_TemporaryVariable : : UK2Node_TemporaryVariable ( const class FPostConstructInitializeProperties & PCIP )
: Super ( PCIP )
, bIsPersistent ( false )
{
}
void UK2Node_TemporaryVariable : : AllocateDefaultPins ( )
{
const UEdGraphSchema_K2 * K2Schema = GetDefault < UEdGraphSchema_K2 > ( ) ;
UEdGraphPin * VariablePin = CreatePin ( EGPD_Output , TEXT ( " " ) , TEXT ( " " ) , NULL , false , false , TEXT ( " Variable " ) ) ;
VariablePin - > PinType = VariableType ;
Super : : AllocateDefaultPins ( ) ;
}
2014-09-03 18:14:09 -04:00
FText UK2Node_TemporaryVariable : : GetTooltipText ( ) const
2014-03-14 14:13:41 -04:00
{
2014-09-03 18:17:44 -04:00
if ( CachedTooltip . IsOutOfDate ( ) )
{
FFormatNamedArguments Args ;
Args . Add ( TEXT ( " VariableType " ) , UEdGraphSchema_K2 : : TypeToText ( VariableType ) ) ;
// FText::Format() is slow, so we cache this to save on performance
CachedTooltip = FText : : Format ( NSLOCTEXT ( " K2Node " , " LocalTemporaryVariable " , " Local temporary {VariableType} variable " ) , Args ) ;
}
return CachedTooltip ;
2014-03-14 14:13:41 -04:00
}
2014-04-23 18:30:37 -04:00
FText UK2Node_TemporaryVariable : : GetNodeTitle ( ENodeTitleType : : Type TitleType ) const
2014-03-14 14:13:41 -04:00
{
2014-09-02 19:08:09 -04:00
if ( CachedNodeTitle . IsOutOfDate ( ) )
{
FFormatNamedArguments Args ;
Args . Add ( TEXT ( " VariableType " ) , UEdGraphSchema_K2 : : TypeToText ( VariableType ) ) ;
2014-04-23 18:30:37 -04:00
2014-09-02 19:08:09 -04:00
FText TitleFormat = ! bIsPersistent ? NSLOCTEXT ( " K2Node " , " LocalVariable " , " Local {VariableType} " ) : NSLOCTEXT ( " K2Node " , " PersistentLocalVariable " , " Persistent Local {VariableType} " ) ;
// FText::Format() is slow, so we cache this to save on performance
CachedNodeTitle = FText : : Format ( TitleFormat , Args ) ;
}
return CachedNodeTitle ;
2014-04-23 18:30:37 -04:00
}
2014-03-14 14:13:41 -04:00
bool UK2Node_TemporaryVariable : : IsNodePure ( ) const
{
return true ;
}
FString UK2Node_TemporaryVariable : : GetDescriptiveCompiledName ( ) const
{
FString Result = NSLOCTEXT ( " K2Node " , " TempPinCategory " , " Temp_ " ) . ToString ( ) + VariableType . PinCategory ;
if ( ! NodeComment . IsEmpty ( ) )
{
Result + = TEXT ( " _ " ) ;
Result + = NodeComment ;
}
// If this node is persistent, we need to add the NodeGuid, which should be propagated from the macro that created this, in order to ensure persistence
if ( bIsPersistent )
{
Result + = TEXT ( " _ " ) ;
Result + = NodeGuid . ToString ( ) ;
}
return Result ;
}
2014-08-04 12:39:34 -04:00
bool UK2Node_TemporaryVariable : : IsCompatibleWithGraph ( UEdGraph const * TargetGraph ) const
2014-07-14 14:20:04 -04:00
{
2014-08-04 12:39:34 -04:00
bool bIsCompatible = Super : : IsCompatibleWithGraph ( TargetGraph ) ;
if ( bIsCompatible )
2014-07-14 14:20:04 -04:00
{
2014-09-15 12:31:29 -04:00
bIsCompatible = false ;
2014-07-14 14:20:04 -04:00
2014-09-15 12:31:29 -04:00
EGraphType const GraphType = TargetGraph - > GetSchema ( ) - > GetGraphType ( TargetGraph ) ;
if ( GraphType = = GT_Macro )
2014-07-14 14:20:04 -04:00
{
2014-08-04 12:39:34 -04:00
bIsCompatible = ! bIsPersistent ;
2014-07-14 14:20:04 -04:00
}
}
2014-08-04 12:39:34 -04:00
return bIsCompatible ;
2014-07-14 14:20:04 -04:00
}
2014-03-14 14:13:41 -04:00
// get variable pin
UEdGraphPin * UK2Node_TemporaryVariable : : GetVariablePin ( )
{
return FindPin ( TEXT ( " Variable " ) ) ;
}
FNodeHandlingFunctor * UK2Node_TemporaryVariable : : CreateNodeHandler ( FKismetCompilerContext & CompilerContext ) const
{
return new FKCHandler_TemporaryVariable ( CompilerContext ) ;
}
2014-07-14 14:20:04 -04:00
2014-08-23 20:16:29 -04:00
void UK2Node_TemporaryVariable : : GetMenuActions ( FBlueprintActionDatabaseRegistrar & ActionRegistrar ) const
2014-07-14 14:20:04 -04:00
{
2014-09-10 17:09:26 -04:00
// actions get registered under specific object-keys; the idea is that
// actions might have to be updated (or deleted) if their object-key is
// mutated (or removed)... here we use the node's class (so if the node
// type disappears, then the action should go with it)
UClass * ActionKey = GetClass ( ) ;
// 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 ( ActionKey ) )
{
return ;
}
2014-09-29 07:29:14 -04:00
auto MakeTempVarNodeSpawner = [ ] ( FEdGraphPinType const & VarType , bool bIsPersistent )
2014-07-14 14:20:04 -04:00
{
UBlueprintNodeSpawner * NodeSpawner = UBlueprintNodeSpawner : : Create ( UK2Node_TemporaryVariable : : StaticClass ( ) ) ;
check ( NodeSpawner ! = nullptr ) ;
auto PostSpawnLambda = [ ] ( UEdGraphNode * NewNode , bool bIsTemplateNode , FEdGraphPinType VarType , bool bIsPersistent )
{
UK2Node_TemporaryVariable * TempVarNode = CastChecked < UK2Node_TemporaryVariable > ( NewNode ) ;
TempVarNode - > VariableType = VarType ;
TempVarNode - > bIsPersistent = bIsPersistent ;
} ;
NodeSpawner - > CustomizeNodeDelegate = UBlueprintNodeSpawner : : FCustomizeNodeDelegate : : CreateStatic ( PostSpawnLambda , VarType , bIsPersistent ) ;
return NodeSpawner ;
} ;
UEdGraphSchema_K2 const * K2Schema = GetDefault < UEdGraphSchema_K2 > ( ) ;
2014-09-10 17:09:26 -04:00
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Int , TEXT ( " " ) , nullptr , /*bIsArray =*/ false , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Int , TEXT ( " " ) , nullptr , /*bIsArray =*/ true , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Float , TEXT ( " " ) , nullptr , /*bIsArray =*/ false , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Float , TEXT ( " " ) , nullptr , /*bIsArray =*/ true , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Boolean , TEXT ( " " ) , nullptr , /*bIsArray =*/ false , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Boolean , TEXT ( " " ) , nullptr , /*bIsArray =*/ true , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_String , TEXT ( " " ) , nullptr , /*bIsArray =*/ false , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_String , TEXT ( " " ) , nullptr , /*bIsArray =*/ true , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Text , TEXT ( " " ) , nullptr , /*bIsArray =*/ false , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Text , TEXT ( " " ) , nullptr , /*bIsArray =*/ true , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
2014-07-14 14:20:04 -04:00
UScriptStruct * VectorStruct = FindObjectChecked < UScriptStruct > ( UObject : : StaticClass ( ) , TEXT ( " Vector " ) ) ;
2014-09-10 17:09:26 -04:00
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Struct , TEXT ( " Vector " ) , VectorStruct , /*bIsArray =*/ false , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Struct , TEXT ( " Vector " ) , VectorStruct , /*bIsArray =*/ true , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
2014-07-14 14:20:04 -04:00
UScriptStruct * RotatorStruct = FindObjectChecked < UScriptStruct > ( UObject : : StaticClass ( ) , TEXT ( " Rotator " ) ) ;
2014-09-10 17:09:26 -04:00
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Struct , TEXT ( " Rotator " ) , RotatorStruct , /*bIsArray =*/ false , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Struct , TEXT ( " Rotator " ) , RotatorStruct , /*bIsArray =*/ true , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
2014-07-14 14:20:04 -04:00
UScriptStruct * TransformStruct = FindObjectChecked < UScriptStruct > ( UObject : : StaticClass ( ) , TEXT ( " Transform " ) ) ;
2014-09-10 17:09:26 -04:00
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Struct , TEXT ( " Transform " ) , TransformStruct , /*bIsArray =*/ false , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Struct , TEXT ( " Transform " ) , TransformStruct , /*bIsArray =*/ true , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
2014-07-14 14:20:04 -04:00
UScriptStruct * BlendSampleStruct = FindObjectChecked < UScriptStruct > ( ANY_PACKAGE , TEXT ( " BlendSampleData " ) ) ;
2014-09-10 17:09:26 -04:00
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Struct , TEXT ( " BlendSampleData " ) , BlendSampleStruct , /*bIsArray =*/ false , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Struct , TEXT ( " BlendSampleData " ) , BlendSampleStruct , /*bIsArray =*/ true , /*bIsReference =*/ false ) , /*bIsPersistent =*/ false ) ) ;
2014-07-14 14:20:04 -04:00
// add persistent bool and int types (for macro graphs)
2014-09-10 17:09:26 -04:00
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Int , TEXT ( " " ) , nullptr , /*bIsArray =*/ false , /*bIsReference =*/ false ) , /*bIsPersistent =*/ true ) ) ;
ActionRegistrar . AddBlueprintAction ( ActionKey , MakeTempVarNodeSpawner ( FEdGraphPinType ( K2Schema - > PC_Boolean , TEXT ( " " ) , nullptr , /*bIsArray =*/ false , /*bIsReference =*/ false ) , /*bIsPersistent =*/ true ) ) ;
2014-07-14 14:20:04 -04:00
}
FText UK2Node_TemporaryVariable : : GetMenuCategory ( ) const
{
return FEditorCategoryUtils : : GetCommonCategory ( FCommonEditorCategory : : Macro ) ;
}
2014-09-17 17:07:37 -04:00
FBlueprintNodeSignature UK2Node_TemporaryVariable : : GetSignature ( ) const
{
FBlueprintNodeSignature NodeSignature = Super : : GetSignature ( ) ;
FString TypeString ;
if ( bIsPersistent )
{
TypeString = TEXT ( " Persistent " ) ;
}
TypeString + = UEdGraphSchema_K2 : : TypeToText ( VariableType ) . ToString ( ) ;
static const FName VarTypeSignatureKey ( TEXT ( " VarType " ) ) ;
NodeSignature . AddNamedValue ( VarTypeSignatureKey , TypeString ) ;
return NodeSignature ;
}