Files
UnrealEngineUWP/Engine/Source/Editor/BlueprintGraph/Private/K2Node_AssignDelegate.cpp
Michael Schoell 75200e5a0d Cached node titles can now be forced to refresh without iteration over every node.
This will occur with every structural modification to any BP, node titles refresh only when visible.

[CL 2499923 by Michael Schoell in Main branch]
2015-04-02 11:16:23 -04:00

103 lines
3.8 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "BlueprintGraphPrivatePCH.h"
#include "K2Node_AssignDelegate.h"
#include "K2Node_CustomEvent.h" // for CreateFromFunction()
#include "BlueprintEditorUtils.h" // for DoesSupportEventGraphs(), FindUniqueKismetName(), etc.
#include "EditorStyleSettings.h" // for bShowFriendlyNames
#include "ObjectEditorUtils.h" // for GetCategory()
#include "EditorCategoryUtils.h"
#include "Editor/EditorEngine.h" // for GetFriendlyName()
#define LOCTEXT_NAMESPACE "K2Node_AssignDelegate"
//------------------------------------------------------------------------------
UK2Node_AssignDelegate::UK2Node_AssignDelegate(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
//------------------------------------------------------------------------------
FText UK2Node_AssignDelegate::GetNodeTitle(ENodeTitleType::Type TitleType) const
{
if (TitleType == ENodeTitleType::ListView || TitleType == ENodeTitleType::MenuTitle)
{
if (CachedListTitle.IsOutOfDate(this))
{
FText PropertyName;
if (UProperty* Property = GetProperty())
{
bool const bShowFriendlyNames = GetDefault<UEditorStyleSettings>()->bShowFriendlyNames;
PropertyName = FText::FromString(bShowFriendlyNames ? UEditorEngine::GetFriendlyName(Property) : Property->GetName());
// FText::Format() is slow, so we cache this to save on performance
CachedListTitle.SetCachedText(FText::Format(LOCTEXT("AssignDelegateTitle", "Assign {0}"), PropertyName), this);
}
else
{
return LOCTEXT("InvalidPropertyTitle", "Assign <invalid delegate>");
}
}
return CachedListTitle;
}
return Super::GetNodeTitle(TitleType);
}
//------------------------------------------------------------------------------
FText UK2Node_AssignDelegate::GetMenuCategory() const
{
FText MenuCategory = FEditorCategoryUtils::GetCommonCategory(FCommonEditorCategory::Delegates);
if (UProperty* Property = GetProperty())
{
MenuCategory = FText::FromString(FObjectEditorUtils::GetCategory(Property));
}
return MenuCategory;
}
//------------------------------------------------------------------------------
bool UK2Node_AssignDelegate::IsCompatibleWithGraph(const UEdGraph* TargetGraph) const
{
bool bIsCompatible = Super::IsCompatibleWithGraph(TargetGraph);
UBlueprint* Blueprint = FBlueprintEditorUtils::FindBlueprintForGraph(TargetGraph);
check(Blueprint != nullptr);
UEdGraphSchema const* Schema = TargetGraph->GetSchema();
EGraphType GraphType = Schema->GetGraphType(TargetGraph);
bool const bAllowEvents = (GraphType == GT_Ubergraph) && FBlueprintEditorUtils::DoesSupportEventGraphs(Blueprint);
return bAllowEvents && Super::IsCompatibleWithGraph(TargetGraph);
}
//------------------------------------------------------------------------------
void UK2Node_AssignDelegate::PostPlacedNewNode()
{
UEdGraphPin* InDelegatePin = GetDelegatePin();
if (InDelegatePin->LinkedTo.Num() == 0)
{
if (UMulticastDelegateProperty* DelegateProp = Cast<UMulticastDelegateProperty>(GetProperty()))
{
FVector2D const LocationOffset(-150.f, +150.f);
FText DelegateName = FText::FromName(DelegateProp->GetFName());
FText DesiredEventName = FText::Format(LOCTEXT("BindedEventName", "{0}_Event"), DelegateName);
FName EventName = FBlueprintEditorUtils::FindUniqueKismetName(GetBlueprint(), DesiredEventName.ToString());
UK2Node_CustomEvent* EventNode = UK2Node_CustomEvent::CreateFromFunction(
FVector2D(NodePosX, NodePosY) + LocationOffset,
GetGraph(), EventName.ToString(), DelegateProp->SignatureFunction, /*bSelectNewNode =*/false);
if (EventNode != nullptr)
{
UEdGraphSchema_K2 const* K2Schema = GetDefault<UEdGraphSchema_K2>();
UEdGraphPin* OutDelegatePin = EventNode->FindPinChecked(UK2Node_CustomEvent::DelegateOutputName);
K2Schema->TryCreateConnection(OutDelegatePin, InDelegatePin);
}
}
}
}
#undef LOCTEXT_NAMESPACE