170 - High Ping Warning
This commit is contained in:
parent
8f24aab496
commit
72cf9d1833
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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,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;
|
||||
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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue