Files
UnrealEngineUWP/Engine/Source/Editor/AnimGraph/Private/AnimGraphNode_SaveCachedPose.cpp
Michael Schoell 0a41fb741e #summary Can search for nodes in the palette menu in Blueprints with both the native name and the localized name.
#add Added UEdGraphNode::GetNodeNativeTitle to return a native title for a node.
#add Added UEdGraphNode::GetNodeSearchTitle to return the native and localized title for a node, together, for searching.
#add Can hold "alt" over a node (in the graph panel, or the palette) to see the native name of the node.

#ttp 331252 - Blueprints: Editor: L10N: Blueprints need to consistently show localized node names and when searching need to search both the localized name and the native name

#codereview justin.sargent

[CL 2044506 by Michael Schoell in Main branch]
2014-04-23 18:30:37 -04:00

111 lines
3.7 KiB
C++

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#include "AnimGraphPrivatePCH.h"
#include "GraphEditorActions.h"
#include "ScopedTransaction.h"
#include "Kismet2NameValidators.h"
#include "K2ActionMenuBuilder.h" // for FK2ActionMenuBuilder::AddNewNodeAction()
/////////////////////////////////////////////////////
// FCachedPoseNameValidator
class FCachedPoseNameValidator : public FStringSetNameValidator
{
public:
FCachedPoseNameValidator(class UBlueprint* InBlueprint, const FString& InExistingName)
: FStringSetNameValidator(InExistingName)
{
TArray<UAnimGraphNode_SaveCachedPose*> Nodes;
FBlueprintEditorUtils::GetAllNodesOfClass<UAnimGraphNode_SaveCachedPose>(InBlueprint, Nodes);
for (auto NodeIt = Nodes.CreateIterator(); NodeIt; ++NodeIt)
{
auto Node = *NodeIt;
Names.Add(Node->CacheName);
}
}
};
/////////////////////////////////////////////////////
// UAnimGraphNode_ComponentToLocalSpace
#define LOCTEXT_NAMESPACE "A3Nodes"
UAnimGraphNode_SaveCachedPose::UAnimGraphNode_SaveCachedPose(const FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
bCanRenameNode = true;
CacheName = TEXT("SavedPose");
}
FString UAnimGraphNode_SaveCachedPose::GetTooltip() const
{
return TEXT("Denotes an animation tree that can be referenced elsewhere in the blueprint, which will be evaluated at most once per frame and then cached.");
}
FText UAnimGraphNode_SaveCachedPose::GetNodeTitle(ENodeTitleType::Type TitleType) const
{
if (TitleType == ENodeTitleType::EditableTitle)
{
return FText::FromString(CacheName);
}
else
{
FFormatNamedArguments Args;
Args.Add(TEXT("NodeTitle"), FText::FromString(CacheName));
return FText::Format(LOCTEXT("AnimGraphNode_SaveCachedPose_Title", "Save cached pose '{NodeTitle}'"), Args);
}
}
FString UAnimGraphNode_SaveCachedPose::GetNodeNativeTitle(ENodeTitleType::Type TitleType) const
{
// Do not setup this function for localization, intentionally left unlocalized!
if (TitleType == ENodeTitleType::EditableTitle)
{
return CacheName;
}
else
{
return FString::Printf(TEXT("Save cached pose '%s'"), *CacheName);
}
}
FString UAnimGraphNode_SaveCachedPose::GetNodeCategory() const
{
return TEXT("Cached Poses");
}
void UAnimGraphNode_SaveCachedPose::GetMenuEntries(FGraphContextMenuBuilder& ContextMenuBuilder) const
{
//@TODO: Check the type of the from pin to make sure it's a pose
if ((ContextMenuBuilder.FromPin == NULL) || (ContextMenuBuilder.FromPin->Direction == EGPD_Output))
{
// Disallow the graph being cached from residing in a state for safety and sanity; the tree is in effect it's own graph entirely and should be treated that way
const bool bNotInStateMachine = ContextMenuBuilder.CurrentGraph->GetOuter()->IsA(UAnimBlueprint::StaticClass());
if (bNotInStateMachine)
{
// Offer save cached pose
UAnimGraphNode_SaveCachedPose* SaveCachedPose = NewObject<UAnimGraphNode_SaveCachedPose>();
SaveCachedPose->CacheName += FString::FromInt(FMath::Rand());
TSharedPtr<FEdGraphSchemaAction_K2NewNode> SaveCachedPoseAction = FK2ActionMenuBuilder::AddNewNodeAction(ContextMenuBuilder, GetNodeCategory(), LOCTEXT("NewSaveCachedPose", "New Save cached pose..."), SaveCachedPose->GetTooltip(), 0, SaveCachedPose->GetKeywords());
SaveCachedPoseAction->NodeTemplate = SaveCachedPose;
SaveCachedPoseAction->SearchTitle = SaveCachedPoseAction->NodeTemplate->GetNodeSearchTitle();
}
}
}
void UAnimGraphNode_SaveCachedPose::OnRenameNode(const FString& NewName)
{
CacheName = NewName;
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(GetBlueprint());
}
TSharedPtr<class INameValidatorInterface> UAnimGraphNode_SaveCachedPose::MakeNameValidator() const
{
return MakeShareable(new FCachedPoseNameValidator(GetBlueprint(), CacheName));
}
#undef LOCTEXT_NAMESPACE