blaster/Source/Blaster/HUD/OverheadWidget.cpp

57 lines
1.2 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "OverheadWidget.h"
#include "Components/TextBlock.h"
#include "GameFramework/PlayerState.h"
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");
}
}
void UOverheadWidget::OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld)
{
RemoveFromParent();
Super::OnLevelRemovedFromWorld(InLevel, InWorld);
}