diff --git a/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset b/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset index 6185c49..4923297 100644 Binary files a/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset and b/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset differ diff --git a/Content/Blueprints/HUD/WBP_Announcement.uasset b/Content/Blueprints/HUD/WBP_Announcement.uasset index b31d1e3..6215a1c 100644 Binary files a/Content/Blueprints/HUD/WBP_Announcement.uasset and b/Content/Blueprints/HUD/WBP_Announcement.uasset differ diff --git a/Source/Blaster/GameMode/BlasterGameMode.cpp b/Source/Blaster/GameMode/BlasterGameMode.cpp index 012418d..365d459 100644 --- a/Source/Blaster/GameMode/BlasterGameMode.cpp +++ b/Source/Blaster/GameMode/BlasterGameMode.cpp @@ -47,6 +47,10 @@ void ABlasterGameMode::Tick(float DeltaSeconds) SetMatchState(MatchState::Cooldown); } } + else if (MatchState == MatchState::Cooldown) + { + CountDownTime = CooldownTime + WarmupTime + MatchTime - GetWorld()->GetTimeSeconds() + LevelStartingTime; + } } void ABlasterGameMode::OnMatchStateSet() diff --git a/Source/Blaster/GameMode/BlasterGameMode.h b/Source/Blaster/GameMode/BlasterGameMode.h index 1be767a..1cf19f4 100644 --- a/Source/Blaster/GameMode/BlasterGameMode.h +++ b/Source/Blaster/GameMode/BlasterGameMode.h @@ -44,4 +44,7 @@ protected: private: float CountDownTime = 0.f; + +public: + FORCEINLINE float GetCountdownTime() const { return CountDownTime; } }; diff --git a/Source/Blaster/HUD/Announcement.h b/Source/Blaster/HUD/Announcement.h index d9e28e7..9f14d29 100644 --- a/Source/Blaster/HUD/Announcement.h +++ b/Source/Blaster/HUD/Announcement.h @@ -20,7 +20,7 @@ public: class UTextBlock* AnnouncementText; UPROPERTY(meta = (BindWidget)) - UTextBlock* WarmupTime; + UTextBlock* CountdownText; UPROPERTY(meta = (BindWidget)) UTextBlock* AnnouncementMessage; diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index 43394ef..d41e7dc 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -18,7 +18,7 @@ void ABlasterPlayerController::BeginPlay() { Super::BeginPlay(); - + BlasterHUD = Cast(GetHUD()); ServerCheckMatchState(); } @@ -33,7 +33,7 @@ void ABlasterPlayerController::GetLifetimeReplicatedProps(TArrayCharacterOverlay->RemoveFromParent(); - if (BlasterHUD->Announcement) + bool bHUDValid = + BlasterHUD->Announcement && + BlasterHUD->Announcement->AnnouncementText && + BlasterHUD->Announcement->AnnouncementMessage; + + if (bHUDValid) { + const FString AnnouncementText("New match starts in:"); + BlasterHUD->Announcement->AnnouncementText->SetText(FText::FromString(AnnouncementText)); + BlasterHUD->Announcement->AnnouncementMessage->SetText(FText()); BlasterHUD->Announcement->SetVisibility(ESlateVisibility::Visible); } } @@ -136,17 +144,19 @@ void ABlasterPlayerController::ServerCheckMatchState_Implementation() LevelStartingTime = GameMode->LevelStartingTime; WarmupTime = GameMode->WarmupTime; MatchTime = GameMode->MatchTime; + CooldownTime = GameMode->CooldownTime; MatchState = GameMode->GetMatchState(); - ClientJoinMidGame(MatchState, WarmupTime, MatchTime, LevelStartingTime); + ClientJoinMidGame(MatchState, WarmupTime, MatchTime, CooldownTime, LevelStartingTime); } } -void ABlasterPlayerController::ClientJoinMidGame_Implementation(FName StateOfMatch, float Warmup, float Match, float StartingTime) +void ABlasterPlayerController::ClientJoinMidGame_Implementation(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime) { LevelStartingTime = StartingTime; WarmupTime = Warmup; MatchTime = Match; + CooldownTime = Cooldown; MatchState = StateOfMatch; OnMatchStateSet(MatchState); @@ -175,12 +185,22 @@ void ABlasterPlayerController::SetHUDTime() float TimeLeft = 0.f; if (MatchState == MatchState::WaitingToStart) TimeLeft = WarmupTime - GetServerTime() + LevelStartingTime; else if (MatchState == MatchState::InProgress) TimeLeft = WarmupTime + MatchTime - GetServerTime() + LevelStartingTime; - - const uint32 SecondsLeft = FMath::CeilToInt(TimeLeft); + else if (MatchState == MatchState::Cooldown) TimeLeft = WarmupTime + MatchTime + CooldownTime - GetServerTime() + LevelStartingTime; + uint32 SecondsLeft = FMath::CeilToInt(TimeLeft); + + if (HasAuthority()) + { + BlasterGameMode = BlasterGameMode == nullptr ? Cast(UGameplayStatics::GetGameMode(this)) : BlasterGameMode; + if (BlasterGameMode) + { + SecondsLeft = FMath::CeilToInt(BlasterGameMode->GetCountdownTime() + LevelStartingTime); + } + } + if (CountdownInt != SecondsLeft) { - if (MatchState == MatchState::WaitingToStart) SetHUDAnnouncementCountdown(TimeLeft); - if (MatchState == MatchState::InProgress) SetHUDMatchCountdown(TimeLeft); + if (MatchState == MatchState::WaitingToStart || MatchState == MatchState::Cooldown) SetHUDAnnouncementCountdown(TimeLeft); + if (MatchState == MatchState::InProgress) SetHUDMatchCountdown(TimeLeft); } CountdownInt = SecondsLeft; @@ -288,6 +308,11 @@ void ABlasterPlayerController::SetHUDMatchCountdown(float CountdownTime) if (bHUDValid) { + if (CountdownTime < 0.f) + { + BlasterHUD->CharacterOverlay->MatchCountdownText->SetText(FText()); + return; + } const int32 Minutes = FMath::FloorToInt(CountdownTime / 60); const int32 Seconds = CountdownTime - Minutes * 60; @@ -303,14 +328,19 @@ void ABlasterPlayerController::SetHUDAnnouncementCountdown(float CountdownTime) BlasterHUD && BlasterHUD->Announcement && BlasterHUD->Announcement->AnnouncementText && - BlasterHUD->Announcement->WarmupTime; + BlasterHUD->Announcement->CountdownText; if (bHUDValid) { + if (CountdownTime < 0.f) + { + BlasterHUD->Announcement->CountdownText->SetText(FText()); + return; + } const int32 Minutes = FMath::FloorToInt(CountdownTime / 60); const int32 Seconds = CountdownTime - Minutes * 60; const FString CountdownText = FString::Printf(TEXT("%02d:%02d"), Minutes, Seconds); - BlasterHUD->Announcement->WarmupTime->SetText(FText::FromString(CountdownText)); + BlasterHUD->Announcement->CountdownText->SetText(FText::FromString(CountdownText)); } } diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.h b/Source/Blaster/PlayerController/BlasterPlayerController.h index 0d47584..245955a 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.h +++ b/Source/Blaster/PlayerController/BlasterPlayerController.h @@ -65,15 +65,19 @@ protected: void ServerCheckMatchState(); UFUNCTION(Client, Reliable) - void ClientJoinMidGame(FName StateOfMatch, float Warmup, float Match, float StartingTime); + void ClientJoinMidGame(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime); private: UPROPERTY() class ABlasterHUD* BlasterHUD; + UPROPERTY() + class ABlasterGameMode* BlasterGameMode; + float LevelStartingTime = 0.f; float MatchTime = 0.f; float WarmupTime = 0.f; + float CooldownTime = 0.f; uint32 CountdownInt = 0; UPROPERTY(ReplicatedUsing=OnRep_MatchState)