Restore gameplay input after MVP frontend

This commit is contained in:
2026-05-21 16:56:54 +00:00
parent 40f7b7e814
commit 03dbcbc5f8
2 changed files with 59 additions and 23 deletions
@@ -168,23 +168,7 @@ void AAgrarianGamePlayerController::SetupInputComponent()
// only add IMCs for local player controllers
if (IsLocalPlayerController())
{
// Add Input Mapping Contexts
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
{
for (UInputMappingContext* CurrentContext : DefaultMappingContexts)
{
Subsystem->AddMappingContext(CurrentContext, 0);
}
// only add these IMCs if we're not using mobile touch input
if (!ShouldUseTouchControls())
{
for (UInputMappingContext* CurrentContext : MobileExcludedMappingContexts)
{
Subsystem->AddMappingContext(CurrentContext, 0);
}
}
}
ApplyDefaultInputMappingContexts();
}
}
@@ -224,8 +208,6 @@ void AAgrarianGamePlayerController::ShowMvpFrontend()
SetMvpFrontendPresentationActive(true);
SetInputMode(FInputModeUIOnly().SetWidgetToFocus(MvpFrontendWidget->TakeWidget()).SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock));
bShowMouseCursor = true;
SetIgnoreMoveInput(true);
SetIgnoreLookInput(true);
}
void AAgrarianGamePlayerController::ShowMvpPauseMenu()
@@ -262,8 +244,6 @@ void AAgrarianGamePlayerController::ShowMvpPauseMenu()
SetMvpFrontendPresentationActive(true);
SetInputMode(FInputModeUIOnly().SetWidgetToFocus(MvpFrontendWidget->TakeWidget()).SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock));
bShowMouseCursor = true;
SetIgnoreMoveInput(true);
SetIgnoreLookInput(true);
}
void AAgrarianGamePlayerController::HandleMvpConfirmInput()
@@ -296,10 +276,23 @@ void AAgrarianGamePlayerController::HandleMvpEscapeInput()
void AAgrarianGamePlayerController::SetMvpFrontendPresentationActive(bool bNewActive)
{
const bool bWasActive = bMvpFrontendPresentationActive;
bMvpFrontendPresentationActive = bNewActive;
SetIgnoreMoveInput(bNewActive);
SetIgnoreLookInput(bNewActive);
if (bNewActive)
{
if (!bWasActive)
{
SetIgnoreMoveInput(true);
SetIgnoreLookInput(true);
}
}
else
{
ResetIgnoreMoveInput();
ResetIgnoreLookInput();
ApplyDefaultInputMappingContexts();
}
APawn* ControlledPawn = GetPawn();
if (ControlledPawn)
@@ -341,6 +334,47 @@ void AAgrarianGamePlayerController::SetMvpFrontendPresentationActive(bool bNewAc
}
}
void AAgrarianGamePlayerController::ApplyDefaultInputMappingContexts()
{
if (!IsLocalPlayerController())
{
return;
}
ULocalPlayer* LocalPlayer = GetLocalPlayer();
if (!LocalPlayer)
{
return;
}
UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(LocalPlayer);
if (!Subsystem)
{
return;
}
for (UInputMappingContext* CurrentContext : DefaultMappingContexts)
{
if (CurrentContext)
{
Subsystem->RemoveMappingContext(CurrentContext);
Subsystem->AddMappingContext(CurrentContext, 0);
}
}
if (!ShouldUseTouchControls())
{
for (UInputMappingContext* CurrentContext : MobileExcludedMappingContexts)
{
if (CurrentContext)
{
Subsystem->RemoveMappingContext(CurrentContext);
Subsystem->AddMappingContext(CurrentContext, 0);
}
}
}
}
void AAgrarianGamePlayerController::CreateOrUpdateMvpFrontendCamera()
{
UWorld* World = GetWorld();
@@ -711,6 +745,7 @@ void AAgrarianGamePlayerController::AgrarianCompleteFrontend()
SetMvpFrontendPresentationActive(false);
SetInputMode(FInputModeGameOnly());
bShowMouseCursor = false;
ApplyDefaultInputMappingContexts();
if (const APawn* ControlledPawn = GetPawn())
{