40 - Network Role

This commit is contained in:
Kingsmedia 2022-04-29 23:38:34 +02:00
parent 712fdb652e
commit 86ff124ae4
7 changed files with 81 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View File

@ -4,6 +4,7 @@
#include "BlasterCharacter.h"
#include "Camera/CameraComponent.h"
#include "Components/WidgetComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/SpringArmComponent.h"
@ -23,6 +24,9 @@ ABlasterCharacter::ABlasterCharacter()
bUseControllerRotationYaw = false;
GetCharacterMovement()->bOrientRotationToMovement = true;
OverheadWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("OverheadWidget"));
OverheadWidget->SetupAttachment(RootComponent);
}
void ABlasterCharacter::BeginPlay()

View File

@ -30,6 +30,9 @@ private:
UPROPERTY(VisibleAnywhere, Category="Camera")
class UCameraComponent* FollowCamera;
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
class UWidgetComponent* OverheadWidget;
public:
};

View File

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

View File

@ -0,0 +1,30 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "OverheadWidget.generated.h"
/**
*
*/
UCLASS()
class BLASTER_API UOverheadWidget : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(meta = (BindWidget))
class UTextBlock* DisplayText;
void SetDisplayText(FString TextToDisplay);
UFUNCTION(BlueprintCallable)
void ShowPlayerNetRole(APawn* InPawn);
protected:
virtual void OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld) override;
};