From e8094794c3dc3749afbd2db073257b619b8f8e3e Mon Sep 17 00:00:00 2001 From: Wilhelm Schuster Date: Tue, 9 May 2023 21:57:27 +0200 Subject: [PATCH] Allow scrolling through recipe handlers (#379) In addition to scrolling through all recipes of a single handler, you can now scroll through all the recipe handlers while hovering over the handler tab bar (or anywhere in the recipe area while holding left shift). --- .../codechicken/nei/recipe/GuiRecipe.java | 6 +++-- .../codechicken/nei/recipe/GuiRecipeTabs.java | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index 16ad0e56..18c39102 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -388,6 +388,8 @@ public abstract class GuiRecipe extends GuiContainer i // the value of the height field will be different from in other mouseover methods, which // could be confusing... + if (recipeTabs.mouseScrolled(i)) return; + for (int recipe : getRecipeIndices()) if (handler.mouseScrolled(this, i, recipe)) return; if (new Rectangle(guiLeft, guiTop, xSize, ySize).contains(GuiDraw.getMousePosition())) { @@ -462,11 +464,11 @@ public abstract class GuiRecipe extends GuiContainer i if (page < 0) page = (handler.numRecipes() - 1) / getRecipesPerPage(); } - private void nextType() { + protected void nextType() { setRecipePage(++recipetype); } - private void prevType() { + protected void prevType() { setRecipePage(--recipetype); } diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipeTabs.java b/src/main/java/codechicken/nei/recipe/GuiRecipeTabs.java index ea7336a2..4b6f7db5 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipeTabs.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipeTabs.java @@ -1,9 +1,13 @@ package codechicken.nei.recipe; +import static codechicken.lib.gui.GuiDraw.getMousePosition; + import java.awt.*; import java.util.ArrayList; import java.util.List; +import org.lwjgl.input.Keyboard; + import codechicken.nei.Button; import codechicken.nei.NEIClientConfig; import codechicken.nei.NEIClientUtils; @@ -192,4 +196,22 @@ public class GuiRecipeTabs { } return false; } + + protected boolean mouseScrolled(int i) { + Point mPos = getMousePosition(); + + // Switch recipe handler tabs if either left shift is held or the tab + // bar is enable and the mouse cursor is positioned over said tab bar. + if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) + || (NEIClientConfig.areJEIStyleTabsVisible() && (mPos.x >= area.x && mPos.x <= (area.x + area.width) + && mPos.y >= area.y + && mPos.y <= (area.y + area.height)))) { + if (i < 0) guiRecipe.nextType(); + else guiRecipe.prevType(); + + return true; + } + + return false; + } }