From 8f6647b5d89bbb56eeda727dfee9916d8514104d Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Tue, 3 Mar 2026 04:59:08 +0800 Subject: [PATCH] fix: fix mouse and controller input handling in container menus --- .../Common/UI/IUIScene_AbstractContainerMenu.cpp | 4 +++- .../Common/UI/IUIScene_AbstractContainerMenu.h | 1 + .../Common/UI/UIScene_AbstractContainerMenu.cpp | 15 +++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp index ffe83081..1b76141d 100644 --- a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp +++ b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp @@ -21,6 +21,7 @@ IUIScene_AbstractContainerMenu::IUIScene_AbstractContainerMenu() m_pointerPos.x = 0.0f; m_pointerPos.y = 0.0f; + m_bPointerDrivenByMouse = false; } @@ -357,6 +358,7 @@ void IUIScene_AbstractContainerMenu::onMouseTick() // If there is any input on sticks, move the pointer. if ( ( fabs( fInputX ) >= 0.01f ) || ( fabs( fInputY ) >= 0.01f ) ) { + m_bPointerDrivenByMouse = false; fInputDirX = ( fInputX > 0.0f ) ? 1.0f : ( fInputX < 0.0f )?-1.0f : 0.0f; fInputDirY = ( fInputY > 0.0f ) ? 1.0f : ( fInputY < 0.0f )?-1.0f : 0.0f; @@ -692,7 +694,7 @@ void IUIScene_AbstractContainerMenu::onMouseTick() // If there is no stick input, and we are over a slot, then snap pointer to slot centre. // 4J - TomK - only if this particular component allows so! - if(CanHaveFocus(eSectionUnderPointer)) + if(!m_bPointerDrivenByMouse && CanHaveFocus(eSectionUnderPointer)) { vPointerPos.x = vSnapPos.x; vPointerPos.y = vSnapPos.y; diff --git a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.h b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.h index 7d16f522..fe79bf19 100644 --- a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.h +++ b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.h @@ -125,6 +125,7 @@ protected: eTutorial_State m_previousTutorialState; UIVec2D m_pointerPos; + bool m_bPointerDrivenByMouse; // Offset from pointer image top left to centre (we use the centre as the actual pointer). float m_fPointerImageOffsetX; diff --git a/Minecraft.Client/Common/UI/UIScene_AbstractContainerMenu.cpp b/Minecraft.Client/Common/UI/UIScene_AbstractContainerMenu.cpp index f769622e..5ad275c3 100644 --- a/Minecraft.Client/Common/UI/UIScene_AbstractContainerMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_AbstractContainerMenu.cpp @@ -187,7 +187,7 @@ void UIScene_AbstractContainerMenu::tick() #ifdef _WINDOWS64 bool mouseActive = (m_iPad == 0 && !KMInput.IsCaptured()); - bool useRawMousePointer = false; + bool drivePointerFromMouse = false; float rawMouseMovieX = 0, rawMouseMovieY = 0; int scrollDelta = 0; // Map Windows mouse position to the virtual pointer in movie coordinates @@ -215,11 +215,13 @@ void UIScene_AbstractContainerMenu::tick() rawMouseMovieX = mx; rawMouseMovieY = my; - // Only let the OS cursor drive the menu when the mouse is actively being used. - // Otherwise a stationary mouse will override the controller cursor every tick. - useRawMousePointer = mouseMoved || KMInput.IsMouseDown(0) || KMInput.IsMouseDown(1) || KMInput.IsMouseDown(2) || scrollDelta != 0; - if (useRawMousePointer) + // Once the mouse has taken over the container cursor, keep following the OS cursor + // until explicit controller input takes ownership back. + drivePointerFromMouse = m_bPointerDrivenByMouse || mouseMoved || KMInput.IsMouseDown(0) || KMInput.IsMouseDown(1) || KMInput.IsMouseDown(2) || scrollDelta != 0; + if (drivePointerFromMouse) { + m_bPointerDrivenByMouse = true; + m_eCurrTapState = eTapStateNoInput; m_pointerPos.x = mx; m_pointerPos.y = my; } @@ -293,7 +295,7 @@ void UIScene_AbstractContainerMenu::tick() #ifdef _WINDOWS64 S32 x, y; - if (mouseActive && useRawMousePointer) + if (mouseActive && m_bPointerDrivenByMouse) { // Send raw mouse position directly as Iggy event to avoid coordinate round-trip errors // Scale mouse client coords to the Iggy display space (which was set to getRenderDimensions()) @@ -386,6 +388,7 @@ void UIScene_AbstractContainerMenu::handleInput(int iPad, int key, bool repeat, if(pressed) { + m_bPointerDrivenByMouse = false; handled = handleKeyDown(m_iPad, key, repeat); } }