Lots of work on FormatMessage and FormatErrorMessage. These can now print enums.
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
#include "UObject/WeakObjectPtr.h"
|
||||
#include "UObject/WeakObjectPtrTemplates.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FormatError"
|
||||
#define LOCTEXT_NAMESPACE "FormatMessage"
|
||||
|
||||
// All argument pins will have Names that start with "A:"
|
||||
|
||||
@@ -71,26 +71,19 @@ static bool IsFormatPin(const UEdGraphPin *Pin) {
|
||||
return (Pin->PinName == FormatPinName);
|
||||
}
|
||||
|
||||
UK2Node_FormatError::UK2Node_FormatError(const FObjectInitializer& ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
NodeTooltip = LOCTEXT("NodeTooltip",
|
||||
"Output an error, warning, or informational message to the log file.\n"
|
||||
"\n"
|
||||
" \u2022 Use {ArgName} to denote format arguments, giving each argument a different ArgName.\n"
|
||||
"\n"
|
||||
"It is often desirable to use this in conjunction with a separate utility that\n"
|
||||
"pauses the execution of the blueprint whenever an error is logged."
|
||||
);
|
||||
static const FName ResultPinName(TEXT("Result"));
|
||||
static bool IsResultPin(const UEdGraphPin *Pin) {
|
||||
return (Pin->PinName == ResultPinName);
|
||||
}
|
||||
|
||||
void UK2Node_FormatError::AllocateDefaultPins()
|
||||
|
||||
void UK2Node_FormatMessage::AllocateDefaultPins()
|
||||
{
|
||||
Super::AllocateDefaultPins();
|
||||
CreateCorrectPins();
|
||||
}
|
||||
|
||||
void UK2Node_FormatError::CreateCorrectPins()
|
||||
void UK2Node_FormatMessage::CreateCorrectPins()
|
||||
{
|
||||
if (FindPin(UEdGraphSchema_K2::PN_Execute) == nullptr) {
|
||||
CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Exec, UEdGraphSchema_K2::PN_Execute);
|
||||
@@ -105,19 +98,34 @@ void UK2Node_FormatError::CreateCorrectPins()
|
||||
P->DefaultValue = TEXT("Error Message");
|
||||
}
|
||||
|
||||
if (FindPin(VerbosityPinName, EGPD_Input) == nullptr) {
|
||||
UEdGraphPin *P = CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Byte, StaticEnum<ElxLogVerbosity>(), VerbosityPinName);
|
||||
P->DefaultValue = TEXT("Error");
|
||||
P->AutogeneratedDefaultValue = P->DefaultValue;
|
||||
// If this is a FormatMessage node, create a pin to output the result as text.
|
||||
//
|
||||
if (!IsFormatErrorMessage())
|
||||
{
|
||||
if (FindPin(ResultPinName, EGPD_Output) == nullptr) {
|
||||
CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Text, ResultPinName);
|
||||
}
|
||||
}
|
||||
|
||||
if (FindPin(DisplayDurationPinName, EGPD_Input) == nullptr) {
|
||||
UEdGraphPin *P = CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Byte, StaticEnum<ElxErrorDisplayDuration>(), DisplayDurationPinName);
|
||||
P->DefaultValue = TEXT("No_Show");
|
||||
P->AutogeneratedDefaultValue = P->DefaultValue;
|
||||
// If this is a FormatErrorMessage node, create pins that control the log verbosity
|
||||
//
|
||||
if (IsFormatErrorMessage())
|
||||
{
|
||||
if (FindPin(VerbosityPinName, EGPD_Input) == nullptr) {
|
||||
UEdGraphPin *P = CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Byte, StaticEnum<ElxLogVerbosity>(), VerbosityPinName);
|
||||
P->DefaultValue = TEXT("Error");
|
||||
P->AutogeneratedDefaultValue = P->DefaultValue;
|
||||
}
|
||||
|
||||
if (FindPin(DisplayDurationPinName, EGPD_Input) == nullptr) {
|
||||
UEdGraphPin *P = CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Byte, StaticEnum<ElxErrorDisplayDuration>(), DisplayDurationPinName);
|
||||
P->DefaultValue = TEXT("No_Show");
|
||||
P->AutogeneratedDefaultValue = P->DefaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Transfer all Existing Argument pins to the Old Pins Map.
|
||||
//
|
||||
TMap<FString, UEdGraphPin *> OldPins;
|
||||
for (auto It = Pins.CreateIterator(); It; ++It)
|
||||
{
|
||||
@@ -130,6 +138,7 @@ void UK2Node_FormatError::CreateCorrectPins()
|
||||
}
|
||||
|
||||
// Create Argument pins in the correct order, reusing old pins where possible.
|
||||
//
|
||||
for (const FString& Name : PinNames)
|
||||
{
|
||||
UEdGraphPin **OldPin = OldPins.Find(Name);
|
||||
@@ -143,6 +152,7 @@ void UK2Node_FormatError::CreateCorrectPins()
|
||||
}
|
||||
|
||||
// Delete any unused pins.
|
||||
//
|
||||
for (auto &iter : OldPins)
|
||||
{
|
||||
iter.Value->Modify();
|
||||
@@ -152,7 +162,7 @@ void UK2Node_FormatError::CreateCorrectPins()
|
||||
}
|
||||
|
||||
|
||||
void UK2Node_FormatError::SynchronizeArgumentPinType(UEdGraphPin* Pin)
|
||||
void UK2Node_FormatMessage::SynchronizeArgumentPinType(UEdGraphPin* Pin)
|
||||
{
|
||||
if (IsArgumentPin(Pin))
|
||||
{
|
||||
@@ -196,12 +206,19 @@ void UK2Node_FormatError::SynchronizeArgumentPinType(UEdGraphPin* Pin)
|
||||
}
|
||||
}
|
||||
|
||||
FText UK2Node_FormatError::GetNodeTitle(ENodeTitleType::Type TitleType) const
|
||||
FText UK2Node_FormatMessage::GetNodeTitle(ENodeTitleType::Type TitleType) const
|
||||
{
|
||||
return LOCTEXT("FormatError_Title", "Format Error Message");
|
||||
if (IsFormatErrorMessage())
|
||||
{
|
||||
return LOCTEXT("FormatErrorMessage_Title", "Format Error Message");
|
||||
}
|
||||
else
|
||||
{
|
||||
return LOCTEXT("FormatMessage_Title", "Format Message");
|
||||
}
|
||||
}
|
||||
|
||||
FText UK2Node_FormatError::GetPinDisplayName(const UEdGraphPin* Pin) const
|
||||
FText UK2Node_FormatMessage::GetPinDisplayName(const UEdGraphPin* Pin) const
|
||||
{
|
||||
// The exec pins don't need labels.
|
||||
if (Pin->PinType.PinCategory == UEdGraphSchema_K2::PC_Exec)
|
||||
@@ -227,10 +244,10 @@ FText UK2Node_FormatError::GetPinDisplayName(const UEdGraphPin* Pin) const
|
||||
return FText::FromName(Pin->PinName);
|
||||
}
|
||||
|
||||
void UK2Node_FormatError::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent)
|
||||
void UK2Node_FormatMessage::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent)
|
||||
{
|
||||
const FName PropertyName = (PropertyChangedEvent.Property ? PropertyChangedEvent.Property->GetFName() : NAME_None);
|
||||
if (PropertyName == GET_MEMBER_NAME_CHECKED(UK2Node_FormatError, PinNames))
|
||||
if (PropertyName == GET_MEMBER_NAME_CHECKED(UK2Node_FormatMessage, PinNames))
|
||||
{
|
||||
ReconstructNode();
|
||||
}
|
||||
@@ -238,13 +255,13 @@ void UK2Node_FormatError::PostEditChangeProperty(struct FPropertyChangedEvent& P
|
||||
GetGraph()->NotifyNodeChanged(this);
|
||||
}
|
||||
|
||||
void UK2Node_FormatError::PinConnectionListChanged(UEdGraphPin* Pin)
|
||||
void UK2Node_FormatMessage::PinConnectionListChanged(UEdGraphPin* Pin)
|
||||
{
|
||||
Modify();
|
||||
SynchronizeArgumentPinType(Pin);
|
||||
}
|
||||
|
||||
void UK2Node_FormatError::PinDefaultValueChanged(UEdGraphPin* Pin)
|
||||
void UK2Node_FormatMessage::PinDefaultValueChanged(UEdGraphPin* Pin)
|
||||
{
|
||||
if(IsFormatPin(Pin))
|
||||
{
|
||||
@@ -255,19 +272,19 @@ void UK2Node_FormatError::PinDefaultValueChanged(UEdGraphPin* Pin)
|
||||
}
|
||||
}
|
||||
|
||||
void UK2Node_FormatError::PinTypeChanged(UEdGraphPin* Pin)
|
||||
void UK2Node_FormatMessage::PinTypeChanged(UEdGraphPin* Pin)
|
||||
{
|
||||
SynchronizeArgumentPinType(Pin);
|
||||
Super::PinTypeChanged(Pin);
|
||||
}
|
||||
|
||||
FText UK2Node_FormatError::GetTooltipText() const
|
||||
FText UK2Node_FormatMessage::GetTooltipText() const
|
||||
{
|
||||
return NodeTooltip;
|
||||
}
|
||||
|
||||
|
||||
void UK2Node_FormatError::PostReconstructNode()
|
||||
void UK2Node_FormatMessage::PostReconstructNode()
|
||||
{
|
||||
Super::PostReconstructNode();
|
||||
|
||||
@@ -284,16 +301,21 @@ void UK2Node_FormatError::PostReconstructNode()
|
||||
|
||||
// Get a function that can convert the specified type into a FFormatArgumentData.
|
||||
//
|
||||
// For example:
|
||||
// * if you pass in a pin of type 'String', it will return UlxFormatDataLibrary::FormatArgumentDataString
|
||||
// * if you pass in a pin of type 'Vector', it will return UlxFormatDataLibrary::FormatArgumentDataVector
|
||||
// and so forth.
|
||||
//
|
||||
UFunction *ToFormatArgumentData(const UEdGraphSchema_K2 *Schema, const FEdGraphPinType& PinType, bool AllowWild)
|
||||
{
|
||||
// Special case. Wildcard Pins are unconnected pins.
|
||||
//
|
||||
if (PinType.PinCategory == UEdGraphSchema_K2::PC_Wildcard && AllowWild)
|
||||
{
|
||||
return UlxFormatDataLibrary::StaticClass()->FindFunctionByName(GET_MEMBER_NAME_CHECKED(UlxFormatDataLibrary, FormatArgumentDataBlank));
|
||||
return UlxBlueprintErrorLibrary::StaticClass()->FindFunctionByName(GET_MEMBER_NAME_CHECKED(UlxBlueprintErrorLibrary, FormatArgumentDataBlank));
|
||||
}
|
||||
|
||||
// Try to find an exact match in the UlxFormatDataLibrary.
|
||||
// Try to find a match in the UlxFormatDataLibrary.
|
||||
//
|
||||
for (auto It = TFieldIterator<UFunction>(UlxFormatDataLibrary::StaticClass()); It; ++It)
|
||||
{
|
||||
@@ -305,6 +327,14 @@ UFunction *ToFormatArgumentData(const UEdGraphSchema_K2 *Schema, const FEdGraphP
|
||||
if (!Schema->ArePinTypesEquivalent(PinType, ValuePinType)) continue;
|
||||
return Function;
|
||||
}
|
||||
|
||||
// A general handler for Enums. You can override this for specific enums by
|
||||
// putting that particular enum into the UlxFormatDataLibrary.
|
||||
//
|
||||
if ((PinType.PinCategory == UEdGraphSchema_K2::PC_Byte) && (nullptr != Cast<const UEnum>(PinType.PinSubCategoryObject)))
|
||||
{
|
||||
return UlxBlueprintErrorLibrary::StaticClass()->FindFunctionByName(GET_MEMBER_NAME_CHECKED(UlxBlueprintErrorLibrary, FormatArgumentDataEnum));
|
||||
}
|
||||
|
||||
// A case for subclasses of 'Object' which are not exactly 'Object'
|
||||
//
|
||||
@@ -320,12 +350,12 @@ UFunction *ToFormatArgumentData(const UEdGraphSchema_K2 *Schema, const FEdGraphP
|
||||
|
||||
|
||||
|
||||
void UK2Node_FormatError::ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph)
|
||||
void UK2Node_FormatMessage::ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph)
|
||||
{
|
||||
Super::ExpandNode(CompilerContext, SourceGraph);
|
||||
|
||||
/**
|
||||
At the end of this, the UK2Node_FormatError will not be a part of the Blueprint, it merely handles connecting
|
||||
At the end of this, the UK2Node_FormatMessage will not be a part of the Blueprint, it merely handles connecting
|
||||
the other nodes into the Blueprint.
|
||||
*/
|
||||
|
||||
@@ -336,9 +366,19 @@ void UK2Node_FormatError::ExpandNode(class FKismetCompilerContext& CompilerConte
|
||||
MakeArrayNode->AllocateDefaultPins();
|
||||
CompilerContext.MessageLog.NotifyIntermediateObjectCreation(MakeArrayNode, this);
|
||||
|
||||
// Decide which formatting function we're going to call.
|
||||
UFunction *FormatFunction;
|
||||
if (IsFormatErrorMessage())
|
||||
{
|
||||
FormatFunction = UlxBlueprintErrorLibrary::StaticClass()->FindFunctionByName(GET_MEMBER_NAME_CHECKED(UlxBlueprintErrorLibrary, FormatErrorInternal));
|
||||
}
|
||||
else
|
||||
{
|
||||
FormatFunction = UKismetTextLibrary::StaticClass()->FindFunctionByName(GET_MEMBER_NAME_CHECKED(UKismetTextLibrary, Format));
|
||||
}
|
||||
|
||||
// This is the node that does all the Format work and outputs the message.
|
||||
UK2Node_CallFunction* CallFormatFunction = CompilerContext.SpawnIntermediateNode<UK2Node_CallFunction>(this, SourceGraph);
|
||||
UFunction *FormatFunction = UlxBlueprintErrorLibrary::StaticClass()->FindFunctionByName(GET_MEMBER_NAME_CHECKED(UlxBlueprintErrorLibrary, FormatErrorInternal));
|
||||
CallFormatFunction->SetFromFunction(FormatFunction);
|
||||
CallFormatFunction->AllocateDefaultPins();
|
||||
CompilerContext.MessageLog.NotifyIntermediateObjectCreation(CallFormatFunction, this);
|
||||
@@ -372,16 +412,23 @@ void UK2Node_FormatError::ExpandNode(class FKismetCompilerContext& CompilerConte
|
||||
CompilerContext.MessageLog.NotifyIntermediateObjectCreation(ConvertNode, this);
|
||||
UEdGraphPin *ValuePin = ConvertNode->FindPin(TEXT("Value"));
|
||||
UEdGraphPin *NamePin = ConvertNode->FindPinChecked(TEXT("Name"));
|
||||
UEdGraphPin *SubCategoryObjectPin = ConvertNode->FindPin(TEXT("PinSubCategoryObject"));
|
||||
|
||||
// Set a value for the 'Name' pin of the converter.
|
||||
ConvertNode->GetSchema()->TrySetDefaultValue(*NamePin, OriginalName);
|
||||
|
||||
// Connect the Value pin of the converter.
|
||||
// Connect the Value pin of the converter, if any.
|
||||
if (ValuePin != nullptr)
|
||||
{
|
||||
CompilerContext.MovePinLinksToIntermediate(*ArgumentPin, *ValuePin);
|
||||
}
|
||||
|
||||
// If the converter wants to know the PinSubCategoryObject, pass it in.
|
||||
if (SubCategoryObjectPin != nullptr)
|
||||
{
|
||||
SubCategoryObjectPin->DefaultObject = Cast<UObject>(ArgumentPin->PinType.PinSubCategoryObject);
|
||||
}
|
||||
|
||||
// The "Make Array" node already has one pin available, so don't create one for ArgIdx == 0
|
||||
if(ArgIdx > 0)
|
||||
{
|
||||
@@ -396,11 +443,18 @@ void UK2Node_FormatError::ExpandNode(class FKismetCompilerContext& CompilerConte
|
||||
ConvertNode->GetReturnValuePin()->MakeLinkTo(InputPin);
|
||||
}
|
||||
|
||||
// Move connection of "Format" pin to the call function's "InPattern" pin
|
||||
// Connect up other pins to the Formatting node.
|
||||
CompilerContext.MovePinLinksToIntermediate(*FindPinChecked(FormatPinName), *CallFormatFunction->FindPinChecked(TEXT("InPattern")));
|
||||
CompilerContext.MovePinLinksToIntermediate(*FindPinChecked(VerbosityPinName), *CallFormatFunction->FindPinChecked(TEXT("Verbosity")));
|
||||
CompilerContext.MovePinLinksToIntermediate(*FindPinChecked(DisplayDurationPinName), *CallFormatFunction->FindPinChecked(TEXT("DisplayDuration")));
|
||||
|
||||
if (IsFormatErrorMessage())
|
||||
{
|
||||
CompilerContext.MovePinLinksToIntermediate(*FindPinChecked(VerbosityPinName), *CallFormatFunction->FindPinChecked(TEXT("Verbosity")));
|
||||
CompilerContext.MovePinLinksToIntermediate(*FindPinChecked(DisplayDurationPinName), *CallFormatFunction->FindPinChecked(TEXT("DisplayDuration")));
|
||||
}
|
||||
else
|
||||
{
|
||||
CompilerContext.MovePinLinksToIntermediate(*FindPinChecked(ResultPinName), *CallFormatFunction->GetReturnValuePin());
|
||||
}
|
||||
|
||||
// Link up the Exec pins.
|
||||
CompilerContext.MovePinLinksToIntermediate(*GetExecPin(), *CallFormatFunction->GetExecPin());
|
||||
CompilerContext.MovePinLinksToIntermediate(*GetThenPin(), *CallFormatFunction->GetThenPin());
|
||||
@@ -409,7 +463,7 @@ void UK2Node_FormatError::ExpandNode(class FKismetCompilerContext& CompilerConte
|
||||
}
|
||||
|
||||
|
||||
UK2Node::ERedirectType UK2Node_FormatError::DoPinsMatchForReconstruction(const UEdGraphPin* NewPin, int32 NewPinIndex, const UEdGraphPin* OldPin, int32 OldPinIndex) const
|
||||
UK2Node::ERedirectType UK2Node_FormatMessage::DoPinsMatchForReconstruction(const UEdGraphPin* NewPin, int32 NewPinIndex, const UEdGraphPin* OldPin, int32 OldPinIndex) const
|
||||
{
|
||||
ERedirectType RedirectType = ERedirectType_None;
|
||||
|
||||
@@ -454,7 +508,7 @@ UK2Node::ERedirectType UK2Node_FormatError::DoPinsMatchForReconstruction(const U
|
||||
return RedirectType;
|
||||
}
|
||||
|
||||
bool UK2Node_FormatError::IsConnectionDisallowed(const UEdGraphPin* MyPin, const UEdGraphPin* OtherPin, FString& OutReason) const
|
||||
bool UK2Node_FormatMessage::IsConnectionDisallowed(const UEdGraphPin* MyPin, const UEdGraphPin* OtherPin, FString& OutReason) const
|
||||
{
|
||||
// The following pins cannot be connected. They are meant to be hardwired constants.
|
||||
if (IsFormatPin(MyPin))
|
||||
@@ -481,7 +535,7 @@ bool UK2Node_FormatError::IsConnectionDisallowed(const UEdGraphPin* MyPin, const
|
||||
}
|
||||
|
||||
|
||||
void UK2Node_FormatError::GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const
|
||||
void UK2Node_FormatMessage::GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const
|
||||
{
|
||||
// actions get registered under specific object-keys; the idea is that
|
||||
// actions might have to be updated (or deleted) if their object-key is
|
||||
@@ -501,10 +555,33 @@ void UK2Node_FormatError::GetMenuActions(FBlueprintActionDatabaseRegistrar& Acti
|
||||
}
|
||||
}
|
||||
|
||||
FText UK2Node_FormatError::GetMenuCategory() const
|
||||
FText UK2Node_FormatMessage::GetMenuCategory() const
|
||||
{
|
||||
return FEditorCategoryUtils::GetCommonCategory(FCommonEditorCategory::Text);
|
||||
}
|
||||
|
||||
UK2Node_FormatMessage::UK2Node_FormatMessage(const FObjectInitializer& ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
NodeTooltip = LOCTEXT("NodeTooltip",
|
||||
"Format a message, and output it as Text.\n"
|
||||
"\n"
|
||||
" \u2022 Use {ArgName} to denote format arguments, giving each argument a different ArgName.\n"
|
||||
"\n"
|
||||
);
|
||||
}
|
||||
|
||||
UK2Node_FormatErrorMessage::UK2Node_FormatErrorMessage(const FObjectInitializer& ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
NodeTooltip = LOCTEXT("NodeTooltip",
|
||||
"Output an error, warning, or informational message to the log file.\n"
|
||||
"\n"
|
||||
" \u2022 Use {ArgName} to denote format arguments, giving each argument a different ArgName.\n"
|
||||
"\n"
|
||||
"It is often desirable to use this in conjunction with a separate utility that\n"
|
||||
"pauses the execution of the blueprint whenever an error is logged."
|
||||
);
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user