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 "BlueprintGraphPrivatePCH.h"
2014-05-29 16:42:22 -04:00
# include "K2Node_InputAxisKeyEvent.h"
2014-03-14 14:13:41 -04:00
# 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/InputAxisKeyDelegateBinding.h"
2014-08-21 18:50:33 -04:00
# include "BlueprintEditorUtils.h"
# include "EdGraphSchema_K2.h"
2014-08-23 20:16:29 -04:00
# include "BlueprintActionDatabaseRegistrar.h"
2014-07-14 13:19:37 -04:00
# define LOCTEXT_NAMESPACE "UK2Node_InputAxisKeyEvent"
2014-03-14 14:13:41 -04:00
2014-10-14 10:29:11 -04:00
UK2Node_InputAxisKeyEvent : : UK2Node_InputAxisKeyEvent ( const FObjectInitializer & ObjectInitializer )
: Super ( ObjectInitializer )
2014-03-14 14:13:41 -04:00
{
bConsumeInput = true ;
bOverrideParentBinding = true ;
2014-04-23 18:26:22 -04:00
bInternalEvent = true ;
2014-03-14 14:13:41 -04:00
2015-02-06 09:41:28 -05:00
EventReference . SetExternalDelegateMember ( FName ( TEXT ( " InputAxisHandlerDynamicSignature__DelegateSignature " ) ) ) ;
2014-03-14 14:13:41 -04:00
}
2015-02-26 13:38:19 -05:00
void UK2Node_InputAxisKeyEvent : : Serialize ( FArchive & Ar )
{
Super : : Serialize ( Ar ) ;
if ( Ar . IsLoading ( ) )
{
if ( Ar . UE4Ver ( ) < VER_UE4_K2NODE_EVENT_MEMBER_REFERENCE & & EventSignatureName_DEPRECATED . IsNone ( ) & & EventSignatureClass_DEPRECATED = = nullptr )
{
EventReference . SetExternalDelegateMember ( FName ( TEXT ( " InputAxisHandlerDynamicSignature__DelegateSignature " ) ) ) ;
}
}
}
2014-03-14 14:13:41 -04:00
void UK2Node_InputAxisKeyEvent : : Initialize ( const FKey InAxisKey )
{
AxisKey = InAxisKey ;
CustomFunctionName = FName ( * FString : : Printf ( TEXT ( " InpAxisKeyEvt_%s_%s " ) , * AxisKey . ToString ( ) , * GetName ( ) ) ) ;
}
2014-04-23 18:30:37 -04:00
FText UK2Node_InputAxisKeyEvent : : GetNodeTitle ( ENodeTitleType : : Type TitleType ) const
2014-03-14 14:13:41 -04:00
{
2014-04-23 18:30:37 -04:00
return AxisKey . GetDisplayName ( ) ;
}
2014-09-03 18:14:09 -04:00
FText UK2Node_InputAxisKeyEvent : : GetTooltipText ( ) const
2014-03-14 14:13:41 -04:00
{
2015-04-02 11:16:23 -04:00
if ( CachedTooltip . IsOutOfDate ( this ) )
2014-09-03 18:17:44 -04:00
{
// FText::Format() is slow, so we cache this to save on performance
2015-04-02 11:16:23 -04:00
CachedTooltip . SetCachedText ( FText : : Format ( NSLOCTEXT ( " K2Node " , " InputAxisKey_Tooltip " , " Event that provides the current value of the {0} axis once per frame when input is enabled for the containing actor. " ) , AxisKey . GetDisplayName ( ) ) , this ) ;
2014-09-03 18:17:44 -04:00
}
return CachedTooltip ;
2014-03-14 14:13:41 -04:00
}
void UK2Node_InputAxisKeyEvent : : ValidateNodeDuringCompilation ( class FCompilerResultsLog & MessageLog ) const
{
Super : : ValidateNodeDuringCompilation ( MessageLog ) ;
if ( ! AxisKey . IsValid ( ) )
{
2014-04-23 18:28:49 -04:00
MessageLog . Warning ( * FText : : Format ( NSLOCTEXT ( " KismetCompiler " , " Invalid_InputAxisKey_Warning " , " InputAxisKey Event specifies invalid FKey'{0}' for @@ " ) , FText : : FromString ( AxisKey . ToString ( ) ) ) . ToString ( ) , this ) ;
2014-03-14 14:13:41 -04:00
}
2014-04-28 11:24:25 -04:00
else if ( ! AxisKey . IsFloatAxis ( ) )
2014-03-14 14:13:41 -04:00
{
2014-04-28 11:24:25 -04:00
MessageLog . Warning ( * FText : : Format ( NSLOCTEXT ( " KismetCompiler " , " NotAxis_InputAxisKey_Warning " , " InputAxisKey Event specifies FKey'{0}' which is not a float axis for @@ " ) , FText : : FromString ( AxisKey . ToString ( ) ) ) . ToString ( ) , this ) ;
2014-03-14 14:13:41 -04:00
}
else if ( ! AxisKey . IsBindableInBlueprints ( ) )
{
2014-04-23 18:28:49 -04:00
MessageLog . Warning ( * FText : : Format ( NSLOCTEXT ( " KismetCompiler " , " NotBindable_InputAxisKey_Warning " , " InputAxisKey Event specifies FKey'{0}' that is not blueprint bindable for @@ " ) , FText : : FromString ( AxisKey . ToString ( ) ) ) . ToString ( ) , this ) ;
2014-03-14 14:13:41 -04:00
}
}
UClass * UK2Node_InputAxisKeyEvent : : GetDynamicBindingClass ( ) const
{
return UInputAxisKeyDelegateBinding : : StaticClass ( ) ;
}
FName UK2Node_InputAxisKeyEvent : : GetPaletteIcon ( FLinearColor & OutColor ) const
{
if ( AxisKey . IsMouseButton ( ) )
{
return TEXT ( " GraphEditor.MouseEvent_16x " ) ;
}
else if ( AxisKey . IsGamepadKey ( ) )
{
return TEXT ( " GraphEditor.PadEvent_16x " ) ;
}
else
{
return TEXT ( " GraphEditor.KeyEvent_16x " ) ;
}
}
void UK2Node_InputAxisKeyEvent : : RegisterDynamicBinding ( UDynamicBlueprintBinding * BindingObject ) const
{
UInputAxisKeyDelegateBinding * InputAxisKeyBindingObject = CastChecked < UInputAxisKeyDelegateBinding > ( BindingObject ) ;
FBlueprintInputAxisKeyDelegateBinding Binding ;
Binding . AxisKey = AxisKey ;
Binding . bConsumeInput = bConsumeInput ;
Binding . bExecuteWhenPaused = bExecuteWhenPaused ;
Binding . bOverrideParentBinding = bOverrideParentBinding ;
Binding . FunctionNameToBind = CustomFunctionName ;
InputAxisKeyBindingObject - > InputAxisKeyDelegateBindings . Add ( Binding ) ;
2014-04-02 18:09:23 -04:00
}
2014-08-04 12:39:34 -04:00
bool UK2Node_InputAxisKeyEvent : : 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 ;
// Find the Blueprint that owns the target graph
UBlueprint * Blueprint = FBlueprintEditorUtils : : FindBlueprintForGraph ( TargetGraph ) ;
2014-08-21 18:50:33 -04:00
if ( Blueprint ! = nullptr )
2014-04-02 18:09:23 -04:00
{
2014-08-21 18:50:33 -04:00
bIsCompatible = FBlueprintEditorUtils : : IsActorBased ( Blueprint ) & & Blueprint - > SupportsInputEvents ( ) ;
2014-04-02 18:09:23 -04:00
}
2014-08-21 18:50:33 -04:00
UEdGraphSchema_K2 const * K2Schema = Cast < UEdGraphSchema_K2 > ( TargetGraph - > GetSchema ( ) ) ;
bool const bIsConstructionScript = ( K2Schema ! = nullptr ) ? K2Schema - > IsConstructionScript ( TargetGraph ) : false ;
bIsCompatible & = ! bIsConstructionScript ;
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_InputAxisKeyEvent : : GetMenuActions ( FBlueprintActionDatabaseRegistrar & ActionRegistrar ) const
2014-07-14 13:19:37 -04:00
{
TArray < FKey > AllKeys ;
EKeys : : GetAllKeys ( AllKeys ) ;
2014-09-10 17:09:26 -04:00
auto CustomizeInputNodeLambda = [ ] ( UEdGraphNode * NewNode , bool bIsTemplateNode , FKey Key )
{
UK2Node_InputAxisKeyEvent * InputNode = CastChecked < UK2Node_InputAxisKeyEvent > ( NewNode ) ;
InputNode - > Initialize ( Key ) ;
} ;
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 ( FKey const Key : AllKeys )
{
if ( ! Key . IsBindableInBlueprints ( ) | | ! Key . IsFloatAxis ( ) )
{
continue ;
}
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 , Key ) ;
2014-09-10 17:09:26 -04:00
ActionRegistrar . AddBlueprintAction ( ActionKey , NodeSpawner ) ;
2014-07-14 13:19:37 -04:00
}
}
FText UK2Node_InputAxisKeyEvent : : GetMenuCategory ( ) const
{
2014-09-04 13:00:27 -04:00
enum EAxisKeyCategory
{
GamepadKeyCategory ,
MouseButtonCategory ,
KeyEventCategory ,
AxisKeyCategory_MAX ,
} ;
static FNodeTextCache CachedCategories [ AxisKeyCategory_MAX ] ;
2014-07-14 13:19:37 -04:00
FText SubCategory ;
2014-09-04 13:00:27 -04:00
EAxisKeyCategory CategoryIndex = AxisKeyCategory_MAX ;
2014-07-14 13:19:37 -04:00
if ( AxisKey . IsGamepadKey ( ) )
{
SubCategory = LOCTEXT ( " GamepadCategory " , " Gamepad Events " ) ;
2014-09-04 13:00:27 -04:00
CategoryIndex = GamepadKeyCategory ;
2014-07-14 13:19:37 -04:00
}
else if ( AxisKey . IsMouseButton ( ) )
{
SubCategory = LOCTEXT ( " MouseCategory " , " Mouse Events " ) ;
2014-09-04 13:00:27 -04:00
CategoryIndex = MouseButtonCategory ;
2014-07-14 13:19:37 -04:00
}
else
{
SubCategory = LOCTEXT ( " KeyEventsCategory " , " Key Events " ) ;
2014-09-04 13:00:27 -04:00
CategoryIndex = KeyEventCategory ;
2014-07-14 13:19:37 -04:00
}
2015-04-02 11:16:23 -04:00
if ( CachedCategories [ CategoryIndex ] . IsOutOfDate ( this ) )
2014-09-04 13:00:27 -04:00
{
// FText::Format() is slow, so we cache this to save on performance
2015-04-02 11:16:23 -04:00
CachedCategories [ CategoryIndex ] . SetCachedText ( FEditorCategoryUtils : : BuildCategoryString ( FCommonEditorCategory : : Input , SubCategory ) , this ) ;
2014-09-04 13:00:27 -04:00
}
return CachedCategories [ CategoryIndex ] ;
2014-07-14 13:19:37 -04:00
}
2014-09-17 17:07:37 -04:00
FBlueprintNodeSignature UK2Node_InputAxisKeyEvent : : GetSignature ( ) const
{
FBlueprintNodeSignature NodeSignature = Super : : GetSignature ( ) ;
NodeSignature . AddKeyValue ( AxisKey . ToString ( ) ) ;
return NodeSignature ;
}
2014-07-14 13:19:37 -04:00
# undef LOCTEXT_NAMESPACE