From 0b7049cf5a5e80b974b5684df8664ea1d3ba5314 Mon Sep 17 00:00:00 2001 From: jyelon Date: Tue, 24 Sep 2024 18:58:13 -0400 Subject: [PATCH] Rearrange all Blueprint functions into better categories --- Source/Integration/AnimQueue.h | 16 +++--- Source/Integration/IntegrationGameModeBase.h | 14 ++--- Source/Integration/LuaCall.h | 26 ++++----- Source/Integration/Tangible.cpp | 41 +------------- Source/Integration/Tangible.h | 35 +++++------- Source/Integration/UtilityLibrary.cpp | 59 ++++++++++++++++++++ Source/Integration/UtilityLibrary.h | 36 ++++++++++++ 7 files changed, 137 insertions(+), 90 deletions(-) create mode 100644 Source/Integration/UtilityLibrary.cpp create mode 100644 Source/Integration/UtilityLibrary.h diff --git a/Source/Integration/AnimQueue.h b/Source/Integration/AnimQueue.h index ea85ee7e..987545c0 100644 --- a/Source/Integration/AnimQueue.h +++ b/Source/Integration/AnimQueue.h @@ -92,28 +92,28 @@ class INTEGRATION_API UlxAnimationStepLibrary : public UObject GENERATED_BODY() public: - UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex") + UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step") static FString AnimationStepDebugString(const FlxAnimationStep& step); - UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "into"), Category = Luprex) + UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "into"), Category = "Luprex|Animation Step") static void UnpackAnimationStep(UObject* into, const FlxAnimationStep& step, const FString& VariableNamePrefix = TEXT("aq")); - UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex") + UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step") static bool AnimationStepEqual(const FlxAnimationStep &StepA, const FlxAnimationStep &StepB); - UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex") + UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step") static bool AnimationStepIsIdle(const FlxAnimationStep &step); - UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex") + UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step") static FVector AnimationStepGetVector(const FlxAnimationStep& step, const FString& name); - UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex") + UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step") static double AnimationStepGetFloat(const FlxAnimationStep& step, const FString& name); - UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex") + UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step") static FString AnimationStepGetString(const FlxAnimationStep& step, const FString& name); - UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex") + UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Luprex|Animation Step") static bool AnimationStepGetBool(const FlxAnimationStep& step, const FString& name); }; diff --git a/Source/Integration/IntegrationGameModeBase.h b/Source/Integration/IntegrationGameModeBase.h index cb714d48..05f2bda3 100644 --- a/Source/Integration/IntegrationGameModeBase.h +++ b/Source/Integration/IntegrationGameModeBase.h @@ -35,26 +35,26 @@ public: void ResetToInitialState(); // Set the entire contents of the console output box. - UFUNCTION(BlueprintImplementableEvent, Category = "Luprex") + UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Miscellaneous") void ConsoleSetOutput(const FString& text); // This is called by the GUI whenever the user hits enter. - UFUNCTION(BlueprintCallable, Category = "Luprex") + UFUNCTION(BlueprintCallable, Category = "Luprex|Miscellaneous") void ConsoleSendInput(const FString& text); - UFUNCTION(BlueprintCallable, Category = "Luprex") + UFUNCTION(BlueprintCallable, Category = "Luprex|Miscellaneous") int64 GetPlayerId(); - UFUNCTION(BlueprintCallable, Category = "Luprex") + UFUNCTION(BlueprintCallable, Category = "Luprex|Look-At Detection") void SetLookAt(AActor *actor) { CurrentLookAt = actor; } - UFUNCTION(BlueprintCallable, Category = "Luprex") + UFUNCTION(BlueprintCallable, Category = "Luprex|Look-At Detection") AActor *GetLookAt() const { return CurrentLookAt; } - UFUNCTION(BlueprintCallable, Category = "Luprex") + UFUNCTION(BlueprintCallable, Category = "Luprex|Look-At Detection") bool LookAtChanged() const { return CurrentLookAt != PreviousLookAt; } - UFUNCTION(BlueprintImplementableEvent, Category = "Luprex") + UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Look-At Detection") void CalculateLookAt(AActor *Player, APlayerController *PlayerController, APlayerCameraManager *Camera); // Assemble a lua call. To call into lua: diff --git a/Source/Integration/LuaCall.h b/Source/Integration/LuaCall.h index 01ffb1cc..06775473 100644 --- a/Source/Integration/LuaCall.h +++ b/Source/Integration/LuaCall.h @@ -26,43 +26,43 @@ class INTEGRATION_API UlxLuaCallLibrary : public UObject GENERATED_BODY() public: - UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = Luprex) + UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function") static void LuaCallBegin(UObject *context, const FString &cname, const FString &fname); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = Luprex) + UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function") static void LuaCallAddStringParameter(UObject *context, const FString &pstring); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = Luprex) + UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function") static void LuaCallAddFloatParameter(UObject *context, double pfloat); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = Luprex) + UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function") static void LuaCallAddVectorParameter(UObject *context, const FVector &pvector); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = Luprex) + UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function") static void LuaCallAddBooleanParameter(UObject *context, bool pbool); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = Luprex) + UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function") static void LuaCallInvoke(UObject *context, AActor *place); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = Luprex) + UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function") static void LuaCallProbe(UObject *context, AActor *place); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = Luprex) + UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function") static void InvokeEngioMove(UObject *context, const FString &action, const FVector &xyz, double facing); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = Luprex) + UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function") static ELpxSimpleDynamicTag LuaCallNextResultType(UObject *context); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = Luprex) + UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function") static FString LuaCallGetStringResult(UObject *context); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = Luprex) + UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function") static double LuaCallGetFloatResult(UObject *context); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = Luprex) + UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function") static FVector LuaCallGetVectorResult(UObject *context); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = Luprex) + UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function") static bool LuaCallGetBooleanResult(UObject *context); }; diff --git a/Source/Integration/Tangible.cpp b/Source/Integration/Tangible.cpp index 06d22f71..33499d64 100644 --- a/Source/Integration/Tangible.cpp +++ b/Source/Integration/Tangible.cpp @@ -6,7 +6,7 @@ #include "IntegrationGameModeBase.h" #define DEFAULT_BLUEPRINT (TEXT("TangibleStaticMesh")) -#define LOCTEXT_NAMESPACE "Tangible" +#define LOCTEXT_NAMESPACE "Luprex Tangible" UlxTangible::UlxTangible() { @@ -176,42 +176,3 @@ void UlxTangible::SetAutoFinish(AActor *target, const FString &action, const FVe tan->AnimTracker.SetAutoFinish(action, xyz); } -void UlxTangible::Assert(bool condition, const FString &message) { - if (!condition) { - FBlueprintExceptionInfo ExceptionInfo(EBlueprintExceptionType::FatalError, FText::FromString(message)); - FBlueprintCoreDelegates::ThrowScriptException(FFrame::GetThreadLocalTopStackFrame()->Object, *FFrame::GetThreadLocalTopStackFrame(), ExceptionInfo); - } -} - -void UlxTangible::CallFunctionByName(UObject *object, const FString &namepart1, const FString &namepart2, const FString &fallback) { - FString fullname = namepart1 + namepart2; - if (!IsValid(object)) { - const FBlueprintExceptionInfo ExceptionInfo( - EBlueprintExceptionType::FatalError, - LOCTEXT("CallFunctionByName_ObjectIsNotValid", "In CallFunctionByName, object passed in is not valid.") - ); - FBlueprintCoreDelegates::ThrowScriptException(FFrame::GetThreadLocalTopStackFrame()->Object, *FFrame::GetThreadLocalTopStackFrame(), ExceptionInfo); - return; - } - UFunction* function = object->FindFunction(FName(*fullname)); - if (function == nullptr) { - function = object->FindFunction(FName(*fallback)); - if (function == nullptr) { - const FBlueprintExceptionInfo ExceptionInfo( - EBlueprintExceptionType::FatalError, - LOCTEXT("CallFunctionByName_NoSuchFunction", "In CallFunctionByName, cannot find the named function or the fallback function.") - ); - FBlueprintCoreDelegates::ThrowScriptException(FFrame::GetThreadLocalTopStackFrame()->Object, *FFrame::GetThreadLocalTopStackFrame(), ExceptionInfo); - return; - } - } - if (function->ParmsSize != 0) { - const FBlueprintExceptionInfo ExceptionInfo( - EBlueprintExceptionType::FatalError, - LOCTEXT("CallFunctionByName_FunctionHasParameters", "CallFunctionByName can only call functions that have no parameters and no return values.") - ); - FBlueprintCoreDelegates::ThrowScriptException(FFrame::GetThreadLocalTopStackFrame()->Object, *FFrame::GetThreadLocalTopStackFrame(), ExceptionInfo); - return; - } - object->ProcessEvent(function, nullptr); -} diff --git a/Source/Integration/Tangible.h b/Source/Integration/Tangible.h index 597ed572..d9699d05 100644 --- a/Source/Integration/Tangible.h +++ b/Source/Integration/Tangible.h @@ -32,10 +32,10 @@ class INTEGRATION_API IlxTangibleInterface // Add interface functions to this class. This is the class that will be inherited to implement this interface. public: - UFUNCTION(BlueprintImplementableEvent, Category = "Tangible Functionality") + UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Animation Queue") bool AnimationQueueChanged(); - UFUNCTION(BlueprintImplementableEvent, Category = "Tangible Functionality") + UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Tangible") void BecomePossessed(); }; @@ -157,33 +157,24 @@ private: void SetActorBlueprint(const FString &name); public: - UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = Luprex) + UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Animation Queue") static void GetCurrentAnimation(AActor *target, FlxAnimationStep &step); - UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = Luprex) + UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Animation Queue") static void FinishedAnimation(AActor *target, const FlxAnimationStep &step, bool AutoUpdateXYZ = true, bool AutoUpdateFacing = true, bool AutoUpdatePlane = true); - UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = Luprex) - static FString GetTangiblePlane(AActor* target); - - UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = Luprex) - static void SetTangiblePlane(AActor* target, const FString& plane); - - UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = Luprex) - static bool IsCurrentPlayer(AActor *target); - - UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = Luprex) + UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Animation Queue") static void SetAutoFinish(AActor *target, const FString &action, const FVector &xyz); - // Quit the game, reporting an error message to the log. - UFUNCTION(BlueprintCallable, Category = Luprex) - static void Assert(bool condition, const FString &ErrorMessage); - - // Call a function by name, on any UObject. If the function doesn't exist, calls - // the fallback function instead. If that isn't found either, returns false. - UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = Luprex) - static void CallFunctionByName(UObject *target, const FString &NamePart1, const FString &NamePart2, const FString &fallback); + UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Tangible") + static FString GetTangiblePlane(AActor* target); + + UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Tangible") + static void SetTangiblePlane(AActor* target, const FString& plane); + + UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Tangible") + static bool IsCurrentPlayer(AActor *target); }; diff --git a/Source/Integration/UtilityLibrary.cpp b/Source/Integration/UtilityLibrary.cpp new file mode 100644 index 00000000..1374b6c5 --- /dev/null +++ b/Source/Integration/UtilityLibrary.cpp @@ -0,0 +1,59 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "UtilityLibrary.h" + +#define LOCTEXT_NAMESPACE "Luprex Utility" + +void UlxUtilityLibrary::Assert(bool condition, const FString &message) { + if (!condition) { + FBlueprintExceptionInfo ExceptionInfo(EBlueprintExceptionType::FatalError, FText::FromString(message)); + FBlueprintCoreDelegates::ThrowScriptException(FFrame::GetThreadLocalTopStackFrame()->Object, *FFrame::GetThreadLocalTopStackFrame(), ExceptionInfo); + } +} + +void UlxUtilityLibrary::CallFunctionByName(UObject *object, const FString &namepart1, const FString &namepart2, const FString &fallback) { + FString fullname = namepart1 + namepart2; + if (!IsValid(object)) { + const FBlueprintExceptionInfo ExceptionInfo( + EBlueprintExceptionType::FatalError, + LOCTEXT("CallFunctionByName_ObjectIsNotValid", "In CallFunctionByName, object passed in is not valid.") + ); + FBlueprintCoreDelegates::ThrowScriptException(FFrame::GetThreadLocalTopStackFrame()->Object, *FFrame::GetThreadLocalTopStackFrame(), ExceptionInfo); + return; + } + UFunction* function = object->FindFunction(FName(*fullname)); + if (function == nullptr) { + function = object->FindFunction(FName(*fallback)); + if (function == nullptr) { + const FBlueprintExceptionInfo ExceptionInfo( + EBlueprintExceptionType::FatalError, + LOCTEXT("CallFunctionByName_NoSuchFunction", "In CallFunctionByName, cannot find the named function or the fallback function.") + ); + FBlueprintCoreDelegates::ThrowScriptException(FFrame::GetThreadLocalTopStackFrame()->Object, *FFrame::GetThreadLocalTopStackFrame(), ExceptionInfo); + return; + } + } + if (function->ParmsSize != 0) { + const FBlueprintExceptionInfo ExceptionInfo( + EBlueprintExceptionType::FatalError, + LOCTEXT("CallFunctionByName_FunctionHasParameters", "CallFunctionByName can only call functions that have no parameters and no return values.") + ); + FBlueprintCoreDelegates::ThrowScriptException(FFrame::GetThreadLocalTopStackFrame()->Object, *FFrame::GetThreadLocalTopStackFrame(), ExceptionInfo); + return; + } + object->ProcessEvent(function, nullptr); +} + +FBox UlxUtilityLibrary::GetActorBounds(const AActor *target, bool bOnlyCollidingComponents, bool bIncludeFromChildActors) +{ + FVector ActorOrigin; + FVector BoxExtent; + + // First argument is bOnlyCollidingComponents - if you want to get the bounds for components that don't have collision enabled then set to false + // Last argument is bIncludeFromChildActors. Usually this won't do anything but if we've child-ed an actor - like a gun child-ed to a character + // then we wouldn't want the gun to be part of the bounds so set to false + target->GetActorBounds(bOnlyCollidingComponents, ActorOrigin, BoxExtent, bIncludeFromChildActors); + + return FBox::BuildAABB(ActorOrigin, BoxExtent); +} diff --git a/Source/Integration/UtilityLibrary.h b/Source/Integration/UtilityLibrary.h new file mode 100644 index 00000000..9e916cec --- /dev/null +++ b/Source/Integration/UtilityLibrary.h @@ -0,0 +1,36 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "UtilityLibrary.generated.h" + +/** + * + * UlxUtilityLibrary is for functions that are just generally-useful functionality + * that Unreal includes, but for some reason was not made accessible to Blueprints. + * + */ +UCLASS() +class INTEGRATION_API UlxUtilityLibrary : public UObject +{ + GENERATED_BODY() + +public: + + // If condition is false, quit the game, reporting an error message to the log. + // + UFUNCTION(BlueprintCallable, Category = "Luprex|Utility") + static void Assert(bool condition, const FString &ErrorMessage); + + // Call a function by name, on any UObject. If the function doesn't exist, calls + // the fallback function instead. If that isn't found either, returns false. + // + UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Utility") + static void CallFunctionByName(UObject *target, const FString &NamePart1, const FString &NamePart2, const FString &fallback); + + // Get the axis-aligned bounding box of an actor. + // + UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Utility") + static FBox GetActorBounds(const AActor *target, bool bOnlyCollidingComponents = false, bool bIncludeFromChildActors = false); +};