diff --git a/Content/Assets/Textures/Grenades/GrenadeIcon_Transparant.uasset b/Content/Assets/Textures/Grenades/GrenadeIcon_Transparant.uasset index 97e1574..ecd96cd 100644 Binary files a/Content/Assets/Textures/Grenades/GrenadeIcon_Transparant.uasset and b/Content/Assets/Textures/Grenades/GrenadeIcon_Transparant.uasset differ diff --git a/Content/Assets/Textures/Overlay/HealthIcon.uasset b/Content/Assets/Textures/Overlay/HealthIcon.uasset new file mode 100644 index 0000000..65d65b7 Binary files /dev/null and b/Content/Assets/Textures/Overlay/HealthIcon.uasset differ diff --git a/Content/Assets/Textures/Overlay/ShieldIcon.uasset b/Content/Assets/Textures/Overlay/ShieldIcon.uasset new file mode 100644 index 0000000..d08d811 Binary files /dev/null and b/Content/Assets/Textures/Overlay/ShieldIcon.uasset differ diff --git a/Content/Assets/Textures/Overlay/Wifi_Signal.uasset b/Content/Assets/Textures/Overlay/Wifi_Signal.uasset new file mode 100644 index 0000000..7b54af2 Binary files /dev/null and b/Content/Assets/Textures/Overlay/Wifi_Signal.uasset differ diff --git a/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset b/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset index 6f1c3f0..a488d7f 100644 Binary files a/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset and b/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset differ diff --git a/Source/Blaster/HUD/CharacterOverlay.h b/Source/Blaster/HUD/CharacterOverlay.h index 58cf937..d189dff 100644 --- a/Source/Blaster/HUD/CharacterOverlay.h +++ b/Source/Blaster/HUD/CharacterOverlay.h @@ -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; }; diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index 2bd2eb7..5d04a09 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -34,6 +34,13 @@ void ABlasterPlayerController::GetLifetimeReplicatedProps(TArrayDebugWidget && 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() : 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(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(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(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; diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.h b/Source/Blaster/PlayerController/BlasterPlayerController.h index 2f6dd33..4dd6a0e 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.h +++ b/Source/Blaster/PlayerController/BlasterPlayerController.h @@ -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; };