Bind updating of EXPBar in code

This commit is contained in:
baz 2024-11-16 02:22:41 +00:00
parent 0c90ade615
commit 4386f0e383
6 changed files with 50 additions and 5 deletions

BIN
Content/Player/BP_PlayerController.uasset (Stored with Git LFS)

Binary file not shown.

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

Binary file not shown.

View File

@ -4,6 +4,7 @@
#include "VampirePlayerController.h"
#include "EXPComponent.h"
#include "HealthComponent.h"
#include "Blueprint/UserWidget.h"
#include "Widgets/HUDWidget.h"
@ -15,6 +16,12 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
{
currentPlayerHUD = CreateWidget<UHUDWidget, AVampirePlayerController*>(this, PlayerHUD.Get());
if (UEXPComponent* expComponent = aPawn->GetComponentByClass<UEXPComponent>())
{
expComponent->OnEXPGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerEXPHUD);
UpdatePlayerEXPHUD(expComponent->GetCurrentEXP(), expComponent->GetCurrentLevelPercent());
}
if (currentPlayerHUD)
{
currentPlayerHUD->AddToViewport();
@ -22,3 +29,10 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
}
}
void AVampirePlayerController::UpdatePlayerEXPHUD(int exp, float currentLevelPercent)
{
if (currentPlayerHUD)
{
currentPlayerHUD->UpdateEXPBar(currentLevelPercent);
}
}

View File

@ -27,4 +27,6 @@ private:
protected:
virtual void OnPossess(APawn* aPawn) override;
UFUNCTION()
void UpdatePlayerEXPHUD(int exp, float currentLevelPercent);
};

View File

@ -3,3 +3,21 @@
#include "HUDWidget.h"
#include "Components/ProgressBar.h"
void UHUDWidget::Init()
{
}
void UHUDWidget::UpdateEXPBar(float currentLevelPercent)
{
EXPbar->SetPercent(currentLevelPercent);
}
void UHUDWidget::UpdateLevelBlock()
{
}
void UHUDWidget::UpdateTimerBlock()
{
}

View File

@ -27,4 +27,15 @@ public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* TimerBLock;
void Init();
UFUNCTION()
void UpdateEXPBar(float currentLevelPercent);
UFUNCTION()
void UpdateLevelBlock();
UFUNCTION()
void UpdateTimerBlock();
};