From df9897f0f74004fddcad225de9c7216ac12c024e Mon Sep 17 00:00:00 2001 From: kirillsaint Date: Sun, 5 Nov 2023 14:12:22 +0600 Subject: [PATCH 1/2] Custom Resource Packs GUI --- .../resourcepacks/SilentResourcePacksGui.java | 428 +++++++++++++++++- .../client/gui/util/RenderUtil.java | 20 +- .../client/mixin/mixins/MinecraftMixin.java | 27 +- .../silentclient/client/utils/GuiUtils.java | 9 + .../silentclient/client/utils/Scissor.java | 22 + .../client/utils/ScrollHelper.java | 71 +++ .../client/utils/types/GlobalSettings.java | 10 + .../silentclient/icons/lightoverlay.png | Bin 0 -> 2567 bytes 8 files changed, 565 insertions(+), 22 deletions(-) create mode 100644 src/main/java/net/silentclient/client/utils/GuiUtils.java create mode 100644 src/main/java/net/silentclient/client/utils/Scissor.java create mode 100644 src/main/java/net/silentclient/client/utils/ScrollHelper.java create mode 100755 src/main/resources/assets/minecraft/silentclient/icons/lightoverlay.png 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 d8d7ec3..7abb56b 100644 --- a/src/main/java/net/silentclient/client/gui/resourcepacks/SilentResourcePacksGui.java +++ b/src/main/java/net/silentclient/client/gui/resourcepacks/SilentResourcePacksGui.java @@ -1,21 +1,443 @@ package net.silentclient.client.gui.resourcepacks; +import com.google.common.collect.Lists; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.resources.ResourcePackListEntry; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.resources.ResourcePackRepository; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.Util; +import net.silentclient.client.Client; import net.silentclient.client.gui.SilentScreen; +import net.silentclient.client.gui.elements.Button; +import net.silentclient.client.gui.elements.IconButton; +import net.silentclient.client.gui.elements.Input; +import net.silentclient.client.gui.elements.TooltipIconButton; +import net.silentclient.client.gui.font.SilentFontRenderer; +import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils; +import net.silentclient.client.gui.lite.clickgui.utils.RenderUtils; +import net.silentclient.client.gui.theme.Theme; +import net.silentclient.client.gui.util.RenderUtil; +import net.silentclient.client.utils.*; +import org.apache.commons.io.FilenameUtils; +import org.lwjgl.Sys; +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.util.Collections; import java.util.List; public class SilentResourcePacksGui extends SilentScreen { private final GuiScreen parentScreen; - private List availableResourcePacks; - private List selectedResourcePacks; + private List availableResourcePacks; + private List selectedResourcePacks; private boolean changed = false; + private int blockX = 0; + private int blockY = 0; + private int blockWidth = 0; + private int blockHeight = 0; + private ScrollHelper scrollHelper = new ScrollHelper(); + private ScrollHelper scrollHelper2 = new ScrollHelper(); public SilentResourcePacksGui(GuiScreen parentScreenIn) { this.parentScreen = parentScreenIn; } + @Override + public void initGui() { + super.initGui(); + this.defaultCursor = false; + Client.backgroundPanorama.updateWidthHeight(this.width, this.height); + this.buttonList.clear(); + this.silentInputs.clear(); + blockWidth = 400; + blockHeight = height - 20; + blockX = (width / 2) - (blockWidth / 2); + blockY = 10; + this.buttonList.add(new IconButton(1, blockX + blockWidth - 14 - 5, blockY + 5, 14, 14, 8, 8, new ResourceLocation("silentclient/icons/exit.png"))); + if(mc.thePlayer != null) { + this.buttonList.add(new TooltipIconButton(2, blockX + blockWidth - 14 - 5, blockY + blockHeight - 5 - 14, 14, 14, 8, 8, new ResourceLocation("silentclient/icons/lightoverlay.png"), "Toggle Background Panorama")); + } + this.buttonList.add(new Button(3, blockX + 40, blockY + blockHeight - 5 - 14, 100, 14, "Open Pack Folder")); + this.buttonList.add(new Button(4, blockX + 40 + 100 + 5, blockY + blockHeight - 5 - 14, 100, 14, "Apply")); + this.buttonList.add(new Button(5, blockX + 40 + 100 + 5 + 100 + 5, blockY + blockHeight - 5 - 14, 100, 14, "Done")); + this.silentInputs.add(new Input("Search")); + if(!this.changed) { + this.availableResourcePacks = Lists.newArrayList(); + this.selectedResourcePacks = Lists.newArrayList(); + ResourcePackRepository resourcepackrepository = this.mc.getResourcePackRepository(); + resourcepackrepository.updateRepositoryEntriesAll(); + List list = Lists.newArrayList(resourcepackrepository.getRepositoryEntriesAll()); + list.removeAll(resourcepackrepository.getRepositoryEntries()); + for (ResourcePackRepository.Entry resourcepackrepository$entry : list) + { + this.availableResourcePacks.add(resourcepackrepository$entry); + } + for (ResourcePackRepository.Entry resourcepackrepository$entry1 : Lists.reverse(resourcepackrepository.getRepositoryEntries())) + { + this.selectedResourcePacks.add(resourcepackrepository$entry1); + } + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + MouseCursorHandler.CursorType cursorType = getCursor(silentInputs, buttonList); + if(mc.thePlayer == null || Client.getInstance().getGlobalSettings().isPacksPanoramaEnabled()) { + GlStateManager.disableAlpha(); + Client.backgroundPanorama.renderSkybox(mouseX, mouseY, partialTicks); + GlStateManager.enableAlpha(); + if(Client.getInstance().getGlobalSettings().isLite()) { + this.drawGradientRect(0, 0, this.width, this.height, new Color(0, 0, 0, 127).getRGB(), new Color(0, 0, 0, 200).getRGB()); + } else { + this.drawGradientRect(0, 0, this.width, this.height, 0, Integer.MIN_VALUE); + } + } else { + MenuBlurUtils.renderBackground(this); + } + 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); + if(cursorType1 != null) { + cursorType = cursorType1; + } + MouseCursorHandler.CursorType cursorType2 = this.drawActiveResourcePacks(blockX + blockWidth - 193 - 5, blockY + 14 + 5 + 2, mouseX, mouseY); + if(cursorType2 != null) { + cursorType = cursorType2; + } + + super.drawScreen(mouseX, mouseY, partialTicks); + + Client.getInstance().getMouseCursorHandler().enableCursor(cursorType); + } + + private MouseCursorHandler.CursorType drawAvailableResourcePacks(float x, float y, int mouseX, int mouseY) { + MouseCursorHandler.CursorType cursorType = null; + RenderUtil.drawRoundedOutline(x, y, 193, blockHeight - 45, 3, 1, Theme.borderColor().getRGB()); + scrollHelper.setStep(5); + scrollHelper.setElementsHeight(availableResourcePacks.size() * 37 + 19); + scrollHelper.setMaxScroll(blockHeight - 45); + scrollHelper.setSpeed(100); + + if(MouseUtils.isInside(mouseX, mouseY, x, y, 193, blockHeight - 45)) { + scrollHelper.setFlag(true); + } else { + scrollHelper.setFlag(false); + } + + float itemY = y + 19 + scrollHelper.getScroll(); + + 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); + + for(ResourcePackRepository.Entry entry : availableResourcePacks) { + if((!this.silentInputs.get(0).getValue().trim().equals("") && !entry.getResourcePackName().toLowerCase().contains(this.silentInputs.get(0).getValue().trim().toLowerCase()))) { + continue; + } + if(GuiUtils.blockInOtherBlock(x + 3, itemY, 187, 35, x, y, 193, blockHeight - 45)) { + int i = entry.func_183027_f(); + boolean isHovered = MouseUtils.isInside(mouseX, mouseY, x, itemY, 187, 35); + RenderUtil.drawRoundedOutline(x + 3, itemY, 187, 35, 3, 1, i != 1 ? Color.RED.getRGB() : Theme.borderColor().getRGB()); + if(isHovered) { + RenderUtil.drawRoundedRect(x + 3, itemY, 187, 35, 3, new Color(255, 255, 255, 30).getRGB()); + cursorType = MouseCursorHandler.CursorType.POINTER; + } + entry.bindTexturePackIcon(mc.getTextureManager()); + RenderUtil.drawImage(null, x + 5, itemY + 2, 31, 31, false); + String s = FilenameUtils.getBaseName(entry.getResourcePackName()); + int i1 = this.mc.fontRendererObj.getStringWidth(s); + + if (i1 > 153) + { + s = this.mc.fontRendererObj.trimStringToWidth(s, 153 - this.mc.fontRendererObj.getStringWidth("...")) + "..."; + } + + this.mc.fontRendererObj.drawStringWithShadow(s, x + 5 + 31 + 3, itemY + 3, 16777215); + List list = this.mc.fontRendererObj.listFormattedStringToWidth(entry.getTexturePackDescription(), 153); + + for (int l = 0; l < 2 && l < list.size(); ++l) + { + this.mc.fontRendererObj.drawStringWithShadow(list.get(l), x + 5 + 31 + 3, itemY + 3 + 12 + 10 * l, 8421504); + } + } + itemY += 37; + } + Scissor.end(); + + return cursorType; + } + + private void availableResourcePacksClick(float x, float y, int mouseX, int mouseY) { + float itemY = y + 19 + scrollHelper.getScroll(); + + for(ResourcePackRepository.Entry entry : availableResourcePacks) { + if((!this.silentInputs.get(0).getValue().trim().equals("") && !entry.getResourcePackName().toLowerCase().contains(this.silentInputs.get(0).getValue().trim().toLowerCase()))) { + continue; + } + if(GuiUtils.blockInOtherBlock(x + 3, itemY, 187, 35, x, y, 193, blockHeight - 45)) { + boolean isHovered = MouseUtils.isInside(mouseX, mouseY, x, itemY, 187, 35); + if(isHovered) { + availableResourcePacks.remove(entry); + selectedResourcePacks.add(0, entry); + this.markChanged(); + break; + } + } + itemY += 37; + } + } + + 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); + + float itemY = y + 19 + scrollHelper2.getScroll(); + int packIndex = 0; + + for(ResourcePackRepository.Entry entry : selectedResourcePacks) { + if(GuiUtils.blockInOtherBlock(x + 3, itemY, 187, 35, x, y, 193, blockHeight - 45)) { + int i = entry.func_183027_f(); + RenderUtil.drawRoundedOutline(x + 3, itemY, 187, 35, 3, 1, i != 1 ? Color.RED.getRGB() : Theme.borderColor().getRGB()); + boolean isHovered = MouseUtils.isInside(mouseX, mouseY, x, itemY, 187, 35); + if(isHovered) { + RenderUtil.drawRoundedRect(x + 3, itemY, 187, 35, 3, new Color(255, 255, 255, 30).getRGB()); + cursorType = MouseCursorHandler.CursorType.POINTER; + } + entry.bindTexturePackIcon(mc.getTextureManager()); + RenderUtil.drawImage(null, x + 5, itemY + 2, 31, 31, false); + if(MouseUtils.isInside(mouseX, mouseY, x + 5, itemY + 2, 31, 31)) { + if(this.canUpSwap(packIndex)) { + RenderUtil.drawImage(new ResourceLocation("silentclient/icons/page-up.png"), x + 5 + (31 / 2) - (15 / 2), itemY + 2, 15, 15, true, MouseUtils.isInside(mouseX, mouseY, x + 5 + (31 / 2) - (15 / 2), itemY + 2, 15, 15) ? new Color(255, 255, 255).getRGB() : Theme.borderColor().getRGB()); + } + + if(this.canDownSwap(packIndex)) { + RenderUtil.drawImage(new ResourceLocation("silentclient/icons/page-down.png"), x + 5 + (31 / 2) - (15 / 2), itemY + 2 + 31 - 16, 15, 15, true, MouseUtils.isInside(mouseX, mouseY, x + 5 + (31 / 2) - (15 / 2), itemY + 2 + 31 - 16, 15, 15) ? new Color(255, 255, 255).getRGB() : Theme.borderColor().getRGB()); + } + } + String s = FilenameUtils.getBaseName(entry.getResourcePackName()); + int i1 = this.mc.fontRendererObj.getStringWidth(s); + + if (i1 > 153) + { + s = this.mc.fontRendererObj.trimStringToWidth(s, 153 - this.mc.fontRendererObj.getStringWidth("...")) + "..."; + } + + this.mc.fontRendererObj.drawStringWithShadow(s, x + 5 + 31 + 3, itemY + 3, 16777215); + List list = this.mc.fontRendererObj.listFormattedStringToWidth(entry.getTexturePackDescription(), 153); + + for (int l = 0; l < 2 && l < list.size(); ++l) + { + this.mc.fontRendererObj.drawStringWithShadow(list.get(l), x + 5 + 31 + 3, itemY + 3 + 12 + 10 * l, 8421504); + } + } + itemY += 37; + packIndex++; + } + + Scissor.end(); + return cursorType; + } + + public void activeResourcePacksClick(float x, float y, int mouseX, int mouseY) { + float itemY = y + 19 + scrollHelper2.getScroll(); + int packIndex = 0; + + for(ResourcePackRepository.Entry entry : selectedResourcePacks) { + if(GuiUtils.blockInOtherBlock(x + 3, itemY, 187, 35, x, y, 193, blockHeight - 45)) { + int i = entry.func_183027_f(); + RenderUtil.drawRoundedOutline(x + 3, itemY, 187, 35, 3, 1, i != 1 ? Color.RED.getRGB() : Theme.borderColor().getRGB()); + boolean isHovered = MouseUtils.isInside(mouseX, mouseY, x, itemY, 187, 35); + if(isHovered) { + if(MouseUtils.isInside(mouseX, mouseY, x + 5, itemY + 2, 31, 31)) { + if(this.canUpSwap(packIndex) && MouseUtils.isInside(mouseX, mouseY, x + 5 + (31 / 2) - (15 / 2), itemY + 2, 15, 15)) { + List list1 = this.selectedResourcePacks; + int k = list1.indexOf(entry); + list1.remove(entry); + list1.add(k - 1, entry); + this.markChanged(); + break; + } + + if(this.canDownSwap(packIndex) && MouseUtils.isInside(mouseX, mouseY, x + 5 + (31 / 2) - (15 / 2), itemY + 2 + 31 - 16, 15, 15)) { + List list = this.selectedResourcePacks; + int i2 = list.indexOf(entry); + list.remove(entry); + list.add(i2 + 1, entry); + this.markChanged(); + break; + } + } + selectedResourcePacks.remove(entry); + availableResourcePacks.add(0, entry); + this.markChanged(); + break; + } + } + itemY += 37; + packIndex++; + } + } + + public void apply() { + if (this.changed) + { + this.scrollHelper2.resetScroll(); + this.scrollHelper.resetScroll(); + List list = Lists.newArrayList(); + + for (ResourcePackRepository.Entry resourcepacklistentry : this.selectedResourcePacks) + { + list.add(resourcepacklistentry); + } + + Collections.reverse(list); + this.mc.getResourcePackRepository().setRepositories(list); + this.mc.gameSettings.resourcePacks.clear(); + this.mc.gameSettings.incompatibleResourcePacks.clear(); + + for (ResourcePackRepository.Entry resourcepackrepository$entry : list) + { + this.mc.gameSettings.resourcePacks.add(resourcepackrepository$entry.getResourcePackName()); + + if (resourcepackrepository$entry.func_183027_f() != 1) + { + this.mc.gameSettings.incompatibleResourcePacks.add(resourcepackrepository$entry.getResourcePackName()); + } + } + + this.mc.gameSettings.saveOptions(); + this.mc.refreshResources(); + this.initGui(); + this.scrollHelper2.resetScroll(); + this.scrollHelper.resetScroll(); + } + } + + @Override + protected void actionPerformed(GuiButton button) throws IOException { + super.actionPerformed(button); + switch (button.id) { + case 1: + mc.displayGuiScreen(parentScreen); + break; + case 2: + Client.getInstance().getGlobalSettings().setPacksPanoramaEnabled(!Client.getInstance().getGlobalSettings().isPacksPanoramaEnabled()); + Client.getInstance().getGlobalSettings().save(); + break; + case 3: + File file1 = this.mc.getResourcePackRepository().getDirResourcepacks(); + String s = file1.getAbsolutePath(); + + if (Util.getOSType() == Util.EnumOS.OSX) + { + try + { + Client.logger.info(s); + Runtime.getRuntime().exec(new String[] {"/usr/bin/open", s}); + return; + } + catch (IOException ioexception1) + { + Client.logger.error("Couldn't open file", ioexception1); + } + } + else if (Util.getOSType() == Util.EnumOS.WINDOWS) + { + String s1 = String.format("cmd.exe /C start \"Open file\" \"%s\"", s); + + try + { + Runtime.getRuntime().exec(s1); + return; + } + catch (IOException ioexception) + { + Client.logger.error("Couldn't open file", ioexception); + } + } + + boolean flag = false; + + try + { + Class oclass = Class.forName("java.awt.Desktop"); + Object object = oclass.getMethod("getDesktop", new Class[0]).invoke(null); + oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, file1.toURI()); + } + catch (Throwable throwable) + { + Client.logger.error("Couldn't open link", throwable); + flag = true; + } + + if (flag) + { + Client.logger.info("Opening via system class!"); + Sys.openURL("file://" + s); + } + break; + case 4: + this.apply(); + break; + case 5: + this.apply(); + mc.displayGuiScreen(parentScreen); + break; + } + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + this.silentInputs.get(0).onClick(mouseX, mouseY, blockX + 5 + 193 - 3 - 100, blockY + 14 + 5 + 2 + 2, 100, true); + this.availableResourcePacksClick(blockX + 5, blockY + 14 + 5 + 2, mouseX, mouseY); + 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(); + Client.backgroundPanorama.tickPanorama(); + } + + @Override + 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()) { + this.scrollHelper.resetScroll(); + } + } + + public void markChanged() + { + this.changed = true; + } + + public boolean canUpSwap(int index) + { + return index > 0; + } + + public boolean canDownSwap(int index) + { + return index < this.selectedResourcePacks.size() - 1; + } } diff --git a/src/main/java/net/silentclient/client/gui/util/RenderUtil.java b/src/main/java/net/silentclient/client/gui/util/RenderUtil.java index 3606e0c..8bcd615 100644 --- a/src/main/java/net/silentclient/client/gui/util/RenderUtil.java +++ b/src/main/java/net/silentclient/client/gui/util/RenderUtil.java @@ -183,10 +183,12 @@ public class RenderUtil { OpenGlHelper.glBlendFunc((int) 770, (int) 771, (int) 1, (int) 0); GL11.glColor4f((float) 1.0f, (float) 1.0f, (float) 1.0f, 1f); ColorUtils.setColor(color); - if(mip) { - Client.getInstance().getTextureManager().bindTextureMipmapped(image); - } else { - Minecraft.getMinecraft().getTextureManager().bindTexture(image); + if(image != null) { + if(mip) { + Client.getInstance().getTextureManager().bindTextureMipmapped(image); + } else { + Minecraft.getMinecraft().getTextureManager().bindTexture(image); + } } drawModalRectWithCustomSizedTexture(x, y, 0.0f, 0.0f, width, height, width, height); GL11.glDepthMask((boolean) true); @@ -221,10 +223,12 @@ public class RenderUtil { GL11.glDepthMask((boolean) false); OpenGlHelper.glBlendFunc((int) 770, (int) 771, (int) 1, (int) 0); GL11.glColor4f((float) 1.0f, (float) 1.0f, (float) 1.0f, 1f); - if(mip) { - Client.getInstance().getTextureManager().bindTextureMipmapped(image); - } else { - ((TextureManagerExt) Minecraft.getMinecraft().getTextureManager()).waitBindTexture(new StaticResourceLocation(image), new StaticResourceLocation("silentclient/transparent.png")); + if(image != null) { + if(mip) { + Client.getInstance().getTextureManager().bindTextureMipmapped(image); + } else { + ((TextureManagerExt) Minecraft.getMinecraft().getTextureManager()).waitBindTexture(new StaticResourceLocation(image), new StaticResourceLocation("silentclient/transparent.png")); + } } Gui.drawModalRectWithCustomSizedTexture((int) x, (int) y, (float) 0.0f, (float) 0.0f, (int) width, (int) height, (float) width, (float) height); GL11.glDepthMask((boolean) true); diff --git a/src/main/java/net/silentclient/client/mixin/mixins/MinecraftMixin.java b/src/main/java/net/silentclient/client/mixin/mixins/MinecraftMixin.java index 1dbc6ac..0c9340e 100644 --- a/src/main/java/net/silentclient/client/mixin/mixins/MinecraftMixin.java +++ b/src/main/java/net/silentclient/client/mixin/mixins/MinecraftMixin.java @@ -23,6 +23,7 @@ import net.silentclient.client.event.impl.*; import net.silentclient.client.gui.SilentScreen; import net.silentclient.client.gui.lite.LiteMainMenu; import net.silentclient.client.gui.multiplayer.SilentMultiplayerGui; +import net.silentclient.client.gui.resourcepacks.SilentResourcePacksGui; import net.silentclient.client.gui.silentmainmenu.MainMenuConcept; import net.silentclient.client.gui.util.BackgroundPanorama; import net.silentclient.client.hooks.MinecraftHook; @@ -65,9 +66,6 @@ public abstract class MinecraftMixin implements MinecraftExt { if(Client.backgroundPanorama == null) { Client.backgroundPanorama = new BackgroundPanorama(Minecraft.getMinecraft()); } -// if(Client.getInstance().getGlobalSettings() != null) { -// displayGuiScreen(Client.getInstance().getGlobalSettings().isLite() ? new GuiNews() : new MainMenuConcept()); -// } } @Override @@ -134,27 +132,34 @@ public abstract class MinecraftMixin implements MinecraftExt { @Shadow private Timer timer; - @Inject(method = "displayGuiScreen", at = @At("RETURN"), cancellable = true) + @Inject(method = "displayGuiScreen", at = @At("HEAD"), cancellable = true) public void displayGuiScreenInject(GuiScreen guiScreenIn, CallbackInfo ci) { + if(guiScreenIn instanceof SilentScreen) { + Client.logger.info("Opening menu: " + guiScreenIn.getClass().toString()); + } if(Client.backgroundPanorama == null) { Client.backgroundPanorama = new BackgroundPanorama(Minecraft.getMinecraft()); } - if(guiScreenIn instanceof GuiMainMenu) { - if(Client.getInstance().getGlobalSettings() != null) { - displayGuiScreen(Client.getInstance().getGlobalSettings().isLite() ? new LiteMainMenu() : new MainMenuConcept()); - } + if((guiScreenIn instanceof GuiMainMenu || (guiScreenIn == null && this.theWorld == null)) && Client.getInstance().getGlobalSettings() != null) { + displayGuiScreen(Client.getInstance().getGlobalSettings().isLite() ? new LiteMainMenu() : new MainMenuConcept()); + ci.cancel(); + return; + } + if(guiScreenIn instanceof GuiScreenResourcePacks) { + displayGuiScreen(new SilentResourcePacksGui(this.currentScreen)); + ci.cancel(); return; } if(guiScreenIn instanceof GuiMultiplayer) { displayGuiScreen(new SilentMultiplayerGui((GuiScreen) ((GuiMultiplayerExt) guiScreenIn).silent$getParentScreen())); + ci.cancel(); + return; } if(guiScreenIn instanceof GuiIngameMenu) { displayGuiScreen(new net.silentclient.client.gui.minecraft.GuiIngameMenu()); + ci.cancel(); return; } - if(guiScreenIn != null && guiScreenIn instanceof SilentScreen) { - Client.logger.info("Opening menu: " + guiScreenIn.getClass().toString()); - } } /** diff --git a/src/main/java/net/silentclient/client/utils/GuiUtils.java b/src/main/java/net/silentclient/client/utils/GuiUtils.java new file mode 100644 index 0000000..dd04fb9 --- /dev/null +++ b/src/main/java/net/silentclient/client/utils/GuiUtils.java @@ -0,0 +1,9 @@ +package net.silentclient.client.utils; + +import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils; + +public class GuiUtils { + public static boolean blockInOtherBlock(float blockX, float blockY, int blockWidth, int blockHeight, float parentX, float parentY, int parentWidth, int parentHeight) { + return MouseUtils.isInside((int) blockX, (int) blockY, parentX, parentY, parentWidth, parentHeight) || MouseUtils.isInside((int) blockX, (int) blockY + blockHeight, parentX, parentY, parentWidth, parentHeight); + } +} diff --git a/src/main/java/net/silentclient/client/utils/Scissor.java b/src/main/java/net/silentclient/client/utils/Scissor.java new file mode 100644 index 0000000..a64f3ce --- /dev/null +++ b/src/main/java/net/silentclient/client/utils/Scissor.java @@ -0,0 +1,22 @@ +package net.silentclient.client.utils; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import org.lwjgl.opengl.GL11; + +public class Scissor { + public static void start(int x, int y, int width, int height) { + ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); + GL11.glEnable(GL11.GL_SCISSOR_TEST); + GL11.glScissor( + x * sr.getScaleFactor(), + (sr.getScaledHeight() - y) * sr.getScaleFactor() - height * sr.getScaleFactor(), + width * sr.getScaleFactor(), + height * sr.getScaleFactor() + ); + } + + public static void end() { + GL11.glDisable(GL11.GL_SCISSOR_TEST); + } +} diff --git a/src/main/java/net/silentclient/client/utils/ScrollHelper.java b/src/main/java/net/silentclient/client/utils/ScrollHelper.java new file mode 100644 index 0000000..079997e --- /dev/null +++ b/src/main/java/net/silentclient/client/utils/ScrollHelper.java @@ -0,0 +1,71 @@ +package net.silentclient.client.utils; + +import net.minecraft.util.MathHelper; +import org.lwjgl.input.Mouse; +import net.minecraft.client.Minecraft; + +public class ScrollHelper { + private float step = 0,real = 0,scroll = 0,elementsHeight = 0,maxScroll = 0,speed = 300F; + private boolean flag = true; + + /** + Returns the smoothed scroll value, only call this once after you set all the setters + */ + public float getScroll() { + int wheel = Mouse.getDWheel(); + float delta = 1f/Minecraft.getDebugFPS(); + if(flag) + real -= wheel / 120f * step; + float divider = delta*2*Math.min(speed, elementsHeight); + if(scroll > real) { + scroll -= ((scroll - real) / 50) * divider; + } + if(scroll < real) { + scroll += ((real - scroll) / 50) * divider; + } + + real = MathHelper.clamp_float(real, 0, elementsHeight > maxScroll ? elementsHeight - maxScroll : 0); + real = ((int)(real*100))/100f; + return -scroll; + } + + public void resetScroll() { + this.scroll = 0; + this.real = 0; + } + + /** + How much to increment each scroll + */ + public void setStep(float step) { + this.step = step; + } + + /** + Height and gaps of all elements to be scrolled combined + */ + public void setElementsHeight(float elementsHeight) { + this.elementsHeight = elementsHeight; + } + + /** + Maximum scroll, for example height of your scrollable panel + */ + public void setMaxScroll(float maxScroll) { + this.maxScroll = maxScroll; + } + + /** + Speed of the scrolling + */ + public void setSpeed(float speed) { + this.speed = speed; + } + + /** + Scrolling will only happen when this flag is true (be default its always true) + */ + public void setFlag(boolean flag) { + this.flag = flag; + } +} \ No newline at end of file diff --git a/src/main/java/net/silentclient/client/utils/types/GlobalSettings.java b/src/main/java/net/silentclient/client/utils/types/GlobalSettings.java index e1f828d..d8dbe15 100644 --- a/src/main/java/net/silentclient/client/utils/types/GlobalSettings.java +++ b/src/main/java/net/silentclient/client/utils/types/GlobalSettings.java @@ -9,11 +9,13 @@ public class GlobalSettings { public boolean lite; public boolean displayedTutorial; public boolean configsMigrated; + public boolean packsPanoramaEnabled; public GlobalSettings() { this.config = "Default.txt"; this.lite = false; this.displayedTutorial = false; + this.packsPanoramaEnabled = true; } public String getConfig() { @@ -45,6 +47,14 @@ public class GlobalSettings { this.configsMigrated = configsMigrated; } + public boolean isPacksPanoramaEnabled() { + return packsPanoramaEnabled; + } + + public void setPacksPanoramaEnabled(boolean packsPanoramaEnabled) { + this.packsPanoramaEnabled = packsPanoramaEnabled; + } + public void save() { try { FileOutputStream outputStream = new FileOutputStream(Client.getInstance().getGlobalSettingsFile()); diff --git a/src/main/resources/assets/minecraft/silentclient/icons/lightoverlay.png b/src/main/resources/assets/minecraft/silentclient/icons/lightoverlay.png new file mode 100755 index 0000000000000000000000000000000000000000..0350662080bb2e6540636b6ee02b4ba09122484b GIT binary patch literal 2567 zcmeH|`#Td1AI9epGaGXrB6B|En6o@Dvt=8W!&=N^rV|MXPi0FOwp6sVM-GwWP>w}8 z4O_`nDrZ8CR7@h#!GpctKj8fjp8LAL_x=0l`d-(a>5KD(fHXh=004qPBmH-q|GxuD z>}CO-R0{xz@ALJ>qeTDeUjqN1z_v@I((cE!B>3Y30E#yL@wckm2R^Kds>Jt`vpN>{ z{D=Bj>qPyU#yLKSw_}z2P0XuHa*Q->(W8{V9r#eL{J^`gUs8EbbSLeX5F6e>1`&eDyyhTINcn7)*WIk8|%5( zJ^W=O@asg{LUvhar~xAZ`f8-Mgd6ur!O(7HhT=MijCNbM#A06D{%y4E%h|#c?n1yn z|AuGQ9f|SRj7bClq~}afJO>xvVjLBCnRap7 z;xnCaF=+>ISx@jY(V<=!2Kr#hD-}o`LDmk!c1%@U4%zGJ6{Bf58--9R%CtyKHa{V< zNImF`Tbmy{+EJ{>Be^_auz2hTj~1 z_+9oxgV)4Ne}b5hdExfaafe@7d+sOO6sP*|JLZ;MsXt5JPiSO>ZPiV68rcn>6TZ(= zpW4M~VMDmu6ipJe(KeQgin8o}z2^=a{)X08HlO7MwuY@cwrh)%gJ$F2+Qr!V-?pb0 zrvsW)%uWyI*;bg^U$sa_6Ch=-<;T!|$rN?*T9QZbrk>rI#dE;M7}w>%YxpSGY!XoD za3~`Bsg$F`MOYG0%s!gk5|%bQp}MIg9+fpTr0Uqh?8+cdohK53;i~DE!0!FFL>coG zJ(q=WU}LW}QbLAXykRT6HvjUZ8+>94Sq|1e9_m4c6QtYdRyn>s0z_l7q7R51niRl%A4C?uPg`-cX? zRF}1ps@12ffr!2HfNwqF>!t$VfYfw}{~S@EDX})vTW)b!=_T1^q(ZXEEh2&tkSpUg zGn!6@pk~4}oSlX-xt_ZK zQpXM|!s-T9XtJ!@RE*=j{qwp8gI3^NzaX?T>IK=i#Jqw%IVsnQ3I-BQPN%vTwlf_K zqOFVxYH^u4$M{3l7LvWJ3U^k$)d^{XMd-j0SX_Qi8#KfZ_JEmV20dv4cEVy*k&_^g zdjA}V-%TDg-PoA6Q1Fboq&$ycRasY9?n#7Z*wUvig&`B+Ri%<$uLM7wdDM7d1}T+_H+ww&6IcwpQvUA|e(W@^K+ zWgAxahm;koszIuzb{W%E)rzV(Q&6JYBqq?Q!svt)ia}m1Ens@GT+=IsBqCzdf8@T# zSd58GP30HWsE82-MNN-M1?qj~Ri+s$gVK||9|E7!4#?dTTpR%m@<=mktTO+_#A-Bi z*;T2GKPld6;f*z)C_V6|&$g{3iH+$a&38`n^7eC|aczop~tQetq5N<{% zWqHmLEbt-2jXEOMrTP;!efh;{wv=o7=2SJeD;o`&ox$`I9H8#}yn6x1ZAfuohtVl4 z3yK%-r>;=>obl#WZCun3rwW0Ac@$l*(0Lo2$tn5!l~3%av>Wi-#lu6=jvIrIna}&0 z*A=ppglk48rZk94o8Zscm%qXF&wsS8OIpmrKjp~RXnDA3+$?C&W*iiH1+(=~O|^WJ58qIYjBehT$9a+IQq?@wNy`d9^HC8Qf>L#`5vt*!#4G` z$mQH~-p?umVqavM)TdWep54CenGN-J5;M-Pdy_;Q8`xK_q04|1y29 zgFMWQ*6LjkJtsZ=b6IEm{HkUrbHOWl!>32HsbPJ19ClDigy_DM`NYe!W8p@9`RZ6z z;rf%l!>iK_9Hs8N#8%_!1DuvbrAuq2`R`8e$cXewo#hViIOv|EFN6yj?I%}fH02Go zy4|5Xmylvt&VlPGBWizE1=p*M=(*V)em?{`dv{DH;xL<$SMX-t$hXvUi(u(IxW11U<$$p}0kGHdA4ER{ zGyoX}ObPrw*gcb)Ics3)7rgHPYQPoum7Np6PLNG01OQUBx(@w{UeO Date: Sun, 5 Nov 2023 19:31:44 +0600 Subject: [PATCH 2/2] Better Scroll --- .../client/cosmetics/gui/CosmeticsGui.java | 62 ++++++------------- .../client/cosmetics/gui/OutfitsGui.java | 45 +++----------- .../gui/multiplayer/SilentMultiplayerGui.java | 45 ++++---------- .../resourcepacks/SilentResourcePacksGui.java | 25 ++++---- .../client/utils/ScrollHelper.java | 5 +- 5 files changed, 57 insertions(+), 125 deletions(-) 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);