diff --git a/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset b/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset index 18c0edc..287227c 100644 Binary files a/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset and b/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset differ diff --git a/Source/Blaster/HUD/CharacterOverlay.h b/Source/Blaster/HUD/CharacterOverlay.h index 58c181f..874a491 100644 --- a/Source/Blaster/HUD/CharacterOverlay.h +++ b/Source/Blaster/HUD/CharacterOverlay.h @@ -34,4 +34,7 @@ public: UPROPERTY(meta = (BindWidget)) UTextBlock* CarriedAmmoValue; + UPROPERTY(meta = (BindWidget)) + UTextBlock* MatchCountdownText; + }; diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index 7c1ed29..ff10229 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -17,6 +17,13 @@ void ABlasterPlayerController::BeginPlay() BlasterHUD = Cast(GetHUD()); } +void ABlasterPlayerController::Tick(float DeltaSeconds) +{ + Super::Tick(DeltaSeconds); + + SetHUDTime(); +} + void ABlasterPlayerController::OnPossess(APawn* InPawn) { Super::OnPossess(InPawn); @@ -27,6 +34,18 @@ void ABlasterPlayerController::OnPossess(APawn* InPawn) } } +void ABlasterPlayerController::SetHUDTime() +{ + const uint32 SecondsLeft = FMath::CeilToInt(MatchTime - GetWorld()->GetTimeSeconds()); + + if (CountdownInt != SecondsLeft) + { + SetHUDMatchCountdown(MatchTime - GetWorld()->GetTimeSeconds()); + } + + CountdownInt = SecondsLeft; +} + void ABlasterPlayerController::SetHUDHealth(float Health, float MaxHealth) { BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; @@ -104,3 +123,21 @@ void ABlasterPlayerController::SetHUDCarriedAmmo(int32 Ammo) BlasterHUD->CharacterOverlay->CarriedAmmoValue->SetText(FText::FromString(CarriedAmmoAmount)); } } + +void ABlasterPlayerController::SetHUDMatchCountdown(float CountdownTime) +{ + BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; + bool bHUDValid = + BlasterHUD && + BlasterHUD->CharacterOverlay && + BlasterHUD->CharacterOverlay->MatchCountdownText; + + if (bHUDValid) + { + int32 Minutes = FMath::FloorToInt(CountdownTime / 60); + int32 Seconds = CountdownTime - Minutes * 60; + + const FString CountdownText = FString::Printf(TEXT("%02d:%02d"), Minutes, Seconds); + BlasterHUD->CharacterOverlay->MatchCountdownText->SetText(FText::FromString(CountdownText)); + } +} diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.h b/Source/Blaster/PlayerController/BlasterPlayerController.h index 44d3b9b..c4be8a6 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.h +++ b/Source/Blaster/PlayerController/BlasterPlayerController.h @@ -16,20 +16,26 @@ class BLASTER_API ABlasterPlayerController : public APlayerController public: + virtual void Tick(float DeltaSeconds) override; + virtual void OnPossess(APawn* InPawn) override; + void SetHUDHealth(float Health, float MaxHealth); void SetHUDScore(float Score); void SetHUDDefeats(int32 Defeats); void SetHUDWeaponAmmo(int32 Ammo); void SetHUDCarriedAmmo(int32 Ammo); - virtual void OnPossess(APawn* InPawn) override; + void SetHUDMatchCountdown(float CountdownTime); protected: virtual void BeginPlay() override; + void SetHUDTime(); private: UPROPERTY() class ABlasterHUD* BlasterHUD; - + + float MatchTime = 120.f; + uint32 CountdownInt = 0; };