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 "CoreMinimal.h"
#include "Blueprint/UserWidget.h" #include "Blueprint/UserWidget.h"
#include "Components/Image.h"
#include "CharacterOverlay.generated.h" #include "CharacterOverlay.generated.h"
/** /**
@ -46,4 +47,9 @@ public:
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
UTextBlock* GrenadesAmount; 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); 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) void ABlasterPlayerController::Tick(float DeltaTime)
{ {
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
@ -41,6 +48,7 @@ void ABlasterPlayerController::Tick(float DeltaTime)
SetHUDTime(); SetHUDTime();
CheckTimeSync(DeltaTime); CheckTimeSync(DeltaTime);
PollInit(); PollInit();
CheckPing(DeltaTime);
if (DebugWidget) if (DebugWidget)
{ {
@ -52,11 +60,41 @@ 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; HighPingRunningTime += DeltaTime;
if (bHUDValid) BlasterHUD->DebugWidget->DebugMsg1->SetText(FText::FromString(Key.Append(Value))); 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) void ABlasterPlayerController::SetDebugMsg2(FString Key, FString Value)
{ {
@ -269,7 +307,8 @@ void ABlasterPlayerController::SetHUDGrenades(int32 Grenades)
{ {
FString GrenadesText = FString::Printf(TEXT("%d"), Grenades); FString GrenadesText = FString::Printf(TEXT("%d"), Grenades);
BlasterHUD->CharacterOverlay->GrenadesAmount->SetText(FText::FromString(GrenadesText)); BlasterHUD->CharacterOverlay->GrenadesAmount->SetText(FText::FromString(GrenadesText));
} else }
else
{ {
bInitializeGrenades = true; bInitializeGrenades = true;
HUDGrenades = Grenades; HUDGrenades = Grenades;
@ -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) void ABlasterPlayerController::ServerRequestServerTime_Implementation(float TimeOfClientRequest)
{ {
float ServerTimeOfReceipt = GetWorld()->GetTimeSeconds(); float ServerTimeOfReceipt = GetWorld()->GetTimeSeconds();

View File

@ -76,6 +76,9 @@ protected:
UFUNCTION(Client, Reliable) UFUNCTION(Client, Reliable)
void ClientJoinMidgame(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime); void ClientJoinMidgame(FName StateOfMatch, float Warmup, float Match, float Cooldown, float StartingTime);
void HighPingWarning();
void StopHighPingWarning();
private: private:
UPROPERTY() UPROPERTY()
@ -125,4 +128,15 @@ private:
float bInitializeHUDWeaponAmmo = false; float bInitializeHUDWeaponAmmo = false;
float HUDWeaponAmmo; 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;
}; };