diff --git a/Content/Blueprints/HUD/BP_BlasterHUD.uasset b/Content/Blueprints/HUD/BP_BlasterHUD.uasset index 92481c8..254e30f 100644 Binary files a/Content/Blueprints/HUD/BP_BlasterHUD.uasset and b/Content/Blueprints/HUD/BP_BlasterHUD.uasset differ diff --git a/Content/Blueprints/HUD/WBP_ElimAnnouncement.uasset b/Content/Blueprints/HUD/WBP_ElimAnnouncement.uasset new file mode 100644 index 0000000..ac2c8f0 Binary files /dev/null and b/Content/Blueprints/HUD/WBP_ElimAnnouncement.uasset differ diff --git a/Content/Blueprints/Weapon/BP_GenadeLauncher.uasset b/Content/Blueprints/Weapon/BP_GenadeLauncher.uasset index 9f62f91..5180cbe 100644 Binary files a/Content/Blueprints/Weapon/BP_GenadeLauncher.uasset and b/Content/Blueprints/Weapon/BP_GenadeLauncher.uasset differ diff --git a/Content/Blueprints/Weapon/BP_RocketLauncher.uasset b/Content/Blueprints/Weapon/BP_RocketLauncher.uasset index 6bb603e..054cb2d 100644 Binary files a/Content/Blueprints/Weapon/BP_RocketLauncher.uasset and b/Content/Blueprints/Weapon/BP_RocketLauncher.uasset differ diff --git a/Content/Maps/BlasterMap.umap b/Content/Maps/BlasterMap.umap index a2b4085..4ffdb4d 100644 Binary files a/Content/Maps/BlasterMap.umap and b/Content/Maps/BlasterMap.umap differ diff --git a/Source/Blaster/GameMode/BlasterGameMode.cpp b/Source/Blaster/GameMode/BlasterGameMode.cpp index f8af36b..3001a4a 100644 --- a/Source/Blaster/GameMode/BlasterGameMode.cpp +++ b/Source/Blaster/GameMode/BlasterGameMode.cpp @@ -121,6 +121,15 @@ void ABlasterGameMode::PlayerEliminated(class ABlasterCharacter* EliminatedChara { EliminatedCharacter->Eliminated(false); } + + for (FConstPlayerControllerIterator It = GetWorld()->GetPlayerControllerIterator(); It; ++It) + { + ABlasterPlayerController* BlasterPlayer = Cast(*It); + if (BlasterPlayer && AttackerPlayerState && VictimPlayerState) + { + BlasterPlayer->BroadcastElim(AttackerPlayerState, VictimPlayerState); + } + } } void ABlasterGameMode::RequestRespawn(ACharacter* EliminatedCharacter, AController* EliminatedController) diff --git a/Source/Blaster/HUD/BlasterHUD.cpp b/Source/Blaster/HUD/BlasterHUD.cpp index 6760288..8d8a9cb 100644 --- a/Source/Blaster/HUD/BlasterHUD.cpp +++ b/Source/Blaster/HUD/BlasterHUD.cpp @@ -6,6 +6,7 @@ #include "Announcement.h" #include "CharacterOverlay.h" #include "DebugWidget.h" +#include "ElimAnnouncement.h" #include "Blueprint/UserWidget.h" #include "Components/TextBlock.h" @@ -44,6 +45,20 @@ void ABlasterHUD::AddAnnouncementOverlay() } } +void ABlasterHUD::AddElimAnnouncement(FString Attacker, FString Victim) +{ + OwningPlayer = OwningPlayer == nullptr ? GetOwningPlayerController() : OwningPlayer; + if (OwningPlayer && ElimAnnouncementClass) + { + UElimAnnouncement* ElimAnnouncementWidget = CreateWidget(OwningPlayer, ElimAnnouncementClass); + if (ElimAnnouncementWidget) + { + ElimAnnouncementWidget->SetElimAnnouncementText(Attacker, Victim); + ElimAnnouncementWidget->AddToViewport(); + } + } +} + void ABlasterHUD::DrawHUD() { Super::DrawHUD(); diff --git a/Source/Blaster/HUD/BlasterHUD.h b/Source/Blaster/HUD/BlasterHUD.h index b689d03..8d9c1f8 100644 --- a/Source/Blaster/HUD/BlasterHUD.h +++ b/Source/Blaster/HUD/BlasterHUD.h @@ -34,6 +34,7 @@ public: void AddDebugWidget(); void AddCharacterOverlay(); void AddAnnouncementOverlay(); + void AddElimAnnouncement(FString Attacker, FString Victim); UPROPERTY(EditAnywhere, Category = "Player Stats") TSubclassOf CharacterOverlayClass; @@ -57,6 +58,9 @@ protected: virtual void BeginPlay() override; private: + UPROPERTY() + class APlayerController* OwningPlayer; + FHUDPackage HUDPackage; void DrawCrosshair(UTexture2D* Texture, FVector2D ViewportCenter, FVector2D Spread, FLinearColor CrosshairColor); @@ -64,6 +68,9 @@ private: UPROPERTY(EditAnywhere) float CrosshairSpreadMax = 16.f; + UPROPERTY(EditAnywhere) + TSubclassOf ElimAnnouncementClass; + public: FORCEINLINE void SetHUDPackage(const FHUDPackage& Package) { HUDPackage = Package; }; }; diff --git a/Source/Blaster/HUD/ElimAnnouncement.cpp b/Source/Blaster/HUD/ElimAnnouncement.cpp new file mode 100644 index 0000000..dc9be88 --- /dev/null +++ b/Source/Blaster/HUD/ElimAnnouncement.cpp @@ -0,0 +1,16 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "ElimAnnouncement.h" + +#include "Components/TextBlock.h" + +void UElimAnnouncement::SetElimAnnouncementText(FString AttackerName, FString VictimName) +{ + FString ElimAnnouncementText = FString::Printf(TEXT("%s killed %s"), *AttackerName, *VictimName); + + if (AnnouncementText) + { + AnnouncementText->SetText(FText::FromString(ElimAnnouncementText)); + } +} diff --git a/Source/Blaster/HUD/ElimAnnouncement.h b/Source/Blaster/HUD/ElimAnnouncement.h new file mode 100644 index 0000000..36da6fa --- /dev/null +++ b/Source/Blaster/HUD/ElimAnnouncement.h @@ -0,0 +1,26 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Blueprint/UserWidget.h" +#include "ElimAnnouncement.generated.h" + +/** + * + */ +UCLASS() +class BLASTER_API UElimAnnouncement : public UUserWidget +{ + GENERATED_BODY() + +public: + void SetElimAnnouncementText(FString AttackerName, FString VictimName); + + UPROPERTY(meta = (BindWidget)) + class UHorizontalBox* AnnouncementBox; + + UPROPERTY(meta = (BindWidget)) + class UTextBlock* AnnouncementText; + +}; diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index fe38fa7..fb667cd 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -19,6 +19,44 @@ #include "Kismet/GameplayStatics.h" #include "Net/UnrealNetwork.h" +void ABlasterPlayerController::BroadcastElim(APlayerState* Attacker, APlayerState* Victim) +{ + ClientElimAnnouncement(Attacker, Victim); +} + +void ABlasterPlayerController::ClientElimAnnouncement_Implementation(APlayerState* Attacker, APlayerState* Victim) +{ + const APlayerState* Self = GetPlayerState(); + if (Attacker && Victim && Self) + { + BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; + if (BlasterHUD) + { + if (Attacker == Self && Victim != Self) + { + BlasterHUD->AddElimAnnouncement("You", Victim->GetPlayerName()); + return; + } + if (Victim == Self && Attacker != Self) + { + BlasterHUD->AddElimAnnouncement(Attacker->GetPlayerName(), "you"); + return; + } + if (Attacker == Victim && Attacker == Self) + { + BlasterHUD->AddElimAnnouncement("You", "yourself"); + return; + } + if (Attacker == Victim && Attacker != Self) + { + BlasterHUD->AddElimAnnouncement(Attacker->GetPlayerName(), "themselves"); + return; + } + + BlasterHUD->AddElimAnnouncement(Attacker->GetPlayerName(), Victim->GetPlayerName()); + } + } +} void ABlasterPlayerController::BeginPlay() { diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.h b/Source/Blaster/PlayerController/BlasterPlayerController.h index 940fa4f..22d8c42 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.h +++ b/Source/Blaster/PlayerController/BlasterPlayerController.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "GameFramework/PlayerController.h" +#include "GameFramework/PlayerState.h" #include "BlasterPlayerController.generated.h" DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FHighPingDelegate, bool, bPingTooHigh); @@ -50,6 +51,8 @@ public: float SingleTripTime = 0.f; FHighPingDelegate HighPingDelegate; + + void BroadcastElim(APlayerState* Attacker, APlayerState* Victim); protected: virtual void SetupInputComponent() override; @@ -87,6 +90,9 @@ protected: void StopHighPingWarning(); void ShowReturnToMainMenu(); + + UFUNCTION(Client, Reliable) + void ClientElimAnnouncement(APlayerState* Attacker, APlayerState* Victim); private: UPROPERTY()