Harden MVP menu input and quit flow
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "Engine/LocalPlayer.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
#include "InputCoreTypes.h"
|
||||
#include "InputMappingContext.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "TimerManager.h"
|
||||
@@ -84,6 +85,9 @@ void AAgrarianGamePlayerController::BeginPlay()
|
||||
{
|
||||
if (MvpFrontendStartupDelaySeconds > 0.0f)
|
||||
{
|
||||
SetIgnoreMoveInput(true);
|
||||
SetIgnoreLookInput(true);
|
||||
bShowMouseCursor = false;
|
||||
GetWorldTimerManager().SetTimer(
|
||||
MvpFrontendStartupTimerHandle,
|
||||
this,
|
||||
@@ -121,6 +125,11 @@ void AAgrarianGamePlayerController::SetupInputComponent()
|
||||
{
|
||||
Super::SetupInputComponent();
|
||||
|
||||
InputComponent->BindKey(EKeys::Enter, IE_Pressed, this, &AAgrarianGamePlayerController::HandleMvpConfirmInput);
|
||||
InputComponent->BindKey(EKeys::SpaceBar, IE_Pressed, this, &AAgrarianGamePlayerController::HandleMvpConfirmInput);
|
||||
InputComponent->BindKey(EKeys::BackSpace, IE_Pressed, this, &AAgrarianGamePlayerController::HandleMvpBackInput);
|
||||
InputComponent->BindKey(EKeys::Escape, IE_Pressed, this, &AAgrarianGamePlayerController::HandleMvpEscapeInput);
|
||||
|
||||
// only add IMCs for local player controllers
|
||||
if (IsLocalPlayerController())
|
||||
{
|
||||
@@ -152,7 +161,7 @@ bool AAgrarianGamePlayerController::ShouldUseTouchControls() const
|
||||
|
||||
void AAgrarianGamePlayerController::ShowMvpFrontend()
|
||||
{
|
||||
if (!IsLocalPlayerController() || MvpFrontendWidget)
|
||||
if (!IsLocalPlayerController() || (MvpFrontendWidget && MvpFrontendWidget->IsInViewport()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -162,16 +171,90 @@ void AAgrarianGamePlayerController::ShowMvpFrontend()
|
||||
MvpFrontendWidgetClass = UAgrarianMvpFrontendWidget::StaticClass();
|
||||
}
|
||||
|
||||
MvpFrontendWidget = CreateWidget<UAgrarianMvpFrontendWidget>(this, MvpFrontendWidgetClass);
|
||||
if (!MvpFrontendWidget)
|
||||
{
|
||||
MvpFrontendWidget = CreateWidget<UAgrarianMvpFrontendWidget>(this, MvpFrontendWidgetClass);
|
||||
}
|
||||
|
||||
if (!MvpFrontendWidget)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MvpFrontendWidget->SetActiveScreen(EAgrarianMvpFrontendScreen::CharacterSelection);
|
||||
MvpFrontendWidget->AddToPlayerScreen(10);
|
||||
if (!MvpFrontendWidget->IsInViewport())
|
||||
{
|
||||
MvpFrontendWidget->AddToPlayerScreen(10);
|
||||
}
|
||||
SetInputMode(FInputModeGameAndUI().SetWidgetToFocus(MvpFrontendWidget->TakeWidget()).SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock));
|
||||
bShowMouseCursor = true;
|
||||
SetIgnoreMoveInput(true);
|
||||
SetIgnoreLookInput(true);
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::ShowMvpPauseMenu()
|
||||
{
|
||||
if (!IsLocalPlayerController())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MvpFrontendWidgetClass)
|
||||
{
|
||||
MvpFrontendWidgetClass = UAgrarianMvpFrontendWidget::StaticClass();
|
||||
}
|
||||
|
||||
if (!MvpFrontendWidget || !MvpFrontendWidget->IsInViewport())
|
||||
{
|
||||
if (!MvpFrontendWidget)
|
||||
{
|
||||
MvpFrontendWidget = CreateWidget<UAgrarianMvpFrontendWidget>(this, MvpFrontendWidgetClass);
|
||||
}
|
||||
|
||||
if (MvpFrontendWidget)
|
||||
{
|
||||
MvpFrontendWidget->AddToPlayerScreen(10);
|
||||
}
|
||||
}
|
||||
|
||||
if (!MvpFrontendWidget)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MvpFrontendWidget->SetActiveScreen(EAgrarianMvpFrontendScreen::MainMenu);
|
||||
SetInputMode(FInputModeGameAndUI().SetWidgetToFocus(MvpFrontendWidget->TakeWidget()).SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock));
|
||||
bShowMouseCursor = true;
|
||||
SetIgnoreMoveInput(true);
|
||||
SetIgnoreLookInput(true);
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::HandleMvpConfirmInput()
|
||||
{
|
||||
if (MvpFrontendWidget && MvpFrontendWidget->IsInViewport())
|
||||
{
|
||||
MvpFrontendWidget->ConfirmActiveScreen();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::HandleMvpBackInput()
|
||||
{
|
||||
if (MvpFrontendWidget && MvpFrontendWidget->IsInViewport())
|
||||
{
|
||||
MvpFrontendWidget->BackFromActiveScreen();
|
||||
}
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::HandleMvpEscapeInput()
|
||||
{
|
||||
if (MvpFrontendWidget && MvpFrontendWidget->IsInViewport())
|
||||
{
|
||||
MvpFrontendWidget->BackFromActiveScreen();
|
||||
return;
|
||||
}
|
||||
|
||||
ShowMvpPauseMenu();
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::AgrarianGrantItem(FName ItemId, int32 Quantity)
|
||||
|
||||
Reference in New Issue
Block a user