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 // only add IMCs for local player controllers
if (IsLocalPlayerController()) if (IsLocalPlayerController())
{ {
// Add Input Mapping Contexts ApplyDefaultInputMappingContexts();
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);
}
}
}
} }
} }
@@ -224,8 +208,6 @@ void AAgrarianGamePlayerController::ShowMvpFrontend()
SetMvpFrontendPresentationActive(true); SetMvpFrontendPresentationActive(true);
SetInputMode(FInputModeUIOnly().SetWidgetToFocus(MvpFrontendWidget->TakeWidget()).SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock)); SetInputMode(FInputModeUIOnly().SetWidgetToFocus(MvpFrontendWidget->TakeWidget()).SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock));
bShowMouseCursor = true; bShowMouseCursor = true;
SetIgnoreMoveInput(true);
SetIgnoreLookInput(true);
} }
void AAgrarianGamePlayerController::ShowMvpPauseMenu() void AAgrarianGamePlayerController::ShowMvpPauseMenu()
@@ -262,8 +244,6 @@ void AAgrarianGamePlayerController::ShowMvpPauseMenu()
SetMvpFrontendPresentationActive(true); SetMvpFrontendPresentationActive(true);
SetInputMode(FInputModeUIOnly().SetWidgetToFocus(MvpFrontendWidget->TakeWidget()).SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock)); SetInputMode(FInputModeUIOnly().SetWidgetToFocus(MvpFrontendWidget->TakeWidget()).SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock));
bShowMouseCursor = true; bShowMouseCursor = true;
SetIgnoreMoveInput(true);
SetIgnoreLookInput(true);
} }
void AAgrarianGamePlayerController::HandleMvpConfirmInput() void AAgrarianGamePlayerController::HandleMvpConfirmInput()
@@ -296,10 +276,23 @@ void AAgrarianGamePlayerController::HandleMvpEscapeInput()
void AAgrarianGamePlayerController::SetMvpFrontendPresentationActive(bool bNewActive) void AAgrarianGamePlayerController::SetMvpFrontendPresentationActive(bool bNewActive)
{ {
const bool bWasActive = bMvpFrontendPresentationActive;
bMvpFrontendPresentationActive = bNewActive; bMvpFrontendPresentationActive = bNewActive;
SetIgnoreMoveInput(bNewActive); if (bNewActive)
SetIgnoreLookInput(bNewActive); {
if (!bWasActive)
{
SetIgnoreMoveInput(true);
SetIgnoreLookInput(true);
}
}
else
{
ResetIgnoreMoveInput();
ResetIgnoreLookInput();
ApplyDefaultInputMappingContexts();
}
APawn* ControlledPawn = GetPawn(); APawn* ControlledPawn = GetPawn();
if (ControlledPawn) 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() void AAgrarianGamePlayerController::CreateOrUpdateMvpFrontendCamera()
{ {
UWorld* World = GetWorld(); UWorld* World = GetWorld();
@@ -711,6 +745,7 @@ void AAgrarianGamePlayerController::AgrarianCompleteFrontend()
SetMvpFrontendPresentationActive(false); SetMvpFrontendPresentationActive(false);
SetInputMode(FInputModeGameOnly()); SetInputMode(FInputModeGameOnly());
bShowMouseCursor = false; bShowMouseCursor = false;
ApplyDefaultInputMappingContexts();
if (const APawn* ControlledPawn = GetPawn()) if (const APawn* ControlledPawn = GetPawn())
{ {
@@ -69,6 +69,7 @@ protected:
void HandleMvpEscapeInput(); void HandleMvpEscapeInput();
void ApplyMvpCharacterProxyToPawn(); void ApplyMvpCharacterProxyToPawn();
void SetMvpFrontendPresentationActive(bool bNewActive); void SetMvpFrontendPresentationActive(bool bNewActive);
void ApplyDefaultInputMappingContexts();
void CreateOrUpdateMvpFrontendCamera(); void CreateOrUpdateMvpFrontendCamera();
void CacheAndApplyMvpHudSuppression(bool bSuppress); void CacheAndApplyMvpHudSuppression(bool bSuppress);
virtual void AcknowledgePossession(APawn* P) override; virtual void AcknowledgePossession(APawn* P) override;