126 - Cooldown Announcement

This commit is contained in:
Kingsmedia 2022-05-10 15:29:00 +02:00
parent fa53d656d9
commit ad556e0523
7 changed files with 54 additions and 13 deletions

View File

@ -47,6 +47,10 @@ void ABlasterGameMode::Tick(float DeltaSeconds)
SetMatchState(MatchState::Cooldown); SetMatchState(MatchState::Cooldown);
} }
} }
else if (MatchState == MatchState::Cooldown)
{
CountDownTime = CooldownTime + WarmupTime + MatchTime - GetWorld()->GetTimeSeconds() + LevelStartingTime;
}
} }
void ABlasterGameMode::OnMatchStateSet() void ABlasterGameMode::OnMatchStateSet()

View File

@ -44,4 +44,7 @@ protected:
private: private:
float CountDownTime = 0.f; float CountDownTime = 0.f;
public:
FORCEINLINE float GetCountdownTime() const { return CountDownTime; }
}; };

View File

@ -20,7 +20,7 @@ public:
class UTextBlock* AnnouncementText; class UTextBlock* AnnouncementText;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
UTextBlock* WarmupTime; UTextBlock* CountdownText;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
UTextBlock* AnnouncementMessage; UTextBlock* AnnouncementMessage;

View File

@ -18,7 +18,7 @@
void ABlasterPlayerController::BeginPlay() void ABlasterPlayerController::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
BlasterHUD = Cast<ABlasterHUD>(GetHUD()); BlasterHUD = Cast<ABlasterHUD>(GetHUD());
ServerCheckMatchState(); ServerCheckMatchState();
} }
@ -33,7 +33,7 @@ void ABlasterPlayerController::GetLifetimeReplicatedProps(TArray<FLifetimeProper
void ABlasterPlayerController::Tick(float DeltaSeconds) void ABlasterPlayerController::Tick(float DeltaSeconds)
{ {
Super::Tick(DeltaSeconds); Super::Tick(DeltaSeconds);
SetHUDTime(); SetHUDTime();
CheckTimeSync(DeltaSeconds); CheckTimeSync(DeltaSeconds);
PollInit(); PollInit();
@ -95,8 +95,16 @@ void ABlasterPlayerController::HandleCooldown()
if (BlasterHUD) if (BlasterHUD)
{ {
BlasterHUD->CharacterOverlay->RemoveFromParent(); BlasterHUD->CharacterOverlay->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); BlasterHUD->Announcement->SetVisibility(ESlateVisibility::Visible);
} }
} }
@ -136,17 +144,19 @@ void ABlasterPlayerController::ServerCheckMatchState_Implementation()
LevelStartingTime = GameMode->LevelStartingTime; LevelStartingTime = GameMode->LevelStartingTime;
WarmupTime = GameMode->WarmupTime; WarmupTime = GameMode->WarmupTime;
MatchTime = GameMode->MatchTime; MatchTime = GameMode->MatchTime;
CooldownTime = GameMode->CooldownTime;
MatchState = GameMode->GetMatchState(); 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; LevelStartingTime = StartingTime;
WarmupTime = Warmup; WarmupTime = Warmup;
MatchTime = Match; MatchTime = Match;
CooldownTime = Cooldown;
MatchState = StateOfMatch; MatchState = StateOfMatch;
OnMatchStateSet(MatchState); OnMatchStateSet(MatchState);
@ -175,12 +185,22 @@ void ABlasterPlayerController::SetHUDTime()
float TimeLeft = 0.f; float TimeLeft = 0.f;
if (MatchState == MatchState::WaitingToStart) TimeLeft = WarmupTime - GetServerTime() + LevelStartingTime; if (MatchState == MatchState::WaitingToStart) TimeLeft = WarmupTime - GetServerTime() + LevelStartingTime;
else if (MatchState == MatchState::InProgress) TimeLeft = WarmupTime + MatchTime - GetServerTime() + LevelStartingTime; else if (MatchState == MatchState::InProgress) TimeLeft = WarmupTime + MatchTime - GetServerTime() + LevelStartingTime;
else if (MatchState == MatchState::Cooldown) TimeLeft = WarmupTime + MatchTime + CooldownTime - GetServerTime() + LevelStartingTime;
const uint32 SecondsLeft = FMath::CeilToInt(TimeLeft); uint32 SecondsLeft = FMath::CeilToInt(TimeLeft);
if (HasAuthority())
{
BlasterGameMode = BlasterGameMode == nullptr ? Cast<ABlasterGameMode>(UGameplayStatics::GetGameMode(this)) : BlasterGameMode;
if (BlasterGameMode)
{
SecondsLeft = FMath::CeilToInt(BlasterGameMode->GetCountdownTime() + LevelStartingTime);
}
}
if (CountdownInt != SecondsLeft) if (CountdownInt != SecondsLeft)
{ {
if (MatchState == MatchState::WaitingToStart) SetHUDAnnouncementCountdown(TimeLeft); if (MatchState == MatchState::WaitingToStart || MatchState == MatchState::Cooldown) SetHUDAnnouncementCountdown(TimeLeft);
if (MatchState == MatchState::InProgress) SetHUDMatchCountdown(TimeLeft); if (MatchState == MatchState::InProgress) SetHUDMatchCountdown(TimeLeft);
} }
CountdownInt = SecondsLeft; CountdownInt = SecondsLeft;
@ -288,6 +308,11 @@ void ABlasterPlayerController::SetHUDMatchCountdown(float CountdownTime)
if (bHUDValid) if (bHUDValid)
{ {
if (CountdownTime < 0.f)
{
BlasterHUD->CharacterOverlay->MatchCountdownText->SetText(FText());
return;
}
const int32 Minutes = FMath::FloorToInt(CountdownTime / 60); const int32 Minutes = FMath::FloorToInt(CountdownTime / 60);
const int32 Seconds = CountdownTime - Minutes * 60; const int32 Seconds = CountdownTime - Minutes * 60;
@ -303,14 +328,19 @@ void ABlasterPlayerController::SetHUDAnnouncementCountdown(float CountdownTime)
BlasterHUD && BlasterHUD &&
BlasterHUD->Announcement && BlasterHUD->Announcement &&
BlasterHUD->Announcement->AnnouncementText && BlasterHUD->Announcement->AnnouncementText &&
BlasterHUD->Announcement->WarmupTime; BlasterHUD->Announcement->CountdownText;
if (bHUDValid) if (bHUDValid)
{ {
if (CountdownTime < 0.f)
{
BlasterHUD->Announcement->CountdownText->SetText(FText());
return;
}
const int32 Minutes = FMath::FloorToInt(CountdownTime / 60); const int32 Minutes = FMath::FloorToInt(CountdownTime / 60);
const int32 Seconds = CountdownTime - Minutes * 60; const int32 Seconds = CountdownTime - Minutes * 60;
const FString CountdownText = FString::Printf(TEXT("%02d:%02d"), Minutes, Seconds); const FString CountdownText = FString::Printf(TEXT("%02d:%02d"), Minutes, Seconds);
BlasterHUD->Announcement->WarmupTime->SetText(FText::FromString(CountdownText)); BlasterHUD->Announcement->CountdownText->SetText(FText::FromString(CountdownText));
} }
} }

View File

@ -65,15 +65,19 @@ protected:
void ServerCheckMatchState(); void ServerCheckMatchState();
UFUNCTION(Client, Reliable) 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: private:
UPROPERTY() UPROPERTY()
class ABlasterHUD* BlasterHUD; class ABlasterHUD* BlasterHUD;
UPROPERTY()
class ABlasterGameMode* BlasterGameMode;
float LevelStartingTime = 0.f; float LevelStartingTime = 0.f;
float MatchTime = 0.f; float MatchTime = 0.f;
float WarmupTime = 0.f; float WarmupTime = 0.f;
float CooldownTime = 0.f;
uint32 CountdownInt = 0; uint32 CountdownInt = 0;
UPROPERTY(ReplicatedUsing=OnRep_MatchState) UPROPERTY(ReplicatedUsing=OnRep_MatchState)