From dd8cc06e333c02210c0acdfc1b3ab9bfd3603865 Mon Sep 17 00:00:00 2001 From: baz Date: Sat, 16 Nov 2024 02:18:36 +0000 Subject: [PATCH] Make delegates DYNAMIC_MULTICAST --- Source/vampires/EXPComponent.cpp | 12 ++++++------ Source/vampires/EXPComponent.h | 7 +++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Source/vampires/EXPComponent.cpp b/Source/vampires/EXPComponent.cpp index d0acb78..2f0b25d 100644 --- a/Source/vampires/EXPComponent.cpp +++ b/Source/vampires/EXPComponent.cpp @@ -19,13 +19,13 @@ void UEXPComponent::IncrementEXP(int value) int oldLevel = CurrentLevel; CurrentEXP += value; - OnEXPGained.ExecuteIfBound(value); + OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent()); CurrentLevel = FMath::Floor(CurrentEXP / 100.0f); if (CurrentLevel != oldLevel) { - OnEXPLevelUp.ExecuteIfBound(CurrentLevel); + OnEXPLevelUp.Broadcast(CurrentLevel); } } @@ -36,13 +36,13 @@ void UEXPComponent::SetCurrentEXP(int value) // TODO: I should be updating the level here CurrentEXP = value; - OnEXPGained.ExecuteIfBound(value); + OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent()); CurrentLevel = FMath::Floor(CurrentEXP / 100.0f); if (CurrentLevel != oldLevel) { - OnEXPLevelUp.ExecuteIfBound(CurrentLevel); + OnEXPLevelUp.Broadcast(CurrentLevel); } } @@ -60,8 +60,8 @@ void UEXPComponent::Reset() { CurrentEXP = 0; CurrentLevel = 0; - OnEXPGained.ExecuteIfBound(CurrentEXP); - OnEXPLevelUp.ExecuteIfBound(CurrentLevel); + OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent()); + OnEXPLevelUp.Broadcast(CurrentLevel); } float UEXPComponent::GetCurrentLevelPercent() diff --git a/Source/vampires/EXPComponent.h b/Source/vampires/EXPComponent.h index 9e137da..465391d 100644 --- a/Source/vampires/EXPComponent.h +++ b/Source/vampires/EXPComponent.h @@ -6,8 +6,8 @@ #include "Components/ActorComponent.h" #include "EXPComponent.generated.h" -DECLARE_DELEGATE_OneParam(FOnEXPGainedDelegate, int) -DECLARE_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int) +DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnEXPGainedDelegate, int, exp, float, currentLevelPercent); +DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int, level); UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class VAMPIRES_API UEXPComponent : public UActorComponent @@ -15,7 +15,10 @@ class VAMPIRES_API UEXPComponent : public UActorComponent GENERATED_BODY() public: + + UPROPERTY(BlueprintAssignable, Category="EXP") FOnEXPGainedDelegate OnEXPGained; + UPROPERTY(BlueprintAssignable, Category="EXP") FOnEXPLevelUpDelegate OnEXPLevelUp; protected: