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)
|
void UGoldComponent::IncrementGold(int value)
|
||||||
{
|
{
|
||||||
CurrentGold += value;
|
CurrentGold += value;
|
||||||
OnGoldGained.ExecuteIfBound();
|
OnGoldGained.Broadcast(CurrentGold);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UGoldComponent::SetCurrentGold(int value)
|
void UGoldComponent::SetCurrentGold(int value)
|
||||||
{
|
{
|
||||||
CurrentGold = value;
|
CurrentGold = value;
|
||||||
OnGoldGained.ExecuteIfBound();
|
OnGoldGained.Broadcast(CurrentGold);
|
||||||
}
|
}
|
||||||
|
|
||||||
int UGoldComponent::GetCurrentGold()
|
int UGoldComponent::GetCurrentGold()
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include "Components/ActorComponent.h"
|
#include "Components/ActorComponent.h"
|
||||||
#include "GoldComponent.generated.h"
|
#include "GoldComponent.generated.h"
|
||||||
|
|
||||||
DECLARE_DELEGATE(FOnGoldGainedDelegate)
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnGoldGainedDelegate, int, gold);
|
||||||
|
|
||||||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
||||||
class VAMPIRES_API UGoldComponent : public UActorComponent
|
class VAMPIRES_API UGoldComponent : public UActorComponent
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "EnhancedInputComponent.h"
|
#include "EnhancedInputComponent.h"
|
||||||
#include "EnhancedInputSubsystems.h"
|
#include "EnhancedInputSubsystems.h"
|
||||||
#include "EXPComponent.h"
|
#include "EXPComponent.h"
|
||||||
|
#include "GoldComponent.h"
|
||||||
#include "Inputable.h"
|
#include "Inputable.h"
|
||||||
#include "VampireGameMode.h"
|
#include "VampireGameMode.h"
|
||||||
#include "Blueprint/UserWidget.h"
|
#include "Blueprint/UserWidget.h"
|
||||||
@ -40,6 +41,12 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
|
|||||||
UpdatePlayerLevelHUD(expComponent->GetCurrentLevel());
|
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())))
|
if (AVampireGameMode* gamemode = Cast<AVampireGameMode>(UGameplayStatics::GetGameMode(GetWorld())))
|
||||||
{
|
{
|
||||||
gamemode->OnEnemyDeathCountIncrementDelegate.AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD);
|
gamemode->OnEnemyDeathCountIncrementDelegate.AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD);
|
||||||
@ -171,3 +178,11 @@ void AVampirePlayerController::UpdateKillCountHUD(int killCount)
|
|||||||
currentPlayerHUD->UpdateKillBlock(killCount);
|
currentPlayerHUD->UpdateKillBlock(killCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AVampirePlayerController::UpdateGoldCountHUD(int goldCount)
|
||||||
|
{
|
||||||
|
if (currentPlayerHUD)
|
||||||
|
{
|
||||||
|
currentPlayerHUD->UpdateGoldBlock(goldCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -74,4 +74,7 @@ protected:
|
|||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void UpdateKillCountHUD(int killCount);
|
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)));
|
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))
|
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||||
UTextBlock* KillBLock;
|
UTextBlock* KillBLock;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||||
|
UTextBlock* GoldBLock;
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
@ -44,4 +47,7 @@ public:
|
|||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void UpdateKillBlock(int killCount);
|
void UpdateKillBlock(int killCount);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void UpdateGoldBlock(int goldCount);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user