2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-04-23 18:29:30 -04:00
# include "BlueprintGraphPrivatePCH.h"
2014-05-29 16:42:22 -04:00
# include "K2Node_GetInputAxisKeyValue.h"
2014-04-23 18:29:30 -04:00
# include "CompilerResultsLog.h"
2014-07-14 16:30:29 -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-04-23 18:29:30 -04:00
2014-07-14 13:19:37 -04:00
# define LOCTEXT_NAMESPACE "K2Node_GetInputAxisKeyValue"
2014-10-14 10:29:11 -04:00
UK2Node_GetInputAxisKeyValue : : UK2Node_GetInputAxisKeyValue ( const FObjectInitializer & ObjectInitializer )
: Super ( ObjectInitializer )
2014-04-23 18:29:30 -04:00
{
bConsumeInput = true ;
}
void UK2Node_GetInputAxisKeyValue : : AllocateDefaultPins ( )
{
Super : : AllocateDefaultPins ( ) ;
UEdGraphPin * InputAxisKeyPin = FindPinChecked ( TEXT ( " InputAxisKey " ) ) ;
InputAxisKeyPin - > DefaultValue = InputAxisKey . ToString ( ) ;
}
void UK2Node_GetInputAxisKeyValue : : Initialize ( const FKey AxisKey )
{
InputAxisKey = AxisKey ;
SetFromFunction ( AActor : : StaticClass ( ) - > FindFunctionByName ( TEXT ( " GetInputAxisKeyValue " ) ) ) ;
2014-09-03 18:17:44 -04:00
CachedTooltip . MarkDirty ( ) ;
2014-09-02 19:08:09 -04:00
CachedNodeTitle . MarkDirty ( ) ;
2014-04-23 18:29:30 -04:00
}
2014-04-23 18:31:10 -04:00
FText UK2Node_GetInputAxisKeyValue : : GetNodeTitle ( ENodeTitleType : : Type TitleType ) const
2014-04-23 18:29:30 -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 InputAxisKey . GetDisplayName ( ) ;
2014-07-14 13:19:37 -04:00
}
2015-04-02 11:16:23 -04:00
else if ( CachedNodeTitle . IsOutOfDate ( this ) )
2014-09-02 19:08:09 -04:00
{
FFormatNamedArguments Args ;
Args . Add ( TEXT ( " AxisKey " ) , InputAxisKey . GetDisplayName ( ) ) ;
// FText::Format() is slow, so we cache this to save on performance
2015-04-02 11:16:23 -04:00
CachedNodeTitle . SetCachedText ( FText : : Format ( NSLOCTEXT ( " K2Node " , " GetInputAxisKey_Name " , " Get {AxisKey} " ) , Args ) , this ) ;
2014-09-02 19:08:09 -04:00
}
return CachedNodeTitle ;
2014-04-23 18:29:30 -04:00
}
2014-09-03 18:14:09 -04:00
FText UK2Node_GetInputAxisKeyValue : : GetTooltipText ( ) const
2014-04-23 18:29:30 -04:00
{
2015-04-02 11:16:23 -04:00
if ( CachedTooltip . IsOutOfDate ( this ) )
2014-09-03 18:17:44 -04:00
{
FFormatNamedArguments Args ;
Args . Add ( TEXT ( " AxisKey " ) , InputAxisKey . GetDisplayName ( ) ) ;
// 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 " , " GetInputAxisKey_Tooltip " , " Returns the current value of input axis key {AxisKey}. If input is disabled for the actor the value will be 0. " ) , Args ) , this ) ;
2014-09-03 18:17:44 -04:00
}
return CachedTooltip ;
2014-04-23 18:29:30 -04:00
}
2014-08-21 18:50:33 -04:00
bool UK2Node_GetInputAxisKeyValue : : IsCompatibleWithGraph ( UEdGraph const * Graph ) const
{
UBlueprint * Blueprint = FBlueprintEditorUtils : : FindBlueprintForGraph ( Graph ) ;
UEdGraphSchema_K2 const * K2Schema = Cast < UEdGraphSchema_K2 > ( Graph - > GetSchema ( ) ) ;
bool const bIsConstructionScript = ( K2Schema ! = nullptr ) ? K2Schema - > IsConstructionScript ( Graph ) : false ;
return ( Blueprint ! = nullptr ) & & Blueprint - > SupportsInputEvents ( ) & & ! bIsConstructionScript & & Super : : IsCompatibleWithGraph ( Graph ) ;
}
2014-04-23 18:29:30 -04:00
void UK2Node_GetInputAxisKeyValue : : ValidateNodeDuringCompilation ( class FCompilerResultsLog & MessageLog ) const
{
Super : : ValidateNodeDuringCompilation ( MessageLog ) ;
if ( ! InputAxisKey . IsValid ( ) )
{
MessageLog . Warning ( * FText : : Format ( NSLOCTEXT ( " KismetCompiler " , " Invalid_GetInputAxisKey_Warning " , " GetInputAxisKey Value specifies invalid FKey'{0}' for @@ " ) , FText : : FromString ( InputAxisKey . ToString ( ) ) ) . ToString ( ) , this ) ;
}
2014-04-28 11:24:25 -04:00
else if ( ! InputAxisKey . IsFloatAxis ( ) )
2014-04-23 18:29:30 -04:00
{
2014-04-28 11:24:25 -04:00
MessageLog . Warning ( * FText : : Format ( NSLOCTEXT ( " KismetCompiler " , " NotAxis_GetInputAxisKey_Warning " , " GetInputAxisKey Value specifies FKey'{0}' which is not a float axis for @@ " ) , FText : : FromString ( InputAxisKey . ToString ( ) ) ) . ToString ( ) , this ) ;
2014-04-23 18:29:30 -04:00
}
else if ( ! InputAxisKey . IsBindableInBlueprints ( ) )
{
MessageLog . Warning ( * FText : : Format ( NSLOCTEXT ( " KismetCompiler " , " NotBindanble_GetInputAxisKey_Warning " , " GetInputAxisKey Value specifies FKey'{0}' that is not blueprint bindable for @@ " ) , FText : : FromString ( InputAxisKey . ToString ( ) ) ) . ToString ( ) , this ) ;
}
}
UClass * UK2Node_GetInputAxisKeyValue : : GetDynamicBindingClass ( ) const
{
return UInputAxisKeyDelegateBinding : : StaticClass ( ) ;
}
void UK2Node_GetInputAxisKeyValue : : RegisterDynamicBinding ( UDynamicBlueprintBinding * BindingObject ) const
{
UInputAxisKeyDelegateBinding * InputAxisKeyBindingObject = CastChecked < UInputAxisKeyDelegateBinding > ( BindingObject ) ;
FBlueprintInputAxisKeyDelegateBinding Binding ;
Binding . AxisKey = InputAxisKey ;
Binding . bConsumeInput = bConsumeInput ;
Binding . bExecuteWhenPaused = bExecuteWhenPaused ;
InputAxisKeyBindingObject - > InputAxisKeyDelegateBindings . Add ( Binding ) ;
}
FName UK2Node_GetInputAxisKeyValue : : GetPaletteIcon ( FLinearColor & OutColor ) const
{
if ( InputAxisKey . IsMouseButton ( ) )
{
return TEXT ( " GraphEditor.MouseEvent_16x " ) ;
}
else if ( InputAxisKey . IsGamepadKey ( ) )
{
return TEXT ( " GraphEditor.PadEvent_16x " ) ;
}
else
{
return TEXT ( " GraphEditor.KeyEvent_16x " ) ;
}
2014-07-14 13:19:37 -04:00
}
2014-08-23 20:16:29 -04:00
void UK2Node_GetInputAxisKeyValue : : 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_GetInputAxisKeyValue * InputNode = CastChecked < UK2Node_GetInputAxisKeyValue > ( 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_GetInputAxisKeyValue : : GetMenuCategory ( ) const
{
2014-09-04 13:00:27 -04:00
enum EAxisKeyCategory
{
GamepadKeyCategory ,
MouseButtonCategory ,
KeyValueCategory ,
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 ( InputAxisKey . IsGamepadKey ( ) )
{
SubCategory = LOCTEXT ( " GamepadSubCategory " , " Gamepad Values " ) ;
2014-09-04 13:00:27 -04:00
CategoryIndex = GamepadKeyCategory ;
2014-07-14 13:19:37 -04:00
}
else if ( InputAxisKey . IsMouseButton ( ) )
{
SubCategory = LOCTEXT ( " MouseSubCategory " , " Mouse Values " ) ;
2014-09-04 13:00:27 -04:00
CategoryIndex = MouseButtonCategory ;
2014-07-14 13:19:37 -04:00
}
else
{
SubCategory = LOCTEXT ( " KeySubCategory " , " Key Values " ) ;
2014-09-04 13:00:27 -04:00
CategoryIndex = KeyValueCategory ;
2014-07-14 13:19:37 -04:00
}
2014-09-04 13:00:27 -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_GetInputAxisKeyValue : : GetSignature ( ) const
{
FBlueprintNodeSignature NodeSignature = Super : : GetSignature ( ) ;
NodeSignature . AddKeyValue ( InputAxisKey . ToString ( ) ) ;
return NodeSignature ;
}
2014-07-14 13:19:37 -04:00
# undef LOCTEXT_NAMESPACE