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