170 - High Ping Warning

This commit is contained in:
Kingsmedia 2022-05-26 13:06:33 +02:00
parent 8f24aab496
commit 72cf9d1833
8 changed files with 98 additions and 8 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -4,6 +4,7 @@
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Components/Image.h"
#include "CharacterOverlay.generated.h"
/**
@ -46,4 +47,9 @@ public:
UPROPERTY(meta = (BindWidget))
UTextBlock* GrenadesAmount;
UPROPERTY(meta = (BindWidget))
UImage* HighPingImage;
UPROPERTY(meta = (BindWidgetAnim), Transient)
UWidgetAnimation* HighPingAnimation;
};

View File

@ -34,6 +34,13 @@ void ABlasterPlayerController::GetLifetimeReplicatedProps(TArray<FLifetimeProper
DOREPLIFETIME(ABlasterPlayerController, MatchState);
}
void ABlasterPlayerController::SetDebugMsg1(FString Key, FString Value)
{
bool bHUDValid = BlasterHUD && BlasterHUD->DebugWidget && BlasterHUD->DebugWidget->DebugMsg1;
if (bHUDValid) BlasterHUD->DebugWidget->DebugMsg1->SetText(FText::FromString(Key.Append(Value)));
}
void ABlasterPlayerController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
@ -41,6 +48,7 @@ void ABlasterPlayerController::Tick(float DeltaTime)
SetHUDTime();
CheckTimeSync(DeltaTime);
PollInit();
CheckPing(DeltaTime);
if (DebugWidget)
{
@ -52,12 +60,42 @@ void ABlasterPlayerController::Tick(float DeltaTime)
}
}
void ABlasterPlayerController::SetDebugMsg1(FString Key, FString Value)
void ABlasterPlayerController::CheckPing(float DeltaTime)
{
bool bHUDValid = BlasterHUD && BlasterHUD->DebugWidget && BlasterHUD->DebugWidget->DebugMsg1;
if (bHUDValid) BlasterHUD->DebugWidget->DebugMsg1->SetText(FText::FromString(Key.Append(Value)));
HighPingRunningTime += DeltaTime;
if (HighPingRunningTime > CheckPingFrequency)
{
HighPingRunningTime = 0.f;
PlayerState = PlayerState == nullptr ? GetPlayerState<APlayerState>() : PlayerState;
if (PlayerState)
{
UE_LOG(LogTemp, Warning, TEXT("Ping: %f"), PlayerState->GetPingInMilliseconds());
if (PlayerState->GetPingInMilliseconds() > HighPingThreshold)
{
HighPingWarning();
PingAnimationRunningTime = 0.f;
}
}
}
bool bHighPingAnimationPlaying =
BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->HighPingAnimation &&
BlasterHUD->CharacterOverlay->IsAnimationPlaying(BlasterHUD->CharacterOverlay->HighPingAnimation);
if (bHighPingAnimationPlaying)
{
PingAnimationRunningTime += DeltaTime;
if (PingAnimationRunningTime > HighPingDuration)
{
StopHighPingWarning();
}
}
}
void ABlasterPlayerController::SetDebugMsg2(FString Key, FString Value)
{
bool bHUDValid = BlasterHUD && BlasterHUD->DebugWidget && BlasterHUD->DebugWidget->DebugMsg2;
@ -269,7 +307,8 @@ void ABlasterPlayerController::SetHUDGrenades(int32 Grenades)
{
FString GrenadesText = FString::Printf(TEXT("%d"), Grenades);
BlasterHUD->CharacterOverlay->GrenadesAmount->SetText(FText::FromString(GrenadesText));
} else
}
else
{
bInitializeGrenades = true;
HUDGrenades = Grenades;
@ -326,9 +365,9 @@ void ABlasterPlayerController::SetHUDTime()
if (MatchState == MatchState::WaitingToStart) TimeLeft = WarmupTime - GetServerTime(); // + LevelStartingTime;
else if (MatchState == MatchState::InProgress) TimeLeft = WarmupTime + MatchTime - GetServerTime(); // + LevelStartingTime;
else if (MatchState == MatchState::Cooldown) TimeLeft = WarmupTime + MatchTime + CooldownTime - GetServerTime(); // + LevelStartingTime;
uint32 SecondsLeft = FMath::CeilToInt(TimeLeft);
if (HasAuthority())
{
BlasterGameMode = BlasterGameMode == nullptr ? Cast<ABlasterGameMode>(UGameplayStatics::GetGameMode(this)) : BlasterGameMode;
@ -337,7 +376,7 @@ void ABlasterPlayerController::SetHUDTime()
SecondsLeft = FMath::CeilToInt(BlasterGameMode->GetCountdownTime());
}
}
if (CountdownInt != SecondsLeft)
{
if (MatchState == MatchState::WaitingToStart || MatchState == MatchState::Cooldown)
@ -389,6 +428,37 @@ void ABlasterPlayerController::PollInit()
}
}
void ABlasterPlayerController::HighPingWarning()
{
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
bool bHUDValid = BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->HighPingImage &&
BlasterHUD->CharacterOverlay->HighPingAnimation;
if (bHUDValid)
{
BlasterHUD->CharacterOverlay->HighPingImage->SetOpacity(1.f);
BlasterHUD->CharacterOverlay->PlayAnimation(BlasterHUD->CharacterOverlay->HighPingAnimation, 0.f, 5);
}
}
void ABlasterPlayerController::StopHighPingWarning()
{
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
bool bHUDValid = BlasterHUD &&
BlasterHUD->CharacterOverlay &&
BlasterHUD->CharacterOverlay->HighPingImage &&
BlasterHUD->CharacterOverlay->HighPingAnimation;
if (bHUDValid)
{
BlasterHUD->CharacterOverlay->HighPingImage->SetOpacity(0.f);
if (BlasterHUD->CharacterOverlay->IsAnimationPlaying(BlasterHUD->CharacterOverlay->HighPingAnimation))
{
BlasterHUD->CharacterOverlay->StopAnimation(BlasterHUD->CharacterOverlay->HighPingAnimation);
}
}
}
void ABlasterPlayerController::ServerRequestServerTime_Implementation(float TimeOfClientRequest)
{
float ServerTimeOfReceipt = GetWorld()->GetTimeSeconds();
@ -465,7 +535,7 @@ void ABlasterPlayerController::HandleCooldown()
{
BlasterHUD->CharacterOverlay->RemoveFromParent();
}
bool bHUDValid = BlasterHUD->Announcement &&
BlasterHUD->Announcement->AnnouncementText &&
BlasterHUD->Announcement->AnnouncementMessage;

View File

@ -76,6 +76,9 @@ protected:
UFUNCTION(Client, Reliable)
void ClientJoinMidgame(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime);
void HighPingWarning();
void StopHighPingWarning();
private:
UPROPERTY()
@ -125,4 +128,15 @@ private:
float bInitializeHUDWeaponAmmo = false;
float HUDWeaponAmmo;
// High Ping Indicator
void CheckPing(float DeltaTime);
float HighPingRunningTime = 0.f;
UPROPERTY(EditAnywhere)
float HighPingDuration = 5.f;
float PingAnimationRunningTime = 0.f;
UPROPERTY(EditAnywhere)
float CheckPingFrequency = 20.f;
UPROPERTY(EditAnywhere)
float HighPingThreshold = 50.f;
};