124 - Updating Warmup Time
This commit is contained in:
parent
9f8760f862
commit
85f667c086
|
@ -23,6 +23,8 @@ public:
|
|||
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
float WarmupTime = 10.f;
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
float MatchTime = 120.f;
|
||||
|
||||
float LevelStartingTime = 0.f;
|
||||
|
||||
|
|
|
@ -4,12 +4,14 @@
|
|||
#include "BlasterPlayerController.h"
|
||||
|
||||
#include "Blaster/Character/BlasterCharacter.h"
|
||||
#include "Blaster/GameMode/BlasterGameMode.h"
|
||||
#include "Blaster/HUD/Announcement.h"
|
||||
#include "Blaster/HUD/BlasterHUD.h"
|
||||
#include "Blaster/HUD/CharacterOverlay.h"
|
||||
#include "Components/ProgressBar.h"
|
||||
#include "Components/TextBlock.h"
|
||||
#include "GameFramework/GameMode.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Net/UnrealNetwork.h"
|
||||
|
||||
|
||||
|
@ -18,10 +20,7 @@ void ABlasterPlayerController::BeginPlay()
|
|||
Super::BeginPlay();
|
||||
|
||||
BlasterHUD = Cast<ABlasterHUD>(GetHUD());
|
||||
if (BlasterHUD)
|
||||
{
|
||||
BlasterHUD->AddAnnouncementOverlay();
|
||||
}
|
||||
ServerCheckMatchState();
|
||||
}
|
||||
|
||||
void ABlasterPlayerController::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
||||
|
@ -35,9 +34,9 @@ void ABlasterPlayerController::Tick(float DeltaSeconds)
|
|||
{
|
||||
Super::Tick(DeltaSeconds);
|
||||
|
||||
PollInit();
|
||||
SetHUDTime();
|
||||
CheckTimeSync(DeltaSeconds);
|
||||
PollInit();
|
||||
}
|
||||
|
||||
void ABlasterPlayerController::OnPossess(APawn* InPawn)
|
||||
|
@ -108,6 +107,34 @@ void ABlasterPlayerController::OnRep_MatchState()
|
|||
}
|
||||
}
|
||||
|
||||
void ABlasterPlayerController::ServerCheckMatchState_Implementation()
|
||||
{
|
||||
ABlasterGameMode* GameMode = Cast<ABlasterGameMode>(UGameplayStatics::GetGameMode(this));
|
||||
if (GameMode)
|
||||
{
|
||||
LevelStartingTime = GameMode->LevelStartingTime;
|
||||
WarmupTime = GameMode->WarmupTime;
|
||||
MatchTime = GameMode->MatchTime;
|
||||
MatchState = GameMode->GetMatchState();
|
||||
ClientJoinMidGame(MatchState, WarmupTime, MatchTime, LevelStartingTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ABlasterPlayerController::ClientJoinMidGame_Implementation(FName StateOfMatch, float Warmup, float Match, float StartingTime)
|
||||
{
|
||||
LevelStartingTime = StartingTime;
|
||||
WarmupTime = Warmup;
|
||||
MatchTime = Match;
|
||||
MatchState = StateOfMatch;
|
||||
OnMatchStateSet(MatchState);
|
||||
|
||||
if (BlasterHUD && MatchState == MatchState::WaitingToStart)
|
||||
{
|
||||
BlasterHUD->AddAnnouncementOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
void ABlasterPlayerController::ServerRequestServerTime_Implementation(float TimeOfClientRequest)
|
||||
{
|
||||
const float ServerTimeOfReceipt = GetWorld()->GetTimeSeconds();
|
||||
|
@ -124,11 +151,15 @@ void ABlasterPlayerController::ClientReportServerTime_Implementation(float TimeO
|
|||
|
||||
void ABlasterPlayerController::SetHUDTime()
|
||||
{
|
||||
const uint32 SecondsLeft = FMath::CeilToInt(MatchTime - GetServerTime());
|
||||
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);
|
||||
if (CountdownInt != SecondsLeft)
|
||||
{
|
||||
SetHUDMatchCountdown(MatchTime - GetServerTime());
|
||||
if (MatchState == MatchState::WaitingToStart) SetHUDAnnouncementCountdown(TimeLeft);
|
||||
if (MatchState == MatchState::InProgress) SetHUDMatchCountdown(TimeLeft);
|
||||
}
|
||||
|
||||
CountdownInt = SecondsLeft;
|
||||
|
@ -243,3 +274,22 @@ void ABlasterPlayerController::SetHUDMatchCountdown(float CountdownTime)
|
|||
BlasterHUD->CharacterOverlay->MatchCountdownText->SetText(FText::FromString(CountdownText));
|
||||
}
|
||||
}
|
||||
|
||||
void ABlasterPlayerController::SetHUDAnnouncementCountdown(float CountdownTime)
|
||||
{
|
||||
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
|
||||
bool bHUDValid =
|
||||
BlasterHUD &&
|
||||
BlasterHUD->Announcement &&
|
||||
BlasterHUD->Announcement->AnnouncementText &&
|
||||
BlasterHUD->Announcement->WarmupTime;
|
||||
|
||||
if (bHUDValid)
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ public:
|
|||
void SetHUDWeaponAmmo(int32 Ammo);
|
||||
void SetHUDCarriedAmmo(int32 Ammo);
|
||||
void SetHUDMatchCountdown(float CountdownTime);
|
||||
void SetHUDAnnouncementCountdown(float CountdownTime);
|
||||
|
||||
// Synced with server world clock
|
||||
virtual float GetServerTime();
|
||||
|
@ -58,12 +59,20 @@ protected:
|
|||
float TimeSyncFrequency = 5.f;
|
||||
|
||||
float TimeSyncRunningTime = 0.f;
|
||||
|
||||
UFUNCTION(Server, Reliable)
|
||||
void ServerCheckMatchState();
|
||||
|
||||
UFUNCTION(Client, Reliable)
|
||||
void ClientJoinMidGame(FName StateOfMatch, float Warmup, float Match, float StartingTime);
|
||||
private:
|
||||
|
||||
UPROPERTY()
|
||||
class ABlasterHUD* BlasterHUD;
|
||||
|
||||
float MatchTime = 120.f;
|
||||
float LevelStartingTime = 0.f;
|
||||
float MatchTime = 0.f;
|
||||
float WarmupTime = 0.f;
|
||||
uint32 CountdownInt = 0;
|
||||
|
||||
UPROPERTY(ReplicatedUsing=OnRep_MatchState)
|
||||
|
|
Loading…
Reference in New Issue