From b539f0715c9d3e0e60a9867b14152528bdf4c55a Mon Sep 17 00:00:00 2001 From: kirillsaint Date: Mon, 6 Nov 2023 15:02:05 +0600 Subject: [PATCH] Better Scroll --- .../gui/resourcepacks/SilentResourcePacksGui.java | 15 +++++++++------ .../silentclient/client/utils/ScrollHelper.java | 10 +++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/silentclient/client/gui/resourcepacks/SilentResourcePacksGui.java b/src/main/java/net/silentclient/client/gui/resourcepacks/SilentResourcePacksGui.java index 7b54050..213dcd1 100644 --- a/src/main/java/net/silentclient/client/gui/resourcepacks/SilentResourcePacksGui.java +++ b/src/main/java/net/silentclient/client/gui/resourcepacks/SilentResourcePacksGui.java @@ -21,6 +21,7 @@ import net.silentclient.client.gui.util.RenderUtil; import net.silentclient.client.utils.*; import org.apache.commons.io.FilenameUtils; import org.lwjgl.Sys; +import org.lwjgl.input.Mouse; import java.awt.*; import java.io.File; @@ -102,11 +103,13 @@ public class SilentResourcePacksGui extends SilentScreen { RenderUtils.drawRect(blockX, blockY, blockWidth, blockHeight, Theme.backgroundColor().getRGB()); Client.getInstance().getSilentFontRenderer().drawString("Resource Packs", blockX + 5, blockY + 5, 14, SilentFontRenderer.FontType.TITLE); - MouseCursorHandler.CursorType cursorType1 = this.drawAvailableResourcePacks(blockX + 5, blockY + 14 + 5 + 2, mouseX, mouseY); + int wheel = Mouse.getDWheel(); + + MouseCursorHandler.CursorType cursorType1 = this.drawAvailableResourcePacks(blockX + 5, blockY + 14 + 5 + 2, mouseX, mouseY, wheel); if(cursorType1 != null) { cursorType = cursorType1; } - MouseCursorHandler.CursorType cursorType2 = this.drawActiveResourcePacks(blockX + blockWidth - 193 - 5, blockY + 14 + 5 + 2, mouseX, mouseY); + MouseCursorHandler.CursorType cursorType2 = this.drawActiveResourcePacks(blockX + blockWidth - 193 - 5, blockY + 14 + 5 + 2, mouseX, mouseY, wheel); if(cursorType2 != null) { cursorType = cursorType2; } @@ -116,7 +119,7 @@ public class SilentResourcePacksGui extends SilentScreen { Client.getInstance().getMouseCursorHandler().enableCursor(cursorType); } - private MouseCursorHandler.CursorType drawAvailableResourcePacks(float x, float y, int mouseX, int mouseY) { + private MouseCursorHandler.CursorType drawAvailableResourcePacks(float x, float y, int mouseX, int mouseY, int wheel) { MouseCursorHandler.CursorType cursorType = null; RenderUtil.drawRoundedOutline(x, y, 193, blockHeight - 45, 3, 1, Theme.borderColor().getRGB()); scrollHelper.setStep(5); @@ -130,7 +133,7 @@ public class SilentResourcePacksGui extends SilentScreen { scrollHelper.setFlag(false); } - float scrollY = scrollHelper.getScroll(); + float scrollY = scrollHelper.getScroll(wheel); float itemY = y + 19 + scrollY; @@ -195,7 +198,7 @@ public class SilentResourcePacksGui extends SilentScreen { } } - private MouseCursorHandler.CursorType drawActiveResourcePacks(float x, float y, int mouseX, int mouseY) { + private MouseCursorHandler.CursorType drawActiveResourcePacks(float x, float y, int mouseX, int mouseY, int wheel) { MouseCursorHandler.CursorType cursorType = null; RenderUtil.drawRoundedOutline(x, y, 193, blockHeight - 45, 3, 1, Theme.borderColor().getRGB()); scrollHelper2.setStep(5); @@ -207,7 +210,7 @@ public class SilentResourcePacksGui extends SilentScreen { } else { scrollHelper2.setFlag(false); } - float scrollY = scrollHelper2.getScroll(); + float scrollY = scrollHelper2.getScroll(wheel); Scissor.start((int) x, (int) y, 193, blockHeight - 45); Client.getInstance().getSilentFontRenderer().drawString("Active", x + 3, y + 3 + scrollY, 14, SilentFontRenderer.FontType.TITLE); diff --git a/src/main/java/net/silentclient/client/utils/ScrollHelper.java b/src/main/java/net/silentclient/client/utils/ScrollHelper.java index d8d67be..2c1e20b 100644 --- a/src/main/java/net/silentclient/client/utils/ScrollHelper.java +++ b/src/main/java/net/silentclient/client/utils/ScrollHelper.java @@ -8,14 +8,14 @@ public class ScrollHelper { private float step = 0,real = 0,scroll = 0,elementsHeight = 0,maxScroll = 0,speed = 300F; private boolean flag = true; + public float getScroll() { + return getScroll(Mouse.getDWheel()); + } + /** Returns the smoothed scroll value, only call this once after you set all the setters */ - public float getScroll() { - if(!flag) { - return -scroll; - } - int wheel = Mouse.getDWheel(); + public float getScroll(int wheel) { float delta = 1f / Minecraft.getDebugFPS(); if(flag) real -= wheel / 120f * step;