From 444bc4ae2e5800aefc66460703199218cdd0d8ec Mon Sep 17 00:00:00 2001 From: Parker Hawke Date: Mon, 31 Jul 2023 10:20:16 -0400 Subject: [PATCH] Add enhancement to support scroll wheel for inventory --- GameMods.hpp | 1 + platforms/windows/main.cpp | 6 ++++++ source/App/Minecraft.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/GameMods.hpp b/GameMods.hpp index cb0b48d..437e841 100644 --- a/GameMods.hpp +++ b/GameMods.hpp @@ -26,6 +26,7 @@ #define ENH_HIGHLIGHT_BY_HOVER // Highlight buttons by hovering them instead of the usual way. #define ENH_ALLOW_SAND_GRAVITY // Allow sand to fall. #define ENH_USE_GUI_SCALE_2 // Use a 2x GUI scale instead of 3x. Looks better on PC +#define ENH_ALLOW_SCROLL_WHEEL // Allow use of the scroll wheel to change selected inventory slots // Mods //#define MOD_USE_FLAT_WORLD // Use a flat world instead of the regular world generation diff --git a/platforms/windows/main.cpp b/platforms/windows/main.cpp index 1080525..ea86732 100644 --- a/platforms/windows/main.cpp +++ b/platforms/windows/main.cpp @@ -135,6 +135,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) break; } +#ifdef ENH_ALLOW_SCROLL_WHEEL + case WM_MOUSEWHEEL: + Mouse::feed(3, GET_WHEEL_DELTA_WPARAM(wParam), g_MousePosX, g_MousePosY); + + break; +#endif case WM_SIZE: { UINT width = LOWORD(lParam); diff --git a/source/App/Minecraft.cpp b/source/App/Minecraft.cpp index b4b9be7..b5d895f 100644 --- a/source/App/Minecraft.cpp +++ b/source/App/Minecraft.cpp @@ -341,6 +341,35 @@ void Minecraft::tickInput() handleMouseClick(2); field_DAC = field_DA8; } +#ifdef ENH_ALLOW_SCROLL_WHEEL + if (input.field_0 == 3) + { + int slot = m_pLocalPlayer->m_pInventory->m_SelectedHotbarSlot; + +#ifdef ENH_ENABLE_9TH_SLOT +#define MAX_ITEMS (C_MAX_HOTBAR_ITEMS - 1) +#else +#define MAX_ITEMS (C_MAX_HOTBAR_ITEMS - 2) +#endif + + if (input.field_4 > 0) // @NOTE: Scroll up + { + if (slot-- == 0) + { + slot = MAX_ITEMS; + } + } + else + { + if (slot++ == MAX_ITEMS) // @NOTE: Scroll down + { + slot = 0; + } + } + + m_pLocalPlayer->m_pInventory->selectSlot(slot); + } +#endif } }