2020-01-22 17:58:55 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
#include "RigVMModel/Nodes/RigVMUnitNode.h"
|
2020-09-24 00:43:27 -04:00
|
|
|
#include "RigVMCore/RigVMStruct.h"
|
|
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
FString URigVMUnitNode::GetNodeTitle() const
|
2020-09-24 00:43:27 -04:00
|
|
|
{
|
|
|
|
|
if (UScriptStruct* Struct = GetScriptStruct())
|
|
|
|
|
{
|
|
|
|
|
return Struct->GetDisplayNameText().ToString();
|
|
|
|
|
}
|
|
|
|
|
return Super::GetNodeTitle();
|
|
|
|
|
}
|
2020-01-22 17:58:55 -05:00
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
FText URigVMUnitNode::GetToolTipText() const
|
2020-01-22 17:58:55 -05:00
|
|
|
{
|
2020-09-24 00:43:27 -04:00
|
|
|
if (UScriptStruct* Struct = GetScriptStruct())
|
2020-01-22 17:58:55 -05:00
|
|
|
{
|
|
|
|
|
return Struct->GetToolTipText();
|
|
|
|
|
}
|
|
|
|
|
return URigVMNode::GetToolTipText();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
bool URigVMUnitNode::IsDefinedAsConstant() const
|
2020-09-24 00:43:27 -04:00
|
|
|
{
|
|
|
|
|
if (UScriptStruct* Struct = GetScriptStruct())
|
|
|
|
|
{
|
|
|
|
|
return Struct->HasMetaData(FRigVMStruct::ConstantMetaName);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
bool URigVMUnitNode::IsDefinedAsVarying() const
|
2020-09-24 00:43:27 -04:00
|
|
|
{
|
|
|
|
|
if (UScriptStruct* Struct = GetScriptStruct())
|
|
|
|
|
{
|
|
|
|
|
return Struct->HasMetaData(FRigVMStruct::VaryingMetaName);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
FName URigVMUnitNode::GetEventName() const
|
2020-09-24 00:43:27 -04:00
|
|
|
{
|
|
|
|
|
TSharedPtr<FStructOnScope> StructOnScope = ConstructStructInstance(true);
|
|
|
|
|
if (StructOnScope.IsValid())
|
|
|
|
|
{
|
|
|
|
|
const FRigVMStruct* StructMemory = (FRigVMStruct*)StructOnScope->GetStructMemory();
|
|
|
|
|
return StructMemory->GetEventName();
|
|
|
|
|
}
|
|
|
|
|
return NAME_None;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
FText URigVMUnitNode::GetToolTipTextForPin(const URigVMPin* InPin) const
|
2020-01-22 17:58:55 -05:00
|
|
|
{
|
|
|
|
|
if(UScriptStruct* Struct = GetScriptStruct())
|
|
|
|
|
{
|
|
|
|
|
TArray<FString> Parts;
|
|
|
|
|
URigVMPin::SplitPinPath(InPin->GetPinPath(), Parts);
|
|
|
|
|
|
|
|
|
|
for (int32 PartIndex = 1; PartIndex < Parts.Num(); PartIndex++)
|
|
|
|
|
{
|
|
|
|
|
FProperty* Property = Struct->FindPropertyByName(*Parts[PartIndex]);
|
|
|
|
|
if (!Property)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (FArrayProperty* ArrayProperty = CastField<FArrayProperty>(Property))
|
|
|
|
|
{
|
|
|
|
|
if (PartIndex < Parts.Num() - 1)
|
|
|
|
|
{
|
|
|
|
|
Property = ArrayProperty->Inner;
|
|
|
|
|
PartIndex++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PartIndex == Parts.Num() - 1)
|
|
|
|
|
{
|
|
|
|
|
return Property->GetToolTipText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (FStructProperty* StructProperty = CastField<FStructProperty>(Property))
|
|
|
|
|
{
|
|
|
|
|
Struct = StructProperty->Struct;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return URigVMNode::GetToolTipTextForPin(InPin);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
bool URigVMUnitNode::IsDeprecated() const
|
2020-09-24 00:43:27 -04:00
|
|
|
{
|
|
|
|
|
return !GetDeprecatedMetadata().IsEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
FString URigVMUnitNode::GetDeprecatedMetadata() const
|
2020-09-24 00:43:27 -04:00
|
|
|
{
|
|
|
|
|
if (UScriptStruct* Struct = GetScriptStruct())
|
|
|
|
|
{
|
|
|
|
|
FString DeprecatedMetadata;
|
|
|
|
|
if(Struct->GetStringMetaDataHierarchical(FRigVMStruct::DeprecatedMetaName, &DeprecatedMetadata))
|
|
|
|
|
{
|
|
|
|
|
return DeprecatedMetadata;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return FString();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
UScriptStruct* URigVMUnitNode::GetScriptStruct() const
|
2020-01-22 17:58:55 -05:00
|
|
|
{
|
|
|
|
|
return ScriptStruct;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
bool URigVMUnitNode::IsLoopNode() const
|
2020-09-24 00:43:27 -04:00
|
|
|
{
|
|
|
|
|
TSharedPtr<FStructOnScope> StructOnScope = ConstructStructInstance(true);
|
|
|
|
|
if (StructOnScope.IsValid())
|
|
|
|
|
{
|
|
|
|
|
const FRigVMStruct* StructMemory = (FRigVMStruct*)StructOnScope->GetStructMemory();
|
|
|
|
|
return StructMemory->IsForLoop();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
FName URigVMUnitNode::GetMethodName() const
|
2020-01-22 17:58:55 -05:00
|
|
|
{
|
|
|
|
|
return MethodName;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
FString URigVMUnitNode::GetStructDefaultValue() const
|
2020-01-22 17:58:55 -05:00
|
|
|
{
|
|
|
|
|
TArray<FString> PinDefaultValues;
|
|
|
|
|
for (URigVMPin* Pin : GetPins())
|
|
|
|
|
{
|
|
|
|
|
if (Pin->GetDirection() == ERigVMPinDirection::Hidden)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
FString PinDefaultValue = Pin->GetDefaultValue();
|
|
|
|
|
if (Pin->IsStringType())
|
|
|
|
|
{
|
|
|
|
|
PinDefaultValue = TEXT("\"") + PinDefaultValue + TEXT("\"");
|
|
|
|
|
}
|
|
|
|
|
else if (PinDefaultValue.IsEmpty() || PinDefaultValue == TEXT("()"))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
PinDefaultValues.Add(FString::Printf(TEXT("%s=%s"), *Pin->GetName(), *PinDefaultValue));
|
|
|
|
|
}
|
|
|
|
|
if (PinDefaultValues.Num() == 0)
|
|
|
|
|
{
|
|
|
|
|
return TEXT("()");
|
|
|
|
|
}
|
|
|
|
|
return FString::Printf(TEXT("(%s)"), *FString::Join(PinDefaultValues, TEXT(",")));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 10:59:58 -04:00
|
|
|
TSharedPtr<FStructOnScope> URigVMUnitNode::ConstructStructInstance(bool bUseDefault) const
|
2020-01-22 17:58:55 -05:00
|
|
|
{
|
|
|
|
|
if (ScriptStruct)
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FStructOnScope> StructOnScope = MakeShareable(new FStructOnScope(ScriptStruct));
|
|
|
|
|
FRigVMStruct* StructMemory = (FRigVMStruct*)StructOnScope->GetStructMemory();
|
|
|
|
|
if (bUseDefault)
|
|
|
|
|
{
|
|
|
|
|
ScriptStruct->InitializeDefaultValue((uint8*)StructMemory);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FString StructDefaultValue = GetStructDefaultValue();
|
|
|
|
|
ScriptStruct->ImportText(*StructDefaultValue, StructMemory, nullptr, PPF_None, nullptr, ScriptStruct->GetName());
|
|
|
|
|
}
|
|
|
|
|
return StructOnScope;
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|