91 lines
3.0 KiB
C++
91 lines
3.0 KiB
C++
// Copyright (c) Samuel Kahn (samuel@kahncode.com). All Rights Reserved.
|
|
|
|
#include "K2Node_StructToJson.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_StructToJson"
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// UK2Node_StructToJson
|
|
|
|
void UK2Node_StructToJson::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_String, FName(TEXT("JsonString")));
|
|
}
|
|
|
|
FText UK2Node_StructToJson::GetNodeTitle(ENodeTitleType::Type TitleType) const
|
|
{
|
|
if (CachedNodeTitle.IsOutOfDate(this))
|
|
{
|
|
CachedNodeTitle.SetCachedText(LOCTEXT("StructToJson_Title", "Struct To Json"), this);
|
|
}
|
|
return CachedNodeTitle;
|
|
}
|
|
|
|
FText UK2Node_StructToJson::GetTooltipText() const
|
|
{
|
|
if (CachedTooltip.IsOutOfDate(this))
|
|
{
|
|
CachedTooltip.SetCachedText(LOCTEXT("StructToJsonToNullStruct_Tooltip", "Writes a struct as a json string"), this);
|
|
}
|
|
return CachedTooltip;
|
|
}
|
|
|
|
FSlateIcon UK2Node_StructToJson::GetIconAndTint(FLinearColor& OutColor) const
|
|
{
|
|
static FSlateIcon Icon("EditorStyle", "GraphEditor.MakeStruct_16x");
|
|
return Icon;
|
|
}
|
|
|
|
void UK2Node_StructToJson::ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph)
|
|
{
|
|
Super::ExpandNode(CompilerContext, SourceGraph);
|
|
|
|
if (StructType)
|
|
{
|
|
UEdGraphPin* OutJsonStringPin = FindPin(TEXT("JsonString"));
|
|
;
|
|
UEdGraphPin* InStructPin = GetStructPin();
|
|
|
|
UK2Node_CallFunction* PinCallFunction = CompilerContext.SpawnIntermediateNode<UK2Node_CallFunction>(this, SourceGraph);
|
|
const UFunction* Function = UBlobFunctionLibrary::StaticClass()->FindFunctionByName(
|
|
GET_FUNCTION_NAME_CHECKED(UBlobFunctionLibrary, StructToJson));
|
|
PinCallFunction->SetFromFunction(Function);
|
|
PinCallFunction->AllocateDefaultPins();
|
|
|
|
UEdGraphPin* StructPin = PinCallFunction->FindPinChecked(TEXT("Struct"));
|
|
// 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* JsonStringPin = PinCallFunction->FindPinChecked(TEXT("JsonString"));
|
|
CompilerContext.MovePinLinksToIntermediate(*OutJsonStringPin, *JsonStringPin); // 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
|