From 6428194393266f36b121d3c3164aa0d9ea84f554 Mon Sep 17 00:00:00 2001 From: jyelon Date: Wed, 4 Mar 2026 03:00:44 -0500 Subject: [PATCH] Refactor Format Message, step 1 --- Source/Integration/FormatMessage.cpp | 30 ++++++++-------------------- Source/Integration/FormatMessage.h | 13 ++---------- Source/Integration/LuprexK2Node.cpp | 7 +++++++ Source/Integration/LuprexK2Node.h | 3 +++ 4 files changed, 20 insertions(+), 33 deletions(-) diff --git a/Source/Integration/FormatMessage.cpp b/Source/Integration/FormatMessage.cpp index 7fd66052..71dfc6c9 100644 --- a/Source/Integration/FormatMessage.cpp +++ b/Source/Integration/FormatMessage.cpp @@ -43,20 +43,6 @@ // All argument pins will have Names that start with "A:" -static bool IsArgumentPin(const UEdGraphPin *Pin) { - TCHAR pname[FName::StringBufferSize]; - Pin->PinName.ToString(pname); - return pname[0] == 'A' && pname[1] == ':'; -} - -static FName ArgumentNameAddPrefix(const FString &name) { - FString Prefixed = FString("A:") + name; - return FName(*Prefixed); -} - -static FString ArgumentNameRemovePrefix(const FName &name) { - return name.ToString().Mid(2, FName::StringBufferSize); -} static const FName VerbosityPinName(TEXT("Verbosity")); static bool IsVerbosityPin(const UEdGraphPin *Pin) { @@ -121,9 +107,9 @@ void UK2Node_FormatMessage::CreateCorrectPins() for (auto It = Pins.CreateIterator(); It; ++It) { UEdGraphPin* CheckPin = *It; - if (IsArgumentPin(CheckPin)) + if (HasPrefix(CheckPin->PinName, 'A')) { - OldPins.Add(ArgumentNameRemovePrefix(CheckPin->PinName), CheckPin); + OldPins.Add(RemovePrefix(CheckPin->PinName).ToString(), CheckPin); It.RemoveCurrent(); } } @@ -137,7 +123,7 @@ void UK2Node_FormatMessage::CreateCorrectPins() Pins.Emplace(*OldPin); OldPins.Remove(Name); } else { - FName PrefixedName = ArgumentNameAddPrefix(Name); + FName PrefixedName = AddPrefix(Name, 'A'); CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Wildcard, PrefixedName); } } @@ -155,7 +141,7 @@ void UK2Node_FormatMessage::CreateCorrectPins() void UK2Node_FormatMessage::SynchronizeArgumentPinType(UEdGraphPin* Pin) { - if (IsArgumentPin(Pin)) + if (HasPrefix(Pin->PinName, 'A')) { const UEdGraphSchema_K2* K2Schema = Cast(GetSchema()); @@ -227,8 +213,8 @@ FText UK2Node_FormatMessage::GetPinDisplayName(const UEdGraphPin* Pin) const } // For argument pins, we must strip off the Argument Pin Prefix. - if (IsArgumentPin(Pin)) { - return FText::FromString(ArgumentNameRemovePrefix(Pin->PinName)); + if (HasPrefix(Pin->PinName, 'A')) { + return FText::FromName(RemovePrefix(Pin->PinName)); } // Otherwise, just return the Pin Name the normal way. @@ -385,7 +371,7 @@ void UK2Node_FormatMessage::ExpandNode(class FKismetCompilerContext& CompilerCon for(int32 ArgIdx = 0; ArgIdx < PinNames.Num(); ++ArgIdx) { FString OriginalName = PinNames[ArgIdx]; - UEdGraphPin* ArgumentPin = FindPin(ArgumentNameAddPrefix(OriginalName), EGPD_Input); + UEdGraphPin* ArgumentPin = FindPin(AddPrefix(OriginalName, 'A'), EGPD_Input); // Find a function that can convert the input into an FFormatArgumentData. @@ -508,7 +494,7 @@ bool UK2Node_FormatMessage::IsConnectionDisallowed(const UEdGraphPin* MyPin, con } // Argument input pins may only be connected to Byte, Integer, Float, Text, and ETextGender pins... - if (IsArgumentPin(MyPin)) + if (HasPrefix(MyPin->PinName, 'A')) { const UEdGraphSchema_K2* K2Schema = Cast(GetSchema()); const FName& OtherPinCategory = OtherPin->PinType.PinCategory; diff --git a/Source/Integration/FormatMessage.h b/Source/Integration/FormatMessage.h index a6b952c2..f18bbafe 100644 --- a/Source/Integration/FormatMessage.h +++ b/Source/Integration/FormatMessage.h @@ -15,16 +15,7 @@ #include "BreakToDebugger.h" #include "FormatDataLibrary.h" -#include "Containers/Array.h" -#include "CoreMinimal.h" -#include "EdGraph/EdGraphNode.h" -#include "EdGraph/EdGraphPin.h" -#include "HAL/Platform.h" -#include "Internationalization/Text.h" -#include "K2Node.h" -#include "UObject/NameTypes.h" -#include "UObject/ObjectMacros.h" -#include "UObject/UObjectGlobals.h" +#include "LuprexK2Node.h" #include "FormatMessage.generated.h" @@ -86,7 +77,7 @@ class UObject; //////////////////////////////////////////////////////////// UCLASS(MinimalAPI) -class UK2Node_FormatMessage : public UK2Node +class UK2Node_FormatMessage : public UlxK2Node { GENERATED_UCLASS_BODY() diff --git a/Source/Integration/LuprexK2Node.cpp b/Source/Integration/LuprexK2Node.cpp index e9942f11..ebc0c190 100644 --- a/Source/Integration/LuprexK2Node.cpp +++ b/Source/Integration/LuprexK2Node.cpp @@ -15,6 +15,13 @@ FName UlxK2Node::AddPrefix(const FString &Name, char Prefix) return FName(*Prefixed); } +bool UlxK2Node::HasPrefix(FName Name, char Prefix) +{ + TCHAR pname[FName::StringBufferSize]; + Name.ToString(pname); + return (pname[0] == Prefix) && (pname[1] == ':'); +} + FName UlxK2Node::RemovePrefix(FName Name) { TCHAR pname[FName::StringBufferSize]; diff --git a/Source/Integration/LuprexK2Node.h b/Source/Integration/LuprexK2Node.h index 3ba33645..8ee1252b 100644 --- a/Source/Integration/LuprexK2Node.h +++ b/Source/Integration/LuprexK2Node.h @@ -17,6 +17,9 @@ protected: /** Add a single-char prefix to a pin name, e.g. AddPrefix("foo", 'A') -> "A:foo" */ static FName AddPrefix(const FString &Name, char Prefix); + /** Check if a pin name has a given single-char prefix. */ + static bool HasPrefix(FName Name, char Prefix); + /** Strip a single-char prefix from a pin name, returning the original name if no prefix is found. */ static FName RemovePrefix(FName Name);