2024-04-12 13:30:01 -07:00
|
|
|
|
#include "GasaPlayerController.h"
|
2024-04-21 15:56:57 -07:00
|
|
|
|
#include "GasaPlayerController_Inlines.h"
|
2024-04-12 13:30:01 -07:00
|
|
|
|
|
2024-04-13 08:56:19 -07:00
|
|
|
|
#include "AbilitySystemComponent.h"
|
2024-04-12 13:30:01 -07:00
|
|
|
|
#include "Engine/LocalPlayer.h"
|
2024-04-12 14:53:47 -07:00
|
|
|
|
#include "EnhancedInputComponent.h"
|
2024-04-12 13:30:01 -07:00
|
|
|
|
#include "EnhancedInputSubsystems.h"
|
2024-04-21 06:51:51 -07:00
|
|
|
|
#include "GasaDevOptions.h"
|
2024-04-13 08:56:19 -07:00
|
|
|
|
#include "GasaPlayerState.h"
|
2024-04-12 23:31:49 -07:00
|
|
|
|
#include "Actors/CameraMount.h"
|
|
|
|
|
#include "Camera/CameraComponent.h"
|
|
|
|
|
#include "Characters/GasaCharacter.h"
|
|
|
|
|
#include "Components/CapsuleComponent.h"
|
|
|
|
|
#include "GameFramework/SpringArmComponent.h"
|
|
|
|
|
#include "Kismet/KismetSystemLibrary.h"
|
2024-04-21 06:51:51 -07:00
|
|
|
|
using namespace Gasa;
|
|
|
|
|
|
2024-04-12 13:30:01 -07:00
|
|
|
|
AGasaPlayerController::AGasaPlayerController()
|
|
|
|
|
{
|
2024-04-12 23:31:49 -07:00
|
|
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
|
bAutoManageActiveCameraTarget = false;
|
|
|
|
|
|
|
|
|
|
// Replication
|
2024-04-12 13:30:01 -07:00
|
|
|
|
bReplicates = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-21 15:56:57 -07:00
|
|
|
|
|
|
|
|
|
|
2024-04-21 06:51:51 -07:00
|
|
|
|
#pragma region Input
|
2024-04-12 14:53:47 -07:00
|
|
|
|
void AGasaPlayerController::Move(FInputActionValue const& ActionValue)
|
|
|
|
|
{
|
2024-04-12 16:55:34 -07:00
|
|
|
|
APawn* pawn = GetPawn<APawn>();
|
|
|
|
|
if (pawn == nullptr )
|
|
|
|
|
return;
|
2024-04-21 06:51:51 -07:00
|
|
|
|
|
2024-04-12 16:55:34 -07:00
|
|
|
|
// Note(Ed): I did the follow optimization for practice, they are completely unnecessary for this context.
|
2024-04-12 14:53:47 -07:00
|
|
|
|
#if 0
|
|
|
|
|
FVector2D AxisV = ActionValue.Get<FVector2D>();
|
|
|
|
|
FRotator ControlRot = GetControlRotation();
|
|
|
|
|
FRotator YawRot = FRotator(0.f, ControlRot.Yaw, 0.f);
|
|
|
|
|
|
|
|
|
|
FVector FwdDir = FRotationMatrix(YawRot).GetUnitAxis(EAxis::X);
|
|
|
|
|
FVector RightDir = FRotationMatrix(YawRot).GetUnitAxis(EAxis::Y);
|
|
|
|
|
|
2024-04-12 16:55:34 -07:00
|
|
|
|
PPawn->AddMovementInput(FwdDir, AxisV.Y);
|
|
|
|
|
PPawn->AddMovementInput(RightDir, AxisV.X);
|
2024-04-12 14:53:47 -07:00
|
|
|
|
#else
|
|
|
|
|
FVector2f AxisV = FVector2f(ActionValue.Get<FVector2D>());
|
2024-04-12 16:55:34 -07:00
|
|
|
|
|
|
|
|
|
FQuat4f // FQuat isomorphic to FRotor (Hypothetical Def)
|
|
|
|
|
ControlRotor = FQuat4f(GetControlRotation().Quaternion());
|
2024-04-12 14:53:47 -07:00
|
|
|
|
// ControlRotor.Normalize(); // The Quaternion should always be a versor with UE...
|
|
|
|
|
|
2024-04-12 16:55:34 -07:00
|
|
|
|
FVector3f HorizontalForward = ControlRotor.RotateVector(FVector3f::ForwardVector);
|
|
|
|
|
// HorizontalForward.Normalize();
|
|
|
|
|
|
|
|
|
|
// TODO(Ed): Profile which is faster just to know... (atan2 vs FindBetweenVectors)
|
|
|
|
|
// HorizontalForward.Z = 0;
|
|
|
|
|
// FQuat4f
|
|
|
|
|
// YawRotor = FQuat4f::FindBetweenVectors(FVector3f::ForwardVector, HorizontalForward);
|
2024-04-12 14:53:47 -07:00
|
|
|
|
// YawRotor.Normalize(); // The Quaternion should always be a versor with UE...
|
|
|
|
|
|
2024-04-12 16:55:34 -07:00
|
|
|
|
// Need only one axis of rotation so this might be a possible optimization
|
|
|
|
|
float YawAngle = FMath::Atan2(HorizontalForward.Y, HorizontalForward.X);
|
|
|
|
|
FQuat4f YawRotor = FQuat4f(FVector3f::UpVector, YawAngle);
|
2024-04-12 14:53:47 -07:00
|
|
|
|
|
2024-04-12 16:55:34 -07:00
|
|
|
|
// Rotate the combined input by the yaw rotor to get the movement direction
|
|
|
|
|
FVector MoveDir = (FVector) YawRotor.RotateVector( FVector3f(AxisV.Y, AxisV.X, 0.f));
|
|
|
|
|
pawn->AddMovementInput( MoveDir );
|
2024-04-12 14:53:47 -07:00
|
|
|
|
#endif
|
|
|
|
|
}
|
2024-04-21 06:51:51 -07:00
|
|
|
|
#pragma endregion Input
|
|
|
|
|
|
|
|
|
|
#pragma region PlayerController
|
|
|
|
|
void AGasaPlayerController::SpawnDefaultHUD()
|
|
|
|
|
{
|
|
|
|
|
Super::SpawnDefaultHUD();
|
|
|
|
|
}
|
2024-04-12 14:53:47 -07:00
|
|
|
|
|
2024-04-21 15:56:57 -07:00
|
|
|
|
// TODO(Ed): We need to setup Net Slime...
|
2024-04-12 23:31:49 -07:00
|
|
|
|
void AGasaPlayerController::OnPossess(APawn* InPawn)
|
|
|
|
|
{
|
|
|
|
|
Super::OnPossess(InPawn);
|
|
|
|
|
|
|
|
|
|
Cam->AttachToActor(InPawn, FAttachmentTransformRules::KeepRelativeTransform);
|
2024-04-13 08:56:19 -07:00
|
|
|
|
|
|
|
|
|
AGasaPlayerState* PS = GetPlayerState();
|
|
|
|
|
AGasaCharacter* character = Cast<AGasaCharacter>(InPawn);
|
|
|
|
|
// Net Owner setup ability system
|
2024-04-13 15:35:19 -07:00
|
|
|
|
if (0)
|
2024-04-13 08:56:19 -07:00
|
|
|
|
{
|
|
|
|
|
character->AbilitySystem = PS->AbilitySystem;
|
|
|
|
|
character->Attributes = PS->Attributes;
|
|
|
|
|
character->AbilitySystem->InitAbilityActorInfo(PS, character);
|
|
|
|
|
}
|
2024-04-12 23:31:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AGasaPlayerController::OnUnPossess()
|
|
|
|
|
{
|
|
|
|
|
Super::OnUnPossess();
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-12 19:05:09 -07:00
|
|
|
|
void AGasaPlayerController::PlayerTick(float DeltaTime)
|
|
|
|
|
{
|
|
|
|
|
Super::PlayerTick(DeltaTime);
|
|
|
|
|
|
|
|
|
|
// Cursor Trace
|
|
|
|
|
for (int32 do_once = 0; do_once != 1; ++ do_once)
|
|
|
|
|
{
|
|
|
|
|
FHitResult CursorHit;
|
|
|
|
|
GetHitResultUnderCursor(ECC_Pawn, false, CursorHit);
|
|
|
|
|
if (! CursorHit.bBlockingHit)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
HoverPrev = HoverCurr;
|
|
|
|
|
HoverCurr = Cast<AGasaCharacter>(CursorHit.GetActor());
|
|
|
|
|
if (HoverPrev == nullptr)
|
|
|
|
|
{
|
|
|
|
|
// We didn't have a prev to de-highlight so we just need to highlight newly detected character.
|
|
|
|
|
if (HoverCurr)
|
|
|
|
|
HoverCurr->Highlight();
|
|
|
|
|
|
|
|
|
|
// No matter what we need to not go to the next case as there is no previous.
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//else Previous is valid...
|
|
|
|
|
|
|
|
|
|
// We are no longer hovering the previous with no new character, we just need to de-highlight previous.
|
|
|
|
|
if ( HoverCurr == nullptr )
|
|
|
|
|
HoverPrev->Dehighlight();
|
|
|
|
|
|
|
|
|
|
// We had a prev and curr change between frames. They both don't match; we need to switch highlighting.
|
|
|
|
|
else if ( HoverPrev != HoverCurr )
|
|
|
|
|
{
|
|
|
|
|
HoverPrev->Dehighlight();
|
|
|
|
|
HoverCurr->Highlight();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-12 14:53:47 -07:00
|
|
|
|
void AGasaPlayerController::SetupInputComponent()
|
|
|
|
|
{
|
|
|
|
|
Super::SetupInputComponent();
|
|
|
|
|
|
|
|
|
|
UEnhancedInputComponent*
|
|
|
|
|
EIC = CastChecked<UEnhancedInputComponent>(InputComponent);
|
|
|
|
|
{
|
|
|
|
|
EIC->BindAction(IA_Move, ETriggerEvent::Triggered, this, &ThisClass::Move);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#pragma endregion PlayerController
|
|
|
|
|
|
|
|
|
|
#pragma region Actor
|
2024-04-12 13:30:01 -07:00
|
|
|
|
void AGasaPlayerController::BeginPlay()
|
|
|
|
|
{
|
|
|
|
|
Super::BeginPlay();
|
|
|
|
|
|
|
|
|
|
check(IMC);
|
2024-04-12 23:31:49 -07:00
|
|
|
|
|
2024-04-12 13:30:01 -07:00
|
|
|
|
UEnhancedInputLocalPlayerSubsystem*
|
|
|
|
|
EILP_Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer());
|
|
|
|
|
check(EILP_Subsystem);
|
|
|
|
|
EILP_Subsystem->AddMappingContext(IMC, 0);
|
|
|
|
|
{
|
|
|
|
|
bShowMouseCursor = true;
|
|
|
|
|
DefaultMouseCursor = EMouseCursor::Default;
|
|
|
|
|
FInputModeGameAndUI MouseMode;
|
|
|
|
|
MouseMode.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock);
|
|
|
|
|
MouseMode.SetHideCursorDuringCapture(false);
|
|
|
|
|
SetInputMode(MouseMode);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-12 23:31:49 -07:00
|
|
|
|
|
|
|
|
|
void AGasaPlayerController::PostInitializeComponents()
|
|
|
|
|
{
|
|
|
|
|
Super::PostInitializeComponents();
|
|
|
|
|
|
2024-04-21 06:51:51 -07:00
|
|
|
|
Cam = GetWorld()->SpawnActor<ACameraMount>(GetDevOptions()->Template_PlayerCamera.Get(), FActorSpawnParameters() );
|
2024-04-12 23:31:49 -07:00
|
|
|
|
SetViewTarget(Cam);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AGasaPlayerController::Tick(float DeltaSeconds)
|
|
|
|
|
{
|
|
|
|
|
Super::Tick(DeltaSeconds);
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
switch (HighlightState)
|
|
|
|
|
{
|
|
|
|
|
case EHighlight::Disabled:
|
|
|
|
|
break;
|
|
|
|
|
case EHighlight::Enabled:
|
|
|
|
|
{
|
|
|
|
|
UCapsuleComponent* Capsule = GetCapsuleComponent();
|
|
|
|
|
|
|
|
|
|
UKismetSystemLibrary::DrawDebugCapsule(this
|
|
|
|
|
, Capsule->GetComponentLocation()
|
|
|
|
|
, Capsule->GetScaledCapsuleHalfHeight()
|
|
|
|
|
, Capsule->GetScaledCapsuleRadius()
|
|
|
|
|
, Capsule->GetComponentRotation()
|
|
|
|
|
, HighlightColor
|
|
|
|
|
, 0.f
|
|
|
|
|
, 1.f
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2024-04-12 14:53:47 -07:00
|
|
|
|
#pragma endregion Actor
|