diff --git a/src/main/java/net/silentclient/client/cosmetics/gui/CosmeticsGui.java b/src/main/java/net/silentclient/client/cosmetics/gui/CosmeticsGui.java index dc17181..3d5864a 100644 --- a/src/main/java/net/silentclient/client/cosmetics/gui/CosmeticsGui.java +++ b/src/main/java/net/silentclient/client/cosmetics/gui/CosmeticsGui.java @@ -11,20 +11,19 @@ import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.silentclient.client.Client; import net.silentclient.client.gui.SilentScreen; -import net.silentclient.client.gui.animation.SimpleAnimation; -import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils; -import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils.Scroll; import net.silentclient.client.gui.elements.Button; import net.silentclient.client.gui.elements.Input; import net.silentclient.client.gui.font.SilentFontRenderer; +import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils; import net.silentclient.client.gui.theme.Theme; +import net.silentclient.client.gui.theme.button.DefaultButtonTheme; +import net.silentclient.client.gui.theme.button.SelectedButtonTheme; import net.silentclient.client.gui.util.RenderUtil; import net.silentclient.client.mods.settings.CosmeticsMod; import net.silentclient.client.mods.settings.GeneralMod; -import net.silentclient.client.gui.theme.button.DefaultButtonTheme; -import net.silentclient.client.gui.theme.button.SelectedButtonTheme; import net.silentclient.client.utils.MenuBlurUtils; import net.silentclient.client.utils.MouseCursorHandler; +import net.silentclient.client.utils.ScrollHelper; import net.silentclient.client.utils.Sounds; import net.silentclient.client.utils.types.PlayerResponse.Account.Cosmetics.CosmeticItem; import org.lwjgl.input.Mouse; @@ -36,10 +35,9 @@ import java.net.URI; import java.util.ArrayList; public class CosmeticsGui extends SilentScreen { - public static double scrollY; - public static SimpleAnimation scrollAnimation = new SimpleAnimation(0.0F); public static String selectedCategory = "capes"; private int rotate = 0; + private ScrollHelper scrollHelper = new ScrollHelper(); @Override public void initGui() { @@ -51,7 +49,6 @@ public class CosmeticsGui extends SilentScreen { MenuBlurUtils.loadBlur(); } this.silentInputs.add(new Input("Search")); - CosmeticsGui.scrollY = 0; CosmeticsGui.selectedCategory = "capes"; Client.getInstance().updateUserInformation(); int categoryOffsetY = 25; @@ -166,7 +163,6 @@ public class CosmeticsGui extends SilentScreen { } this.silentInputs.get(0).setValue(""); - scrollY = 0; } if(button.id == 7) { @@ -300,6 +296,10 @@ public class CosmeticsGui extends SilentScreen { } if(can_show) { + scrollHelper.setStep(5); + scrollHelper.setElementsHeight((items != null ? items.size() : 0) * 35); + scrollHelper.setMaxScroll(height - 25); + scrollHelper.setSpeed(100); GL11.glPushMatrix(); GL11.glEnable(GL11.GL_SCISSOR_TEST); ScaledResolution r = new ScaledResolution(mc); @@ -308,8 +308,8 @@ public class CosmeticsGui extends SilentScreen { GL11.glScissor(x * s, translatedY * s, width * s, (height - 25) * s); if(items != null) { for(CosmeticItem m : items) { - RenderUtil.drawRoundedOutline(x + 100, y + modOffsetY + scrollAnimation.getValue(), 135, 28, 10, 2, selected_item.contains(m.getId()) ? new Color(32, 252, 3).getRGB() : new Color(252, 3, 3).getRGB()); - if(MouseUtils.isInside(mouseX, mouseY, x + 100, y + modOffsetY + scrollAnimation.getValue(), 135, 28)) { + RenderUtil.drawRoundedOutline(x + 100, y + modOffsetY + scrollHelper.getScroll(), 135, 28, 10, 2, selected_item.contains(m.getId()) ? new Color(32, 252, 3).getRGB() : new Color(252, 3, 3).getRGB()); + if(MouseUtils.isInside(mouseX, mouseY, x + 100, y + modOffsetY + scrollHelper.getScroll(), 135, 28)) { cursorType = MouseCursorHandler.CursorType.POINTER; } GL11.glDisable((int) 2929); @@ -320,14 +320,14 @@ public class CosmeticsGui extends SilentScreen { GL11.glDepthMask((boolean) true); GL11.glDisable((int) 3042); GL11.glEnable((int) 2929); - Client.getInstance().getSilentFontRenderer().drawString(m.getName(), x + 110, y + modOffsetY + 10 + (int) scrollAnimation.getValue() - 3, 14, SilentFontRenderer.FontType.TITLE, 100); + Client.getInstance().getSilentFontRenderer().drawString(m.getName(), x + 110, y + modOffsetY + 10 + scrollHelper.getScroll() - 3, 14, SilentFontRenderer.FontType.TITLE, 100); boolean favorite = false; for(Number i : getFavoriteItems()) { if(i.intValue() == m.getId()) { favorite = true; } } - RenderUtil.drawImage(favorite ? new ResourceLocation("silentclient/icons/star.png") : new ResourceLocation("silentclient/icons/star_outline.png"), x + 100 + 120, y + modOffsetY + scrollAnimation.getValue() + 8, 12, 12, false); + RenderUtil.drawImage(favorite ? new ResourceLocation("silentclient/icons/star.png") : new ResourceLocation("silentclient/icons/star_outline.png"), x + 100 + 120, y + modOffsetY + scrollHelper.getScroll() + 8, 12, 12, false); modOffsetY+= 35; modIndex += 1; @@ -364,39 +364,10 @@ public class CosmeticsGui extends SilentScreen { } Client.getInstance().getMouseCursorHandler().enableCursor(cursorType); - - final Scroll scroll = MouseUtils.scroll(); - - if(scroll != null) { - switch (scroll) { - case DOWN: - if(scrollY > -((modIndex - 5.5) * 38)) { - scrollY -=20; - } - - if(modIndex > 5) { - if(scrollY < -((modIndex - 7) * 38)) { - scrollY = -((modIndex - 6.1) * 38); - } - } - break; - case UP: - if(scrollY < -10) { - scrollY +=20; - }else { - if(modIndex > 5) { - scrollY = 0; - } - } - break; - } - } if(can_show) { this.silentInputs.get(0).render(mouseX, mouseY, x + width - 140, y + 2, 135); } - - scrollAnimation.setAnimation((float) scrollY, 16); } public void updateScreen() @@ -478,9 +449,9 @@ public class CosmeticsGui extends SilentScreen { if(items != null && can_show) { this.silentInputs.get(0).onClick(mouseX, mouseY, x + width - 140, y + 2, 135); for(CosmeticItem m : items) { - if(MouseUtils.isInside(mouseX, mouseY, x + 100 + 120, y + modOffsetY + scrollAnimation.getValue() + 8, 12, 12)) { + if(MouseUtils.isInside(mouseX, mouseY, x + 100 + 120, y + modOffsetY + scrollHelper.getScroll() + 8, 12, 12)) { Client.getInstance().getAccount().updateFavorite(m.getId(), selectedCategory); - } else if(MouseUtils.isInside(mouseX, mouseY,x + 100, y + modOffsetY + scrollAnimation.getValue(), 135, 28) && mouseButton == 0) { + } else if(MouseUtils.isInside(mouseX, mouseY,x + 100, y + modOffsetY + scrollHelper.getScroll(), 135, 28) && mouseButton == 0) { Sounds.playButtonSound(); if(selectedCategory == "capes") { Client.getInstance().getAccount().setSelectedCape(m.getId()); @@ -521,6 +492,9 @@ public class CosmeticsGui extends SilentScreen { } if(can_show) { this.silentInputs.get(0).onKeyTyped(typedChar, keyCode); + if(this.silentInputs.get(0).isFocused()) { + this.scrollHelper.resetScroll(); + } } } diff --git a/src/main/java/net/silentclient/client/cosmetics/gui/OutfitsGui.java b/src/main/java/net/silentclient/client/cosmetics/gui/OutfitsGui.java index 1727401..957d8ae 100644 --- a/src/main/java/net/silentclient/client/cosmetics/gui/OutfitsGui.java +++ b/src/main/java/net/silentclient/client/cosmetics/gui/OutfitsGui.java @@ -9,7 +9,6 @@ import net.minecraft.util.ResourceLocation; import net.silentclient.client.Client; import net.silentclient.client.cosmetics.Outfits; import net.silentclient.client.gui.SilentScreen; -import net.silentclient.client.gui.animation.SimpleAnimation; import net.silentclient.client.gui.elements.IconButton; import net.silentclient.client.gui.font.SilentFontRenderer; import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils; @@ -17,9 +16,9 @@ import net.silentclient.client.gui.theme.Theme; import net.silentclient.client.gui.util.RenderUtil; import net.silentclient.client.utils.MenuBlurUtils; import net.silentclient.client.utils.MouseCursorHandler; +import net.silentclient.client.utils.ScrollHelper; import net.silentclient.client.utils.types.PlayerResponse; import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import java.awt.*; @@ -27,9 +26,8 @@ import java.io.IOException; public class OutfitsGui extends SilentScreen { private final GuiScreen parentScreen; - private SimpleAnimation scrollAnimation = new SimpleAnimation(0.0F); - private float scrollY = 0; private int outfitIndex = 0; + private ScrollHelper scrollHelper = new ScrollHelper(); public OutfitsGui(GuiScreen parentScreen) { this.parentScreen = parentScreen; @@ -40,7 +38,6 @@ public class OutfitsGui extends SilentScreen { public void initGui() { super.initGui(); defaultCursor = false; - this.scrollY = 0; if(mc.thePlayer == null) { Client.backgroundPanorama.updateWidthHeight(this.width, this.height); } else { @@ -72,6 +69,12 @@ public class OutfitsGui extends SilentScreen { int height = 200; int x = this.width / 2 - (width / 2); int y = this.height / 2 - (height / 2); + scrollHelper.setStep(5); + scrollHelper.setElementsHeight((float) Math.ceil((Outfits.getOutfits().size() + 2) / 3) * 85); + scrollHelper.setMaxScroll(height - 20); + scrollHelper.setSpeed(100); + scrollHelper.setFlag(true); + float scrollY = scrollHelper.getScroll(); RenderUtil.drawRoundedRect(x, y, width, height, 4, Theme.backgroundColor().getRGB()); Client.getInstance().getSilentFontRenderer().drawString(x + 3, y + 3, "Outfits", 14, SilentFontRenderer.FontType.TITLE); super.drawScreen(mouseX, mouseY, partialTicks); @@ -83,7 +86,7 @@ public class OutfitsGui extends SilentScreen { int translatedY = r.getScaledHeight() - y - 20 - listHeight; GL11.glScissor(0 * s, translatedY * s, this.width * s, listHeight * s); int outfitX = x + 3; - float outfitY = (int) (y + 20 - scrollAnimation.getValue()); + float outfitY = y + 20 + scrollY; int outfitIndex = 0; boolean isCreateHovered = MouseUtils.isInside(mouseX, mouseY, outfitX, outfitY, 80, 80); if(isCreateHovered) { @@ -178,34 +181,6 @@ public class OutfitsGui extends SilentScreen { GL11.glDisable(GL11.GL_SCISSOR_TEST); GL11.glPopMatrix(); - - scrollAnimation.setAnimation(scrollY, 12); - } - - @Override - public void handleMouseInput() throws IOException { - super.handleMouseInput(); - int dw = Mouse.getEventDWheel(); - double newScrollY = this.scrollY; - int height = 200; - if(dw != 0) { - if (dw > 0) { - dw = -1; - } else { - dw = 1; - } - float amountScrolled = (float) (dw * 10); - if (newScrollY + amountScrolled > 0) - newScrollY += amountScrolled; - else - newScrollY = 0; - if((newScrollY < (this.outfitIndex * 26) && (this.outfitIndex * 26) > height - 20) || amountScrolled < 0) { - this.scrollY = (float) newScrollY; - if(this.scrollY < 0) { - this.scrollY = 0; - } - } - } } @Override @@ -224,7 +199,7 @@ public class OutfitsGui extends SilentScreen { int x = this.width / 2 - (width / 2); int y = this.height / 2 - (height / 2); int outfitX = x + 3; - float outfitY = (int) (y + 20 - scrollAnimation.getValue()); + float outfitY = (int) (y + 20 + scrollHelper.getScroll()); int outfitIndex = 0; if(MouseUtils.isInside(mouseX, mouseY, outfitX, outfitY, 80, 80)) { mc.displayGuiScreen(new NewOutfitModal(this)); diff --git a/src/main/java/net/silentclient/client/gui/multiplayer/SilentMultiplayerGui.java b/src/main/java/net/silentclient/client/gui/multiplayer/SilentMultiplayerGui.java index 71f59a9..ae1964c 100644 --- a/src/main/java/net/silentclient/client/gui/multiplayer/SilentMultiplayerGui.java +++ b/src/main/java/net/silentclient/client/gui/multiplayer/SilentMultiplayerGui.java @@ -11,7 +11,6 @@ import net.minecraft.client.renderer.GlStateManager; import net.silentclient.client.Client; import net.silentclient.client.ServerDataFeature; import net.silentclient.client.gui.SilentScreen; -import net.silentclient.client.gui.animation.SimpleAnimation; import net.silentclient.client.gui.elements.Button; import net.silentclient.client.gui.elements.Input; import net.silentclient.client.gui.font.SilentFontRenderer; @@ -22,7 +21,7 @@ import net.silentclient.client.gui.multiplayer.components.ServerComponent; import net.silentclient.client.gui.theme.Theme; import net.silentclient.client.mixin.ducks.ServerListExt; import net.silentclient.client.utils.MouseCursorHandler; -import org.lwjgl.input.Mouse; +import net.silentclient.client.utils.ScrollHelper; import org.lwjgl.opengl.GL11; import java.awt.*; @@ -42,9 +41,8 @@ public class SilentMultiplayerGui extends SilentScreen { private Button btnDeleteServer; private boolean initialized; private ArrayList servers = new ArrayList<>(); - private SimpleAnimation scrollAnimation = new SimpleAnimation(0.0F); - private float scrollY = 0; private int selectedServer = -1; + private ScrollHelper scrollHelper = new ScrollHelper(); public SilentMultiplayerGui(GuiScreen parentScreen) { this.parentScreen = parentScreen; @@ -140,8 +138,11 @@ public class SilentMultiplayerGui extends SilentScreen { Client.getInstance().getSilentFontRenderer().drawCenteredString("Play Multiplayer", blockX + blockWidth / 2, blockY + 3, 16, SilentFontRenderer.FontType.TITLE); this.silentInputs.get(0).render(mouseX, mouseY, blockX + 5, blockY + 3 + 16 + 5, blockWidth - 10, true); - - float serverY = blockY + 43 - scrollAnimation.getValue(); + scrollHelper.setStep(5); + scrollHelper.setElementsHeight(servers.size() * 38); + scrollHelper.setMaxScroll(blockHeight - 43 - 41); + scrollHelper.setSpeed(100); + float serverY = blockY + 43 + scrollHelper.getScroll(); trimContentStart(); int serverIndex = -1; for (ServerComponent serverComponent : servers) @@ -163,8 +164,6 @@ public class SilentMultiplayerGui extends SilentScreen { super.drawScreen(mouseX, mouseY, partialTicks); Client.getInstance().getMouseCursorHandler().enableCursor(cursorType); - - scrollAnimation.setAnimation(scrollY, 12); } public void connectToSelected() { @@ -293,7 +292,7 @@ public class SilentMultiplayerGui extends SilentScreen { } } this.silentInputs.get(0).onClick(mouseX, mouseY, blockX + 5, blockY + 3 + 16 + 5, blockWidth - 10, true); - float serverY = blockY + 43 - scrollAnimation.getValue(); + float serverY = blockY + 43 + scrollHelper.getScroll(); int serverIndex = -1; boolean isReset = true; for (ServerComponent serverComponent : servers) @@ -320,6 +319,9 @@ public class SilentMultiplayerGui extends SilentScreen { protected void keyTyped(char typedChar, int keyCode) throws IOException { super.keyTyped(typedChar, keyCode); this.silentInputs.get(0).onKeyTyped(typedChar, keyCode); + if(this.silentInputs.get(0).isFocused()) { + scrollHelper.resetScroll(); + } } @Override @@ -343,31 +345,6 @@ public class SilentMultiplayerGui extends SilentScreen { GL11.glPopMatrix(); } - @Override - public void handleMouseInput() throws IOException { - super.handleMouseInput(); - int dw = Mouse.getEventDWheel(); - double newScrollY = this.scrollY; - if(dw != 0) { - if (dw > 0) { - dw = -1; - } else { - dw = 1; - } - float amountScrolled = (float) (dw * 10); - if (newScrollY + amountScrolled > 0) - newScrollY += amountScrolled; - else - newScrollY = 0; - if((newScrollY < blockHeight && ((servers.size() + 1) * 38) > blockHeight - 43 - 41) || amountScrolled < 0) { - this.scrollY = (float) newScrollY; - if(this.scrollY < 0) { - this.scrollY = 0; - } - } - } - } - public void refreshServerList() { this.mc.displayGuiScreen(new SilentMultiplayerGui(this.parentScreen)); 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 7abb56b..7b54050 100644 --- a/src/main/java/net/silentclient/client/gui/resourcepacks/SilentResourcePacksGui.java +++ b/src/main/java/net/silentclient/client/gui/resourcepacks/SilentResourcePacksGui.java @@ -130,11 +130,13 @@ public class SilentResourcePacksGui extends SilentScreen { scrollHelper.setFlag(false); } - float itemY = y + 19 + scrollHelper.getScroll(); + float scrollY = scrollHelper.getScroll(); + + float itemY = y + 19 + scrollY; Scissor.start((int) x, (int) y, 193, blockHeight - 45); - Client.getInstance().getSilentFontRenderer().drawString("Available", x + 3, y + 3 + scrollHelper.getScroll(), 14, SilentFontRenderer.FontType.TITLE); - this.silentInputs.get(0).render(mouseX, mouseY, x + 193 - 3 - 100, y + 2 + scrollHelper.getScroll(), 100, true); + Client.getInstance().getSilentFontRenderer().drawString("Available", x + 3, y + 3 + scrollY, 14, SilentFontRenderer.FontType.TITLE); + this.silentInputs.get(0).render(mouseX, mouseY, x + 193 - 3 - 100, y + 2 + scrollY, 100, true); for(ResourcePackRepository.Entry entry : availableResourcePacks) { if((!this.silentInputs.get(0).getValue().trim().equals("") && !entry.getResourcePackName().toLowerCase().contains(this.silentInputs.get(0).getValue().trim().toLowerCase()))) { @@ -196,14 +198,20 @@ public class SilentResourcePacksGui extends SilentScreen { private MouseCursorHandler.CursorType drawActiveResourcePacks(float x, float y, int mouseX, int mouseY) { MouseCursorHandler.CursorType cursorType = null; RenderUtil.drawRoundedOutline(x, y, 193, blockHeight - 45, 3, 1, Theme.borderColor().getRGB()); - Scissor.start((int) x, (int) y, 193, blockHeight - 45); scrollHelper2.setStep(5); scrollHelper2.setElementsHeight(selectedResourcePacks.size() * 37 + 19); scrollHelper2.setMaxScroll(blockHeight - 45); scrollHelper2.setSpeed(100); - Client.getInstance().getSilentFontRenderer().drawString("Active", x + 3, y + 3 + scrollHelper2.getScroll(), 14, SilentFontRenderer.FontType.TITLE); + if(MouseUtils.isInside(mouseX, mouseY, x, y, 193, blockHeight - 45)) { + scrollHelper2.setFlag(true); + } else { + scrollHelper2.setFlag(false); + } + float scrollY = scrollHelper2.getScroll(); + Scissor.start((int) x, (int) y, 193, blockHeight - 45); + Client.getInstance().getSilentFontRenderer().drawString("Active", x + 3, y + 3 + scrollY, 14, SilentFontRenderer.FontType.TITLE); - float itemY = y + 19 + scrollHelper2.getScroll(); + float itemY = y + 19 + scrollY; int packIndex = 0; for(ResourcePackRepository.Entry entry : selectedResourcePacks) { @@ -406,11 +414,6 @@ public class SilentResourcePacksGui extends SilentScreen { this.activeResourcePacksClick(blockX + blockWidth - 193 - 5, blockY + 14 + 5 + 2, mouseX, mouseY); } - @Override - public void handleMouseInput() throws IOException { - super.handleMouseInput(); - } - @Override public void updateScreen() { super.updateScreen(); diff --git a/src/main/java/net/silentclient/client/utils/ScrollHelper.java b/src/main/java/net/silentclient/client/utils/ScrollHelper.java index 079997e..d8d67be 100644 --- a/src/main/java/net/silentclient/client/utils/ScrollHelper.java +++ b/src/main/java/net/silentclient/client/utils/ScrollHelper.java @@ -12,8 +12,11 @@ public class ScrollHelper { 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(); - float delta = 1f/Minecraft.getDebugFPS(); + float delta = 1f / Minecraft.getDebugFPS(); if(flag) real -= wheel / 120f * step; float divider = delta*2*Math.min(speed, elementsHeight);