Format Error Message is in good condition.

This commit is contained in:
2024-11-19 21:41:09 -05:00
parent 26fca0fca8
commit c332fea06b
2 changed files with 142 additions and 38 deletions

View File

@@ -76,7 +76,15 @@ static bool IsFormatPin(const UEdGraphPin *Pin) {
UK2Node_FormatError::UK2Node_FormatError(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
NodeTooltip = LOCTEXT("NodeTooltip", "Builds a formatted string using available format argument values.\n \u2022 Use {} to denote format arguments.\n \u2022 Argument types may be Byte, Integer, Float, Text, String, Name, Boolean, Object or ETextGender.");
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"
" \u2022 Arguments may be Byte, Integer, Float, Text, String, Name, Boolean, Object or ETextGender.\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."
);
}
void UK2Node_FormatError::AllocateDefaultPins()
@@ -198,14 +206,18 @@ FText UK2Node_FormatError::GetNodeTitle(ENodeTitleType::Type TitleType) const
FText UK2Node_FormatError::GetPinDisplayName(const UEdGraphPin* Pin) const
{
// Many pins can go unlabeled if they have default values.
if ((Pin->PinType.PinCategory == UEdGraphSchema_K2::PC_Exec) ||
IsFormatPin(Pin) || IsVerbosityPin(Pin) || IsDisplayDurationPin(Pin))
// The exec pins don't need labels.
if (Pin->PinType.PinCategory == UEdGraphSchema_K2::PC_Exec)
{
if (Pin->LinkedTo.Num() == 0) {
return FText::GetEmpty();
}
// Many pins can go unlabeled if they have default values.
if (IsFormatPin(Pin) || IsVerbosityPin(Pin) || IsDisplayDurationPin(Pin))
{
if (Pin->LinkedTo.Num() == 0)
{
return FText::GetEmpty();
} else {
return FText::FromName(Pin->PinName);
}
}
@@ -214,7 +226,7 @@ FText UK2Node_FormatError::GetPinDisplayName(const UEdGraphPin* Pin) const
return FText::FromString(ArgumentNameRemovePrefix(Pin->PinName));
}
// Probably should never get here.
// Otherwise, just return the Pin Name the normal way.
return FText::FromName(Pin->PinName);
}
@@ -596,17 +608,20 @@ FText UK2Node_FormatError::GetMenuCategory() const
return FEditorCategoryUtils::GetCommonCategory(FCommonEditorCategory::Text);
}
void UlxFormatErrorLibrary::FormatErrorInternal(ElxLogVerbosity Verbosity, ElxDisplayDuration DisplayDuration, FText InPattern, TArray<FFormatArgumentData> InArgs)
void UlxFormatErrorLibrary::FormatErrorInternal(UObject *Context, ElxLogVerbosity Verbosity, ElxDisplayDuration DisplayDuration, FText InPattern, TArray<FFormatArgumentData> InArgs)
{
// Generate the formatted string.
//
FText Message = FTextFormatter::Format(MoveTemp(InPattern), MoveTemp(InArgs), false, false);
FString MessageString = Message.ToString();
// Convert the DisplayDuration enum into a number of seconds.
//
int Seconds = int(DisplayDuration);
if (Seconds > 100) Seconds = (Seconds - 100) * 60;
// Choose a color appropriate to the verbosity level.
//
FLinearColor Color;
switch (Verbosity) {
case ElxLogVerbosity::Fatal : Color = FLinearColor(1.0, 0.6, 0.6); break;
@@ -615,21 +630,48 @@ void UlxFormatErrorLibrary::FormatErrorInternal(ElxLogVerbosity Verbosity, ElxDi
default: Color = FLinearColor(0.8, 0.8, 0.8); break;
}
// Output to Log
// Convert verbosity to an internal value.
//
ELogVerbosity::Type VerbosityValue;
switch (Verbosity) {
case ElxLogVerbosity::Fatal: UE_LOG(LogBlueprint, Fatal, TEXT("%s"), *MessageString); break;
case ElxLogVerbosity::Error: UE_LOG(LogBlueprint, Error, TEXT("%s"), *MessageString); break;
case ElxLogVerbosity::Warning: UE_LOG(LogBlueprint, Warning, TEXT("%s"), *MessageString); break;
case ElxLogVerbosity::Display: UE_LOG(LogBlueprint, Display, TEXT("%s"), *MessageString); break;
case ElxLogVerbosity::Log: UE_LOG(LogBlueprint, Log, TEXT("%s"), *MessageString); break;
case ElxLogVerbosity::Verbose: UE_LOG(LogBlueprint, Verbose, TEXT("%s"), *MessageString); break;
case ElxLogVerbosity::VeryVerbose: UE_LOG(LogBlueprint, VeryVerbose, TEXT("%s"), *MessageString); break;
case ElxLogVerbosity::Error: VerbosityValue = ELogVerbosity::Error; break;
case ElxLogVerbosity::Warning: VerbosityValue = ELogVerbosity::Warning; break;
case ElxLogVerbosity::Display: VerbosityValue = ELogVerbosity::Display; break;
case ElxLogVerbosity::Log: VerbosityValue = ELogVerbosity::Log; break;
case ElxLogVerbosity::Verbose: VerbosityValue = ELogVerbosity::Verbose; break;
case ElxLogVerbosity::VeryVerbose: VerbosityValue = ELogVerbosity::VeryVerbose; break;
case ElxLogVerbosity::Fatal: VerbosityValue = ELogVerbosity::Fatal; break;
}
// Output to Screen (Maybe)
if (Seconds != 0) {
// Get the blueprint name.
//
// Normally, the log function expects you to pass in a filename, and a log
// category name. We use the blueprint name for both.
//
// Using the blueprint name as a log category name is not technically
// correct. However, there is no correct way to create log categories
// from inside of blueprints. Doing it this way at least produces a reasonable
// message inside the log. What doesn't work correctly is the log message
// suppression system. Ie, console commands like 'log <category> verbose'
// don't have any effect here. The design of the log message suppression
// system is such that there just is no reasonable way to hook into it from
// inside of blueprints.
//
FString BlueprintNameString = Context->GetClass()->GetName();
auto BlueprintNameAnsi = StringCast<ANSICHAR>(*BlueprintNameString);
FLogCategoryName BlueprintNameLogCategory(Context->GetClass()->GetFName());
// Output to Screen, if requested.
//
if (Seconds != 0)
{
UKismetSystemLibrary::PrintText(NULL, Message, true, false, Color, Seconds, NAME_None);
}
// Output to Log
//
FMsg::Logf(BlueprintNameAnsi.Get(), 0, BlueprintNameLogCategory, VerbosityValue, TEXT("%s"), *MessageString);
}