// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved. #include "BlueprintGraphPrivatePCH.h" #include "BlueprintPropertyNodeSpawner.h" #include "K2Node_Variable.h" #include "EditorStyleSettings.h" // for bShowFriendlyNames #include "ObjectEditorUtils.h" // for GetCategory() #include "BlueprintEditorUtils.h" // for FindBlueprintForNodeChecked() #define LOCTEXT_NAMESPACE "BlueprintPropertyNodeSpawner" /******************************************************************************* * UBlueprintPropertyNodeSpawner ******************************************************************************/ //------------------------------------------------------------------------------ UBlueprintPropertyNodeSpawner* UBlueprintPropertyNodeSpawner::Create(UProperty const* const Property, UObject* Outer/* = nullptr*/) { check(Property != nullptr); if (Outer == nullptr) { Outer = GetTransientPackage(); } UBlueprintPropertyNodeSpawner* NodeSpawner = NewObject(Outer); NodeSpawner->Property = Property; return NodeSpawner; } //------------------------------------------------------------------------------ UBlueprintPropertyNodeSpawner::UBlueprintPropertyNodeSpawner(class FPostConstructInitializeProperties const& PCIP) : Super(PCIP) , Property(nullptr) { } //------------------------------------------------------------------------------ UEdGraphNode* UBlueprintPropertyNodeSpawner::Invoke(UEdGraph* ParentGraph, FVector2D const Location) const { auto PostSpawnSetupLambda = [](UEdGraphNode* NewNode, bool bIsTemplateNode, UProperty const* Property, FCustomizeNodeDelegate UserDelegate) { UBlueprint* Blueprint = FBlueprintEditorUtils::FindBlueprintForNodeChecked(NewNode); UClass* OwnerClass = Property->GetOwnerClass(); bool const bIsSelfContext = Blueprint->SkeletonGeneratedClass->IsChildOf(OwnerClass); if (UK2Node_Variable* VarNode = Cast(NewNode)) { VarNode->SetFromProperty(Property, bIsSelfContext); } else if (UK2Node_BaseMCDelegate* DelegateNode = Cast(NewNode)) { DelegateNode->SetFromProperty(Property, bIsSelfContext); } UserDelegate.ExecuteIfBound(NewNode, bIsTemplateNode); }; FCustomizeNodeDelegate PostSpawnSetupDelegate = FCustomizeNodeDelegate::CreateStatic(PostSpawnSetupLambda, Property, CustomizeNodeDelegate); return Super::Invoke(ParentGraph, Location, PostSpawnSetupDelegate); } //------------------------------------------------------------------------------ FText UBlueprintPropertyNodeSpawner::GetDefaultMenuName() const { check(Property != nullptr); FText MenuName; if (GetDefault()->bShowFriendlyNames) { MenuName = FText::FromString(UEditorEngine::GetFriendlyName(Property)); } else { MenuName = FText::FromName(Property->GetFName()); } if (NodeClass != nullptr) { if (NodeClass->IsChildOf()) { MenuName = FText::Format(LOCTEXT("GetterMenuName", "Get {0}"), MenuName); } else if (NodeClass->IsChildOf()) { MenuName = FText::Format(LOCTEXT("SetterMenuName", "Set {0}"), MenuName); } else if (IsDelegateProperty()) { // there are bunch of different delegate node type, so let that // determine the menu entry text MenuName = FText::GetEmpty(); } } return MenuName; } //------------------------------------------------------------------------------ FText UBlueprintPropertyNodeSpawner::GetDefaultMenuCategory() const { check(Property != nullptr); FText PropertyCategory = FText::FromString(FObjectEditorUtils::GetCategory(Property)); if (!IsDelegateProperty()) { PropertyCategory = FText::Format(LOCTEXT("VariableCategory", "Variables|{0}"), PropertyCategory); } else if (PropertyCategory.IsEmpty()) { PropertyCategory = LOCTEXT("DefaultDelegateCategory", "Event Dispatchers"); } return PropertyCategory; } //------------------------------------------------------------------------------ FName UBlueprintPropertyNodeSpawner::GetDefaultMenuIcon(FLinearColor& ColorOut) const { FName BrushName = Super::GetDefaultMenuIcon(ColorOut); if (NodeClass == nullptr) { if (IsDelegateProperty()) { BrushName = TEXT("GraphEditor.Delegate_16x"); } } return BrushName; } //------------------------------------------------------------------------------ UProperty const* UBlueprintPropertyNodeSpawner::GetProperty() const { return Property; } //------------------------------------------------------------------------------ bool UBlueprintPropertyNodeSpawner::IsDelegateProperty() const { check(Property != nullptr); return Property->IsA(UMulticastDelegateProperty::StaticClass()); } #undef LOCTEXT_NAMESPACE