From df9897f0f74004fddcad225de9c7216ac12c024e Mon Sep 17 00:00:00 2001 From: kirillsaint Date: Sun, 5 Nov 2023 14:12:22 +0600 Subject: [PATCH] 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#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