diff --git a/Plugins/UEWingman/Source/UEWingman/Private/WingTypes.cpp b/Plugins/UEWingman/Source/UEWingman/Private/WingTypes.cpp index 3a277301..9c78be5d 100644 --- a/Plugins/UEWingman/Source/UEWingman/Private/WingTypes.cpp +++ b/Plugins/UEWingman/Source/UEWingman/Private/WingTypes.cpp @@ -1,4 +1,5 @@ #include "WingTypes.h" +#include "WingUtils.h" #include "WingServer.h" #include "Editor.h" #include "EdGraphSchema_K2.h" @@ -12,7 +13,7 @@ // Choose Short Name // --------------------------------------------------------------------------- -FString UWingTypes::GetNameWithoutUnderscoreC(const UObject *Obj) +FString UWingTypes::GetProposedName(const UObject *Obj) { FString Name = Obj->GetName(); if (Name.EndsWith(TEXT("_C"))) @@ -23,6 +24,7 @@ FString UWingTypes::GetNameWithoutUnderscoreC(const UObject *Obj) Name.LeftChopInline(2); } } + WingUtils::SanitizeNameInPlace(Name); return Name; } @@ -67,10 +69,18 @@ FString UWingTypes::ChooseShortName(const FString &Proposal, const FString &Full FString UWingTypes::ChooseShortName(const UObject* Obj) { + // If it's a blueprint, register its generated class instead. + if (const UBlueprint* BP = Cast(Obj)) + { + if (BP->GeneratedClass) + return ChooseShortName(BP->GeneratedClass); + return FString(); + } + if (!Cast(Obj) && !Cast(Obj) && !Cast(Obj)) return FString(); - FString ProposedName = GetNameWithoutUnderscoreC(Obj); + FString ProposedName = GetProposedName(Obj); return ChooseShortName(ProposedName, Obj->GetPathName()); } @@ -208,6 +218,15 @@ FString UWingTypes::TypeToText(const UObject* Obj) return Types->ChooseShortName(Obj); } +FString UWingTypes::TypeToTextOrDie(const UObject* Obj) +{ + UWingTypes* Types = GEditor->GetEditorSubsystem(); + if (!Types) return FString(); + FString Result = Types->ChooseShortName(Obj); + check(!Result.IsEmpty()); + return Result; +} + // --------------------------------------------------------------------------- // Subsystem lifecycle // --------------------------------------------------------------------------- diff --git a/Plugins/UEWingman/Source/UEWingman/Private/WingUtils.cpp b/Plugins/UEWingman/Source/UEWingman/Private/WingUtils.cpp index a4a10910..c3915cde 100644 --- a/Plugins/UEWingman/Source/UEWingman/Private/WingUtils.cpp +++ b/Plugins/UEWingman/Source/UEWingman/Private/WingUtils.cpp @@ -106,7 +106,7 @@ FString WingUtils::FormatName(const UWorld *World) FString WingUtils::FormatName(const UBlueprint *BP) { - return BP->GetPathName(); + return UWingTypes::TypeToTextOrDie(BP); } FString WingUtils::FormatName(const UActorComponent *C) @@ -121,7 +121,6 @@ FString WingUtils::FormatName(const USCS_Node *Node) FString WingUtils::FormatName(const UEdGraph *Graph) { - return SanitizeName(Graph->GetName()); } @@ -147,9 +146,16 @@ FString WingUtils::FormatName(const FBPVariableDescription &Var) FString WingUtils::FormatName(const UStruct *Struct) { + if (Cast(Struct) || Cast(Struct)) + return UWingTypes::TypeToTextOrDie(Struct); return SanitizeName(Struct->GetName()); } +FString WingUtils::FormatName(const UClass *Class) +{ + return UWingTypes::TypeToTextOrDie(Class); +} + FString WingUtils::FormatName(const UMaterial *Material) { return Material->GetPathName(); @@ -197,12 +203,12 @@ FString WingUtils::FormatName(const UTexture *Texture) FString WingUtils::FormatName(const UScriptStruct *Struct) { - return SanitizeName(Struct->GetName());; + return UWingTypes::TypeToTextOrDie(Struct); } FString WingUtils::FormatName(const UEnum *Enum) { - return SanitizeName(Enum->GetName()); + return UWingTypes::TypeToTextOrDie(Enum); } FString WingUtils::FormatName(const FProperty *Prop) diff --git a/Plugins/UEWingman/Source/UEWingman/Public/WingTypes.h b/Plugins/UEWingman/Source/UEWingman/Public/WingTypes.h index a38606d1..8cc904d6 100644 --- a/Plugins/UEWingman/Source/UEWingman/Public/WingTypes.h +++ b/Plugins/UEWingman/Source/UEWingman/Public/WingTypes.h @@ -18,20 +18,25 @@ public: virtual void Initialize(FSubsystemCollectionBase& Collection) override; virtual void Deinitialize() override; - // Convert a pin type to a type string. Returns empty string on failure. + // Convert a pin type to a type string. Returns empty string + // on failure. static FString TypeToText(const FEdGraphPinType& PinType); static FString TypeToText(const FProperty *Property); - // Get the short name for a UClass, UScriptStruct, or UEnum. + // Get the type name for a UClass, UScriptStruct, or UEnum. // Returns empty string if the object is not one of those types. static FString TypeToText(const UObject* Obj); + // Get the type name for a UClass, UScriptStruct, or UEnum. + // Check fail if the result is empty. + static FString TypeToTextOrDie(const UObject* Obj); + // Try to parse a type. If there's a problem, returns an error // message. If all goes well, returns empty string. static FString TryTextToType(const FString& Text, FEdGraphPinType& OutPinType); // Try to parse a type. If there's a problem, prints an error - // via UWingServer and returns false. + // message and returns false. static bool TextToType(const FString& Text, FEdGraphPinType& OutPinType); // Parse a type string and verify it's a single object class (PC_Object, @@ -50,7 +55,7 @@ private: // Get the object's name, not including the _C generated // by the blueprint compiler for generated classes. - static FString GetNameWithoutUnderscoreC(const UObject *Obj); + static FString GetProposedName(const UObject *Obj); // Reserve the short name for a primitive type. // The value stored in the map is just "PRIMITIVE". diff --git a/Plugins/UEWingman/Source/UEWingman/Public/WingUtils.h b/Plugins/UEWingman/Source/UEWingman/Public/WingUtils.h index 5d38ae7c..2f9f3dcf 100644 --- a/Plugins/UEWingman/Source/UEWingman/Public/WingUtils.h +++ b/Plugins/UEWingman/Source/UEWingman/Public/WingUtils.h @@ -58,6 +58,7 @@ public: static FString FormatName(const FMemberReference &Ref); static FString FormatName(const FBPVariableDescription &Var); static FString FormatName(const UStruct *Struct); + static FString FormatName(const UClass *Class); static FString FormatName(const UMaterial *Material); static FString FormatName(const UMaterialInstance *MaterialInstance); static FString FormatName(const UMaterialFunction *MaterialFunction);