Files
UnrealEngineUWP/Engine/Source/Editor/BlueprintGraph/Private/BlueprintPropertyNodeSpawner.cpp
Mike Beach 1dddac5edb Adding in missing menu icons for the new blueprint action menu systems.
[CL 2249059 by Mike Beach in Main branch]
2014-08-08 18:16:41 -04:00

145 lines
4.6 KiB
C++

// 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<UBlueprintPropertyNodeSpawner>(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<UK2Node_Variable>(NewNode))
{
VarNode->SetFromProperty(Property, bIsSelfContext);
}
else if (UK2Node_BaseMCDelegate* DelegateNode = Cast<UK2Node_BaseMCDelegate>(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<UEditorStyleSettings>()->bShowFriendlyNames)
{
MenuName = FText::FromString(UEditorEngine::GetFriendlyName(Property));
}
else
{
MenuName = FText::FromName(Property->GetFName());
}
if (NodeClass != nullptr)
{
if (NodeClass->IsChildOf<UK2Node_VariableGet>())
{
MenuName = FText::Format(LOCTEXT("GetterMenuName", "Get {0}"), MenuName);
}
else if (NodeClass->IsChildOf<UK2Node_VariableSet>())
{
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