From d2bba6f5f1a6bf9caa43d79e044abcee74101cef Mon Sep 17 00:00:00 2001 From: refactoring Date: Tue, 2 Jan 2024 06:09:43 -0500 Subject: [PATCH] (fix) implement color pickers in lite menus --- .../gui/lite/clickgui/GuiColorPicker.java | 78 ++++++------------- .../client/gui/lite/clickgui/ModSettings.java | 21 ++++- .../client/gui/modmenu/ColorPicker.java | 1 + 3 files changed, 42 insertions(+), 58 deletions(-) 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 d5c117b..3170972 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 @@ -8,6 +8,7 @@ import net.minecraft.util.ResourceLocation; import net.silentclient.client.Client; import net.silentclient.client.gui.SilentScreen; import net.silentclient.client.gui.animation.normal.Direction; +import net.silentclient.client.gui.elements.HSBPicker; import net.silentclient.client.gui.lite.clickgui.utils.GlUtils; import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils; import net.silentclient.client.gui.lite.clickgui.utils.RenderUtils; @@ -38,12 +39,16 @@ public class GuiColorPicker extends SilentScreen { private final String value; private long initTime; - public GuiColorPicker(Mod mod, String value, GuiScreen parent) { + private HSBPicker hsb; + + public GuiColorPicker(Mod mod, String value, GuiScreen parentScreen) { if (mod == null) throw new IllegalArgumentException("Mod is null"); this.mod = mod; - this.parentScreen = parent; + this.parentScreen = parentScreen; this.value = value; + float colorY = 80; + int colorX = 3; } @Override @@ -51,21 +56,6 @@ public class GuiColorPicker extends SilentScreen { defaultCursor = false; this.initTime = System.currentTimeMillis(); colors.clear(); - colors.add(new Color(255, 255, 255)); - colors.add(new Color(156, 157, 151)); - colors.add(new Color(71,79,82)); - colors.add(new Color(0, 0, 0)); - colors.add(new Color(255,216,61)); - colors.add(new Color(249,128,29)); - colors.add(new Color(176,46,38)); - colors.add(new Color(130,84,50)); - colors.add(new Color(128,199,31)); - colors.add(new Color(58,179,218)); - colors.add(new Color(22,156,157)); - colors.add(new Color(60,68,169)); - colors.add(new Color(243,140,170)); - colors.add(new Color(198,79,189)); - colors.add(new Color(137,50,183)); MenuBlurUtils.loadBlur(); int addX = 190; int addY = 110; @@ -74,6 +64,8 @@ public class GuiColorPicker extends SilentScreen { int height = addY * 2; this.buttonList.add(new Button(1, x + 5, y + 25, 75, 20, "< Back")); this.buttonList.add(new Button(2, x + 5, (y + height) - 26, 75, 20, "Edit HUD")); + hsb = new HSBPicker(x + 100, y + 70, 120, 70, true, value); + hsb.init(); } @Override @@ -111,33 +103,13 @@ public class GuiColorPicker extends SilentScreen { int spacing = 100; Setting setting = Client.getInstance().getSettingsManager().getSettingByName(mod, this.value); - - for(Color color : colors) { - RenderUtils.drawRect(x + spacing, settingY - 1, 22, 22, new Color(0, 0, 0).getRGB()); - RenderUtils.drawRect(x + spacing + 1, settingY - 1 + 1, 20, 20, new Color(color.getRed(), color.getGreen(), color.getBlue(), setting.getOpacity()).getRGB()); - if(MouseUtils.isInside(mouseX, mouseY, x + spacing, settingY - 1, 22, 22)) { - cursorType = MouseCursorHandler.CursorType.POINTER; - } - spacing += 25; - colorIndex += 1; - if(colorIndex == 5 || colorIndex == 10) { - spacing = 100; - settingY += 30; - } - } + + hsb.render(mouseX, mouseY); + + setting.setValColor(hsb.getSelectedColorFinal()); + setting.setOpacity(hsb.getSelectedColorFinal().getAlpha()); int settingHeight = 10 + 5; - settingY += settingHeight; - if(setting.isCanChangeOpacity()) { - settingY += settingHeight; - Slider.render(x, settingY - 1, width, "Opacity", 255, setting.getOpacity()); - if (Slider.isDrag(mouseX, mouseY, x, settingY - 1, width) && (System.currentTimeMillis() - initTime) > 500) { - double diff = 255 - 0; - double mouse = MathHelper.clamp_double((mouseX - Slider.getLeft(x, width)) / 90D, 0, 1); - double newVal = 0 + mouse * diff; - setting.setOpacity((int) newVal); - } - } settingY += settingHeight; @@ -196,19 +168,7 @@ public class GuiColorPicker extends SilentScreen { Setting setting = Client.getInstance().getSettingsManager().getSettingByName(mod, this.value); - for(Color color : colors) { - if(MouseUtils.isInside(mouseX, mouseY, x + spacing, settingY - 1, 22, 22) && mouseButton == 0) { - Sounds.playButtonSound(); - Client.getInstance().getSettingsManager().getSettingByName(mod, this.value).setValColor(color); - mc.displayGuiScreen(parentScreen); - } - spacing += 25; - colorIndex += 1; - if(colorIndex == 5 || colorIndex == 10) { - spacing = 100; - settingY += 30; - } - } + hsb.mouseClicked(mouseX, mouseY, mouseButton); int settingHeight = 10 + 5; @@ -219,7 +179,13 @@ public class GuiColorPicker extends SilentScreen { setting.setChroma(!setting.isChroma()); } } - + + @Override + protected void mouseReleased(int mouseX, int mouseY, int state) { + hsb.mouseReleased(mouseX, mouseY, state); + super.mouseReleased(mouseX, mouseY, state); + } + @Override protected void keyTyped(char typedChar, int keyCode) throws IOException { if (keyCode == Keyboard.KEY_ESCAPE) { diff --git a/src/main/java/net/silentclient/client/gui/lite/clickgui/ModSettings.java b/src/main/java/net/silentclient/client/gui/lite/clickgui/ModSettings.java index 8f4c4ef..9bf847a 100644 --- a/src/main/java/net/silentclient/client/gui/lite/clickgui/ModSettings.java +++ b/src/main/java/net/silentclient/client/gui/lite/clickgui/ModSettings.java @@ -16,6 +16,7 @@ import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils.Scroll; import net.silentclient.client.gui.elements.*; import net.silentclient.client.gui.font.SilentFontRenderer; import net.silentclient.client.gui.hud.HUDConfigScreen; +import net.silentclient.client.gui.modmenu.CellGrid; import net.silentclient.client.gui.theme.Theme; import net.silentclient.client.gui.theme.input.DefaultInputTheme; import net.silentclient.client.gui.util.RenderUtil; @@ -198,6 +199,10 @@ public class ModSettings extends SilentScreen { cursorType = MouseCursorHandler.CursorType.POINTER; } } + if(setting.isCellGrid()) { + CellGrid.render(mouseX, mouseY, x + 100, settingY, setting); + settingY += 135; + } if (setting.isSlider()) { Slider.render(x, settingY - 1, width, setting.getName(), setting.getMax(), setting.getValDouble()); @@ -354,7 +359,9 @@ public class ModSettings extends SilentScreen { settingY += 5; inputIndex++; } - + if(setting.isCellGrid()) { + CellGrid.click(mouseX, mouseY, mouseButton, setting); + } if(setting.isCombo()) { int index = 0; String curr = setting.getValString(); @@ -436,7 +443,17 @@ public class ModSettings extends SilentScreen { } } } - + + @Override + protected void mouseReleased(int mouseX, int mouseY, int state) { + for (Setting setting : Client.getInstance().getSettingsManager().getSettingByMod(mod)) { + if(setting.isCellGrid()) { + CellGrid.release(); + } + } + super.mouseReleased(mouseX, mouseY, state); + } + @Override public boolean doesGuiPauseGame() { return !(this.mod instanceof TimeChangerMod); 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 6e349e2..09a05e0 100644 --- a/src/main/java/net/silentclient/client/gui/modmenu/ColorPicker.java +++ b/src/main/java/net/silentclient/client/gui/modmenu/ColorPicker.java @@ -73,6 +73,7 @@ public class ColorPicker extends SilentScreen { float colorY = 66; hsb.render(mouseX, mouseY); + setting.setOpacity(hsb.getSelectedColorFinal().getAlpha()); Client.getInstance().getSettingsManager().getSettingByName(mod, this.value).setValColor(hsb.getSelectedColorFinal());