diff options
author | Hendrik Horstmann <65970327+heinrich26@users.noreply.github.com> | 2023-10-02 21:22:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-02 21:22:12 +0200 |
commit | 8d742e5a471aa2399cd077a9cda9883a0b7c1bb7 (patch) | |
tree | 47d176608c20a916999cad24814f5a790f1c6047 /src | |
parent | f877ce10737f657fadab950d7fc7f5aee9e53d6c (diff) | |
download | NotEnoughUpdates-8d742e5a471aa2399cd077a9cda9883a0b7c1bb7.tar.gz NotEnoughUpdates-8d742e5a471aa2399cd077a9cda9883a0b7c1bb7.tar.bz2 NotEnoughUpdates-8d742e5a471aa2399cd077a9cda9883a0b7c1bb7.zip |
Scrolling through recipes (#841)
* Enable recipe paging with mouse wheel
* Only scroll while no tooltip is displayed / tooltip-scrolling is disable
* Update GuiItemRecipe.java
Make the comment more clear.
Diffstat (limited to 'src')
3 files changed, 31 insertions, 1 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/TooltipTextScrolling.java b/src/main/java/io/github/moulberry/notenoughupdates/TooltipTextScrolling.java index ccb28dd6..fa721e1e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/TooltipTextScrolling.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/TooltipTextScrolling.java @@ -33,7 +33,7 @@ import java.util.Objects; public class TooltipTextScrolling { static List<String> lastRenderedTooltip = null; static int scrollOffset = 0; - static boolean didRenderTooltip = false; + public static boolean didRenderTooltip = false; public static List<String> handleTextLineRendering(List<String> tooltip) { didRenderTooltip = true; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java index e9bff8f6..a6a61b34 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java @@ -181,6 +181,24 @@ public class ArrowPagesUtils { return false; } + public static boolean onPageSwitchScroll( + int currentPage, + int totalPages, + Consumer<Integer> pageChange + ) { + if (Mouse.getEventDWheel() > 0) { + int newPage = currentPage - 1; + pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1)); + return true; + } else if (Mouse.getEventDWheel() < 0) { + int newPage = currentPage + 1; + pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1)); + return true; + } + + return false; + } + private static boolean isWithinRect(int x, int y, int topLeftX, int topLeftY, int width, int height) { return topLeftX <= x && x < topLeftX + width && topLeftY <= y && y < topLeftY + height; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java index 3627a94e..6dc64ab6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java @@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.miscgui; import com.google.common.collect.ImmutableList; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.TooltipTextScrolling; import io.github.moulberry.notenoughupdates.core.util.ArrowPagesUtils; import io.github.moulberry.notenoughupdates.recipes.NeuRecipe; import io.github.moulberry.notenoughupdates.recipes.RecipeHistory; @@ -336,6 +337,17 @@ public class GuiItemRecipe extends GuiScreen { int mouseY = scaledResolution.getScaledHeight() - Mouse.getY() * scaledResolution.getScaledHeight() / Minecraft.getMinecraft().displayHeight - 1; getCurrentRecipe().genericMouseInput(mouseX, mouseY); + + + // Allow Paging with Scroll-Wheel + + // Block scrolling while Tooltip is displayed + if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.scrollableTooltips && + TooltipTextScrolling.didRenderTooltip) return; + + if (Mouse.getEventDWheel() != 0) { + ArrowPagesUtils.onPageSwitchScroll(currentIndex, getCurrentRecipeList().size(), pageChange -> changeRecipe(currentTab, pageChange)); + } } public void arrowKeyboardInput() { |