2014-03-14 14:13:41 -04:00
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
# include "BlueprintGraphPrivatePCH.h"
# include "CompilerResultsLog.h"
2014-07-14 13:19:37 -04:00
# include "BlueprintNodeSpawner.h"
# include "EditorCategoryUtils.h"
2014-08-11 03:23:38 -04:00
# include "Engine/InputAxisDelegateBinding.h"
2014-07-14 13:19:37 -04:00
# define LOCTEXT_NAMESPACE "K2Node_InputAxisEvent"
2014-03-14 14:13:41 -04:00
UK2Node_InputAxisEvent : : UK2Node_InputAxisEvent ( const class FPostConstructInitializeProperties & PCIP )
: Super ( PCIP )
{
bConsumeInput = true ;
bOverrideParentBinding = true ;
2014-04-23 18:26:22 -04:00
bInternalEvent = true ;
2014-03-14 14:13:41 -04:00
EventSignatureName = TEXT ( " InputAxisHandlerDynamicSignature__DelegateSignature " ) ;
EventSignatureClass = UInputComponent : : StaticClass ( ) ;
}
void UK2Node_InputAxisEvent : : PostLoad ( )
{
Super : : PostLoad ( ) ;
if ( GetLinkerUE4Version ( ) < VER_UE4_BLUEPRINT_INPUT_BINDING_OVERRIDES )
{
// Don't change existing behaviors
bOverrideParentBinding = false ;
}
}
void UK2Node_InputAxisEvent : : Initialize ( const FName AxisName )
{
InputAxisName = AxisName ;
CustomFunctionName = FName ( * FString : : Printf ( TEXT ( " InpAxisEvt_%s_%s " ) , * InputAxisName . ToString ( ) , * GetName ( ) ) ) ;
}
2014-04-23 18:30:37 -04:00
FText UK2Node_InputAxisEvent : : 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 ( " InputAxisName " ) , FText : : FromName ( InputAxisName ) ) ;
2014-07-14 13:19:37 -04:00
FText LocFormat = NSLOCTEXT ( " K2Node " , " InputAxis_Name " , " InputAxis {InputAxisName} " ) ;
if ( TitleType = = ENodeTitleType : : ListView )
{
LocFormat = NSLOCTEXT ( " K2Node " , " InputAxis_ListTitle " , " {InputAxisName} " ) ;
}
return FText : : Format ( LocFormat , Args ) ;
2014-04-23 18:30:37 -04:00
}
2014-03-14 14:13:41 -04:00
FString UK2Node_InputAxisEvent : : GetTooltip ( ) const
{
return FString : : Printf ( * NSLOCTEXT ( " K2Node " , " InputAxis_Tooltip " , " Event that provides the current value of the %s axis once per frame when input is enabled for the containing actor. " ) . ToString ( ) , * InputAxisName . ToString ( ) ) ;
}
void UK2Node_InputAxisEvent : : ValidateNodeDuringCompilation ( class FCompilerResultsLog & MessageLog ) const
{
Super : : ValidateNodeDuringCompilation ( MessageLog ) ;
TArray < FName > AxisNames ;
GetDefault < UInputSettings > ( ) - > GetAxisNames ( AxisNames ) ;
if ( ! AxisNames . Contains ( InputAxisName ) )
{
MessageLog . Warning ( * FString : : Printf ( * NSLOCTEXT ( " KismetCompiler " , " MissingInputAxisEvent_Warning " , " Input Axis Event references unknown Axis '%s' for @@ " ) . ToString ( ) , * InputAxisName . ToString ( ) ) , this ) ;
}
}
UClass * UK2Node_InputAxisEvent : : GetDynamicBindingClass ( ) const
{
return UInputAxisDelegateBinding : : StaticClass ( ) ;
}
void UK2Node_InputAxisEvent : : RegisterDynamicBinding ( UDynamicBlueprintBinding * BindingObject ) const
{
UInputAxisDelegateBinding * InputAxisBindingObject = CastChecked < UInputAxisDelegateBinding > ( BindingObject ) ;
FBlueprintInputAxisDelegateBinding Binding ;
Binding . InputAxisName = InputAxisName ;
Binding . bConsumeInput = bConsumeInput ;
Binding . bExecuteWhenPaused = bExecuteWhenPaused ;
Binding . bOverrideParentBinding = bOverrideParentBinding ;
Binding . FunctionNameToBind = CustomFunctionName ;
InputAxisBindingObject - > InputAxisDelegateBindings . Add ( Binding ) ;
2014-04-02 18:09:23 -04:00
}
2014-08-04 12:39:34 -04:00
bool UK2Node_InputAxisEvent : : IsCompatibleWithGraph ( const UEdGraph * TargetGraph ) const
2014-04-02 18:09:23 -04:00
{
// By default, to be safe, we don't allow events to be pasted, except under special circumstances (see below)
2014-08-04 12:39:34 -04:00
bool bIsCompatible = false ;
2014-04-02 18:09:23 -04:00
2014-08-04 12:39:34 -04:00
// Find the Blueprint that owns the target graph
UBlueprint * Blueprint = FBlueprintEditorUtils : : FindBlueprintForGraph ( TargetGraph ) ;
if ( Blueprint & & Blueprint - > SkeletonGeneratedClass )
2014-04-02 18:09:23 -04:00
{
2014-08-04 12:39:34 -04:00
bIsCompatible = Blueprint - > ParentClass - > IsChildOf ( AActor : : StaticClass ( ) ) ;
2014-04-02 18:09:23 -04:00
}
2014-08-04 12:39:34 -04:00
return bIsCompatible & & Super : : IsCompatibleWithGraph ( TargetGraph ) ;
2014-04-02 18:09:23 -04:00
}
2014-07-14 13:19:37 -04:00
void UK2Node_InputAxisEvent : : GetMenuActions ( TArray < UBlueprintNodeSpawner * > & ActionListOut ) const
{
TArray < FName > AxisNames ;
GetDefault < UInputSettings > ( ) - > GetAxisNames ( AxisNames ) ;
for ( FName const InputAxisName : AxisNames )
{
UBlueprintNodeSpawner * NodeSpawner = UBlueprintNodeSpawner : : Create ( GetClass ( ) ) ;
check ( NodeSpawner ! = nullptr ) ;
auto CustomizeInputNodeLambda = [ ] ( UEdGraphNode * NewNode , bool bIsTemplateNode , FName AxisName )
{
UK2Node_InputAxisEvent * InputNode = CastChecked < UK2Node_InputAxisEvent > ( NewNode ) ;
InputNode - > Initialize ( AxisName ) ;
} ;
NodeSpawner - > CustomizeNodeDelegate = UBlueprintNodeSpawner : : FCustomizeNodeDelegate : : CreateStatic ( CustomizeInputNodeLambda , InputAxisName ) ;
ActionListOut . Add ( NodeSpawner ) ;
}
}
FText UK2Node_InputAxisEvent : : GetMenuCategory ( ) const
{
return FEditorCategoryUtils : : BuildCategoryString ( FCommonEditorCategory : : Input , LOCTEXT ( " ActionMenuCategory " , " Axis Events " ) ) ;
}
# undef LOCTEXT_NAMESPACE