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-08-23 20:16:29 -04:00
# include "BlueprintActionDatabaseRegistrar.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-09-16 15:01:38 -04:00
if ( TitleType = = ENodeTitleType : : MenuTitle )
2014-07-14 13:19:37 -04:00
{
2014-09-02 19:08:09 -04:00
return FText : : FromName ( InputAxisName ) ;
}
else if ( CachedNodeTitle . IsOutOfDate ( ) )
{
FFormatNamedArguments Args ;
Args . Add ( TEXT ( " InputAxisName " ) , FText : : FromName ( InputAxisName ) ) ;
FText LocFormat = NSLOCTEXT ( " K2Node " , " InputAxis_Name " , " InputAxis {InputAxisName} " ) ;
// FText::Format() is slow, so we cache this to save on performance
CachedNodeTitle = FText : : Format ( LocFormat , Args ) ;
2014-07-14 13:19:37 -04:00
}
2014-09-02 19:08:09 -04:00
return CachedNodeTitle ;
2014-04-23 18:30:37 -04:00
}
2014-09-03 18:14:09 -04:00
FText UK2Node_InputAxisEvent : : GetTooltipText ( ) const
2014-03-14 14:13:41 -04:00
{
2014-09-03 18:17:44 -04:00
if ( CachedTooltip . IsOutOfDate ( ) )
{
// FText::Format() is slow, so we cache this to save on performance
CachedTooltip = FText : : Format ( NSLOCTEXT ( " K2Node " , " InputAxis_Tooltip " , " Event that provides the current value of the {0} axis once per frame when input is enabled for the containing actor. " ) , FText : : FromName ( InputAxisName ) ) ;
}
return CachedTooltip ;
2014-03-14 14:13:41 -04:00
}
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
2014-08-23 20:16:29 -04:00
void UK2Node_InputAxisEvent : : GetMenuActions ( FBlueprintActionDatabaseRegistrar & ActionRegistrar ) const
2014-07-14 13:19:37 -04:00
{
TArray < FName > AxisNames ;
GetDefault < UInputSettings > ( ) - > GetAxisNames ( AxisNames ) ;
2014-09-10 17:09:26 -04:00
auto CustomizeInputNodeLambda = [ ] ( UEdGraphNode * NewNode , bool bIsTemplateNode , FName AxisName )
{
UK2Node_InputAxisEvent * InputNode = CastChecked < UK2Node_InputAxisEvent > ( NewNode ) ;
InputNode - > Initialize ( AxisName ) ;
} ;
2014-09-17 17:07:37 -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 ( ) ;
2014-07-14 13:19:37 -04:00
for ( FName const InputAxisName : AxisNames )
{
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 ( ActionKey ) )
{
continue ;
}
2014-07-14 13:19:37 -04:00
UBlueprintNodeSpawner * NodeSpawner = UBlueprintNodeSpawner : : Create ( GetClass ( ) ) ;
check ( NodeSpawner ! = nullptr ) ;
NodeSpawner - > CustomizeNodeDelegate = UBlueprintNodeSpawner : : FCustomizeNodeDelegate : : CreateStatic ( CustomizeInputNodeLambda , InputAxisName ) ;
2014-09-10 17:09:26 -04:00
ActionRegistrar . AddBlueprintAction ( ActionKey , NodeSpawner ) ;
2014-07-14 13:19:37 -04:00
}
}
FText UK2Node_InputAxisEvent : : GetMenuCategory ( ) const
{
2014-09-04 13:00:27 -04:00
static FNodeTextCache CachedCategory ;
if ( CachedCategory . IsOutOfDate ( ) )
{
// FText::Format() is slow, so we cache this to save on performance
CachedCategory = FEditorCategoryUtils : : BuildCategoryString ( FCommonEditorCategory : : Input , LOCTEXT ( " ActionMenuCategory " , " Axis Events " ) ) ;
}
return CachedCategory ;
2014-07-14 13:19:37 -04:00
}
2014-09-17 17:07:37 -04:00
FBlueprintNodeSignature UK2Node_InputAxisEvent : : GetSignature ( ) const
{
FBlueprintNodeSignature NodeSignature = Super : : GetSignature ( ) ;
NodeSignature . AddKeyValue ( InputAxisName . ToString ( ) ) ;
return NodeSignature ;
}
2014-07-14 13:19:37 -04:00
# undef LOCTEXT_NAMESPACE