209 - Elim Announcements

This commit is contained in:
Kingsmedia 2022-05-29 12:42:42 +02:00
parent d2e581afe5
commit fa685e4b62
12 changed files with 117 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View File

@ -121,6 +121,15 @@ void ABlasterGameMode::PlayerEliminated(class ABlasterCharacter* EliminatedChara
{
EliminatedCharacter->Eliminated(false);
}
for (FConstPlayerControllerIterator It = GetWorld()->GetPlayerControllerIterator(); It; ++It)
{
ABlasterPlayerController* BlasterPlayer = Cast<ABlasterPlayerController>(*It);
if (BlasterPlayer && AttackerPlayerState && VictimPlayerState)
{
BlasterPlayer->BroadcastElim(AttackerPlayerState, VictimPlayerState);
}
}
}
void ABlasterGameMode::RequestRespawn(ACharacter* EliminatedCharacter, AController* EliminatedController)

View File

@ -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<UElimAnnouncement>(OwningPlayer, ElimAnnouncementClass);
if (ElimAnnouncementWidget)
{
ElimAnnouncementWidget->SetElimAnnouncementText(Attacker, Victim);
ElimAnnouncementWidget->AddToViewport();
}
}
}
void ABlasterHUD::DrawHUD()
{
Super::DrawHUD();

View File

@ -34,6 +34,7 @@ public:
void AddDebugWidget();
void AddCharacterOverlay();
void AddAnnouncementOverlay();
void AddElimAnnouncement(FString Attacker, FString Victim);
UPROPERTY(EditAnywhere, Category = "Player Stats")
TSubclassOf<class UUserWidget> 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<class UElimAnnouncement> ElimAnnouncementClass;
public:
FORCEINLINE void SetHUDPackage(const FHUDPackage& Package) { HUDPackage = Package; };
};

View File

@ -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));
}
}

View File

@ -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;
};

View File

@ -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<APlayerState>();
if (Attacker && Victim && Self)
{
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(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()
{

View File

@ -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);
@ -51,6 +52,8 @@ public:
FHighPingDelegate HighPingDelegate;
void BroadcastElim(APlayerState* Attacker, APlayerState* Victim);
protected:
virtual void SetupInputComponent() override;
virtual void BeginPlay() override;
@ -88,6 +91,9 @@ protected:
void ShowReturnToMainMenu();
UFUNCTION(Client, Reliable)
void ClientElimAnnouncement(APlayerState* Attacker, APlayerState* Victim);
private:
UPROPERTY()
class UDebugWidget* DebugWidget;