diff --git a/Content/Widgets/HUD/BP_HUDWidget.uasset b/Content/Widgets/HUD/BP_HUDWidget.uasset index 3715442..4055080 100644 --- a/Content/Widgets/HUD/BP_HUDWidget.uasset +++ b/Content/Widgets/HUD/BP_HUDWidget.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fb07fd9c1fb2ebf0469bafa5bd0d1d8258b2b6f3ea85e18f9bb576d93190b300 -size 111070 +oid sha256:097c58be0bbe9df05e980eb49cd8e615cd7fb1ed12c2370c02b2457baae9084f +size 38915 diff --git a/Source/vampires/VampirePlayerController.cpp b/Source/vampires/VampirePlayerController.cpp index a500880..ff004a8 100644 --- a/Source/vampires/VampirePlayerController.cpp +++ b/Source/vampires/VampirePlayerController.cpp @@ -32,6 +32,8 @@ void AVampirePlayerController::OnPossess(APawn* aPawn) gamemode->OnEnemyDeathCountIncrementDelegate.AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD); UpdateKillCountHUD(gamemode->GetEnemyDeathCount()); } + + GetWorld()->GetTimerManager().SetTimer(pawnLifeTimeHandle, this, &AVampirePlayerController::UpdateTimerHUD, 1.0f, true,0.f); if (currentPlayerHUD) { @@ -56,6 +58,14 @@ void AVampirePlayerController::UpdatePlayerLevelHUD(int level) } } +void AVampirePlayerController::UpdateTimerHUD() +{ + if (currentPlayerHUD) + { + currentPlayerHUD->UpdateTimerBlock(GetPawn()); + } +} + void AVampirePlayerController::UpdateKillCountHUD(int killCount) { if (currentPlayerHUD) diff --git a/Source/vampires/VampirePlayerController.h b/Source/vampires/VampirePlayerController.h index bafc124..17a1385 100644 --- a/Source/vampires/VampirePlayerController.h +++ b/Source/vampires/VampirePlayerController.h @@ -24,6 +24,8 @@ private: TObjectPtr 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); }; diff --git a/Source/vampires/Widgets/HUDWidget.cpp b/Source/vampires/Widgets/HUDWidget.cpp index 85a4516..30f06dc 100644 --- a/Source/vampires/Widgets/HUDWidget.cpp +++ b/Source/vampires/Widgets/HUDWidget.cpp @@ -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) diff --git a/Source/vampires/Widgets/HUDWidget.h b/Source/vampires/Widgets/HUDWidget.h index 290f9f2..ad88deb 100644 --- a/Source/vampires/Widgets/HUDWidget.h +++ b/Source/vampires/Widgets/HUDWidget.h @@ -39,7 +39,7 @@ public: void UpdateLevelBlock(int level); UFUNCTION() - void UpdateTimerBlock(); + void UpdateTimerBlock(APawn* pawn); UFUNCTION() void UpdateKillBlock(int killCount);