2014-03-14 14:13:41 -04:00
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
# include "BlueprintGraphPrivatePCH.h"
2014-05-29 16:42:22 -04:00
# include "K2Node_InputActionEvent.h"
2014-03-14 14:13:41 -04:00
# include "CompilerResultsLog.h"
# include "KismetCompiler.h"
2014-07-14 13:19:37 -04:00
# include "BlueprintNodeSpawner.h"
# include "EditorCategoryUtils.h"
# define LOCTEXT_NAMESPACE "K2Node_InputAction"
2014-03-14 14:13:41 -04:00
UK2Node_InputAction : : UK2Node_InputAction ( const class FPostConstructInitializeProperties & PCIP )
: Super ( PCIP )
{
bConsumeInput = true ;
bOverrideParentBinding = true ;
}
void UK2Node_InputAction : : PostLoad ( )
{
Super : : PostLoad ( ) ;
if ( GetLinkerUE4Version ( ) < VER_UE4_BLUEPRINT_INPUT_BINDING_OVERRIDES )
{
// Don't change existing behaviors
bOverrideParentBinding = false ;
}
}
void UK2Node_InputAction : : AllocateDefaultPins ( )
{
const UEdGraphSchema_K2 * K2Schema = GetDefault < UEdGraphSchema_K2 > ( ) ;
CreatePin ( EGPD_Output , K2Schema - > PC_Exec , TEXT ( " " ) , NULL , false , false , TEXT ( " Pressed " ) ) ;
CreatePin ( EGPD_Output , K2Schema - > PC_Exec , TEXT ( " " ) , NULL , false , false , TEXT ( " Released " ) ) ;
Super : : AllocateDefaultPins ( ) ;
}
FLinearColor UK2Node_InputAction : : GetNodeTitleColor ( ) const
{
2014-05-20 19:00:53 -04:00
return GetDefault < UGraphEditorSettings > ( ) - > EventNodeTitleColor ;
2014-03-14 14:13:41 -04:00
}
2014-04-23 18:30:37 -04:00
FText UK2Node_InputAction : : GetNodeTitle ( ENodeTitleType : : Type TitleType ) const
2014-03-14 14:13:41 -04:00
{
2014-04-23 18:30:37 -04:00
FFormatNamedArguments Args ;
Args . Add ( TEXT ( " InputActionName " ) , FText : : FromName ( InputActionName ) ) ;
2014-07-14 13:19:37 -04:00
FText LocFormat = NSLOCTEXT ( " K2Node " , " InputAction_Name " , " InputAction {InputActionName} " ) ;
if ( TitleType = = ENodeTitleType : : ListView )
{
LocFormat = NSLOCTEXT ( " K2Node " , " InputAction_ListTitle " , " {InputActionName} " ) ;
}
return FText : : Format ( LocFormat , Args ) ;
2014-04-23 18:30:37 -04:00
}
2014-03-14 14:13:41 -04:00
FString UK2Node_InputAction : : GetTooltip ( ) const
{
return FString : : Printf ( * NSLOCTEXT ( " K2Node " , " InputAction_Tooltip " , " Event for when the keys bound to input action %s are pressed or released. " ) . ToString ( ) , * InputActionName . ToString ( ) ) ;
}
UEdGraphPin * UK2Node_InputAction : : GetPressedPin ( ) const
{
return FindPin ( TEXT ( " Pressed " ) ) ;
}
UEdGraphPin * UK2Node_InputAction : : GetReleasedPin ( ) const
{
return FindPin ( TEXT ( " Released " ) ) ;
}
void UK2Node_InputAction : : ValidateNodeDuringCompilation ( class FCompilerResultsLog & MessageLog ) const
{
Super : : ValidateNodeDuringCompilation ( MessageLog ) ;
TArray < FName > ActionNames ;
GetDefault < UInputSettings > ( ) - > GetActionNames ( ActionNames ) ;
if ( ! ActionNames . Contains ( InputActionName ) )
{
MessageLog . Warning ( * FString : : Printf ( * NSLOCTEXT ( " KismetCompiler " , " MissingInputAction_Warning " , " InputAction Event references unknown Action '%s' for @@ " ) . ToString ( ) , * InputActionName . ToString ( ) ) , this ) ;
}
}
void UK2Node_InputAction : : CreateInputActionEvent ( FKismetCompilerContext & CompilerContext , UEdGraph * SourceGraph , UEdGraphPin * InputActionPin , const EInputEvent InputKeyEvent )
{
if ( InputActionPin - > LinkedTo . Num ( ) > 0 )
{
UK2Node_InputActionEvent * InputActionEvent = CompilerContext . SpawnIntermediateNode < UK2Node_InputActionEvent > ( this , SourceGraph ) ;
InputActionEvent - > CustomFunctionName = FName ( * FString : : Printf ( TEXT ( " InpActEvt_%s_%s " ) , * InputActionName . ToString ( ) , * InputActionEvent - > GetName ( ) ) ) ;
InputActionEvent - > InputActionName = InputActionName ;
InputActionEvent - > bConsumeInput = bConsumeInput ;
InputActionEvent - > bExecuteWhenPaused = bExecuteWhenPaused ;
InputActionEvent - > bOverrideParentBinding = bOverrideParentBinding ;
InputActionEvent - > InputKeyEvent = InputKeyEvent ;
InputActionEvent - > EventSignatureName = TEXT ( " InputActionHandlerDynamicSignature__DelegateSignature " ) ;
InputActionEvent - > EventSignatureClass = UInputComponent : : StaticClass ( ) ;
InputActionEvent - > bInternalEvent = true ;
InputActionEvent - > AllocateDefaultPins ( ) ;
// Move any exec links from the InputActionNode pin to the InputActionEvent node
UEdGraphPin * EventOutput = CompilerContext . GetSchema ( ) - > FindExecutionPin ( * InputActionEvent , EGPD_Output ) ;
if ( EventOutput ! = NULL )
{
2014-04-23 17:45:37 -04:00
CompilerContext . MovePinLinksToIntermediate ( * InputActionPin , * EventOutput ) ;
2014-03-14 14:13:41 -04:00
}
}
}
void UK2Node_InputAction : : ExpandNode ( FKismetCompilerContext & CompilerContext , UEdGraph * SourceGraph )
{
Super : : ExpandNode ( CompilerContext , SourceGraph ) ;
if ( CompilerContext . bIsFullCompile )
{
CreateInputActionEvent ( CompilerContext , SourceGraph , GetPressedPin ( ) , IE_Pressed ) ;
CreateInputActionEvent ( CompilerContext , SourceGraph , GetReleasedPin ( ) , IE_Released ) ;
}
2014-07-14 13:19:37 -04:00
}
void UK2Node_InputAction : : GetMenuActions ( TArray < UBlueprintNodeSpawner * > & ActionListOut ) const
{
TArray < FName > ActionNames ;
GetDefault < UInputSettings > ( ) - > GetActionNames ( ActionNames ) ;
for ( FName const InputActionName : ActionNames )
{
UBlueprintNodeSpawner * NodeSpawner = UBlueprintNodeSpawner : : Create ( GetClass ( ) ) ;
check ( NodeSpawner ! = nullptr ) ;
auto CustomizeInputNodeLambda = [ ] ( UEdGraphNode * NewNode , bool bIsTemplateNode , FName ActionName )
{
UK2Node_InputAction * InputNode = CastChecked < UK2Node_InputAction > ( NewNode ) ;
InputNode - > InputActionName = ActionName ;
} ;
NodeSpawner - > CustomizeNodeDelegate = UBlueprintNodeSpawner : : FCustomizeNodeDelegate : : CreateStatic ( CustomizeInputNodeLambda , InputActionName ) ;
ActionListOut . Add ( NodeSpawner ) ;
}
}
FText UK2Node_InputAction : : GetMenuCategory ( ) const
{
return FEditorCategoryUtils : : BuildCategoryString ( FCommonEditorCategory : : Input , LOCTEXT ( " ActionMenuCategory " , " Action Events " ) ) ;
}
# undef LOCTEXT_NAMESPACE