From 83e28d38283b2d0e443079445df9c15445a1cb96 Mon Sep 17 00:00:00 2001 From: Daniel Poveda Date: Sun, 12 Oct 2025 15:19:25 +0200 Subject: [PATCH] fix: inputs --- .../Blueprints/BP_MainPlayerController.uasset | 4 +- Content/Input/IMC_UI.uasset | 3 ++ Content/UI/WBP_SkillNode.uasset | 4 +- Content/UI/WBP_SkillTree.uasset | 4 +- Source/UTAD_UI/UTAD_UIPlayerController.cpp | 42 ++++++++++++++++--- Source/UTAD_UI/UTAD_UIPlayerController.h | 7 +++- 6 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 Content/Input/IMC_UI.uasset diff --git a/Content/Blueprints/BP_MainPlayerController.uasset b/Content/Blueprints/BP_MainPlayerController.uasset index 6349249..97957d7 100644 --- a/Content/Blueprints/BP_MainPlayerController.uasset +++ b/Content/Blueprints/BP_MainPlayerController.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3e39e2619235b70ec969458e3e02ad066a9a38695e7e7bd51bb6819fa629401b -size 22101 +oid sha256:8202c9a6a8047db6f8a7147b1b4593d1cc25fbebdfa47ab436e68ffe576b5179 +size 22277 diff --git a/Content/Input/IMC_UI.uasset b/Content/Input/IMC_UI.uasset new file mode 100644 index 0000000..be9eb07 --- /dev/null +++ b/Content/Input/IMC_UI.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ec19397d6979f077d3e126702cb2f4a75959a369ef9dc4a49f226740ca8f6c1 +size 2780 diff --git a/Content/UI/WBP_SkillNode.uasset b/Content/UI/WBP_SkillNode.uasset index f0332ff..3526046 100644 --- a/Content/UI/WBP_SkillNode.uasset +++ b/Content/UI/WBP_SkillNode.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fbae4dd9457a9da175c1dfd1447dd77e9c4631a9d78f82908d7104568f750b6d -size 283220 +oid sha256:50d80d3fda9d5eee62200c98af7a43a3e679459e1e92334fb71598b377977c8b +size 283216 diff --git a/Content/UI/WBP_SkillTree.uasset b/Content/UI/WBP_SkillTree.uasset index e9a4c3c..cd272b9 100644 --- a/Content/UI/WBP_SkillTree.uasset +++ b/Content/UI/WBP_SkillTree.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e6e0c146fd7a416f8a3b0ac66ecaf1a061d87be97d55edcb410c1471c347f5bb -size 282145 +oid sha256:f8f60c1cae98e35b9971c51f6278386a26a46de56daa1bb4c5962c85b97a9eac +size 292870 diff --git a/Source/UTAD_UI/UTAD_UIPlayerController.cpp b/Source/UTAD_UI/UTAD_UIPlayerController.cpp index 5c2c0e1..c66698a 100644 --- a/Source/UTAD_UI/UTAD_UIPlayerController.cpp +++ b/Source/UTAD_UI/UTAD_UIPlayerController.cpp @@ -195,12 +195,29 @@ void AUTAD_UIPlayerController::ShowSkillTree() { SkillTreeWidget->AddToViewport(1); - // Set input mode to Game and UI - FInputModeGameAndUI InputMode; + // Switch to UI-only input mode to block gameplay actions (like click-to-move) + FInputModeUIOnly InputMode; InputMode.SetWidgetToFocus(SkillTreeWidget->TakeWidget()); InputMode.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock); SetInputMode(InputMode); bShowMouseCursor = true; + + // Switch input mapping context from gameplay to UI + if (UEnhancedInputLocalPlayerSubsystem* Subsystem = + ULocalPlayer::GetSubsystem( + GetLocalPlayer())) + { + // Remove gameplay context + if (DefaultMappingContext) + { + Subsystem->RemoveMappingContext(DefaultMappingContext); + } + // Add UI context with higher priority + if (UIMappingContext) + { + Subsystem->AddMappingContext(UIMappingContext, 1); + } + } } } @@ -210,14 +227,29 @@ void AUTAD_UIPlayerController::HideSkillTree() { SkillTreeWidget->RemoveFromParent(); - // Set input mode back to game and UI for top-down gameplay - // This allows mouse clicks to work for character movement + // Restore game and UI input mode for top-down gameplay FInputModeGameAndUI InputMode; InputMode.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock); InputMode.SetHideCursorDuringCapture(false); SetInputMode(InputMode); - // Keep mouse cursor visible for top-down game bShowMouseCursor = true; + + // Switch input mapping context back from UI to gameplay + if (UEnhancedInputLocalPlayerSubsystem* Subsystem = + ULocalPlayer::GetSubsystem( + GetLocalPlayer())) + { + // Remove UI context + if (UIMappingContext) + { + Subsystem->RemoveMappingContext(UIMappingContext); + } + // Restore gameplay context + if (DefaultMappingContext) + { + Subsystem->AddMappingContext(DefaultMappingContext, 0); + } + } } } diff --git a/Source/UTAD_UI/UTAD_UIPlayerController.h b/Source/UTAD_UI/UTAD_UIPlayerController.h index 4c609df..386c800 100644 --- a/Source/UTAD_UI/UTAD_UIPlayerController.h +++ b/Source/UTAD_UI/UTAD_UIPlayerController.h @@ -43,11 +43,16 @@ public: UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input) UNiagaraSystem* FXCursor; - /** MappingContext */ + /** Gameplay Mapping Context (for movement and game actions) */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) UInputMappingContext* DefaultMappingContext; + /** UI Mapping Context (for UI-specific actions like closing menus) */ + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, + meta = (AllowPrivateAccess = "true")) + UInputMappingContext* UIMappingContext; + /** Jump Input Action */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))