Files
UnrealEngineUWP/Engine/Source/Editor/BlueprintGraph/Private/K2Node_LocalVariable.cpp

192 lines
7.4 KiB
C++
Raw Normal View History

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "K2Node_LocalVariable.h"
#include "Engine/Blueprint.h"
#include "EdGraphSchema_K2.h"
#include "K2Node_AssignmentStatement.h"
#include "K2Node_FunctionEntry.h"
#include "K2Node_VariableGet.h"
#include "K2Node_VariableSet.h"
#include "Kismet2/BlueprintEditorUtils.h"
#include "ScopedTransaction.h"
UDEPRECATED_K2Node_LocalVariable::UDEPRECATED_K2Node_LocalVariable(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
bCanRenameNode = true;
CustomVariableName = TEXT("NewLocalVar");
}
FText UDEPRECATED_K2Node_LocalVariable::GetTooltipText() const
{
if(VariableTooltip.IsEmpty())
{
return Super::GetTooltipText();
}
return VariableTooltip;
}
FText UDEPRECATED_K2Node_LocalVariable::GetNodeTitle(ENodeTitleType::Type TitleType) const
{
if (TitleType == ENodeTitleType::EditableTitle)
{
return FText::FromName(CustomVariableName);
}
else if(TitleType == ENodeTitleType::ListView || TitleType == ENodeTitleType::MenuTitle)
{
FFormatNamedArguments Args;
Args.Add(TEXT("TypeName"), UEdGraphSchema_K2::TypeToText(VariableType));
return FText::Format(NSLOCTEXT("K2Node", "LocalVariable", "Local {TypeName}"), Args);
}
FFormatNamedArguments Args;
Args.Add(TEXT("Title"), FText::FromName(CustomVariableName));
return FText::Format(NSLOCTEXT("K2Node", "LocalVariable_Name", "{Title}\nLocal Variable"), Args);
}
void UDEPRECATED_K2Node_LocalVariable::OnRenameNode(const FString& NewName)
{
if(CustomVariableName != *NewName)
{
const FScopedTransaction Transaction( NSLOCTEXT( "K2Node", "RenameLocalVariable", "Rename Local Variable" ) );
Modify();
CustomVariableName = *NewName;
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(GetBlueprint());
}
}
TSharedPtr<class INameValidatorInterface> UDEPRECATED_K2Node_LocalVariable::MakeNameValidator() const
{
return MakeShareable(new FKismetNameValidator(GetBlueprint(), *GetNodeTitle(ENodeTitleType::EditableTitle).ToString()));
}
void UDEPRECATED_K2Node_LocalVariable::ChangeVariableType(const FEdGraphPinType& InVariableType)
{
// Local variables can never change type when the variable pin is hooked up
check(GetVariablePin()->LinkedTo.Num() == 0);
// Update the variable and the pin's type so that it properly reflects
VariableType = InVariableType;
GetVariablePin()->PinType = InVariableType;
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(GetBlueprint());
}
void UDEPRECATED_K2Node_LocalVariable::PostPlacedNewNode()
{
Super::PostPlacedNewNode();
CustomVariableName = FBlueprintEditorUtils::FindUniqueKismetName(GetBlueprint(), CustomVariableName.ToString());
}
void UDEPRECATED_K2Node_LocalVariable::PostPasteNode()
{
Super::PostPasteNode();
// Assign the local variable a unique name
CustomVariableName = FBlueprintEditorUtils::FindUniqueKismetName(GetBlueprint(), CustomVariableName.GetPlainNameString());
}
bool UDEPRECATED_K2Node_LocalVariable::IsCompatibleWithGraph(const UEdGraph* TargetGraph) const
{
bool const bIsCompatible = (TargetGraph->GetSchema()->GetGraphType(TargetGraph) == GT_Function);
return bIsCompatible && Super::IsCompatibleWithGraph(TargetGraph);
}
void UDEPRECATED_K2Node_LocalVariable::ReconstructNode()
{
UEdGraph* Graph = GetGraph();
UEdGraph* TopLevelGraph = FBlueprintEditorUtils::GetTopLevelGraph(Graph);
if(TopLevelGraph->GetSchema()->GetGraphType(TopLevelGraph) == GT_Function)
{
const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();
// First, add the variable to the entry node
FBPVariableDescription NewVar;
NewVar.VarName = *GetNodeTitle(ENodeTitleType::EditableTitle).ToString();
NewVar.VarGuid = FGuid::NewGuid();
NewVar.VarType = GetVariablePin()->PinType;
NewVar.FriendlyName = FName::NameToDisplayString( NewVar.VarName.ToString(), (NewVar.VarType.PinCategory == K2Schema->PC_Boolean) ? true : false );
NewVar.Category = K2Schema->VR_DefaultCategory;
// Find the function entry node in the graph
TArray<UK2Node_FunctionEntry*> FunctionEntryNodes;
TopLevelGraph->GetNodesOfClass<UK2Node_FunctionEntry>(FunctionEntryNodes);
check(FunctionEntryNodes.Num() == 1);
UK2Node_FunctionEntry* FunctionEntry = FunctionEntryNodes[0];
FunctionEntry->LocalVariables.Add(NewVar);
// Duplicate the array, it is semi-destructive as we iterate through
TArray< UEdGraphPin* > VariableLinkedPins = GetVariablePin()->LinkedTo;
// Search through all linked pins for AssignmentStatement nodes, those need to be replaced with a VariableSet node and hooked up to the new variable
for( auto LinkedPin : VariableLinkedPins )
{
if(LinkedPin->GetOwningNode()->IsA(UK2Node_AssignmentStatement::StaticClass()))
{
UK2Node_AssignmentStatement* AssignementNode = Cast<UK2Node_AssignmentStatement>(LinkedPin->GetOwningNode());
// Only replace the node if hooked up to the variable pin
if(AssignementNode->GetVariablePin() == LinkedPin)
{
UK2Node_VariableSet* SetNode = NewObject<UK2Node_VariableSet>(Graph);
SetNode->VariableReference.SetLocalMember(NewVar.VarName, TopLevelGraph->GetName(), NewVar.VarGuid);
Graph->AddNode(SetNode, false, false);
SetNode->CreateNewGuid();
SetNode->PostPlacedNewNode();
// Locally re-construct the pins, can't allow the node to do it because the property does not yet exist
UEdGraphPin* ExecPin = SetNode->CreatePin(EGPD_Input, K2Schema->PC_Exec, TEXT(""), NULL, false, false, K2Schema->PN_Execute);
UEdGraphPin* ThenPin = SetNode->CreatePin(EGPD_Output, K2Schema->PC_Exec, TEXT(""), NULL, false, false, K2Schema->PN_Then);
UEdGraphPin* ValuePin = SetNode->CreatePin(EGPD_Input, TEXT(""), TEXT(""), NULL, false, false, NewVar.VarName.ToString());
ValuePin->PinType = NewVar.VarType;
// Move the pin links over to the new node
K2Schema->MovePinLinks(*AssignementNode->FindPin(K2Schema->PN_Execute), *ExecPin);
K2Schema->MovePinLinks(*AssignementNode->FindPin(K2Schema->PN_Then), *ThenPin);
K2Schema->MovePinLinks(*AssignementNode->GetValuePin(), *ValuePin);
// Position the new node
SetNode->NodePosX = AssignementNode->NodePosX;
SetNode->NodePosY = AssignementNode->NodePosY;
// Destroy the assignment node
AssignementNode->DestroyNode();
}
}
}
// Only replace with a get node if the node still has connections
if(GetVariablePin()->LinkedTo.Num())
{
// Only the local variable node needs to be re-constructed as a VariableGet node, there are no other nodes representing this local variable
UK2Node_VariableGet* GetNode = NewObject<UK2Node_VariableGet>(Graph);
GetNode->VariableReference.SetLocalMember(NewVar.VarName, TopLevelGraph->GetName(), NewVar.VarGuid);
Graph->AddNode(GetNode, false, false);
GetNode->CreateNewGuid();
GetNode->PostPlacedNewNode();
// Locally re-construct the pins, can't allow the node to do it because the property does not yet exist
UEdGraphPin* VariablePin = GetNode->CreatePin(EGPD_Output, TEXT(""), TEXT(""), NULL, false, false, NewVar.VarName.ToString());
VariablePin->PinType = NewVar.VarType;
K2Schema->SetPinDefaultValueBasedOnType(VariablePin);
// Position the new node
GetNode->NodePosX = NodePosX;
GetNode->NodePosY = NodePosY;
// Move the pin links over to the new node
K2Schema->MovePinLinks(*GetVariablePin(), *GetNode->GetValuePin());
}
}
// This node should not persist anymore, it is deprecated and the above case catches any still valid uses and deletes the rest (invalid ones are from AnimationTransitionGraph)
DestroyNode();
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
}