105 lines
3.5 KiB
C++
105 lines
3.5 KiB
C++
|
|
// Copyright (c) Samuel Kahn (samuel@kahncode.com). All Rights Reserved.
|
||
|
|
|
||
|
|
#include "K2Node_BlobToStruct.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_BlobToStruct"
|
||
|
|
|
||
|
|
//////////////////////////////////////////////////////////////////////////
|
||
|
|
// UK2Node_BlobToStruct
|
||
|
|
|
||
|
|
void UK2Node_BlobToStruct::AllocateDefaultPins()
|
||
|
|
{
|
||
|
|
Super::AllocateDefaultPins();
|
||
|
|
|
||
|
|
UEdGraphNode::FCreatePinParams PinParams;
|
||
|
|
PinParams.bIsConst = true;
|
||
|
|
PinParams.bIsReference = true;
|
||
|
|
CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Struct, FBlob::StaticStruct(), FName(TEXT("Blob")), PinParams);
|
||
|
|
|
||
|
|
CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Wildcard, FName(TEXT("Struct")));
|
||
|
|
|
||
|
|
AllocateBehaviorPin();
|
||
|
|
AllocateNetContextPin();
|
||
|
|
}
|
||
|
|
|
||
|
|
FText UK2Node_BlobToStruct::GetNodeTitle(ENodeTitleType::Type aTitleType) const
|
||
|
|
{
|
||
|
|
if (CachedNodeTitle.IsOutOfDate(this))
|
||
|
|
{
|
||
|
|
CachedNodeTitle.SetCachedText(LOCTEXT("BlobToStruct_Title", "Blob To Struct"), this);
|
||
|
|
}
|
||
|
|
return CachedNodeTitle;
|
||
|
|
}
|
||
|
|
|
||
|
|
FText UK2Node_BlobToStruct::GetTooltipText() const
|
||
|
|
{
|
||
|
|
if (CachedTooltip.IsOutOfDate(this))
|
||
|
|
{
|
||
|
|
CachedTooltip.SetCachedText(
|
||
|
|
LOCTEXT("BlobToStruct_Tooltip",
|
||
|
|
"Node that serializes a blob into a Struct, only use when you know the contents of the blob match the struct"),
|
||
|
|
this);
|
||
|
|
}
|
||
|
|
return CachedTooltip;
|
||
|
|
}
|
||
|
|
|
||
|
|
FSlateIcon UK2Node_BlobToStruct::GetIconAndTint(FLinearColor& outColor) const
|
||
|
|
{
|
||
|
|
static FSlateIcon Icon("EditorStyle", "GraphEditor.BreakStruct_16x");
|
||
|
|
return Icon;
|
||
|
|
}
|
||
|
|
|
||
|
|
void UK2Node_BlobToStruct::ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph)
|
||
|
|
{
|
||
|
|
// This is where the node is implemented, calls UBinaryBlobFunctionLibrary::BlobToStruct
|
||
|
|
|
||
|
|
Super::ExpandNode(CompilerContext, SourceGraph);
|
||
|
|
|
||
|
|
if (StructType)
|
||
|
|
{
|
||
|
|
UEdGraphPin* InBlobPin = GetBlobPin();
|
||
|
|
UEdGraphPin* OutStructPin = GetStructPin();
|
||
|
|
|
||
|
|
UK2Node_CallFunction* PinCallFunction = CompilerContext.SpawnIntermediateNode<UK2Node_CallFunction>(this, SourceGraph);
|
||
|
|
const UFunction* Function = UBlobFunctionLibrary::StaticClass()->FindFunctionByName(
|
||
|
|
GET_FUNCTION_NAME_CHECKED(UBlobFunctionLibrary, BlobToStruct));
|
||
|
|
PinCallFunction->SetFromFunction(Function);
|
||
|
|
PinCallFunction->AllocateDefaultPins();
|
||
|
|
|
||
|
|
UEdGraphPin* BlobPin = PinCallFunction->FindPinChecked(TEXT("InBlob"));
|
||
|
|
CompilerContext.MovePinLinksToIntermediate(*InBlobPin, *BlobPin);
|
||
|
|
|
||
|
|
UEdGraphPin* StructPin = PinCallFunction->FindPinChecked(TEXT("OutStruct"));
|
||
|
|
|
||
|
|
UEdGraphPin* BehaviorPin = PinCallFunction->FindPinChecked(TEXT("Behavior"));
|
||
|
|
UEdGraphPin* NetContextPin = PinCallFunction->FindPinChecked(TEXT("NetContext"));
|
||
|
|
CompilerContext.MovePinLinksToIntermediate(*GetBehaviorPin(), *BehaviorPin);
|
||
|
|
CompilerContext.MovePinLinksToIntermediate(*GetNetContextPin(), *NetContextPin);
|
||
|
|
|
||
|
|
// Set the type of the OutRow pin on this expanded mode to match original
|
||
|
|
StructPin->PinType = OutStructPin->PinType;
|
||
|
|
StructPin->PinType.PinSubCategoryObject = OutStructPin->PinType.PinSubCategoryObject;
|
||
|
|
|
||
|
|
CompilerContext.MovePinLinksToIntermediate(*OutStructPin, *StructPin); // struct pin out is not recognized properly
|
||
|
|
|
||
|
|
// Move execution pin links
|
||
|
|
CompilerContext.MovePinLinksToIntermediate(*GetThenPin(), *(PinCallFunction->GetThenPin()));
|
||
|
|
CompilerContext.MovePinLinksToIntermediate(*GetExecPin(), *(PinCallFunction->GetExecPin()));
|
||
|
|
}
|
||
|
|
|
||
|
|
// Break any links to the expanded node
|
||
|
|
BreakAllNodeLinks();
|
||
|
|
}
|
||
|
|
|
||
|
|
#undef LOCTEXT_NAMESPACE
|