blaster/Source/Blaster/HUD/OverheadWidget.cpp

57 lines
1.2 KiB
C++
Raw Normal View History

2022-04-29 21:38:34 +00:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "OverheadWidget.h"
#include "Components/TextBlock.h"
#include "GameFramework/PlayerState.h"
2022-04-29 21:38:34 +00:00
void UOverheadWidget::SetDisplayText(FString TextToDisplay)
{
if (DisplayText)
{
DisplayText->SetText(FText::FromString(TextToDisplay));
}
}
void UOverheadWidget::ShowPlayerNetRole(APawn* InPawn)
{
ENetRole RemoveRole = InPawn->GetRemoteRole();
FString Role;
switch (RemoveRole)
{
case ENetRole::ROLE_Authority:
Role = FString("Authority");
break;
case ENetRole::ROLE_AutonomousProxy:
Role = FString("AutonomousProxy");
break;
case ENetRole::ROLE_SimulatedProxy:
Role = FString("SimulatedProxy");
break;
case ENetRole::ROLE_None:
Role = FString("None");
break;
}
FString RemoteRoleString = FString::Printf(TEXT("Remote role: %s"), *Role);
SetDisplayText(RemoteRoleString);
}
void UOverheadWidget::ShowPlayerName(APawn* InPawn)
{
if (APlayerState* PlayerState = InPawn->GetPlayerState())
{
SetDisplayText(PlayerState->GetPlayerName());
} else
{
SetDisplayText("No PlayerState");
}
}
2022-04-29 21:38:34 +00:00
void UOverheadWidget::OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld)
{
RemoveFromParent();
Super::OnLevelRemovedFromWorld(InLevel, InWorld);
}