diff --git a/source/client/app/Minecraft.cpp b/source/client/app/Minecraft.cpp index 2cee86a5..54da23e6 100644 --- a/source/client/app/Minecraft.cpp +++ b/source/client/app/Minecraft.cpp @@ -420,6 +420,11 @@ void Minecraft::tickInput() if (Mouse::isButtonDown(BUTTON_LEFT)) m_gui.handleClick(1, Mouse::getX(), Mouse::getY()); +#ifdef ENH_ALLOW_SCROLL_WHEEL + if (Mouse::getEventButton() == BUTTON_SCROLLWHEEL) + m_gui.handleScroll(Mouse::getEventButtonState() == 1); +#endif + if (!bIsInGUI && getOptions()->field_19) { MouseButtonType buttonType = Mouse::getEventButton(); @@ -428,32 +433,6 @@ void Minecraft::tickInput() handleMouseClick(buttonType); field_DAC = field_DA8; } - -#ifdef ENH_ALLOW_SCROLL_WHEEL - if (Mouse::getEventButton() == BUTTON_SCROLLWHEEL) - { - int slot = m_pLocalPlayer->m_pInventory->m_selectedHotbarSlot; - - int maxItems = m_gui.getNumUsableSlots() - 1; - - if (Mouse::getEventButtonState() == 0) // @NOTE: Scroll up - { - if (slot-- == 0) - { - slot = maxItems; - } - } - else - { - if (slot++ == maxItems) // @NOTE: Scroll down - { - slot = 0; - } - } - - m_pLocalPlayer->m_pInventory->selectSlot(slot); - } -#endif } } @@ -1244,4 +1223,4 @@ void Minecraft::locateMultiplayer() m_pRakNetInstance->pingForHosts(C_DEFAULT_PORT); m_pNetEventCallback = new ClientSideNetworkHandler(this, m_pRakNetInstance); #endif -} \ No newline at end of file +} diff --git a/source/client/gui/Gui.cpp b/source/client/gui/Gui.cpp index 748a3c19..790acd93 100644 --- a/source/client/gui/Gui.cpp +++ b/source/client/gui/Gui.cpp @@ -446,6 +446,26 @@ void Gui::handleClick(int clickID, int mouseX, int mouseY) m_pMinecraft->m_pLocalPlayer->m_pInventory->selectSlot(slot); } +void Gui::handleScroll(bool down) +{ + int slot = m_pMinecraft->m_pLocalPlayer->m_pInventory->m_selectedHotbarSlot; + + int maxItems = getNumUsableSlots() - 1; + + if (down) + { + if (slot++ == maxItems) + slot = 0; + } + else + { + if (slot-- == 0) + slot = maxItems; + } + + m_pMinecraft->m_pLocalPlayer->m_pInventory->selectSlot(slot); +} + void Gui::handleKeyPressed(int keyCode) { if (m_pMinecraft->getOptions()->isKey(KM_INVENTORY, keyCode)) @@ -553,4 +573,4 @@ RectangleArea Gui::getRectangleArea(bool b) Minecraft::height - 24.0f / InvGuiScale, centerX + hotbarWidthHalf, Minecraft::height); -} \ No newline at end of file +} diff --git a/source/client/gui/Gui.hpp b/source/client/gui/Gui.hpp index ddab01f9..76db639c 100644 --- a/source/client/gui/Gui.hpp +++ b/source/client/gui/Gui.hpp @@ -40,6 +40,7 @@ class Gui : public GuiComponent int getSlotIdAt(int mx, int my); bool isInside(int mx, int my); void handleClick(int id, int mx, int my); + void handleScroll(bool down); void handleKeyPressed(int keyCode); void renderMessages(bool bShowAll); int getNumSlots(); // Gets the number of slots in the inventory. Includes the '...' if in touch mode. diff --git a/source/client/gui/Screen.cpp b/source/client/gui/Screen.cpp index 8b73b444..58ec5877 100644 --- a/source/client/gui/Screen.cpp +++ b/source/client/gui/Screen.cpp @@ -120,6 +120,10 @@ void Screen::charInput(char chr) } } +void Screen::handleScroll(bool down) +{ +} + static const char* g_panoramaList[] = { "gui/background/panorama_0.png", @@ -430,6 +434,8 @@ void Screen::mouseEvent() else mouseReleased(m_width * pAction->_posX / Minecraft::width, m_height * pAction->_posY / Minecraft::height - 1 + getYOffset(), Mouse::getEventButton()); } + if (pAction->_buttonType == BUTTON_SCROLLWHEEL) + handleScroll(Mouse::getEventButtonState()); } void Screen::renderBackground(int unk) diff --git a/source/client/gui/Screen.hpp b/source/client/gui/Screen.hpp index 660c28db..6465c83f 100644 --- a/source/client/gui/Screen.hpp +++ b/source/client/gui/Screen.hpp @@ -48,6 +48,7 @@ class Screen : public GuiComponent virtual void mouseReleased(int, int, int); virtual void keyPressed(int); virtual void charInput(char); + virtual void handleScroll(bool down); // ported from 0.8 virtual void renderMenuBackground(float f); diff --git a/source/client/gui/components/RolledSelectionList.cpp b/source/client/gui/components/RolledSelectionList.cpp index cac88078..311582af 100644 --- a/source/client/gui/components/RolledSelectionList.cpp +++ b/source/client/gui/components/RolledSelectionList.cpp @@ -335,3 +335,10 @@ void RolledSelectionList::clickedHeader(int x, int y) { } + +void RolledSelectionList::handleScroll(bool down) +{ + float diff = 5.0f * (down ? -1.0f : 1.0f); + field_34 = field_30 = field_30 + diff; + field_28 = 0; +} diff --git a/source/client/gui/components/RolledSelectionList.hpp b/source/client/gui/components/RolledSelectionList.hpp index 6d02f78a..e830f948 100644 --- a/source/client/gui/components/RolledSelectionList.hpp +++ b/source/client/gui/components/RolledSelectionList.hpp @@ -33,6 +33,7 @@ class RolledSelectionList : public GuiComponent virtual void renderBackground() = 0; virtual void renderDecorations(int x, int y); virtual void clickedHeader(int, int); + virtual void handleScroll(bool down); int getItemAtXPositionRaw(int x); diff --git a/source/client/gui/components/ScrolledSelectionList.cpp b/source/client/gui/components/ScrolledSelectionList.cpp index 12676237..e0ffcc14 100644 --- a/source/client/gui/components/ScrolledSelectionList.cpp +++ b/source/client/gui/components/ScrolledSelectionList.cpp @@ -97,7 +97,6 @@ void ScrolledSelectionList::renderScrollBackground() void ScrolledSelectionList::checkInput(int mouseX, int mouseY) { - int nItems = getNumberOfItems(); if (Mouse::isButtonDown(BUTTON_LEFT)) { if (float(mouseY) >= field_C && float(mouseY) <= field_10 && abs(mouseY - field_28) > 5) @@ -276,3 +275,10 @@ void ScrolledSelectionList::setRenderHeader(bool b, int i) i = 0; field_48 = i; } + +void ScrolledSelectionList::handleScroll(bool down) +{ + float diff = 5.0f * (down ? -1.0f : 1.0f); + field_34 -= diff; + field_38 += diff; +} diff --git a/source/client/gui/components/ScrolledSelectionList.hpp b/source/client/gui/components/ScrolledSelectionList.hpp index 3c979860..a0b6c19b 100644 --- a/source/client/gui/components/ScrolledSelectionList.hpp +++ b/source/client/gui/components/ScrolledSelectionList.hpp @@ -36,6 +36,7 @@ class ScrolledSelectionList : public GuiComponent virtual void checkInput(int mouseX, int mouseY); virtual void onClickItem(int index, int mouseX, int mouseY); virtual void renderScrollBackground(); + virtual void handleScroll(bool down); void setRenderHeader(bool, int); diff --git a/source/client/gui/screens/OptionsScreen.cpp b/source/client/gui/screens/OptionsScreen.cpp index a147b954..a0180894 100644 --- a/source/client/gui/screens/OptionsScreen.cpp +++ b/source/client/gui/screens/OptionsScreen.cpp @@ -71,6 +71,10 @@ void OptionsScreen::buttonClicked(Button* pButton) } } +void OptionsScreen::handleScroll(bool down) +{ + m_pList->handleScroll(down); +} #else diff --git a/source/client/gui/screens/OptionsScreen.hpp b/source/client/gui/screens/OptionsScreen.hpp index 023dc7db..99277c80 100644 --- a/source/client/gui/screens/OptionsScreen.hpp +++ b/source/client/gui/screens/OptionsScreen.hpp @@ -23,6 +23,7 @@ class OptionsScreen : public Screen void render(int, int, float) override; void removed() override; void buttonClicked(Button* pButton) override; + void handleScroll(bool down) override; private: OptionList* m_pList; diff --git a/source/client/gui/screens/SelectWorldScreen.cpp b/source/client/gui/screens/SelectWorldScreen.cpp index 5cd0a44b..df9b99e7 100644 --- a/source/client/gui/screens/SelectWorldScreen.cpp +++ b/source/client/gui/screens/SelectWorldScreen.cpp @@ -222,6 +222,11 @@ void SelectWorldScreen::buttonClicked(Button* pButton) } } +void SelectWorldScreen::handleScroll(bool down) +{ + m_pWorldSelectionList->handleScroll(down); +} + bool SelectWorldScreen::isIndexValid(int idx) { if (!m_pWorldSelectionList) diff --git a/source/client/gui/screens/SelectWorldScreen.hpp b/source/client/gui/screens/SelectWorldScreen.hpp index b4daaea4..85fb6463 100644 --- a/source/client/gui/screens/SelectWorldScreen.hpp +++ b/source/client/gui/screens/SelectWorldScreen.hpp @@ -23,6 +23,7 @@ class SelectWorldScreen : public Screen void render(int mouseX, int mouseY, float f) override; bool handleBackEvent(bool b) override; void buttonClicked(Button* pButton) override; + void handleScroll(bool down) override; bool isIndexValid(int); std::string getUniqueLevelName(const std::string& in);