diff --git a/src/main/java/net/silentclient/client/gui/elements/HSBPicker.java b/src/main/java/net/silentclient/client/gui/elements/HSBPicker.java index 1f97690..f8eb721 100644 --- a/src/main/java/net/silentclient/client/gui/elements/HSBPicker.java +++ b/src/main/java/net/silentclient/client/gui/elements/HSBPicker.java @@ -51,6 +51,16 @@ public class HSBPicker extends Gui { this.alphaSliderHeight = pickerHeight; } + public void setPickerX(int pickerX) { + this.pickerX = pickerX; + this.hueSliderX = pickerX; + } + + public void setPickerY(int pickerY) { + this.pickerY = pickerY; + this.hueSliderY = pickerY + pickerHeight + 6; + } + public void render(int mouseX, int mouseY) { if (this.rainbowState) { double rainbowState = Math.ceil((System.currentTimeMillis() + 200) / 20.0); diff --git a/src/main/java/net/silentclient/client/gui/lite/clickgui/GuiColorPicker.java b/src/main/java/net/silentclient/client/gui/lite/clickgui/GuiColorPicker.java index df021be..cf5a087 100644 --- a/src/main/java/net/silentclient/client/gui/lite/clickgui/GuiColorPicker.java +++ b/src/main/java/net/silentclient/client/gui/lite/clickgui/GuiColorPicker.java @@ -15,17 +15,21 @@ import net.silentclient.client.gui.elements.Slider; import net.silentclient.client.gui.font.SilentFontRenderer; import net.silentclient.client.gui.hud.HUDConfigScreen; import net.silentclient.client.gui.lite.clickgui.utils.GlUtils; +import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils; import net.silentclient.client.gui.theme.Theme; import net.silentclient.client.gui.util.ColorPickerAction; import net.silentclient.client.gui.util.RenderUtil; +import net.silentclient.client.utils.ColorUtils; import net.silentclient.client.utils.MenuBlurUtils; import net.silentclient.client.utils.MouseCursorHandler; import net.silentclient.client.utils.Sounds; +import net.silentclient.client.utils.types.GlobalSettings; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import java.awt.*; import java.io.IOException; +import java.util.ArrayList; public class GuiColorPicker extends SilentScreen { private final GuiScreen parentScreen; @@ -36,6 +40,8 @@ public class GuiColorPicker extends SilentScreen { private final boolean allowChangeOpacity; private int opacity; private ColorPickerAction action; + private ArrayList colors; + private boolean customClose = false; public GuiColorPicker(Color defaultColor, boolean chroma, boolean allowChangeOpacity, int opacity, ColorPickerAction action, GuiScreen parentScreen) { this.parentScreen = parentScreen; @@ -62,11 +68,18 @@ public class GuiColorPicker extends SilentScreen { float[] vals = Color.RGBtoHSB(defaultColor.getRed(), defaultColor.getGreen(), defaultColor.getBlue(), null); hsb.color = new float[] {vals[0],vals[1],vals[2], defaultColor.getAlpha() / 255.0f}; hsb.init(); + colors = Client.getInstance().getGlobalSettings().getLatestColors(); } @Override public void onGuiClosed() { - action.onClose(hsb.getSelectedColorFinal(), chroma, opacity); + if(!customClose) { + action.onClose(hsb.getSelectedColorFinal(), chroma, opacity); + if(!chroma) { + Client.getInstance().getGlobalSettings().addToLatestColors(new Color(hsb.getSelectedColorFinal().getRed(), hsb.getSelectedColorFinal().getGreen(), hsb.getSelectedColorFinal().getBlue(), opacity)); + Client.getInstance().getGlobalSettings().save(); + } + } MenuBlurUtils.unloadBlur(); super.onGuiClosed(); } @@ -87,7 +100,7 @@ public class GuiColorPicker extends SilentScreen { GlStateManager.pushMatrix(); GlUtils.startScale((float) ((x) + (x) + width) / 2, (float) ((y) + (y + height)) / 2, (float) ClickGUI.introAnimation.getValue()); RenderUtil.drawRoundedRect(x, y, width, height, 10, Theme.backgroundColor().getRGB()); - + GL11.glPushMatrix(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); @@ -114,6 +127,25 @@ public class GuiColorPicker extends SilentScreen { double newVal = 0 + mouse * diff; opacity = (int) newVal; } + settingY += 15; + } + int colorX = x + 100; + int colorIndex = 0; + + for(GlobalSettings.CustomColor color : colors) { + ColorUtils.resetColor(); + RenderUtil.drawRoundedRect(colorX, settingY, 20, 20, 3, color.getRGB(!allowChangeOpacity)); + RenderUtil.drawRoundedOutline(colorX, settingY, 20, 20, 3, 2, new Color(0, 0, 0).getRGB()); + if(MouseUtils.isInside(mouseX, mouseY, colorX, settingY, 20, 20)) { + cursorType = MouseCursorHandler.CursorType.POINTER; + } + colorX += 25; + colorIndex += 1; + if(colorIndex == 7) { + colorIndex = 0; + colorX = x + 100; + settingY += 25; + } } GL11.glPopMatrix(); @@ -167,6 +199,31 @@ public class GuiColorPicker extends SilentScreen { Sounds.playButtonSound(); chroma = !chroma; } + + settingY += 15 + 90; + if(allowChangeOpacity) { + settingY += 15; + } + int colorX = x + 100; + int colorIndex = 0; + + for(GlobalSettings.CustomColor customColor : colors) { + if(MouseUtils.isInside(mouseX, mouseY, colorX, settingY, 20, 20)) { + Color color = customColor.getColor(!allowChangeOpacity); + action.onChange(color, false, color.getAlpha()); + customClose = true; + action.onClose(color, false, color.getAlpha()); + mc.displayGuiScreen(parentScreen); + break; + } + colorX += 25; + colorIndex += 1; + if(colorIndex == 7) { + colorIndex = 0; + colorX = x + 100; + settingY += 25; + } + } } @Override diff --git a/src/main/java/net/silentclient/client/gui/modmenu/ColorPicker.java b/src/main/java/net/silentclient/client/gui/modmenu/ColorPicker.java index 648f6a3..5d9a130 100644 --- a/src/main/java/net/silentclient/client/gui/modmenu/ColorPicker.java +++ b/src/main/java/net/silentclient/client/gui/modmenu/ColorPicker.java @@ -9,12 +9,18 @@ import net.silentclient.client.gui.SilentScreen; import net.silentclient.client.gui.elements.Button; import net.silentclient.client.gui.elements.Checkbox; import net.silentclient.client.gui.elements.HSBPicker; +import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils; import net.silentclient.client.gui.util.ColorPickerAction; +import net.silentclient.client.gui.util.RenderUtil; +import net.silentclient.client.utils.ColorUtils; import net.silentclient.client.utils.MenuBlurUtils; import net.silentclient.client.utils.MouseCursorHandler; +import net.silentclient.client.utils.ScrollHelper; +import net.silentclient.client.utils.types.GlobalSettings; import java.awt.*; import java.io.IOException; +import java.util.ArrayList; public class ColorPicker extends SilentScreen { private final GuiScreen parentScreen; @@ -25,6 +31,9 @@ public class ColorPicker extends SilentScreen { private final boolean allowChangeOpacity; private int opacity; private ColorPickerAction action; + private ArrayList colors; + private ScrollHelper scrollHelper = new ScrollHelper(); + private boolean customClose = false; public ColorPicker(Color defaultColor, boolean chroma, boolean allowChangeOpacity, int opacity, ColorPickerAction action, GuiScreen parentScreen) { this.parentScreen = parentScreen; @@ -51,6 +60,7 @@ public class ColorPicker extends SilentScreen { ModMenu.initBaseButtons(this.buttonList); this.buttonList.add(new Button(1, 3, 26, 144, 15, "Back")); + colors = Client.getInstance().getGlobalSettings().getLatestColors(); } @Override @@ -62,9 +72,15 @@ public class ColorPicker extends SilentScreen { super.drawScreen(mouseX, mouseY, partialTicks); - ModMenu.trimContentStart(width, height); + ModMenu.trimContentStart(width, height, true); + scrollHelper.setStep(5); + scrollHelper.setElementsHeight(100 + (allowChangeOpacity ? 30 : 0) + (float) Math.ceil((colors.size() + 5) / 5) * 30); + scrollHelper.setMaxScroll(height - 20); + scrollHelper.setSpeed(200); + scrollHelper.setFlag(true); + float scrollY = scrollHelper.getScroll(); - float colorY = 66; + float colorY = 66 + scrollY; Checkbox.render(mouseX, mouseY, 3, colorY, "Chroma", chroma); if(Checkbox.isHovered(mouseX, mouseY, 3, colorY)) { cursorType = MouseCursorHandler.CursorType.POINTER; @@ -76,6 +92,8 @@ public class ColorPicker extends SilentScreen { colorY += 100; + hsb.setPickerY((int) (80 + scrollY)); + if(allowChangeOpacity) { GlStateManager.color(1, 1, 1, 1); RegularSlider.render(3, colorY, 144, "Opacity", 255, opacity); @@ -85,6 +103,25 @@ public class ColorPicker extends SilentScreen { double newVal = 0 + mouse * diff; opacity = (int) newVal; } + colorY += 30; + } + int colorX = 3; + int colorIndex = 0; + + for(GlobalSettings.CustomColor color : colors) { + ColorUtils.resetColor(); + RenderUtil.drawRoundedRect(colorX, colorY, 20, 20, 3, color.getRGB(!allowChangeOpacity)); + RenderUtil.drawRoundedOutline(colorX, colorY, 20, 20, 3, 2, new Color(0, 0, 0).getRGB()); + if(MouseUtils.isInside(mouseX, mouseY, colorX, colorY, 20, 20)) { + cursorType = MouseCursorHandler.CursorType.POINTER; + } + colorX += 25; + colorIndex += 1; + if(colorIndex == 5) { + colorIndex = 0; + colorX = 3; + colorY += 25; + } } Client.getInstance().getMouseCursorHandler().enableCursor(cursorType); @@ -110,6 +147,30 @@ public class ColorPicker extends SilentScreen { chroma = !chroma; } + colorY += 100; + if(allowChangeOpacity) { + colorY += 30; + } + int colorX = 3; + int colorIndex = 0; + for(GlobalSettings.CustomColor customColor : colors) { + if(MouseUtils.isInside(mouseX, mouseY, colorX, colorY, 20, 20)) { + Color color = customColor.getColor(!allowChangeOpacity); + action.onChange(color, false, color.getAlpha()); + customClose = true; + action.onClose(color, false, color.getAlpha()); + mc.displayGuiScreen(parentScreen); + break; + } + colorX += 25; + colorIndex += 1; + if(colorIndex == 5) { + colorIndex = 0; + colorX = 3; + colorY += 25; + } + } + hsb.mouseClicked(mouseX, mouseY, mouseButton); } @@ -122,7 +183,13 @@ public class ColorPicker extends SilentScreen { @Override public void onGuiClosed() { super.onGuiClosed(); - action.onClose(hsb.getSelectedColorFinal(), chroma, opacity); + if(!customClose) { + action.onClose(hsb.getSelectedColorFinal(), chroma, opacity); + if(!chroma) { + Client.getInstance().getGlobalSettings().addToLatestColors(new Color(hsb.getSelectedColorFinal().getRed(), hsb.getSelectedColorFinal().getGreen(), hsb.getSelectedColorFinal().getBlue(), opacity)); + Client.getInstance().getGlobalSettings().save(); + } + } MenuBlurUtils.unloadBlur(); Client.getInstance().configManager.save(); } diff --git a/src/main/java/net/silentclient/client/gui/modmenu/ModMenu.java b/src/main/java/net/silentclient/client/gui/modmenu/ModMenu.java index 4323a06..f694951 100644 --- a/src/main/java/net/silentclient/client/gui/modmenu/ModMenu.java +++ b/src/main/java/net/silentclient/client/gui/modmenu/ModMenu.java @@ -263,11 +263,15 @@ public class ModMenu extends SilentScreen { } public static void trimContentStart(int width, int height) { + trimContentStart(width, height, false); + } + + public static void trimContentStart(int width, int height, boolean withoutFooter) { GL11.glPushMatrix(); GL11.glEnable(GL11.GL_SCISSOR_TEST); ScaledResolution r = new ScaledResolution(Minecraft.getMinecraft()); int s = r.getScaleFactor(); - int listHeight = height - 66 - 21; + int listHeight = height - 66 - (withoutFooter ? 0 : 21); int translatedY = r.getScaledHeight() - 66 - listHeight; GL11.glScissor(0 * s, translatedY * s, width * s, listHeight * s); } diff --git a/src/main/java/net/silentclient/client/utils/ColorUtils.java b/src/main/java/net/silentclient/client/utils/ColorUtils.java index ce8f39a..6fb99ac 100644 --- a/src/main/java/net/silentclient/client/utils/ColorUtils.java +++ b/src/main/java/net/silentclient/client/utils/ColorUtils.java @@ -1,9 +1,13 @@ package net.silentclient.client.utils; -import java.awt.Color; - import net.minecraft.client.renderer.GlStateManager; +import net.silentclient.client.Client; import net.silentclient.client.gui.animation.SimpleAnimation; +import net.silentclient.client.mods.Mod; +import net.silentclient.client.mods.Setting; + +import java.awt.*; +import java.util.ArrayList; public class ColorUtils { @@ -36,4 +40,23 @@ public class ColorUtils { public static void resetColor() { setColor(-1); } + + public static ArrayList getLatestColors(boolean ignoreOpacity) { + ArrayList colors = new ArrayList<>(); + + for(Mod mod : Client.getInstance().getModInstances().getMods()) { + for(Setting setting : Client.getInstance().getSettingsManager().getSettingByMod(mod)) { + if(setting.isColor() && !setting.isChroma()) { + Color color = !ignoreOpacity ? setting.getValColor() : new Color(setting.getValColor().getRed(), setting.getValColor().getBlue(), setting.getValColor().getGreen()); + if(!colors.contains(color)) { + colors.add(color); + } + } + } + } + + return colors; + } + + } 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 85a2ffa..a6f2e06 100644 --- a/src/main/java/net/silentclient/client/utils/types/GlobalSettings.java +++ b/src/main/java/net/silentclient/client/utils/types/GlobalSettings.java @@ -3,6 +3,7 @@ package net.silentclient.client.utils.types; import net.silentclient.client.Client; import net.silentclient.client.utils.FeaturedServers; +import java.awt.*; import java.io.FileOutputStream; import java.util.ArrayList; @@ -13,6 +14,8 @@ public class GlobalSettings { public boolean configsMigrated; public boolean packsPanoramaEnabled; public ArrayList savedFeaturedServers; + public ArrayList latestColors; + public GlobalSettings() { this.config = "Default.txt"; @@ -20,6 +23,7 @@ public class GlobalSettings { this.displayedTutorial = false; this.packsPanoramaEnabled = true; this.savedFeaturedServers = new ArrayList<>(); + this.latestColors = new ArrayList<>(); } public String getConfig() { @@ -73,6 +77,36 @@ public class GlobalSettings { this.savedFeaturedServers = savedFeaturedServers; } + public ArrayList getLatestColors() { + if(latestColors == null) { + this.latestColors = new ArrayList<>(); + latestColors.add(new CustomColor(new Color(255, 255, 255))); + latestColors.add(new CustomColor(new Color(156, 157, 151))); + latestColors.add(new CustomColor(new Color(71,79,82))); + latestColors.add(new CustomColor(new Color(0, 0, 0))); + latestColors.add(new CustomColor(new Color(255,216,61))); + latestColors.add(new CustomColor(new Color(249,128,29))); + latestColors.add(new CustomColor(new Color(176,46,38))); + latestColors.add(new CustomColor(new Color(130,84,50))); + latestColors.add(new CustomColor(new Color(128,199,31))); + latestColors.add(new CustomColor(new Color(58,179,218))); + latestColors.add(new CustomColor(new Color(22,156,157))); + latestColors.add(new CustomColor(new Color(60,68,169))); + latestColors.add(new CustomColor(new Color(243,140,170))); + latestColors.add(new CustomColor(new Color(198,79,189))); + latestColors.add(new CustomColor(new Color(137,50,183))); + } + return latestColors; + } + + public void addToLatestColors(Color color) { + latestColors.removeIf(customColor -> customColor.color == new Color(color.getRed(), color.getGreen(), color.getBlue()).getRGB() && customColor.opacity == color.getAlpha()); + if(latestColors.size() == 21) { + latestColors.remove(20); + } + latestColors.add(0, new CustomColor(color)); + } + public void save() { try { FileOutputStream outputStream = new FileOutputStream(Client.getInstance().getGlobalSettingsFile()); @@ -84,4 +118,42 @@ public class GlobalSettings { Client.logger.catching(err); } } + + public class CustomColor { + public int color; + public int opacity; + + public CustomColor(Color color) { + this(new Color(color.getRed(), color.getGreen(), color.getBlue()), color.getAlpha()); + } + + public CustomColor(Color color, int opacity) { + this.color = new Color(color.getRed(), color.getGreen(), color.getBlue()).getRGB(); + this.opacity = opacity; + } + + public Color getColor() { + return getColor(false); + } + + public Color getColor(boolean ignoreOpacity) { + if(!ignoreOpacity) { + Color color = new Color(this.color); + return new Color(color.getRed(), color.getGreen(), color.getBlue(), opacity); + } + return new Color(this.color); + } + + public int getRGB() { + return getRGB(false); + } + + public int getRGB(boolean ignoreOpacity) { + if(!ignoreOpacity) { + Color color = new Color(this.color); + return new Color(color.getRed(), color.getGreen(), color.getBlue(), opacity).getRGB(); + } + return this.color; + } + } }