61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
#include "SpaceshipPlayerController.h"
|
|
#include "EnhancedInputComponent.h"
|
|
#include "EnhancedInputSubsystems.h"
|
|
#include "Components/PostProcessComponent.h"
|
|
#include "Materials/MaterialInstanceDynamic.h"
|
|
#include "SpaceShooterGameMode.h"
|
|
|
|
ASpaceshipPlayerController::ASpaceshipPlayerController()
|
|
{
|
|
// Don't automatically show mouse cursor
|
|
bShowMouseCursor = false;
|
|
}
|
|
|
|
void ASpaceshipPlayerController::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
// Add Input Mapping Context
|
|
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
|
|
{
|
|
if (DefaultMappingContext)
|
|
{
|
|
Subsystem->AddMappingContext(DefaultMappingContext, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ASpaceshipPlayerController::SetupInputComponent()
|
|
{
|
|
Super::SetupInputComponent();
|
|
|
|
if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(InputComponent))
|
|
{
|
|
// Bind the pause action
|
|
if (PauseAction)
|
|
{
|
|
EnhancedInputComponent->BindAction(PauseAction, ETriggerEvent::Started,
|
|
this, &ASpaceshipPlayerController::HandlePauseAction);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ASpaceshipPlayerController::HandlePauseAction()
|
|
{
|
|
// Don't allow pausing if game is over
|
|
if (ASpaceShooterGameMode* GameMode = Cast<ASpaceShooterGameMode>(GetWorld()->GetAuthGameMode()))
|
|
{
|
|
if (GameMode->IsGameOver())
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
bool bIsPaused = IsPaused();
|
|
SetPause(!bIsPaused);
|
|
|
|
// Show cursor only when paused, hide when resuming
|
|
bShowMouseCursor = !bIsPaused;
|
|
|
|
// To fix resume not working, don't change input mode from game only to UI only since in UI mode the key mapping for pause won't work
|
|
} |