diff --git a/Content/Widgets/HUD/BP_HUDWidget.uasset b/Content/Widgets/HUD/BP_HUDWidget.uasset index 4055080..633d520 100644 --- a/Content/Widgets/HUD/BP_HUDWidget.uasset +++ b/Content/Widgets/HUD/BP_HUDWidget.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:097c58be0bbe9df05e980eb49cd8e615cd7fb1ed12c2370c02b2457baae9084f -size 38915 +oid sha256:b3540ecb75c9bbdfefea7e713e44caa0679495a90fbe422d04b2c1fedd5cca46 +size 40162 diff --git a/Source/vampires/GoldComponent.cpp b/Source/vampires/GoldComponent.cpp index c871271..111158d 100644 --- a/Source/vampires/GoldComponent.cpp +++ b/Source/vampires/GoldComponent.cpp @@ -16,13 +16,13 @@ UGoldComponent::UGoldComponent() void UGoldComponent::IncrementGold(int value) { CurrentGold += value; - OnGoldGained.ExecuteIfBound(); + OnGoldGained.Broadcast(CurrentGold); } void UGoldComponent::SetCurrentGold(int value) { CurrentGold = value; - OnGoldGained.ExecuteIfBound(); + OnGoldGained.Broadcast(CurrentGold); } int UGoldComponent::GetCurrentGold() diff --git a/Source/vampires/GoldComponent.h b/Source/vampires/GoldComponent.h index 47e2522..026dd3c 100644 --- a/Source/vampires/GoldComponent.h +++ b/Source/vampires/GoldComponent.h @@ -6,7 +6,7 @@ #include "Components/ActorComponent.h" #include "GoldComponent.generated.h" -DECLARE_DELEGATE(FOnGoldGainedDelegate) +DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnGoldGainedDelegate, int, gold); UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class VAMPIRES_API UGoldComponent : public UActorComponent diff --git a/Source/vampires/VampirePlayerController.cpp b/Source/vampires/VampirePlayerController.cpp index 18c8370..c477d94 100644 --- a/Source/vampires/VampirePlayerController.cpp +++ b/Source/vampires/VampirePlayerController.cpp @@ -6,6 +6,7 @@ #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" #include "EXPComponent.h" +#include "GoldComponent.h" #include "Inputable.h" #include "VampireGameMode.h" #include "Blueprint/UserWidget.h" @@ -40,6 +41,12 @@ void AVampirePlayerController::OnPossess(APawn* aPawn) UpdatePlayerLevelHUD(expComponent->GetCurrentLevel()); } + if (UGoldComponent* goldComponent = aPawn->GetComponentByClass()) + { + goldComponent->OnGoldGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdateGoldCountHUD); + UpdateGoldCountHUD(goldComponent->GetCurrentGold()); + } + if (AVampireGameMode* gamemode = Cast(UGameplayStatics::GetGameMode(GetWorld()))) { gamemode->OnEnemyDeathCountIncrementDelegate.AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD); @@ -171,3 +178,11 @@ void AVampirePlayerController::UpdateKillCountHUD(int killCount) currentPlayerHUD->UpdateKillBlock(killCount); } } + +void AVampirePlayerController::UpdateGoldCountHUD(int goldCount) +{ + if (currentPlayerHUD) + { + currentPlayerHUD->UpdateGoldBlock(goldCount); + } +} diff --git a/Source/vampires/VampirePlayerController.h b/Source/vampires/VampirePlayerController.h index d06374e..95f0525 100644 --- a/Source/vampires/VampirePlayerController.h +++ b/Source/vampires/VampirePlayerController.h @@ -74,4 +74,7 @@ protected: UFUNCTION() void UpdateKillCountHUD(int killCount); + + UFUNCTION() + void UpdateGoldCountHUD(int goldCount); }; diff --git a/Source/vampires/Widgets/HUDWidget.cpp b/Source/vampires/Widgets/HUDWidget.cpp index 7f937fb..2ba0b4b 100644 --- a/Source/vampires/Widgets/HUDWidget.cpp +++ b/Source/vampires/Widgets/HUDWidget.cpp @@ -42,3 +42,8 @@ void UHUDWidget::UpdateKillBlock(int killCount) { KillBLock->SetText(FText::FromString("Kills: " + FString::FromInt(killCount))); } + +void UHUDWidget::UpdateGoldBlock(int goldCount) +{ + GoldBLock->SetText(FText::FromString("Gold: " + FString::FromInt(goldCount))); +} diff --git a/Source/vampires/Widgets/HUDWidget.h b/Source/vampires/Widgets/HUDWidget.h index 96fc5db..8e14fc9 100644 --- a/Source/vampires/Widgets/HUDWidget.h +++ b/Source/vampires/Widgets/HUDWidget.h @@ -30,6 +30,9 @@ public: UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UTextBlock* KillBLock; + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + UTextBlock* GoldBLock; + void Init(); UFUNCTION() @@ -43,5 +46,8 @@ public: UFUNCTION() void UpdateKillBlock(int killCount); + + UFUNCTION() + void UpdateGoldBlock(int goldCount); };