Files
UnrealEngineUWP/Engine/Source/Editor/BlueprintGraph/Classes/K2Node_Variable.h
Phillip Kavan f64e3e18d7 Some minor refactoring to assist with auto-importing external type object dependency namespaces into the Blueprint editor context in response to user actions.
Change summary:
- Moved base definition of UK2Node::HasExternalDependencies() up one level to UEdGraphNode (to avoid blind casts in a context where we may not necessarily have a UK2Node subtype).
- Updated subtype headers that override HasExternalDependencies() to relocate the declaration into the class declaration's 'UEdGraphNode overrides' section (for clarity).
- Reverted previous UBlueprintNodeSpawner::ImportTarget solution in favor of using node dependencies; this allows auto-import actions to scale more easily to all existing node subtypes and avoids data duplication.
- Modified SBlueprintActionMenu::OnActionSelected() to utilize the new method for determining which namespace(s) to auto-import after executing a node spawner action in response to a context menu item selection (UE-146803).
- Reverted FBlueprintNamespaceUtilities::GetPropertyValueNamespaces() back to its original 5.0 signature so that it uses a TSet<FString> for the output rather than a TArray<FString>; this fits in better with input to other APIs.
- Renamed FBlueprintEditor::FImportNamespaceParameters to FImportNamespaceExParameters (for clarity).
- Changed the 'FBlueprintEditor::FImportNamespaceParameters::AdditionalNamespaces' member to a TSet<FString> containing *all* namespaces to import rather than limiting to only additional ones.
- Reverted FBlueprintEditor::ImportNamespace() back to its original 5.0 signature and added/implemented FBlueprintEditor::ImportNamespaceEx() as the "extended" version that allows for batched imports and future customizations.
- Revised existing FBlueprintEditor::ImportNamespace() call sites to utilize and/or conform to the extended ImportNamespaceEx() API where appropriate.

#jira UE-146803
#rb Benjamin.Fox
#preflight 623cf3a433709ff50128e8d4

[CL 19505118 by Phillip Kavan in ue5-main branch]
2022-03-24 19:50:46 -04:00

