9ffe9abddb
cpp code
140 lines
4.5 KiB
C++
140 lines
4.5 KiB
C++
// Copyright Team Lumi. All Rights Reserved.
|
|
|
|
|
|
#include "LumiController.h"
|
|
|
|
#include "EnhancedInputComponent.h"
|
|
#include "EnhancedInputSubsystems.h"
|
|
#include "InputMappingContext.h"
|
|
|
|
void ALumiController::ShowMouseCursor()
|
|
{
|
|
FInputModeGameAndUI InputMode;
|
|
InputMode.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock);
|
|
InputMode.SetHideCursorDuringCapture(false);
|
|
bShowMouseCursor = true;
|
|
SetInputMode(InputMode);
|
|
}
|
|
|
|
void ALumiController::HideMouseCursor()
|
|
{
|
|
FInputModeGameAndUI InputMode;
|
|
InputMode.SetLockMouseToViewportBehavior(EMouseLockMode::LockAlways);
|
|
InputMode.SetHideCursorDuringCapture(true);
|
|
bShowMouseCursor = false;
|
|
SetInputMode(InputMode);
|
|
}
|
|
|
|
void ALumiController::GetLumiCharacter(ALumiCharacter*& OutLumiCharacter) const
|
|
{
|
|
OutLumiCharacter = LumiCharacter;
|
|
}
|
|
|
|
void ALumiController::OnPossess(APawn* InPawn)
|
|
{
|
|
Super::OnPossess(InPawn);
|
|
|
|
LumiCharacter = Cast<ALumiCharacter>(InPawn);
|
|
checkf(
|
|
LumiCharacter,
|
|
TEXT("ALumiController::OnPossess() InPawn is not a ALumiCharacter!")
|
|
);
|
|
|
|
EnhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent);
|
|
checkf(
|
|
EnhancedInputComponent,
|
|
TEXT("ALumiController::OnPossess() InputComponent is not a UEnhancedInputComponent!")
|
|
);
|
|
|
|
UEnhancedInputLocalPlayerSubsystem* EnhancedInputSubsystem =
|
|
ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer());
|
|
checkf(
|
|
EnhancedInputSubsystem,
|
|
TEXT("ALumiController::OnPossess() EnhancedInputSubsystem is nullptr!")
|
|
);
|
|
checkf(
|
|
InputMappingContext,
|
|
TEXT("ALumiController::OnPossess() InputMappingContext is nullptr!")
|
|
);
|
|
EnhancedInputSubsystem->ClearAllMappings();
|
|
EnhancedInputSubsystem->AddMappingContext(InputMappingContext, MappingPriority);
|
|
|
|
if (GrabAction)
|
|
{
|
|
EnhancedInputComponent->BindAction(GrabAction,
|
|
ETriggerEvent::Triggered,
|
|
LumiCharacter,
|
|
&ALumiCharacter::OnGrabActionTriggered);
|
|
}
|
|
if (JumpAction)
|
|
{
|
|
EnhancedInputComponent->BindAction(JumpAction,
|
|
ETriggerEvent::Started,
|
|
LumiCharacter,
|
|
&ALumiCharacter::OnJumpActionStarted);
|
|
EnhancedInputComponent->BindAction(JumpAction,
|
|
ETriggerEvent::Ongoing,
|
|
LumiCharacter,
|
|
&ALumiCharacter::OnJumpActionOngoing);
|
|
EnhancedInputComponent->BindAction(JumpAction,
|
|
ETriggerEvent::Completed,
|
|
LumiCharacter,
|
|
&ALumiCharacter::OnJumpActionCompleted);
|
|
}
|
|
if (MoveAction)
|
|
{
|
|
EnhancedInputComponent->BindAction(MoveAction,
|
|
ETriggerEvent::Triggered,
|
|
LumiCharacter,
|
|
&ALumiCharacter::OnMoveActionTriggered);
|
|
}
|
|
if (LookAction)
|
|
{
|
|
EnhancedInputComponent->BindAction(LookAction,
|
|
ETriggerEvent::Triggered,
|
|
LumiCharacter,
|
|
&ALumiCharacter::OnLookActionTriggered);
|
|
}
|
|
if (SpellAction)
|
|
{
|
|
EnhancedInputComponent->BindAction(SpellAction,
|
|
ETriggerEvent::Started,
|
|
LumiCharacter,
|
|
&ALumiCharacter::OnSpellActionStarted);
|
|
EnhancedInputComponent->BindAction(SpellAction,
|
|
ETriggerEvent::Completed,
|
|
this,
|
|
&ALumiController::OnSpellActionCompleted);
|
|
EnhancedInputComponent->BindAction(SpellPositionAction,
|
|
ETriggerEvent::Triggered,
|
|
LumiCharacter,
|
|
&ALumiCharacter::OnSpellPositionActionTriggered);
|
|
}
|
|
if (SpellTrainSwitchAction)
|
|
{
|
|
EnhancedInputComponent->BindAction(SpellTrainSwitchAction,
|
|
ETriggerEvent::Completed,
|
|
LumiCharacter,
|
|
&ALumiCharacter::OnSpellTrainSwitchActionCompleted);
|
|
}
|
|
}
|
|
|
|
void ALumiController::OnUnPossess()
|
|
{
|
|
EnhancedInputComponent->ClearActionBindings();
|
|
|
|
Super::OnUnPossess();
|
|
}
|
|
|
|
void ALumiController::OnSpellActionStarted()
|
|
{
|
|
ShowMouseCursor();
|
|
LumiCharacter->OnSpellActionStarted();
|
|
}
|
|
|
|
void ALumiController::OnSpellActionCompleted()
|
|
{
|
|
LumiCharacter->OnSpellActionCompleted();
|
|
HideMouseCursor();
|
|
}
|