Files
UnrealEngineUWP/Engine/Source/Editor/UnrealEd/Classes/MaterialGraph/MaterialGraphSchema.h
Michael Schoell db9c8e2240 UProperty and UFunction metadata for Category can now be localized and have improved FText usage throughout the editor (Blueprints, Behavior Trees, Materials, etc).
Big conversion of FStrings and FNames to FText.

Version bump to move some MaterialFunction UProperty from a TArray<FString> to TArray<FText> (some Engine assets are older than being allowed to auto-convert the UProperty)

Auto conversion of FName to FText (and back) now supported (as well as TArrays of those types).

Searching categories by both the localized string and the source string is now supported in Blueprints.

#jira UE-14481 - We are missing ability to translate node categories

#codereview Justin.Sargent

[CL 2542875 by Michael Schoell in Main branch]
2015-05-08 10:46:42 -04:00

229 lines
8.6 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "EdGraph/EdGraphSchema.h"
#include "MaterialGraphSchema.generated.h"
/** Action to add an expression node to the graph */
USTRUCT()
struct UNREALED_API FMaterialGraphSchemaAction_NewNode : public FEdGraphSchemaAction
{
GENERATED_USTRUCT_BODY();
/** Class of expression we want to create */
UPROPERTY()
class UClass* MaterialExpressionClass;
// Simple type info
static FName StaticGetTypeId() {static FName Type("FMaterialGraphSchemaAction_NewNode"); return Type;}
virtual FName GetTypeId() const override { return StaticGetTypeId(); }
FMaterialGraphSchemaAction_NewNode()
: FEdGraphSchemaAction()
, MaterialExpressionClass(NULL)
{}
FMaterialGraphSchemaAction_NewNode(const FText& InNodeCategory, const FText& InMenuDesc, const FString& InToolTip, const int32 InGrouping)
: FEdGraphSchemaAction(InNodeCategory, InMenuDesc, InToolTip, InGrouping)
, MaterialExpressionClass(NULL)
{}
// FEdGraphSchemaAction interface
virtual UEdGraphNode* PerformAction(class UEdGraph* ParentGraph, UEdGraphPin* FromPin, const FVector2D Location, bool bSelectNewNode = true) override;
// End of FEdGraphSchemaAction interface
/**
* Sets the type of a Function input based on an EMaterialValueType value.
*
* @param FunctionInput The function input to set.
* @param MaterialValueType Value type we want input to accept.
*/
void SetFunctionInputType(class UMaterialExpressionFunctionInput* FunctionInput, uint32 MaterialValueType) const;
};
/** Action to add a Material Function call to the graph */
USTRUCT()
struct UNREALED_API FMaterialGraphSchemaAction_NewFunctionCall : public FEdGraphSchemaAction
{
GENERATED_USTRUCT_BODY();
/** Path to function that we want to call */
UPROPERTY()
FString FunctionPath;
// Simple type info
static FName StaticGetTypeId() {static FName Type("FMaterialGraphSchemaAction_NewFunctionCall"); return Type;}
virtual FName GetTypeId() const override { return StaticGetTypeId(); }
FMaterialGraphSchemaAction_NewFunctionCall()
: FEdGraphSchemaAction()
{}
FMaterialGraphSchemaAction_NewFunctionCall(const FText& InNodeCategory, const FText& InMenuDesc, const FString& InToolTip, const int32 InGrouping)
: FEdGraphSchemaAction(InNodeCategory, InMenuDesc, InToolTip, InGrouping)
{}
// FEdGraphSchemaAction interface
virtual UEdGraphNode* PerformAction(class UEdGraph* ParentGraph, UEdGraphPin* FromPin, const FVector2D Location, bool bSelectNewNode = true) override;
// End of FEdGraphSchemaAction interface
};
/** Action to add a comment node to the graph */
USTRUCT()
struct UNREALED_API FMaterialGraphSchemaAction_NewComment : public FEdGraphSchemaAction
{
GENERATED_USTRUCT_BODY();
// Simple type info
static FName StaticGetTypeId() {static FName Type("FMaterialGraphSchemaAction_NewComment"); return Type;}
virtual FName GetTypeId() const override { return StaticGetTypeId(); }
FMaterialGraphSchemaAction_NewComment()
: FEdGraphSchemaAction()
{}
FMaterialGraphSchemaAction_NewComment(const FText& InNodeCategory, const FText& InMenuDesc, const FString& InToolTip, const int32 InGrouping)
: FEdGraphSchemaAction(InNodeCategory, InMenuDesc, InToolTip, InGrouping)
{}
// FEdGraphSchemaAction interface
virtual UEdGraphNode* PerformAction(class UEdGraph* ParentGraph, UEdGraphPin* FromPin, const FVector2D Location, bool bSelectNewNode = true) override;
// End of FEdGraphSchemaAction interface
};
/** Action to paste clipboard contents into the graph */
USTRUCT()
struct UNREALED_API FMaterialGraphSchemaAction_Paste : public FEdGraphSchemaAction
{
GENERATED_USTRUCT_BODY();
// Simple type info
static FName StaticGetTypeId() {static FName Type("FMaterialGraphSchemaAction_Paste"); return Type;}
virtual FName GetTypeId() const override { return StaticGetTypeId(); }
FMaterialGraphSchemaAction_Paste()
: FEdGraphSchemaAction()
{}
FMaterialGraphSchemaAction_Paste(const FText& InNodeCategory, const FText& InMenuDesc, const FString& InToolTip, const int32 InGrouping)
: FEdGraphSchemaAction(InNodeCategory, InMenuDesc, InToolTip, InGrouping)
{}
// FEdGraphSchemaAction interface
virtual UEdGraphNode* PerformAction(class UEdGraph* ParentGraph, UEdGraphPin* FromPin, const FVector2D Location, bool bSelectNewNode = true) override;
// End of FEdGraphSchemaAction interface
};
UCLASS(MinimalAPI)
class UMaterialGraphSchema : public UEdGraphSchema
{
GENERATED_UCLASS_BODY()
// Allowable PinType.PinCategory values
UPROPERTY()
FString PC_Mask;
UPROPERTY()
FString PC_Required;
UPROPERTY()
FString PC_Optional;
UPROPERTY()
FString PC_MaterialInput;
// Common PinType.PinSubCategory values
UPROPERTY()
FString PSC_Red;
UPROPERTY()
FString PSC_Green;
UPROPERTY()
FString PSC_Blue;
UPROPERTY()
FString PSC_Alpha;
// Color of certain pins/connections
UPROPERTY()
FLinearColor ActivePinColor;
UPROPERTY()
FLinearColor InactivePinColor;
UPROPERTY()
FLinearColor AlphaPinColor;
/**
* Get menu for breaking links to specific nodes
*
* @param MenuBuilder MenuBuilder we are populating
* @param InGraphPin Pin with links to break
*/
void GetBreakLinkToSubMenuActions(class FMenuBuilder& MenuBuilder, class UEdGraphPin* InGraphPin);
/**
* Connect a pin to one of the Material Function's outputs
*
* @param InGraphPin Pin we are connecting
* @param InFuncPin Desired output pin
*/
void OnConnectToFunctionOutput(UEdGraphPin* InGraphPin, UEdGraphPin* InFuncPin);
/**
* Connect a pin to one of the Material's inputs
*
* @param InGraphPin Pin we are connecting
* @param ConnIndex Index of the Material input to connect to
*/
void OnConnectToMaterial(UEdGraphPin* InGraphPin, int32 ConnIndex);
UNREALED_API void GetPaletteActions(FGraphActionMenuBuilder& ActionMenuBuilder, const FString& CategoryName, bool bMaterialFunction) const;
/** Check whether connecting these pins would cause a loop */
bool ConnectionCausesLoop(const UEdGraphPin* InputPin, const UEdGraphPin* OutputPin) const;
/** Check whether the types of pins are compatible */
bool ArePinsCompatible(const UEdGraphPin* InputPin, const UEdGraphPin* OutputPin, FText& ResponseMessage) const;
/** Gets the type of this pin (must be part of a UMaterialGraphNode_Base) */
UNREALED_API static uint32 GetMaterialValueType(const UEdGraphPin* MaterialPin);
// Begin UEdGraphSchema interface
virtual void GetGraphContextActions(FGraphContextMenuBuilder& ContextMenuBuilder) const override;
virtual void GetContextMenuActions(const UEdGraph* CurrentGraph, const UEdGraphNode* InGraphNode, const UEdGraphPin* InGraphPin, class FMenuBuilder* MenuBuilder, bool bIsDebugging) const override;
virtual const FPinConnectionResponse CanCreateConnection(const UEdGraphPin* A, const UEdGraphPin* B) const override;
virtual bool TryCreateConnection(UEdGraphPin* A, UEdGraphPin* B) const override;
virtual bool ShouldHidePinDefaultValue(UEdGraphPin* Pin) const override { return true; }
virtual FLinearColor GetPinTypeColor(const FEdGraphPinType& PinType) const override;
virtual void BreakNodeLinks(UEdGraphNode& TargetNode) const override;
virtual void BreakPinLinks(UEdGraphPin& TargetPin, bool bSendsNodeNotifcation) const override;
virtual void BreakSinglePinLink(UEdGraphPin* SourcePin, UEdGraphPin* TargetPin) override;
virtual void DroppedAssetsOnGraph(const TArray<class FAssetData>& Assets, const FVector2D& GraphPosition, UEdGraph* Graph) const override;
virtual int32 GetNodeSelectionCount(const UEdGraph* Graph) const override;
virtual TSharedPtr<FEdGraphSchemaAction> GetCreateCommentAction() const override;
virtual bool IsCacheVisualizationOutOfDate(int32 InVisualizationCacheID) const override;
virtual int32 GetCurrentVisualizationCacheID() const override;
virtual void ForceVisualizationCacheClear() const override;
// End UEdGraphSchema interface
private:
/** Adds actions for all Material Functions */
void GetMaterialFunctionActions(FGraphActionMenuBuilder& ActionMenuBuilder) const;
/** Adds action for creating a comment */
void GetCommentAction(FGraphActionMenuBuilder& ActionMenuBuilder, const UEdGraph* CurrentGraph = NULL) const;
/**
* Checks whether a Material Function has any connections that are compatible with a type/direction
*
* @param FunctionAssetData Asset Data for function to test against (may need to be fully loaded).
* @param TestType Material Value Type we are testing.
* @param TestDirection Pin Direction we are testing.
*/
bool HasCompatibleConnection(const FAssetData& FunctionAssetData, uint32 TestType, EEdGraphPinDirection TestDirection) const;
private:
// ID for checking dirty status of node titles against, increases whenever
static int32 CurrentCacheRefreshID;
};