Add gold count to HUDWidget
This commit is contained in:
parent
bac9f7c5e7
commit
f5345cc4ed
BIN
Content/Widgets/HUD/BP_HUDWidget.uasset
(Stored with Git LFS)
BIN
Content/Widgets/HUD/BP_HUDWidget.uasset
(Stored with Git LFS)
Binary file not shown.
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -74,4 +74,7 @@ protected:
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateKillCountHUD(int killCount);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateGoldCountHUD(int goldCount);
|
||||
};
|
||||
|
@ -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)));
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user