From 1a474dbe99522ea1b8d3c853a66eef7fb0eed115 Mon Sep 17 00:00:00 2001 From: kirillsaint Date: Wed, 26 Jul 2023 16:53:42 +0600 Subject: [PATCH] Outfit Scroll --- .../client/cosmetics/gui/OutfitsGui.java | 62 +++++++++++++++++-- 1 file changed, 56 insertions(+), 6 deletions(-) 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 8ba2013..7ad00a4 100644 --- a/src/main/java/net/silentclient/client/cosmetics/gui/OutfitsGui.java +++ b/src/main/java/net/silentclient/client/cosmetics/gui/OutfitsGui.java @@ -1,12 +1,15 @@ package net.silentclient.client.cosmetics.gui; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; 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; @@ -15,12 +18,17 @@ import net.silentclient.client.gui.util.RenderUtil; import net.silentclient.client.utils.MenuBlurUtils; 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.*; 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; public OutfitsGui(GuiScreen parentScreen) { this.parentScreen = parentScreen; @@ -30,6 +38,7 @@ public class OutfitsGui extends SilentScreen { @Override public void initGui() { super.initGui(); + this.scrollY = 0; if(mc.thePlayer == null) { Client.backgroundPanorama.updateWidthHeight(this.width, this.height); } else { @@ -58,27 +67,35 @@ public class OutfitsGui extends SilentScreen { 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); + GL11.glPushMatrix(); + GL11.glEnable(GL11.GL_SCISSOR_TEST); + ScaledResolution r = new ScaledResolution(Minecraft.getMinecraft()); + int s = r.getScaleFactor(); + int listHeight = height - 20; + int translatedY = r.getScaledHeight() - 20 - 20 - listHeight; + GL11.glScissor(0 * s, translatedY * s, this.width * s, listHeight * s); int outfitX = x + 3; - int outfitY = y + 20; + float outfitY = (int) (y + 20 - scrollAnimation.getValue()); int outfitIndex = 0; boolean isCreateHovered = MouseUtils.isInside(mouseX, mouseY, outfitX, outfitY, 80, 80); if(isCreateHovered) { RenderUtil.drawRoundedRect(outfitX, outfitY, 80, 80, 3, new Color(255, 255, 255, 30).getRGB()); } RenderUtil.drawRoundedOutline(outfitX, outfitY, 80, 80, 3, 1, Theme.borderColor().getRGB()); - Client.getInstance().getSilentFontRenderer().drawCenteredString("Create New Outfit", outfitX + 40, outfitY + 40 - 6, 12, SilentFontRenderer.FontType.TITLE); + Client.getInstance().getSilentFontRenderer().drawCenteredString("Create New Outfit", outfitX + 40, (int) (outfitY + 40 - 6), 12, SilentFontRenderer.FontType.TITLE); outfitX += 83; outfitIndex += 1; + this.outfitIndex = 1; for(Outfits.Outfit outfit : Outfits.getOutfits()) { boolean isHovered = MouseUtils.isInside(mouseX, mouseY, outfitX, outfitY, 80, 80) && !MouseUtils.isInside(mouseX, mouseY, outfitX + 80 - 3 - 10, outfitY + 3, 10, 10); if(isHovered) { RenderUtil.drawRoundedRect(outfitX, outfitY, 80, 80, 3, new Color(255, 255, 255, 30).getRGB()); } RenderUtil.drawRoundedOutline(outfitX, outfitY, 80, 80, 3, 1, Theme.borderColor().getRGB()); - Client.getInstance().getSilentFontRenderer().drawString(outfit.name, outfitX + 3, outfitY + 3, 12, SilentFontRenderer.FontType.TITLE, 64); + Client.getInstance().getSilentFontRenderer().drawString(outfit.name, outfitX + 3, (int) (outfitY + 3), 12, SilentFontRenderer.FontType.TITLE, 64); RenderUtil.drawImage(new ResourceLocation("silentclient/icons/trash-icon.png"), outfitX + 80 - 3 - 10, outfitY + 3, 10, 10); - int cosmeticY = outfitY + 18; + int cosmeticY = (int) (outfitY + 18); if(outfit.selected_cape != 0 && Client.getInstance().getCosmetics().getMyCapes().stream().filter((c) -> c.id == outfit.selected_cape).findFirst().isPresent()) { PlayerResponse.Account.Cosmetics.CosmeticItem item = Client.getInstance().getCosmetics().getMyCapes().stream().filter((c) -> c.id == outfit.selected_cape).findFirst().get(); @@ -134,15 +151,47 @@ public class OutfitsGui extends SilentScreen { Client.getInstance().getSilentFontRenderer().drawString(item.name, outfitX + 3, cosmeticY, 10, SilentFontRenderer.FontType.TITLE, 75); } - + this.outfitIndex += 1; outfitIndex += 1; if(outfitIndex == 3) { outfitIndex = 0; + outfitX = x + 3; outfitY += 85; } else { outfitX += 83; } } + + 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 @@ -161,7 +210,7 @@ public class OutfitsGui extends SilentScreen { int x = this.width / 2 - 125; int y = this.height / 2 - 100; int outfitX = x + 3; - int outfitY = y + 20; + float outfitY = (int) (y + 20 - scrollAnimation.getValue()); int outfitIndex = 0; if(MouseUtils.isInside(mouseX, mouseY, outfitX, outfitY, 80, 80)) { mc.displayGuiScreen(new NewOutfitModal(this)); @@ -186,6 +235,7 @@ public class OutfitsGui extends SilentScreen { outfitIndex += 1; if(outfitIndex == 3) { outfitIndex = 0; + outfitX = x + 3; outfitY += 85; } else { outfitX += 83;