221 - Teams Cooldown Announcement

This commit is contained in:
Kingsmedia 2022-05-30 22:35:28 +02:00
parent 5a34578647
commit c964d7bd45
3 changed files with 92 additions and 22 deletions

View File

@ -13,6 +13,7 @@
#include "Blaster/HUD/DebugWidget.h"
#include "Blaster/HUD/ReturnToMainMenu.h"
#include "Blaster/PlayerState/BlasterPlayerState.h"
#include "Blaster/Types/Announcement.h"
#include "Components/ProgressBar.h"
#include "Components/TextBlock.h"
#include "GameFramework/GameMode.h"
@ -697,7 +698,7 @@ void ABlasterPlayerController::HandleCooldown()
if (bHUDValid)
{
BlasterHUD->Announcement->SetVisibility(ESlateVisibility::Visible);
FString AnnouncementText("New match starts in:");
FString AnnouncementText = Announcement::NewMatchStartsIn;
BlasterHUD->Announcement->AnnouncementText->SetText(FText::FromString(AnnouncementText));
ABlasterGameState* BlasterGameState = Cast<ABlasterGameState>(UGameplayStatics::GetGameState(this));
@ -705,27 +706,7 @@ void ABlasterPlayerController::HandleCooldown()
if (BlasterGameState && BlasterPlayerState)
{
TArray<ABlasterPlayerState*> TopPlayers = BlasterGameState->TopScoringPlayers;
FString InfoTextString;
if (TopPlayers.Num() == 0)
{
InfoTextString = FString("There is no winner.");
}
else if (TopPlayers.Num() == 1 && TopPlayers[0] == BlasterPlayerState)
{
InfoTextString = FString("You are the winner!");
}
else if (TopPlayers.Num() == 1)
{
InfoTextString = FString::Printf(TEXT("%s won!"), *TopPlayers[0]->GetPlayerName());
}
else if (TopPlayers.Num() > 1)
{
InfoTextString = FString("Players tied for the win:\n");
for (auto TiedPlayer : TopPlayers)
{
InfoTextString.Append(FString::Printf(TEXT("%s\n"), *TiedPlayer->GetPlayerName()));
}
}
FString InfoTextString = bShowTeamScores ? GetTeamsInfoText(BlasterGameState) : GetInfoText(TopPlayers);
BlasterHUD->Announcement->AnnouncementMessage->SetText(FText::FromString(InfoTextString));
}
@ -738,3 +719,75 @@ void ABlasterPlayerController::HandleCooldown()
BlasterCharacter->GetCombat()->FireButtonPressed(false);
}
}
FString ABlasterPlayerController::GetInfoText(const TArray<ABlasterPlayerState*>& Players)
{
const ABlasterPlayerState* BlasterPlayerState = GetPlayerState<ABlasterPlayerState>();
if (BlasterPlayerState == nullptr) return FString();
FString InfoTextString;
if (Players.Num() == 0)
{
InfoTextString = Announcement::ThereIsNoWinner;
}
else if (Players.Num() == 1 && Players[0] == BlasterPlayerState)
{
InfoTextString = Announcement::YouAreTheWinner;
}
else if (Players.Num() == 1)
{
InfoTextString = FString::Printf(TEXT("%s won!"), *Players[0]->GetPlayerName());
}
else if (Players.Num() > 1)
{
InfoTextString = Announcement::PlayersTiedForTheWin;
InfoTextString.Append(FString("\n"));
for (const auto TiedPlayer : Players)
{
InfoTextString.Append(FString::Printf(TEXT("%s\n"), *TiedPlayer->GetPlayerName()));
}
}
return InfoTextString;
}
FString ABlasterPlayerController::GetTeamsInfoText(ABlasterGameState* BlasterGameState)
{
if (BlasterGameState == nullptr) return FString();
FString InfoTextString;
const int32 RedTeamScore = BlasterGameState->RedTeamScore;
const int32 BlueTeamScore = BlasterGameState->BlueTeamScore;
if (RedTeamScore == 0 && BlueTeamScore == 0)
{
InfoTextString = Announcement::ThereIsNoWinner;
}
else if (RedTeamScore == BlueTeamScore)
{
InfoTextString = FString::Printf(TEXT("%s\n"), *Announcement::TeamsTiedForTheWin);
InfoTextString.Append(Announcement::RedTeam);
InfoTextString.Append(TEXT("\n"));
InfoTextString.Append(Announcement::BlueTeam);
InfoTextString.Append(TEXT("\n"));
}
else if (RedTeamScore > BlueTeamScore)
{
InfoTextString = Announcement::RedTeamWins;
InfoTextString.Append(TEXT("\n"));
InfoTextString.Append(FString::Printf(TEXT("%s: %d"), *Announcement::RedTeam, RedTeamScore));
InfoTextString.Append(TEXT("\n"));
InfoTextString.Append(FString::Printf(TEXT("%s: %d"), *Announcement::BlueTeam, BlueTeamScore));
}
else if (BlueTeamScore > RedTeamScore)
{
InfoTextString = Announcement::BlueTeamWins;
InfoTextString.Append(TEXT("\n"));
InfoTextString.Append(FString::Printf(TEXT("%s: %d"), *Announcement::BlueTeam, BlueTeamScore));
InfoTextString.Append(TEXT("\n"));
InfoTextString.Append(FString::Printf(TEXT("%s: %d"), *Announcement::RedTeam, RedTeamScore));
}
return InfoTextString;
}

View File

@ -103,6 +103,9 @@ protected:
UFUNCTION()
void OnRep_ShowTeamScores();
FString GetInfoText(const TArray<class ABlasterPlayerState*>& Players);
FString GetTeamsInfoText(class ABlasterGameState* BlasterGameState);
private:
UPROPERTY()

View File

@ -0,0 +1,14 @@
#pragma once
namespace Announcement
{
const FString NewMatchStartsIn(TEXT("New match starts in:"));
const FString ThereIsNoWinner(TEXT("There is no winner."));
const FString YouAreTheWinner(TEXT("You are the winner!"));
const FString PlayersTiedForTheWin(TEXT("Players tied for the win:"));
const FString TeamsTiedForTheWin(TEXT("Teams tied for the win:"));
const FString RedTeam(TEXT("Red team"));
const FString BlueTeam(TEXT("Blue team"));
const FString RedTeamWins(TEXT("Red team wins!"));
const FString BlueTeamWins(TEXT("Blue team wins!"));
}