fix: fix mouse and controller input handling in container menus

This commit is contained in:
daoge_cmd
2026-03-03 04:59:08 +08:00
parent f917335b13
commit 8f6647b5d8
3 changed files with 13 additions and 7 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
}
}