Move timer binding to code timer

This commit is contained in:
baz 2024-11-17 21:43:49 +00:00
parent 366dbbfda8
commit a13cad7320
5 changed files with 34 additions and 4 deletions

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

Binary file not shown.

View File

@ -33,6 +33,8 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
UpdateKillCountHUD(gamemode->GetEnemyDeathCount());
}
GetWorld()->GetTimerManager().SetTimer(pawnLifeTimeHandle, this, &AVampirePlayerController::UpdateTimerHUD, 1.0f, true,0.f);
if (currentPlayerHUD)
{
currentPlayerHUD->AddToViewport();
@ -56,6 +58,14 @@ void AVampirePlayerController::UpdatePlayerLevelHUD(int level)
}
}
void AVampirePlayerController::UpdateTimerHUD()
{
if (currentPlayerHUD)
{
currentPlayerHUD->UpdateTimerBlock(GetPawn());
}
}
void AVampirePlayerController::UpdateKillCountHUD(int killCount)
{
if (currentPlayerHUD)

View File

@ -24,6 +24,8 @@ private:
TObjectPtr<UHUDWidget> currentPlayerHUD = nullptr;
FTimerHandle pawnLifeTimeHandle;
protected:
virtual void OnPossess(APawn* aPawn) override;
@ -33,6 +35,9 @@ protected:
UFUNCTION()
void UpdatePlayerLevelHUD(int level);
UFUNCTION()
void UpdateTimerHUD();
UFUNCTION()
void UpdateKillCountHUD(int killCount);
};

View File

@ -19,8 +19,23 @@ void UHUDWidget::UpdateLevelBlock(int level)
LevelBlock->SetText(FText::FromString("LV" + FString::FromInt(level)));
}
void UHUDWidget::UpdateTimerBlock()
void UHUDWidget::UpdateTimerBlock(APawn* pawn)
{
int timeSinceCreation = FMath::FloorToInt(pawn->GetGameTimeSinceCreation());
FString mins = FString::FromInt(timeSinceCreation / 60);
if (timeSinceCreation / 60 < 10)
{
mins = "0" + mins;
}
FString secs = FString::FromInt(timeSinceCreation % 60);
if (timeSinceCreation % 60 < 10)
{
secs = "0" + secs;
}
TimerBLock->SetText(FText::FromString(mins + ":" + secs));
}
void UHUDWidget::UpdateKillBlock(int killCount)

View File

@ -39,7 +39,7 @@ public:
void UpdateLevelBlock(int level);
UFUNCTION()
void UpdateTimerBlock();
void UpdateTimerBlock(APawn* pawn);
UFUNCTION()
void UpdateKillBlock(int killCount);