-
Notifications
You must be signed in to change notification settings - Fork 348
Expand file tree
/
Copy pathFlowNode_FormatText.cpp
More file actions
87 lines (69 loc) · 2.61 KB
/
FlowNode_FormatText.cpp
File metadata and controls
87 lines (69 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright https://github.com/MothCocoon/FlowGraph/graphs/contributors
#include "Nodes/Graph/FlowNode_FormatText.h"
#include "Types/FlowPinTypesStandard.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(FlowNode_FormatText)
#define LOCTEXT_NAMESPACE "FlowNode_FormatText"
const FName UFlowNode_FormatText::OUTPIN_TextOutput("Formatted Text");
UFlowNode_FormatText::UFlowNode_FormatText()
{
#if WITH_EDITOR
Category = TEXT("Graph");
NodeDisplayStyle = FlowNodeStyle::Terminal;
#endif
OutputPins.Add(FFlowPin(OUTPIN_TextOutput, FFlowPinType_Text::GetPinTypeNameStatic()));
}
FFlowDataPinResult UFlowNode_FormatText::TrySupplyDataPin(FName PinName) const
{
if (PinName == OUTPIN_TextOutput)
{
FText FormattedText;
const EFlowDataPinResolveResult FormatResult = TryResolveFormattedText(PinName, FormattedText);
if (FlowPinType::IsSuccess(FormatResult))
{
return FFlowDataPinResult(FFlowDataPinValue_Text(FormattedText));
}
else
{
return FFlowDataPinResult(FormatResult);
}
}
return Super::TrySupplyDataPin(PinName);
}
EFlowDataPinResolveResult UFlowNode_FormatText::TryResolveFormattedText(const FName& PinName, FText& OutFormattedText) const
{
FText ResolvedFormatText = FormatText;
const EFlowDataPinResolveResult ResolveResult = TryResolveDataPinValue<FFlowPinType_Text>(GET_MEMBER_NAME_CHECKED(ThisClass, FormatText), ResolvedFormatText);
if (TryFormatTextWithNamedPropertiesAsParameters(ResolvedFormatText, OutFormattedText))
{
return EFlowDataPinResolveResult::Success;
}
else
{
LogError(FString::Printf(TEXT("Could not format text '%s' with properties as parameters"), *ResolvedFormatText.ToString()), EFlowOnScreenMessageType::Temporary);
return EFlowDataPinResolveResult::FailedWithError;
}
}
#if WITH_EDITOR
void UFlowNode_FormatText::PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChainEvent)
{
const auto& Property = PropertyChainEvent.PropertyChain.GetActiveMemberNode()->GetValue();
constexpr bool bIsInput = true;
OnPostEditEnsureAllNamedPropertiesPinDirection(*Property, bIsInput);
Super::PostEditChangeChainProperty(PropertyChainEvent);
}
void UFlowNode_FormatText::UpdateNodeConfigText_Implementation()
{
constexpr bool bErrorIfInputPinNotFound = true;
FConnectedPin ConnectedPin;
const bool bIsInputConnected = FindFirstInputPinConnection(GET_MEMBER_NAME_CHECKED(ThisClass, FormatText), bErrorIfInputPinNotFound, ConnectedPin);
if (bIsInputConnected)
{
SetNodeConfigText(FText::Format(LOCTEXT("FormatTextFromPin", "Format from: {0}"), { FText::FromString(ConnectedPin.PinName.ToString()) }));
}
else
{
SetNodeConfigText(FormatText);
}
}
#endif
#undef LOCTEXT_NAMESPACE