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 d8d7ec3..7b54050 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,446 @@ 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 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 + 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()))) { + 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()); + scrollHelper2.setStep(5); + scrollHelper2.setElementsHeight(selectedResourcePacks.size() * 37 + 19); + scrollHelper2.setMaxScroll(blockHeight - 45); + scrollHelper2.setSpeed(100); + 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 + scrollY; + 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 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..d8d67be --- /dev/null +++ b/src/main/java/net/silentclient/client/utils/ScrollHelper.java @@ -0,0 +1,74 @@ +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() { + if(!flag) { + return -scroll; + } + 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 0000000..0350662 Binary files /dev/null and b/src/main/resources/assets/minecraft/silentclient/icons/lightoverlay.png differ