58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
#include "TP_VehicleAdvPlayerController.h"
|
|
#include "TP_VehicleAdvPawn.h"
|
|
#include "TP_VehicleAdvUI.h"
|
|
#include "EnhancedInputSubsystems.h"
|
|
#include "ChaosWheeledVehicleMovementComponent.h"
|
|
|
|
void ATP_VehicleAdvPlayerController::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
// spawn the UI widget and add it to the viewport
|
|
VehicleUI = CreateWidget<UTP_VehicleAdvUI>(this, VehicleUIClass);
|
|
|
|
check(VehicleUI);
|
|
|
|
VehicleUI->AddToViewport();
|
|
}
|
|
|
|
void ATP_VehicleAdvPlayerController::SetupInputComponent()
|
|
{
|
|
Super::SetupInputComponent();
|
|
|
|
// get the enhanced input subsystem
|
|
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
|
|
{
|
|
// add the mapping context so we get controls
|
|
Subsystem->AddMappingContext(InputMappingContext, 0);
|
|
|
|
// optionally add the steering wheel context
|
|
if (bUseSteeringWheelControls && SteeringWheelInputMappingContext)
|
|
{
|
|
Subsystem->AddMappingContext(SteeringWheelInputMappingContext, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ATP_VehicleAdvPlayerController::Tick(float Delta)
|
|
{
|
|
Super::Tick(Delta);
|
|
|
|
if (IsValid(VehiclePawn) && IsValid(VehicleUI))
|
|
{
|
|
VehicleUI->UpdateSpeed(VehiclePawn->GetChaosVehicleMovement()->GetForwardSpeed());
|
|
VehicleUI->UpdateGear(VehiclePawn->GetChaosVehicleMovement()->GetCurrentGear());
|
|
}
|
|
}
|
|
|
|
void ATP_VehicleAdvPlayerController::OnPossess(APawn* InPawn)
|
|
{
|
|
Super::OnPossess(InPawn);
|
|
|
|
// get a pointer to the controlled pawn
|
|
VehiclePawn = CastChecked<ATP_VehicleAdvPawn>(InPawn);
|
|
}
|