Add gold count to HUDWidget

This commit is contained in:
baz 2025-02-08 15:36:29 +00:00
parent bac9f7c5e7
commit f5345cc4ed
7 changed files with 34 additions and 5 deletions

BIN
Content/Widgets/HUD/BP_HUDWidget.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -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()

View File

@ -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

View File

@ -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<UGoldComponent>())
{
goldComponent->OnGoldGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdateGoldCountHUD);
UpdateGoldCountHUD(goldComponent->GetCurrentGold());
}
if (AVampireGameMode* gamemode = Cast<AVampireGameMode>(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);
}
}

View File

@ -74,4 +74,7 @@ protected:
UFUNCTION()
void UpdateKillCountHUD(int killCount);
UFUNCTION()
void UpdateGoldCountHUD(int goldCount);
};

View File

@ -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)));
}

View File

@ -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);
};