55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "ShooterPlayerController.h"
|
|
#include "ShooterGameInstance.h"
|
|
|
|
#include "Kismet/GameplayStatics.h"
|
|
#include "Blueprint/UserWidget.h"
|
|
|
|
AShooterPlayerController::AShooterPlayerController()
|
|
{
|
|
}
|
|
|
|
void AShooterPlayerController::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
// Check our HUD Overlay TSubclassOf variable
|
|
if (HUDOverlayClass)
|
|
{
|
|
HUDOverlay = CreateWidget<UUserWidget>(this, HUDOverlayClass);
|
|
|
|
if (HUDOverlay)
|
|
{
|
|
HUDOverlay->AddToViewport();
|
|
HUDOverlay->SetVisibility(ESlateVisibility::Hidden);
|
|
}
|
|
}
|
|
}
|
|
|
|
void AShooterPlayerController::GameHasEnded(AActor* EndGameFocus, bool bIsWinner)
|
|
{
|
|
Super::GameHasEnded(EndGameFocus, bIsWinner);
|
|
if (HUDOverlay)
|
|
HUDOverlay->RemoveFromParent();
|
|
|
|
if (!bIsWinner)
|
|
{
|
|
UUserWidget* LoseScreen = CreateWidget(this, LoseScreenClass);
|
|
if (LoseScreen != nullptr)
|
|
{
|
|
LoseScreen->AddToViewport();
|
|
}
|
|
}
|
|
UShooterGameInstance* GI = Cast<UShooterGameInstance>(UGameplayStatics::GetGameInstance(GetWorld()));
|
|
if (GI)
|
|
{
|
|
// Avoid playing the intro cutscene again
|
|
GI->SetLevelStartSeqAlreadyPlayed(true);
|
|
}
|
|
|
|
GetWorldTimerManager().SetTimer(RestartTimer, this, &APlayerController::RestartLevel, RestartDelay);
|
|
}
|
|
|