diff options
author | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-05-22 14:57:45 +0100 |
---|---|---|
committer | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-05-22 14:57:45 +0100 |
commit | ffcb16e4c7f0f4414c69541238178ce3a128bb74 (patch) | |
tree | 0806698ae4fecfba85146aa8e24f4cc0067ed4ef /src/main | |
parent | 89af4c9fe007e0c4d8ed8edae541b9377e12d8d0 (diff) | |
download | OneConfig-ffcb16e4c7f0f4414c69541238178ce3a128bb74.tar.gz OneConfig-ffcb16e4c7f0f4414c69541238178ce3a128bb74.tar.bz2 OneConfig-ffcb16e4c7f0f4414c69541238178ce3a128bb74.zip |
color selector and loads of stuffs
Diffstat (limited to 'src/main')
15 files changed, 243 insertions, 106 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java index d0697bd..9a50a77 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java @@ -1,7 +1,7 @@ package cc.polyfrost.oneconfig.config; import cc.polyfrost.oneconfig.config.interfaces.Config; -import cc.polyfrost.oneconfig.lwjgl.OneColor; +import cc.polyfrost.oneconfig.config.core.OneColor; import com.google.gson.JsonParser; import cc.polyfrost.oneconfig.config.data.Mod; diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java b/src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java index 9c62d1a..0426090 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java @@ -1,4 +1,4 @@ -package cc.polyfrost.oneconfig.lwjgl; +package cc.polyfrost.oneconfig.config.core; import org.jetbrains.annotations.NotNull; @@ -18,7 +18,7 @@ import java.awt.*; public final class OneColor { transient private Integer rgba = null; private short[] hsba; - private int chroma = -1; + private int dataBit = -1; // rgb constructors @@ -76,7 +76,7 @@ public final class OneColor { this(System.currentTimeMillis() % (int) chromaSpeed / chromaSpeed, saturation, brightness, alpha); if(chromaSpeed < 1) chromaSpeed = 1; if(chromaSpeed > 30) chromaSpeed = 30; - this.chroma = (int) chromaSpeed; + this.dataBit = (int) chromaSpeed; } // internal constructor @@ -85,7 +85,7 @@ public final class OneColor { this.hsba = new short[]{(short) hue, (short) saturation, (short) brightness, (short) alpha}; this.rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]); } else { - this.chroma = chromaSpeed; + this.dataBit = chromaSpeed; this.hsba = new short[]{(short) hue, (short) saturation, (short) brightness, (short) alpha}; } } @@ -128,19 +128,19 @@ public final class OneColor { } /** Get the chroma speed of the color (1s-30s). */ - public int getChroma() { - return chroma == -1 ? -1 : chroma / 1000; + public int getDataBit() { + return dataBit == -1 ? -1 : dataBit / 1000; } /** Set the current chroma speed of the color. -1 to disable. */ public void setChromaSpeed(int speed) { if(speed == -1) { - this.chroma = -1; + this.dataBit = -1; return; } if(speed < 1) speed = 1; if(speed > 30) speed = 30; - this.chroma = speed * 1000; + this.dataBit = speed * 1000; } /** Set the HSBA values of the color. */ @@ -164,13 +164,14 @@ public final class OneColor { * @return the current color in RGBA format (equivalent to getRGB of java.awt.Color) */ public int getRGB() { - if (chroma == -1) { + if (dataBit == 0) dataBit = -1; + if (dataBit == -1) { // fix for when rgba is not set because of deserializing not calling constructor if (rgba == null) rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]); return rgba; } else { - int temp = Color.HSBtoRGB(System.currentTimeMillis() % chroma / (float) chroma, hsba[1] / 100f, hsba[2] / 100f); - hsba[0] = (short) ((System.currentTimeMillis() % chroma / (float) chroma) * 360); + int temp = Color.HSBtoRGB(System.currentTimeMillis() % dataBit / (float) dataBit, hsba[1] / 100f, hsba[2] / 100f); + hsba[0] = (short) ((System.currentTimeMillis() % dataBit / (float) dataBit) * 360); return ((temp & 0x00ffffff) | (hsba[3] << 24)); } } @@ -216,6 +217,9 @@ public final class OneColor { public void setColorFromHex(String hex) { hex = hex.replace("#", ""); + if(hex.length() > 6) { + hex = hex.substring(0, 6); + } if(hex.length() == 3) { hex = charsToString(hex.charAt(0), hex.charAt(0), hex.charAt(1), hex.charAt(1), hex.charAt(2), hex.charAt(2)); } @@ -225,8 +229,17 @@ public final class OneColor { if(hex.length() == 2 && hex.charAt(1) == hex.charAt(0)) { hex = charsToString(hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0)); } - rgba = Integer.parseInt(hex, 16); - hsba = RGBAtoHSBA(0xff000000 | rgba); + StringBuilder hexBuilder = new StringBuilder(hex); + while (hexBuilder.length() < 6) { + hexBuilder.append("0"); + } + hex = hexBuilder.toString(); + //System.out.println(hex); + int r = Integer.valueOf(hex.substring( 0, 2 ), 16); + int g = Integer.valueOf( hex.substring( 2, 4 ), 16); + int b = Integer.valueOf( hex.substring( 4, 6 ), 16); + this.rgba = ((getAlpha() & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF)); + hsba = RGBAtoHSBA(rgba); } public void setAlpha(int alpha) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index 7e12a74..3bfcc74 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -6,7 +6,7 @@ import cc.polyfrost.oneconfig.gui.elements.ColorSelector; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; import cc.polyfrost.oneconfig.gui.pages.HomePage; import cc.polyfrost.oneconfig.gui.pages.Page; -import cc.polyfrost.oneconfig.lwjgl.OneColor; +import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; @@ -32,7 +32,7 @@ public class OneConfigGui extends UScreen { private final BasicElement backArrow = new BasicElement(40, 40, -1, false); private final BasicElement forwardArrow = new BasicElement(40, 40, -1, false); private final ArrayList<Page> parents = new ArrayList<>(); - private ColorSelector currentColorSelector; + public ColorSelector currentColorSelector; public boolean mouseDown; private float scale = 1f; private static OneConfigGui instanceToRestore = null; @@ -229,6 +229,7 @@ public class OneConfigGui extends UScreen { * Correct usage: <code>OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY()));</code> */ public void initColorSelector(ColorSelector colorSelector) { + InputUtils.blockClicks(true); currentColorSelector = colorSelector; } @@ -242,6 +243,11 @@ public class OneConfigGui extends UScreen { return color; } + public OneColor getColor() { + if(currentColorSelector == null) return null; + return currentColorSelector.getColor(); + } + public float getScaleFactor() { return scale; } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java index bcfebd3..887d8d2 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java @@ -16,6 +16,7 @@ public class BasicElement { protected boolean disabled = false; protected int currentColor; protected final float radius; + private boolean block = false; public BasicElement(int width, int height, int colorPalette, boolean hoverFx) { this(width, height, colorPalette, hoverFx, 12f); @@ -50,7 +51,7 @@ public class BasicElement { return; } hovered = InputUtils.isAreaHovered(x - hitBoxX, y - hitBoxY, width + hitBoxX, height + hitBoxY); - clicked = InputUtils.isClicked() && hovered; + clicked = InputUtils.isClicked(block) && hovered; if (clicked) { toggled = !toggled; @@ -58,6 +59,10 @@ public class BasicElement { } } + public void ignoreBlockedTouches(boolean state) { + block = state; + } + public void onClick() { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java index f32abc3..a0c094a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -1,14 +1,15 @@ package cc.polyfrost.oneconfig.gui.elements; import cc.polyfrost.oneconfig.config.OneConfigConfig; +import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.text.NumberInputField; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; -import cc.polyfrost.oneconfig.lwjgl.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.Images; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.utils.IOUtils; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.MathUtils; import org.lwjgl.input.Mouse; @@ -19,17 +20,19 @@ import java.awt.datatransfer.StringSelection; import java.util.ArrayList; public class ColorSelector { - private final int x; - private final int y; + private int x; + private int y; private OneColor color; private float percentMove = 0f; private int mouseX, mouseY; private final ArrayList<BasicElement> buttons = new ArrayList<>(); - private final BasicElement closeBtn = new BasicElement(32, 32, true); + private final BasicElement closeBtn = new BasicElement(32, 32, false); private final BasicElement copyBtn = new BasicElement(32, 32, 2, true); private final BasicElement pasteBtn = new BasicElement(32, 32, 2, true); private final BasicButton guideBtn = new BasicButton(112, 32, "Guide", null, null, 0, BasicButton.ALIGNMENT_CENTER); + private final BasicElement faveBtn = new BasicElement(32, 32, 2, true); + private final BasicElement recentBtn = new BasicElement(32, 32, 2, true); private final NumberInputField hueInput = new NumberInputField(90, 32, 0, 0, 360, 1); private final NumberInputField saturationInput = new NumberInputField(90, 32, 100, 0, 100, 1); @@ -55,76 +58,117 @@ public class ColorSelector { saturationInput.setCurrentValue(color.getSaturation()); brightnessInput.setCurrentValue(color.getBrightness()); alphaInput.setCurrentValue(color.getAlpha() / 255f * 100f); - speedSlider.setValue(color.getChroma()); + speedSlider.setValue(color.getDataBit()); topSlider.setValue(color.getHue()); topSlider.setColor(color); bottomSlider.setValue(color.getAlpha() / 255f * 100f); + hexInput.setInput(color.getHex()); this.x = mouseX - 208; this.y = Math.max(0, mouseY - 776); - for(OneColor color1 : OneConfigConfig.recentColors) { - recentColors.add(new ColorBox(color1)); + if(color.getDataBit() != -1) mode = 2; + if (mode == 0 || mode == 2) { + this.mouseX = (int) (color.getSaturation() / 100f * 384 + x + 16); + this.mouseY = (int) (Math.abs(color.getBrightness() / 100f - 1f) * 288 + y + 120); + } else { + topSlider.setValue(color.getBrightness() / 100f * 360f); + this.mouseX = (int) (Math.sin(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + x + 208); + this.mouseY = (int) (Math.cos(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + y + 264); } - for(OneColor color1 : OneConfigConfig.favoriteColors) { - favoriteColors.add(new ColorBox(color1)); + //for(OneColor color1 : OneConfigConfig.recentColors) { + // recentColors.add(new ColorBox(color1)); + //} + //for(OneColor color1 : OneConfigConfig.favoriteColors) { + // favoriteColors.add(new ColorBox(color1)); + //} + while (favoriteColors.size() < 7) { + favoriteColors.add(new ColorBox(new OneColor(0, 0, 0, 0))); + } + while (recentColors.size() < 7) { + recentColors.add(new ColorBox(new OneColor(0, 0, 0, 0))); } topSlider.setImage(Images.HUE_GRADIENT); } public void draw(long vg) { + InputUtils.blockClicks(false); + if (InputUtils.isAreaHovered(x, y, 368, 64) && Mouse.isButtonDown(0) && !dragging) { + int dx = Mouse.getDX(); + int dy = Mouse.getDY(); + x += dx; + mouseX += dx; + y -= dy; + mouseY -= dy; + } int width = 416; int height = 768; - RenderManager.drawHollowRoundRect(vg, x - 3, y - 3, width + 4, height + 4, new Color(204, 204, 204, 77).getRGB(), 20f, 2f); RenderManager.drawRoundedRect(vg, x, y, width, height, OneConfigConfig.GRAY_800, 20f); RenderManager.drawString(vg, "Color Selector", x + 16, y + 32, OneConfigConfig.WHITE_90, 18f, Fonts.SEMIBOLD); + RenderManager.setAlpha(vg, 0.8f); + if (closeBtn.isHovered()) RenderManager.setAlpha(vg, 1f); + if (closeBtn.isClicked()) RenderManager.setAlpha(vg, 0.5f); closeBtn.draw(vg, x + 368, y + 16); - RenderManager.drawSvg(vg, SVGs.X_CIRCLE, x + 369, y + 17, 32, 32); - if (closeBtn.isClicked()) { - OneConfigGui.INSTANCE.closeColorSelector(); - } + RenderManager.drawSvg(vg, SVGs.X_CIRCLE, x + 368, y + 16, 32, 32); + RenderManager.setAlpha(vg, 1f); // hex parser - if(copyBtn.isClicked()) { + if (copyBtn.isClicked()) { Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(color.getHex()), null); } - if(pasteBtn.isClicked()) { + if (pasteBtn.isClicked() && mode != 2) { try { color.setColorFromHex(Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor).toString()); + hexInput.setInput("#" + color.getHex()); } catch (Exception ignored) { } } hexInput.setErrored(false); - if(hexInput.isToggled()) { // TODO fix this + if ((hexInput.isToggled() || pasteBtn.isClicked()) && mode != 2) { try { color.setColorFromHex(hexInput.getInput()); } catch (Exception e) { hexInput.setErrored(true); e.printStackTrace(); } + saturationInput.setInput(String.format("%.01f", (float) color.getSaturation())); + brightnessInput.setInput(String.format("%.01f", (float) color.getBrightness())); + alphaInput.setInput(String.format("%.01f", color.getAlpha() / 255f * 100f)); + if (mode == 0) topSlider.setValue(color.getHue()); + if (mode == 1) bottomSlider.setValue(color.getBrightness() / 100f * 360f); } // TODO favorite stuff + faveBtn.draw(vg, x + 16, y + 672); + RenderManager.drawSvg(vg, SVGs.HEART_OUTLINE, x + 23, y + 679, 18, 18); + recentBtn.draw(vg, x + 16, y + 720); + RenderManager.drawSvg(vg, SVGs.HISTORY, x + 23, y + 727, 18, 18); + for(int i = 0; i < 7; i++) { + favoriteColors.get(i).draw(vg, x + 104 + i * 44, y + 672); + } + for(int i = 0; i < 7; i++) { + recentColors.get(i).draw(vg, x + 104 + i * 44, y + 720); + } RenderManager.drawRoundedRect(vg, x + 16, y + 64, 384, 32, OneConfigConfig.GRAY_500, 12f); RenderManager.drawRoundedRect(vg, x + 18 + (percentMove * 128), y + 66, 124, 28, OneConfigConfig.PRIMARY_600, 10f); int i = 18; - for(BasicElement button : buttons) { + for (BasicElement button : buttons) { button.draw(vg, x + i, y + 66); - if(button.isClicked()) { + if (button.isClicked()) { mode = buttons.indexOf(button); - if(mode == 1) { + if (mode == 1) { mouseX = (int) (Math.sin(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + x + 208); mouseY = (int) (Math.cos(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + y + 264); topSlider.setValue(color.getBrightness() / 100f * 360f); } - if(mode == 0 || mode == 2) { + if (mode == 0 || mode == 2) { topSlider.setValue(color.getHue()); mouseX = (int) (saturationInput.getCurrentValue() / 100f * 384 + x + 16); mouseY = (int) (Math.abs(brightnessInput.getCurrentValue() / 100f - 1f) * 288 + y + 120); } } - if(percentMove != mode) { + if (percentMove != mode) { button.currentColor = OneConfigConfig.TRANSPARENT; } i += 128; @@ -141,7 +185,7 @@ public class ColorSelector { brightnessInput.draw(vg, x + 104, y + 584); RenderManager.drawString(vg, "Alpha (%)", x + 224, y + 599, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); alphaInput.draw(vg, x + 312, y + 584); - RenderManager.drawString(vg, color.getChroma() == -1 ? "Hex (RGB)" : "Chroma Speed", x + 16, y + 641, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); + RenderManager.drawString(vg, color.getDataBit() == -1 ? "Hex (RGB):" : "Color Code:", x + 16, y + 641, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); hexInput.draw(vg, x + 104, y + 624); copyBtn.draw(vg, x + 204, y + 624); @@ -158,7 +202,7 @@ public class ColorSelector { boolean hovered = Mouse.isButtonDown(0) && InputUtils.isAreaHovered(x + 16, y + 120, 384, 288); if (hovered && isMouseDown && !mouseWasDown) dragging = true; mouseWasDown = isMouseDown; - if(mode != 2) color.setChromaSpeed(-1); + if (mode != 2) color.setChromaSpeed(-1); switch (mode) { default: case 0: @@ -166,30 +210,32 @@ public class ColorSelector { buttons.get(mode).currentColor = OneConfigConfig.TRANSPARENT; topSlider.setImage(Images.HUE_GRADIENT); RenderManager.drawHSBBox(vg, x + 16, y + 120, 384, 288, color.getRGBMax(false)); - if(dragging) { + if (dragging) { mouseX = InputUtils.mouseX(); mouseY = InputUtils.mouseY(); } - if(mouseX < x + 16) mouseX = x + 16; - if(mouseY < y + 120) mouseY = y + 120; - if(mouseX > x + 400) mouseX = x + 400; - if(mouseY > y + 408) mouseY = y + 408; + if (mouseX < x + 16) mouseX = x + 16; + if (mouseY < y + 120) mouseY = y + 120; + if (mouseX > x + 400) mouseX = x + 400; + if (mouseY > y + 408) mouseY = y + 408; float progressX = (mouseX - x - 16f) / 384f; float progressY = Math.abs((mouseY - y - 120f) / 288f - 1f); color.setHSBA((int) topSlider.getValue(), Math.round(progressX * 100), Math.round(progressY * 100), (int) ((bottomSlider.getValue() / 100f) * 255)); - if(mode == 0) { + if (mode == 0) { topSlider.setColor(color); topSlider.draw(vg, x + 16, y + 424); RenderManager.drawString(vg, "Hue", x + 16, y + 560, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); hueInput.draw(vg, x + 104, y + 544); } - if(mode == 2) { + if (mode == 2) { speedSlider.draw(vg, x + 60, y + 424); RenderManager.drawString(vg, "SLOW", x + 16, y + 429, OneConfigConfig.WHITE_80, 12f, Fonts.REGULAR); RenderManager.drawString(vg, "FAST", x + 370, y + 429, OneConfigConfig.WHITE_80, 12f, Fonts.REGULAR); RenderManager.drawString(vg, "Speed (s)", x + 16, y + 560, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); hueInput.draw(vg, x + 104, y + 544); - color.setChromaSpeed((int) speedSlider.getValue()); + if (!speedSlider.isDragging()) { + color.setChromaSpeed((int) Math.abs(speedSlider.getValue() - 29)); + } } break; case 1: @@ -205,14 +251,21 @@ public class ColorSelector { mouseWasDown = isMouseDown; int angle = 0; - if(dragging) { - //if(!(squareDist / (144 * 144) > 1f) - mouseX = InputUtils.mouseX(); - mouseY = InputUtils.mouseY(); - angle = (int) Math.toDegrees(Math.atan2(mouseY - circleCenterY, mouseX - circleCenterX)); - if(angle < 0) angle += 360; + int saturation = color.getSaturation(); + if (dragging) { + angle = (int) Math.toDegrees(Math.atan2(InputUtils.mouseY() - circleCenterY, InputUtils.mouseX() - circleCenterX)); + if (angle < 0) angle += 360; + if ((squareDist / (144 * 144) > 1f)) { + saturation = 100; + mouseX = (int) (Math.sin(Math.toRadians(-angle) + 1.5708) * 144 + x + 208); + mouseY = (int) (Math.cos(Math.toRadians(-angle) + 1.5708) * 144 + y + 264); + } else { + saturation = (int) (squareDist / (144 * 144) * 100); + mouseX = InputUtils.mouseX(); + mouseY = InputUtils.mouseY(); + } } - color.setHSBA(dragging ? angle : color.getHue(), dragging ? (int) (squareDist / (144 * 144) * 100) : color.getSaturation(), (int) (topSlider.getValue() / 360 * 100), (int) ((bottomSlider.getValue() / 100f) * 255)); + color.setHSBA(dragging ? angle : color.getHue(), saturation, (int) (topSlider.getValue() / 360 * 100), (int) ((bottomSlider.getValue() / 100f) * 255)); topSlider.setGradient(OneConfigConfig.BLACK, color.getRGBMax(true)); topSlider.setImage(null); RenderManager.drawString(vg, "Hue", x + 16, y + 560, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); @@ -220,7 +273,7 @@ public class ColorSelector { topSlider.draw(vg, x + 16, y + 424); break; } - if(dragging && InputUtils.isClicked()) { + if (dragging && InputUtils.isClicked(true)) { dragging = false; } bottomSlider.setGradient(OneConfigConfig.TRANSPARENT_25, color.getRGBNoAlpha()); @@ -231,17 +284,17 @@ public class ColorSelector { RenderManager.drawRoundedRect(vg, mouseX - 5, mouseY - 5, 10, 10, color.getRGBNoAlpha(), 10f); // deal with the input fields - if(hueInput.isToggled() || saturationInput.isToggled() || brightnessInput.isToggled() || alphaInput.isToggled() || hueInput.arrowsClicked() || saturationInput.arrowsClicked() || brightnessInput.arrowsClicked() || alphaInput.arrowsClicked()) { - if(mode != 2) { + if (hueInput.isToggled() || saturationInput.isToggled() || brightnessInput.isToggled() || alphaInput.isToggled() || hueInput.arrowsClicked() || saturationInput.arrowsClicked() || brightnessInput.arrowsClicked() || alphaInput.arrowsClicked() || hexInput.isToggled() || pasteBtn.isClicked()) { + if (mode != 2 && !hexInput.isToggled()) { color.setHSBA((int) hueInput.getCurrentValue(), (int) saturationInput.getCurrentValue(), (int) brightnessInput.getCurrentValue(), (int) ((alphaInput.getCurrentValue() / 100f) * 255f)); } - if(mode == 2) { + if (mode == 2) { color.setHSBA(color.getHue(), (int) saturationInput.getCurrentValue(), (int) brightnessInput.getCurrentValue(), (int) ((alphaInput.getCurrentValue() / 100f) * 255f)); color.setChromaSpeed((int) (hueInput.getCurrentValue() / 360f * 30f)); speedSlider.setValue(hueInput.getCurrentValue() / 360f * 30f); } bottomSlider.setValue(color.getAlpha() / 255f * 100f); - if(mode == 0 || mode == 2) { + if (mode == 0 || mode == 2) { mouseX = (int) (saturationInput.getCurrentValue() / 100f * 384 + x + 16); mouseY = (int) (Math.abs(brightnessInput.getCurrentValue() / 100f - 1f) * 288 + y + 120); } else { @@ -249,32 +302,38 @@ public class ColorSelector { mouseX = (int) (Math.sin(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + x + 208); mouseY = (int) (Math.cos(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + y + 264); } - if(mode == 0) { + if (mode == 0) { topSlider.setValue(color.getHue()); } - } - else if(OneConfigGui.INSTANCE.mouseDown) { - if(mode != 2) { + } else if (OneConfigGui.INSTANCE.mouseDown) { + saturationInput.setInput(String.format("%.01f", (float) color.getSaturation())); + brightnessInput.setInput(String.format("%.01f", (float) color.getBrightness())); + alphaInput.setInput(String.format("%.01f", color.getAlpha() / 255f * 100f)); + if (hexInput.isToggled()) return; + if (mode != 2) { hueInput.setInput(String.format("%.01f", (float) color.getHue())); hexInput.setInput("#" + color.getHex()); } else { - hueInput.setInput(String.format("%.01f", (float) color.getChroma())); - hexInput.setInput("Z" + color.getChroma()); + hueInput.setInput(String.format("%.01f", (float) color.getDataBit())); + hexInput.setInput("Z" + color.getDataBit()); } - saturationInput.setInput(String.format("%.01f", (float) color.getSaturation())); - brightnessInput.setInput(String.format("%.01f", (float) color.getBrightness())); - alphaInput.setInput(String.format("%.01f", color.getAlpha() / 255f * 100f)); + } - if(mode != 2 && !hexInput.isToggled()) { + if (mode != 2 && !hexInput.isToggled()) { hueInput.setInput(String.format("%.01f", (float) color.getHue())); hexInput.setInput("#" + color.getHex()); } + if(guideBtn.isClicked()) IOUtils.browseLink("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); // draw the color preview RenderManager.drawHollowRoundRect(vg, x + 15, y + 487, 384, 40, OneConfigConfig.GRAY_300, 12f, 2f); RenderManager.drawImage(vg, Images.ALPHA_GRID, x + 20, y + 492, 376, 32); RenderManager.drawRoundedRect(vg, x + 20, y + 492, 376, 32, color.getRGB(), 8f); + InputUtils.blockClicks(true); + if (closeBtn.isClicked()) { + OneConfigGui.INSTANCE.closeColorSelector(); + } } public OneColor getColor() { @@ -290,18 +349,19 @@ public class ColorSelector { } public void onClose() { - for(int i = 0; i < OneConfigConfig.recentColors.size(); i++) { + InputUtils.blockClicks(false); + /*for (int i = 0; i < OneConfigConfig.recentColors.size(); i++) { OneColor color1 = OneConfigConfig.recentColors.get(i); - if(color1.getRGB() == color.getRGB()) { + if (color1.getRGB() == color.getRGB()) { OneConfigConfig.recentColors.get(i).setFromOneColor(color1); return; } } - OneConfigConfig.recentColors.add(color); + OneConfigConfig.recentColors.add(color);*/ } public void setFavorite(int index) { - if(index < 0 || index >= OneConfigConfig.favoriteColors.size()) { + if (index < 0 || index >= OneConfigConfig.favoriteColors.size()) { return; } OneConfigConfig.favoriteColors.add(index, color); @@ -325,16 +385,17 @@ public class ColorSelector { public void draw(long vg, int x, int y) { update(x, y); super.dragPointerSize = 15f; - if(image != null) { - RenderManager.drawRoundImage(vg, image, x, y, width, height, 8f); + if (image != null) { + RenderManager.drawRoundImage(vg, image, x + 1, y + 1, width - 2, height - 2, 8f); } else { RenderManager.drawGradientRoundedRect(vg, x, y, width, height, gradColorStart, gradColorEnd, 8f); } - RenderManager.drawHollowRoundRect(vg, x - 1.5f, y - 1.5f, width + 2, height + 2, new Color(204, 204, 204, 77).getRGB(), 8f, 1f); - RenderManager.drawHollowRoundRect(vg, currentDragPoint - 2, y - 2, 18, 18, OneConfigConfig.WHITE, 7f, 1f); - if(color != null) { - RenderManager.drawRoundedRect(vg, currentDragPoint, y, 15, 15, color.getRGBNoAlpha(), 7.5f); + RenderManager.drawHollowRoundRect(vg, x - 0.5f, y - 0.5f, width, height, new Color(204, 204, 204, 80).getRGB(), 8f, 1f); + RenderManager.drawHollowRoundRect(vg, currentDragPoint - 1, y - 1, 18, 18, OneConfigConfig.WHITE, 9f, 1f); + RenderManager.drawHollowRoundRect(vg, currentDragPoint, y, 16, 16, OneConfigConfig.BLACK, 8f, 1f); + if (color != null) { + RenderManager.drawRoundedRect(vg, currentDragPoint + 1.5f, y + 1.5f, 14, 14, color.getRGBNoAlpha(), 7f); } } @@ -354,6 +415,7 @@ public class ColorSelector { private static class ColorBox extends BasicElement { protected OneColor color; + public ColorBox(OneColor color) { super(32, 32, false); this.color = color; @@ -362,8 +424,9 @@ public class ColorSelector { @Override public void draw(long vg, int x, int y) { RenderManager.drawRoundedRect(vg, x, y, 32, 32, toggled ? OneConfigConfig.PRIMARY_600 : OneConfigConfig.GRAY_300, 12f); - RenderManager.drawRoundedRect(vg, x + 2, y + 2, 28, 28, OneConfigConfig.GRAY_800, 8f); + RenderManager.drawRoundedRect(vg, x + 2, y + 2, 28, 28, OneConfigConfig.GRAY_800, 10f); RenderManager.drawRoundedRect(vg, x + 4, y + 4, 24, 24, color.getRGB(), 8f); + update(x, y); } public void setColor(OneColor color) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java index 08a2823..3aab5ad 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java @@ -39,7 +39,7 @@ public class Slider extends BasicElement { if (dragging) { value = ((float) InputUtils.mouseX() - x) / width; } - if (dragging && InputUtils.isClicked()) { + if (dragging && InputUtils.isClicked(true)) { dragging = false; value = ((float) InputUtils.mouseX() - x) / width; } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java index 7986598..2068882 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java @@ -6,7 +6,7 @@ import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.BasicElement; import cc.polyfrost.oneconfig.gui.elements.ColorSelector; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; -import cc.polyfrost.oneconfig.lwjgl.OneColor; +import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.Images; @@ -40,10 +40,7 @@ public class ConfigColorElement extends BasicOption { hexField.setErrored(false); if (hexField.isToggled()) { try { - int alpha = color.getAlpha(); color.setColorFromHex(hexField.getInput()); - color.setAlpha(alpha); - setColor(color); } catch (NumberFormatException e) { hexField.setErrored(true); } @@ -64,7 +61,6 @@ public class ConfigColorElement extends BasicOption { input = 100f; } color = new OneColor((float) color.getHue(), color.getSaturation(), color.getBrightness(), Math.round(input * 2.55f)); - setColor(color); } catch (NumberFormatException e) { alphaField.setErrored(true); } @@ -72,12 +68,16 @@ public class ConfigColorElement extends BasicOption { alphaField.draw(vg, x1 + 336, y); element.update(x1 + 416, y); - RenderManager.drawRoundImage(vg, Images.ALPHA_GRID, x1 + 416, y, 64, 32, 12f); - RenderManager.drawRoundedRect(vg, x1 + 416, y, 64, 32, color.getRGB(), 12f); RenderManager.drawHollowRoundRect(vg, x1 + 415, y - 1, 64, 32, OneConfigConfig.GRAY_300, 12f, 2f); + RenderManager.drawRoundImage(vg, Images.ALPHA_GRID, x1 + 420, y + 4, 56, 24, 8f); + RenderManager.drawRoundedRect(vg, x1 + 420, y + 4, 56, 24, color.getRGB(), 8f); if (element.isClicked() && !element.isToggled()) { - OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(new OneColor(40, 30, 20), InputUtils.mouseX(), InputUtils.mouseY())); + OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY())); } + if(OneConfigGui.INSTANCE.currentColorSelector != null) { + color = (OneConfigGui.INSTANCE.getColor()); + } + setColor(color); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java index b367934..e5b3d90 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java @@ -35,7 +35,7 @@ public class ConfigSlider extends BasicOption { inputField.disable(!isEnabled()); if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); boolean isMouseDown = Mouse.isButtonDown(0); - if (hovered && isMouseDown && !mouseWasDown) dragging = true; + if (hovered && isMouseDown && !mouseWasDown && !InputUtils.isBlockingClicks()) dragging = true; mouseWasDown = isMouseDown; if (dragging) { xCoordinate = (int) MathUtils.clamp(InputUtils.mouseX(), x + 352, x + 864); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java new file mode 100644 index 0000000..ec02dce --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java @@ -0,0 +1,12 @@ +package cc.polyfrost.oneconfig.gui.pages; + +public class CreditsPage extends Page { + CreditsPage() { + super("Credits"); + } + + @Override + public void draw(long vg, int x, int y) { + + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java index 91f4181..ca0fe0e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java @@ -4,16 +4,22 @@ import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.BasicButton; import cc.polyfrost.oneconfig.gui.elements.ColorSelector; -import cc.polyfrost.oneconfig.lwjgl.OneColor; +import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; +import cc.polyfrost.oneconfig.utils.IOUtils; import cc.polyfrost.oneconfig.utils.InputUtils; import java.awt.*; public class HomePage extends Page { - private final BasicButton btn = new BasicButton(184, 36, "Socials", SVGs.SHARE, SVGs.POP_OUT, 1, BasicButton.ALIGNMENT_CENTER); + private final BasicButton socialsBtn = new BasicButton(184, 36, "Socials", SVGs.SHARE, SVGs.POP_OUT, 1, BasicButton.ALIGNMENT_CENTER, () -> IOUtils.browseLink("https://twitter.com/polyfrost")); + private final BasicButton discordBtn = new BasicButton(184, 36, "Discord", SVGs.WEBSITE, SVGs.LINK_DIAGONAL, 1, BasicButton.ALIGNMENT_CENTER, () -> IOUtils.browseLink("https://discord.gg/4BdUuGpMdf")); + private final BasicButton webBtn = new BasicButton(184, 36, "Website", SVGs.WEBSITE, null, 1, BasicButton.ALIGNMENT_CENTER, () -> IOUtils.browseLink("https://polyfrost.cc")); + private final BasicButton creditsBtn = new BasicButton(184, 36, "Credits", SVGs.AUDIO_PLAY, SVGs.LINK_DIAGONAL, 0, BasicButton.ALIGNMENT_CENTER, () -> OneConfigGui.INSTANCE.openPage(new CreditsPage())); + private final BasicButton guideBtn = new BasicButton(184, 36, "Online Guide", SVGs.HELP_CIRCLE, null, 0, BasicButton.ALIGNMENT_CENTER, () -> IOUtils.browseLink("https://www.youtube.com/watch?v=dQw4w9WgXcQ")); + public HomePage() { super("Home Dashboard"); @@ -23,9 +29,16 @@ public class HomePage extends Page { RenderManager.drawRoundedRect(vg, x, y, 184, 36, -1, 12f); RenderManager.drawString(vg, "This is a cool string to test pages", x + 32, y + 72, -1, 36f, Fonts.BOLD); RenderManager.drawRoundedRect(vg, x + 350, y + 310, 300, 200, OneConfigConfig.PRIMARY_600, 14f); - //RenderManager.drawRoundedRect(vg); - btn.draw(vg, x + 432, y + 658); - if(btn.isClicked()) { + RenderManager.drawSvg(vg, SVGs.INFO_CIRCLE, x + 20, y + 604, 24, 24); + RenderManager.drawString(vg, "Info", x + 52, y + 618, OneConfigConfig.WHITE_90, 24f, Fonts.MEDIUM); + RenderManager.drawRoundedRect(vg, x + 16, y + 644, 1024, 64, OneConfigConfig.GRAY_700, 20f); + + discordBtn.draw(vg, x + 32, y + 658); + webBtn.draw(vg, x + 232, y + 658); + socialsBtn.draw(vg, x + 432, y + 658); + creditsBtn.draw(vg, x + 632, y + 658); + guideBtn.draw(vg, x + 832, y + 658); + if(socialsBtn.isClicked()) { OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(new OneColor(new Color(255, 0, 255, 127)), InputUtils.mouseX(), InputUtils.mouseY())); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java index 6c36256..c6d58a9 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java @@ -1,6 +1,6 @@ package cc.polyfrost.oneconfig.hud; -import cc.polyfrost.oneconfig.lwjgl.OneColor; +import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; public abstract class BasicHud { diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java index 8f8fadf..a1c4d55 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -49,6 +49,7 @@ public final class RenderManager { fb.enableStencil(); } GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GL11.glDisable(GL11.GL_ALPHA_TEST); if (mcScaling) { nvgBeginFrame(vg, (float) UResolution.getScaledWidth(), (float) UResolution.getScaledHeight(), (float) UResolution.getScaleFactor()); @@ -150,7 +151,7 @@ public final class RenderManager { public static void drawHollowRoundRect(long vg, float x, float y, float width, float height, int color, float radius, float thickness) { nvgBeginPath(vg); nvgRoundedRect(vg, x + thickness, y + thickness, width - thickness, height - thickness, radius); - nvgStrokeWidth(vg, thickness); + nvgStrokeWidth(vg, thickness + 0.5f); nvgPathWinding(vg, NVG_HOLE); color(vg, color); NVGColor nvgColor = color(vg, color); diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java index b5410de..d65fea3 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java @@ -5,7 +5,7 @@ import cc.polyfrost.oneconfig.config.annotations.Option; import cc.polyfrost.oneconfig.config.core.OneKeyBind; import cc.polyfrost.oneconfig.config.data.*; import cc.polyfrost.oneconfig.config.interfaces.Config; -import cc.polyfrost.oneconfig.lwjgl.OneColor; +import cc.polyfrost.oneconfig.config.core.OneColor; import net.minecraftforge.fml.common.FMLCommonHandler; public class TestConfig extends Config { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java index 400dc39..ae5753a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java @@ -25,18 +25,18 @@ public class ColorUtils { switch (colorPalette) { case -2: - return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), new float[]{0.9f, 0.9f, 0.9f, 0.3f}, hover, 20f); + return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), new float[]{0.9f, 0.9f, 0.9f, 0.3f}, hover, 50f); case -1: - return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), splitColor(OneConfigConfig.GRAY_500), hover, 10f); + return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), splitColor(OneConfigConfig.GRAY_500), hover, 50f); default: case 0: - return getColorComponents(color, splitColor(OneConfigConfig.GRAY_600), splitColor(OneConfigConfig.GRAY_300), hover, 25f); + return getColorComponents(color, splitColor(OneConfigConfig.GRAY_600), splitColor(OneConfigConfig.GRAY_300), hover, 50f); case 1: return getColorComponents(color, splitColor(OneConfigConfig.PRIMARY_600), splitColor(OneConfigConfig.PRIMARY_500), hover, 150f); case 2: return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_300), hover, 50f); case 3: - return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_300), hover, 25f); + return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_300), hover, 150f); } } @@ -52,7 +52,7 @@ public class ColorUtils { float[] init = splitColor(initColor); float[] finalC = splitColor(finalColor); float[] current = splitColor(currentColor); - return getColorComponents(current, init, finalC, direction, speed); + return getColorComponents(current, init, finalC, direction, speed + 100f); } private static float[] splitColor(int color) { @@ -65,7 +65,10 @@ public class ColorUtils { currentColor[2] = smooth(currentColor[2], initColor[2], finalColor[2], hover, speed); currentColor[3] = smooth(currentColor[3], initColor[3], finalColor[3], hover, speed); - return new Color(currentColor[0], currentColor[1], currentColor[2], currentColor[3]).getRGB(); + return ((int) (currentColor[3] * 255) << 24) | + ((int) (currentColor[0] * 255) << 16) | + ((int) (currentColor[1] * 255) << 8) | + ((int) (currentColor[2] * 255)); } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java index 7263a19..73a8a13 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java @@ -1,9 +1,11 @@ package cc.polyfrost.oneconfig.utils; +import java.awt.*; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.net.URI; import java.net.URL; import java.nio.Buffer; import java.nio.ByteBuffer; @@ -52,4 +54,23 @@ public final class IOUtils { } } + public static void browseLink(String uri) { + try { + browseLink(new URI(uri)); + } catch (Exception e) { + e.printStackTrace(); + System.err.println("Invalid URI: " + uri); + } + } + public static void browseLink(URI uri) { + if(Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { + try { + Desktop.getDesktop().browse(uri); + } catch (IOException e) { + e.printStackTrace(); + System.err.println("Failed to open URL in browser: " + uri); + } + } + } + }
\ No newline at end of file |