203 lines
7.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "Templates/SubclassOf.h"
#include "Engine/Blueprint.h"
#include "K2Node.h"
#include "Engine/MemberReference.h"
#include "Textures/SlateIcon.h"
#include "K2Node_Variable.generated.h"
class UEdGraph;
UENUM()
namespace ESelfContextInfo
{
enum Type
{
Unspecified,
NotSelfContext,
};
}
UCLASS(abstract)
class BLUEPRINTGRAPH_API UK2Node_Variable : public UK2Node
{
GENERATED_UCLASS_BODY()
/** Reference to variable we want to set/get */
UPROPERTY(meta=(BlueprintSearchable="true", BlueprintSearchableHiddenExplicit="true", BlueprintSearchableFormatVersion="FIB_VER_VARIABLE_REFERENCE"))
FMemberReference VariableReference;
UPROPERTY()
TEnumAsByte<ESelfContextInfo::Type> SelfContextInfo;
protected:
/** Class that this variable is defined in. Should be NULL if bSelfContext is true. */
UPROPERTY()
TSubclassOf<class UObject> VariableSourceClass_DEPRECATED;
/** Name of variable */
UPROPERTY()
FName VariableName_DEPRECATED;
/** Whether or not this should be a "self" context */
UPROPERTY()
uint32 bSelfContext_DEPRECATED:1;
/**
* Remap a reference from one variable to another, if this variable is of class type 'MatchInVariableClass', and if linked to anything that is a child of 'RemapIfLinkedToClass'.
* Only intended for versioned fixup where redirects can't be applied.
*/
bool RemapRestrictedLinkReference(FName OldVariableName, FName NewVariableName, const UClass* MatchInVariableClass, const UClass* RemapIfLinkedToClass, bool bLogWarning);
public:
//~ Begin UObject Interface
virtual void Serialize(FArchive& Ar) override;
//~ End UObject Interface
//~ Begin UEdGraphNode Interface
virtual FLinearColor GetNodeTitleColor() const override;
virtual FString GetFindReferenceSearchString() const override;
virtual void ReconstructNode() override;
virtual FString GetDocumentationLink() const override;
virtual FString GetDocumentationExcerptName() const override;
virtual FName GetCornerIcon() const override;
virtual FSlateIcon GetIconAndTint(FLinearColor& OutColor) const override;
virtual void AutowireNewNode(UEdGraphPin* FromPin) override;
virtual bool CanPasteHere(const UEdGraph* TargetGraph) const override;
virtual void PostPasteNode() override;
virtual bool HasDeprecatedReference() const override;
virtual FEdGraphNodeDeprecationResponse GetDeprecationResponse(EEdGraphNodeDeprecationType DeprecationType) const override;
virtual UObject* GetJumpTargetForDoubleClick() const override;
virtual bool CanJumpToDefinition() const override;
virtual void JumpToDefinition() const override;
virtual FString GetPinMetaData(FName InPinName, FName InKey) override;
virtual bool HasExternalDependencies(TArray<class UStruct*>* OptionalOutput) const override;
//~ End UEdGraphNode Interface
//~ Begin K2Node Interface
virtual bool DrawNodeAsVariable() const override { return true; }
virtual ERedirectType DoPinsMatchForReconstruction(const UEdGraphPin* NewPin, int32 NewPinIndex, const UEdGraphPin* OldPin, int32 OldPinIndex) const override;
virtual void ValidateNodeDuringCompilation(class FCompilerResultsLog& MessageLog) const override;
virtual FText GetToolTipHeading() const override;
virtual void GetNodeAttributes(TArray<TKeyValuePair<FString, FString>>& OutNodeAttributes) const override;
virtual void HandleVariableRenamed(UBlueprint* InBlueprint, UClass* InVariableClass, UEdGraph* InGraph, const FName& InOldVarName, const FName& InNewVarName) override;
virtual void ReplaceReferences(UBlueprint* InBlueprint, UBlueprint* InReplacementBlueprint, const FMemberReference& InSource, const FMemberReference& InReplacement) override;
virtual bool ReferencesVariable(const FName& InVarName, const UStruct* InScope) const override;
//~ End K2Node Interface
/** Set up this variable node from the supplied FProperty */
void SetFromProperty(const FProperty* Property, bool bSelfContext, UClass* OwnerClass);
/** Util to get variable name as a string */
FString GetVarNameString() const
{
return GetVarName().ToString();
}
FText GetVarNameText() const
{
return FText::FromName( GetVarName() );
}
/** Util to get variable name */
FName GetVarName() const
{
return VariableReference.GetMemberName();
}
/**
* Creates a reader or writer pin for a variable.
*
* @param Direction The direction of the variable access.
* @param InPinName Optional pin name, will default to the variable name if not included.
*
* @return true if it succeeds, false if it fails.
*/
bool CreatePinForVariable(EEdGraphPinDirection Direction, FName InPinName = NAME_None);
/** Creates 'self' pin */
void CreatePinForSelf();
/**
* Creates a reader or writer pin for a variable from an old pin.
*
* @param Direction The direction of the variable access.
* @param OldPins Old pins.
* @param InPinName Optional pin name, will default to the variable name if not included.
*
* @return true if it succeeds, false if it fails.
*/
bool RecreatePinForVariable(EEdGraphPinDirection Direction, TArray<UEdGraphPin*>& OldPins, FName InPinName = NAME_None);
/** Get the class to look for this variable in */
UClass* GetVariableSourceClass() const;
/** Get the FProperty for this variable node */
FProperty* GetPropertyForVariable() const;
FProperty* GetPropertyForVariableFromSkeleton() const;
/** Returns true if the variable names match, this looks for redirectors */
static bool DoesRenamedVariableMatch(FName OldVariableName, FName NewVariableName, UStruct* StructType);
private:
/**
* Gets the property for the variable on the owning class or on the owning class's sparse class data structure.
*/
FProperty* GetPropertyForVariable_Internal(UClass* OwningClass) const;
public:
/** Accessor for the value output pin of the node */
UEdGraphPin* GetValuePin() const;
/** Validates there are no errors in the node */
void CheckForErrors(const class UEdGraphSchema_K2* Schema, class FCompilerResultsLog& MessageLog);
/**
* Utility method intended to serve as a choke point for various slate
* widgets to grab an icon from (for a specified variable).
*
* @param VarScope The scope that owns the variable in question.
* @param VarName The name of the variable you're querying for.
* @param IconColorOut A color out, further discerning the variable's type.
* @return A icon representing the specified variable's type.
*/
static FSlateIcon GetVariableIconAndColor(const UStruct* VarScope, FName VarName, FLinearColor& IconColorOut);
/**
* Utility method intended to serve as a choke point for various slate
* widgets to grab an icon from (for a specified variable pin type).
*
* @param InPinType The pin type of the variable in question.
* @param IconColorOut A color out, further discerning the variable's type.
* @return A icon representing the specified variable's type.
*/
static FSlateIcon GetVarIconFromPinType(const FEdGraphPinType& InPinType, FLinearColor& IconColorOut);
protected:
/**
*
*
* @return
*/
FBPVariableDescription const* GetBlueprintVarDescription() const;
/**
* Utility function to retrieve actor component for variable property.
*
* @return Found UActorComponent for the FProperty, else nullptr
*/
const UActorComponent* GetActorComponent(const FProperty* VariableProperty) const;
/** Returns whether a Function Graph contains a parameter with the given name */
static bool FunctionParameterExists(const UEdGraph* InFunctionGraph, const FName InParameterName);
};