diff --git a/Source/AgrarianGame/AgrarianGamePlayerController.cpp b/Source/AgrarianGame/AgrarianGamePlayerController.cpp index 2e0c850..191b197 100644 --- a/Source/AgrarianGame/AgrarianGamePlayerController.cpp +++ b/Source/AgrarianGame/AgrarianGamePlayerController.cpp @@ -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(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(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()) { diff --git a/Source/AgrarianGame/AgrarianGamePlayerController.h b/Source/AgrarianGame/AgrarianGamePlayerController.h index 3dabe48..763dabb 100644 --- a/Source/AgrarianGame/AgrarianGamePlayerController.h +++ b/Source/AgrarianGame/AgrarianGamePlayerController.h @@ -69,6 +69,7 @@ protected: void HandleMvpEscapeInput(); void ApplyMvpCharacterProxyToPawn(); void SetMvpFrontendPresentationActive(bool bNewActive); + void ApplyDefaultInputMappingContexts(); void CreateOrUpdateMvpFrontendCamera(); void CacheAndApplyMvpHudSuppression(bool bSuppress); virtual void AcknowledgePossession(APawn* P) override;