Bind updating of EXPBar in code
This commit is contained in:
parent
0c90ade615
commit
4386f0e383
BIN
Content/Player/BP_PlayerController.uasset (Stored with Git LFS)
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)
BIN
Content/Widgets/HUD/BP_HUDWidget.uasset (Stored with Git LFS)
Binary file not shown.
|
@ -4,6 +4,7 @@
|
||||||
#include "VampirePlayerController.h"
|
#include "VampirePlayerController.h"
|
||||||
|
|
||||||
#include "EXPComponent.h"
|
#include "EXPComponent.h"
|
||||||
|
#include "HealthComponent.h"
|
||||||
#include "Blueprint/UserWidget.h"
|
#include "Blueprint/UserWidget.h"
|
||||||
#include "Widgets/HUDWidget.h"
|
#include "Widgets/HUDWidget.h"
|
||||||
|
|
||||||
|
@ -15,6 +16,12 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
|
||||||
{
|
{
|
||||||
currentPlayerHUD = CreateWidget<UHUDWidget, AVampirePlayerController*>(this, PlayerHUD.Get());
|
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)
|
if (currentPlayerHUD)
|
||||||
{
|
{
|
||||||
currentPlayerHUD->AddToViewport();
|
currentPlayerHUD->AddToViewport();
|
||||||
|
@ -22,3 +29,10 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AVampirePlayerController::UpdatePlayerEXPHUD(int exp, float currentLevelPercent)
|
||||||
|
{
|
||||||
|
if (currentPlayerHUD)
|
||||||
|
{
|
||||||
|
currentPlayerHUD->UpdateEXPBar(currentLevelPercent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -27,4 +27,6 @@ private:
|
||||||
protected:
|
protected:
|
||||||
virtual void OnPossess(APawn* aPawn) override;
|
virtual void OnPossess(APawn* aPawn) override;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void UpdatePlayerEXPHUD(int exp, float currentLevelPercent);
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,3 +3,21 @@
|
||||||
|
|
||||||
#include "HUDWidget.h"
|
#include "HUDWidget.h"
|
||||||
|
|
||||||
|
#include "Components/ProgressBar.h"
|
||||||
|
|
||||||
|
void UHUDWidget::Init()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void UHUDWidget::UpdateEXPBar(float currentLevelPercent)
|
||||||
|
{
|
||||||
|
EXPbar->SetPercent(currentLevelPercent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UHUDWidget::UpdateLevelBlock()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void UHUDWidget::UpdateTimerBlock()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ UCLASS()
|
||||||
class VAMPIRES_API UHUDWidget : public UUserWidget
|
class VAMPIRES_API UHUDWidget : public UUserWidget
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||||
|
@ -26,5 +26,16 @@ public:
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||||
UTextBlock* TimerBLock;
|
UTextBlock* TimerBLock;
|
||||||
|
|
||||||
|
void Init();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void UpdateEXPBar(float currentLevelPercent);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void UpdateLevelBlock();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void UpdateTimerBlock();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue