108 lines
3.7 KiB
C++
108 lines
3.7 KiB
C++
// Copyright (c) Samuel Kahn (samuel@kahncode.com). All Rights Reserved.
|
|
|
|
#include "K2Node_StructToBlob.h"
|
|
|
|
#include "Blob.h"
|
|
#include "BlobFunctionLibrary.h"
|
|
#include "BlueprintActionDatabaseRegistrar.h"
|
|
#include "BlueprintFieldNodeSpawner.h"
|
|
#include "EdGraphSchema_K2.h"
|
|
#include "EdGraphUtilities.h"
|
|
#include "EditorCategoryUtils.h"
|
|
#include "K2Node_CallFunction.h"
|
|
#include "KismetCompiler.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "K2Node_StructToBlob"
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// UK2Node_StructToBlob
|
|
|
|
void UK2Node_StructToBlob::AllocateDefaultPins()
|
|
{
|
|
Super::AllocateDefaultPins();
|
|
|
|
UEdGraphNode::FCreatePinParams PinParams;
|
|
PinParams.bIsConst = true;
|
|
PinParams.bIsReference = true;
|
|
CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Wildcard, FName(TEXT("Struct")), PinParams);
|
|
|
|
CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Struct, FBlob::StaticStruct(), FName(TEXT("Blob")));
|
|
|
|
AllocateBehaviorPin();
|
|
AllocateNetContextPin();
|
|
}
|
|
|
|
FText UK2Node_StructToBlob::GetNodeTitle(ENodeTitleType::Type TitleType) const
|
|
{
|
|
if (CachedNodeTitle.IsOutOfDate(this))
|
|
{
|
|
CachedNodeTitle.SetCachedText(LOCTEXT("StructToBlob_Title", "Struct To Blob"), this);
|
|
}
|
|
return CachedNodeTitle;
|
|
}
|
|
|
|
FText UK2Node_StructToBlob::GetTooltipText() const
|
|
{
|
|
if (CachedTooltip.IsOutOfDate(this))
|
|
{
|
|
CachedTooltip.SetCachedText(
|
|
LOCTEXT("StructToBlob_Tooltip",
|
|
"Node that serializes a struct into a binary blob, make sure to serialize it back to the same type of script at the other end"),
|
|
this);
|
|
}
|
|
return CachedTooltip;
|
|
}
|
|
|
|
FSlateIcon UK2Node_StructToBlob::GetIconAndTint(FLinearColor& OutColor) const
|
|
{
|
|
static FSlateIcon Icon("EditorStyle", "GraphEditor.MakeStruct_16x");
|
|
return Icon;
|
|
}
|
|
|
|
void UK2Node_StructToBlob::ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph)
|
|
{
|
|
// This is where the node is implemented, calls UBinaryBlobFunctionLibrary::StructToBlob
|
|
|
|
Super::ExpandNode(CompilerContext, SourceGraph);
|
|
|
|
if (StructType)
|
|
{
|
|
UEdGraphPin* OutBlobPin = GetBlobPin();
|
|
UEdGraphPin* InStructPin = GetStructPin();
|
|
|
|
UK2Node_CallFunction* PinCallFunction = CompilerContext.SpawnIntermediateNode<UK2Node_CallFunction>(this, SourceGraph);
|
|
const UFunction* Function = GetStructToBlobFunction();
|
|
PinCallFunction->SetFromFunction(Function);
|
|
PinCallFunction->AllocateDefaultPins();
|
|
|
|
UEdGraphPin* StructPin = PinCallFunction->FindPinChecked(TEXT("InStruct"));
|
|
// Set the type of the OutRow pin on this expanded mode to match original
|
|
StructPin->PinType = InStructPin->PinType;
|
|
StructPin->PinType.PinSubCategoryObject = InStructPin->PinType.PinSubCategoryObject;
|
|
|
|
CompilerContext.MovePinLinksToIntermediate(*InStructPin, *StructPin);
|
|
|
|
UEdGraphPin* BlobPin = PinCallFunction->FindPinChecked(TEXT("OutBlob"));
|
|
CompilerContext.MovePinLinksToIntermediate(*OutBlobPin, *BlobPin); // struct pin out is not recognized properly
|
|
|
|
UEdGraphPin* BehaviorPin = PinCallFunction->FindPinChecked(TEXT("Behavior"));
|
|
UEdGraphPin* NetContextPin = PinCallFunction->FindPinChecked(TEXT("NetContext"));
|
|
CompilerContext.MovePinLinksToIntermediate(*GetBehaviorPin(), *BehaviorPin);
|
|
CompilerContext.MovePinLinksToIntermediate(*GetNetContextPin(), *NetContextPin);
|
|
|
|
// Move execution pin links
|
|
CompilerContext.MovePinLinksToIntermediate(*GetThenPin(), *(PinCallFunction->GetThenPin()));
|
|
CompilerContext.MovePinLinksToIntermediate(*GetExecPin(), *(PinCallFunction->GetExecPin()));
|
|
}
|
|
|
|
// Break any links to the expanded node
|
|
BreakAllNodeLinks();
|
|
}
|
|
|
|
const UFunction* UK2Node_StructToBlob::GetStructToBlobFunction() const
|
|
{
|
|
return UBlobFunctionLibrary::StaticClass()->FindFunctionByName(GET_FUNCTION_NAME_CHECKED(UBlobFunctionLibrary, StructToBlob));
|
|
}
|
|
|
|
#undef LOCTEXT_NAMESPACE
|