Remap scroll wheel to LEFT/RIGHT for horizontal controls

The scroll wheel was always remapped to UP/DOWN, which is fine for
vertical lists but useless on horizontal controls like sliders and
the texture pack selector.

Track whether the mouse is hovering a horizontal control during the
hover hit-test (new bool m_bMouseHoverHorizontalList, set for
eTexturePackList and eSlider). When the flag is set, handleKeyPress
emits LEFT/RIGHT instead of UP/DOWN for wheel events.

TexturePackList is also now part of the mouse hover system with
proper hit-testing, relative-coord SetTouchFocus and GetRealHeight
for accurate bounds.
This commit is contained in:
MrTheShy 2026-03-06 17:13:39 +01:00
parent 8b23c71b93
commit fbadb6ac39
2 changed files with 30 additions and 4 deletions

View file

@ -3,6 +3,7 @@
#include "UI.h"
#include "UIScene.h"
#include "UIControl_Slider.h"
#include "UIControl_TexturePackList.h"
#include "..\..\..\Minecraft.World\StringHelpers.h"
#include "..\..\LocalPlayer.h"
#include "..\..\DLCTexturePack.h"
@ -238,6 +239,7 @@ UIController::UIController()
m_mouseDraggingSliderScene = eUIScene_COUNT;
m_mouseDraggingSliderId = -1;
m_mouseClickConsumedByScene = false;
m_bMouseHoverHorizontalList = false;
m_lastHoverMouseX = -1;
m_lastHoverMouseY = -1;
m_accumulatedTicks = 0;
@ -856,6 +858,7 @@ void UIController::tickInput()
// use their own SetTouchFocus for Flash-side hit testing.
if (mouseMoved)
{
m_bMouseHoverHorizontalList = false;
vector<UIControl *> *controls = pScene->GetControls();
if (controls)
{
@ -871,7 +874,7 @@ void UIController::tickInput()
UIControl::eUIControlType type = ctrl->getControlType();
if (type != UIControl::eButton && type != UIControl::eTextInput &&
type != UIControl::eCheckBox && type != UIControl::eSlider &&
type != UIControl::eButtonList)
type != UIControl::eButtonList && type != UIControl::eTexturePackList)
continue;
// If the scene has an active panel (e.g. tab menus),
@ -884,6 +887,10 @@ void UIController::tickInput()
S32 cy = ctrl->getYPos() + panelOffsetY;
S32 cw = ctrl->getWidth();
S32 ch = ctrl->getHeight();
// TexturePackList origin is where the slot area starts,
// not the top-left of the whole control — use GetRealHeight.
if (type == UIControl::eTexturePackList)
ch = ((UIControl_TexturePackList *)ctrl)->GetRealHeight();
if (cw <= 0 || ch <= 0)
continue;
@ -901,12 +908,27 @@ void UIController::tickInput()
hitCtrl = NULL;
break; // ButtonList takes priority
}
if (type == UIControl::eTexturePackList)
{
// TexturePackList expects coords relative to its origin.
UIControl_TexturePackList *pList = (UIControl_TexturePackList *)ctrl;
pScene->SetFocusToElement(ctrl->getId());
pList->SetTouchFocus(
(S32)(sceneMouseX - cx), (S32)(sceneMouseY - cy), false);
m_bMouseHoverHorizontalList = true;
hitControlId = -1;
hitArea = INT_MAX;
hitCtrl = NULL;
break;
}
S32 area = cw * ch;
if (area < hitArea)
{
hitControlId = ctrl->getId();
hitArea = area;
hitCtrl = ctrl;
if (type == UIControl::eSlider)
m_bMouseHoverHorizontalList = true;
}
}
}
@ -1344,11 +1366,14 @@ void UIController::handleKeyPress(unsigned int iPad, unsigned int key)
down = true;
}
// Remap scroll wheel to UP/DOWN so all scenes get it without
// needing per-scene OTHER_STICK handling.
// Remap scroll wheel to navigation actions. Use LEFT/RIGHT when
// hovering a horizontal list (e.g. TexturePackList), UP/DOWN otherwise.
if (pressed && g_KBMInput.IsKBMActive())
{
key = (key == ACTION_MENU_OTHER_STICK_UP) ? ACTION_MENU_UP : ACTION_MENU_DOWN;
if (m_bMouseHoverHorizontalList)
key = (key == ACTION_MENU_OTHER_STICK_UP) ? ACTION_MENU_LEFT : ACTION_MENU_RIGHT;
else
key = (key == ACTION_MENU_OTHER_STICK_UP) ? ACTION_MENU_UP : ACTION_MENU_DOWN;
}
}
}

View file

@ -161,6 +161,7 @@ private:
EUIScene m_mouseDraggingSliderScene;
int m_mouseDraggingSliderId;
bool m_mouseClickConsumedByScene;
bool m_bMouseHoverHorizontalList;
int m_lastHoverMouseX;
int m_lastHoverMouseY;
//bool m_bSysUIShowing;