diff options
Diffstat (limited to 'src/main/java/cc')
5 files changed, 77 insertions, 119 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index 0558799..7ca3e31 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -51,7 +51,7 @@ public class SideBar { if (!button.isClicked()) continue; if (button.equals(buttons.get(selected))) break; buttons.get(selected).setColorPalette(ColorPalette.TERTIARY); - moveAnimation = new EaseInOutQuart(300, buttons.get(selected).x, button.x, false); + moveAnimation = new EaseInOutQuart(300, buttons.get(selected).y, button.y, false); selected = buttons.indexOf(button); } if (moveAnimation != null) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java index 894be2a..834aeb1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java @@ -28,7 +28,9 @@ public abstract class Animation { public float get(long deltaTime) { timePassed += deltaTime; if (timePassed >= duration) return start + change; - return animate(timePassed, duration, start, change); + float value = animate(timePassed, duration, start, change); + System.out.println(value); + return value; } /** diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java index 8166883..71441e6 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -11,7 +11,6 @@ import cc.polyfrost.oneconfig.utils.color.ColorUtils; import org.jetbrains.annotations.NotNull; import org.lwjgl.input.Mouse; - public class BasicButton extends BasicElement { protected String text; @@ -22,8 +21,6 @@ public class BasicButton extends BasicElement { private final int iconSize; public int x, y; public static final int ALIGNMENT_LEFT = 0; - @Deprecated - public static final int ALIGNMENT_RIGHT = 1; public static final int ALIGNMENT_CENTER = 2; public static final int ALIGNMENT_JUSTIFIED = 3; @@ -78,10 +75,11 @@ public class BasicButton extends BasicElement { public void draw(long vg, int x, int y) { this.x = x; this.y = y; + if (disabled) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRect(vg, x, y, this.width, this.height, colorPalette == ColorPalette.TERTIARY || colorPalette == ColorPalette.TERTIARY_DESTRUCTIVE ? OneConfigConfig.TRANSPARENT : currentColor, this.cornerRadius); float contentWidth = 0f; int color = -1; - if(colorPalette == ColorPalette.TERTIARY || colorPalette == ColorPalette.TERTIARY_DESTRUCTIVE) { + if (colorPalette == ColorPalette.TERTIARY || colorPalette == ColorPalette.TERTIARY_DESTRUCTIVE) { color = currentColor; } final float middle = x + width / 2f; @@ -93,41 +91,26 @@ public class BasicButton extends BasicElement { if (alignment == ALIGNMENT_CENTER) { if (icon1 != null && icon2 == null && text == null) { RenderManager.drawSvg(vg, icon1, middle - iconSize / 2f, middleYIcon, iconSize, iconSize); - this.update(x, y); - return; - } - if (icon1 != null) { - contentWidth += iconSize + xSpacing; - } - if (icon2 != null) { - contentWidth += iconSize + xSpacing; - } - if (text != null) { - RenderManager.drawText(vg, text, middle - contentWidth / 2 + (icon1 == null ? 0 : iconSize + xSpacing), middleYText, color, fontSize, Fonts.MEDIUM); - } - if (icon1 != null) { - RenderManager.drawSvg(vg, icon1, middle - contentWidth / 2, middleYIcon, iconSize, iconSize, color); - } - if (icon2 != null) { - RenderManager.drawSvg(vg, icon2, middle + contentWidth / 2 - iconSize, middleYIcon, iconSize, iconSize, color); - } - this.update(x, y); - return; - } - if (alignment == ALIGNMENT_JUSTIFIED) { - if (text != null) { + } else { + if (icon1 != null) + contentWidth += iconSize + xSpacing; + if (icon2 != null) + contentWidth += iconSize + xSpacing; + if (text != null) + RenderManager.drawText(vg, text, middle - contentWidth / 2 + (icon1 == null ? 0 : iconSize + xSpacing), middleYText, color, fontSize, Fonts.MEDIUM); + if (icon1 != null) + RenderManager.drawSvg(vg, icon1, middle - contentWidth / 2, middleYIcon, iconSize, iconSize, color); + if (icon2 != null) + RenderManager.drawSvg(vg, icon2, middle + contentWidth / 2 - iconSize, middleYIcon, iconSize, iconSize, color); + } + } else if (alignment == ALIGNMENT_JUSTIFIED) { + if (text != null) RenderManager.drawText(vg, text, middle - contentWidth / 2, middleYText, color, fontSize, Fonts.MEDIUM); - } - if (icon1 != null) { + if (icon1 != null) RenderManager.drawSvg(vg, icon1, x + xSpacing, middleYIcon, iconSize, iconSize, color); - } - if (icon2 != null) { + if (icon2 != null) RenderManager.drawSvg(vg, icon2, x + width - xSpacing - iconSize, middleYIcon, iconSize, iconSize, color); - } - this.update(x, y); - return; - } - if (alignment == ALIGNMENT_LEFT) { + } else if (alignment == ALIGNMENT_LEFT) { contentWidth = xPadding; if (icon1 != null) { RenderManager.drawSvg(vg, icon1, x + contentWidth, middleYIcon, iconSize, iconSize, color); @@ -137,31 +120,11 @@ public class BasicButton extends BasicElement { RenderManager.drawText(vg, text, x + contentWidth, middleYText, color, fontSize, Fonts.MEDIUM); contentWidth += RenderManager.getTextWidth(vg, text, fontSize, Fonts.MEDIUM) + xSpacing; } - if (icon2 != null) { + if (icon2 != null) RenderManager.drawSvg(vg, icon2, x + contentWidth, middleYIcon, iconSize, iconSize, color); - } - this.update(x, y); - return; } - if (alignment == ALIGNMENT_RIGHT) { - contentWidth = width - xPadding; - if (icon2 != null) { - contentWidth -= iconSize; - RenderManager.drawSvg(vg, icon2, x + contentWidth, middleYIcon, iconSize, iconSize); - contentWidth -= xSpacing; - } - if (text != null) { - contentWidth -= RenderManager.getTextWidth(vg, text, fontSize, Fonts.MEDIUM); - RenderManager.drawText(vg, text, x + contentWidth, middleYText, color, fontSize, Fonts.MEDIUM); - contentWidth -= xSpacing; - } - if (icon1 != null) { - contentWidth -= iconSize; - RenderManager.drawSvg(vg, icon1, x + contentWidth, middleYIcon, iconSize, iconSize); - } - this.update(x, y); - } - + this.update(x, y); + if (disabled) RenderManager.setAlpha(vg, 1f); } @@ -177,17 +140,18 @@ public class BasicButton extends BasicElement { @Override public void update(int x, int y) { super.update(x, y); - if (hoverFx) { + if (hoverFx && !disabled) { if (!toggleable) { currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, hovered && Mouse.isButtonDown(0)); } else { - if (toggled) { + if (toggled) currentColor = ColorUtils.smoothColor(currentColor, OneConfigConfig.GRAY_500, OneConfigConfig.PRIMARY_600, true, 30f); - } else currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, hovered && Mouse.isButtonDown(0)); + else + currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, hovered && Mouse.isButtonDown(0)); } + } else if (hoverFx) { + currentColor = colorPalette.getNormalColor(); } - - } public Page getPage() { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java index b10cf2c..d873006 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java @@ -19,7 +19,7 @@ public class ConfigKeyBind extends BasicOption { public ConfigKeyBind(Field field, Object parent, String name, int size) { super(field, parent, name, size); - button = new BasicButton(256, 32, "", SVGs.KEYSTROKE, null, BasicButton.ALIGNMENT_LEFT, ColorPalette.SECONDARY); + button = new BasicButton(256, 32, "", SVGs.KEYSTROKE, null, BasicButton.ALIGNMENT_JUSTIFIED, ColorPalette.SECONDARY); button.setToggleable(true); } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java b/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java index a233266..26be1b6 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java @@ -44,85 +44,77 @@ public class ColorPalette { */ public static final ColorPalette TERTIARY_DESTRUCTIVE = new ColorPalette(WHITE_90, ERROR_300, ERROR_300_80); - - - private final int colorNormal; private final int colorHovered; private final int colorPressed; - private final int colorDisabled; private final float[] colorNormalf; private final float[] colorHoveredf; private final float[] colorPressedf; - private final float[] colorDisabledf; - /** <h1>Create a new ColorPalette.</h1> + /** + * <h1>Create a new ColorPalette.</h1> * This color palette is used with animations, and the elements like BasicButton, BasicElement, and more. * <br> This method takes integers in ARGB format, like many other classes, such as {@link OneColor} and {@link Color}. - * @param colorNormal the color of the element when it is not hovered or pressed. + * + * @param colorNormal the color of the element when it is not hovered or pressed. * @param colorHovered the color of the element when it is hovered. * @param colorPressed the color of the element when it is pressed. */ public ColorPalette(int colorNormal, int colorHovered, int colorPressed) { - this(colorNormal, colorHovered, colorPressed, colorPressed); - } - - /** <h1>Create a new ColorPalette.</h1> - * This color palette is used with animations, and the elements like BasicButton, BasicElement, and more. - * <br> This method takes integers in ARGB format, like many other classes, such as {@link OneColor} and {@link Color}. - * @param colorNormal the color of the element when it is not hovered or pressed. - * @param colorHovered the color of the element when it is hovered. - * @param colorPressed the color of the element when it is pressed. - * @param colorDisabled the color of the element when it is disabled. - */ - public ColorPalette(int colorNormal, int colorHovered, int colorPressed, int colorDisabled) { this.colorNormal = colorNormal; this.colorHovered = colorHovered; this.colorPressed = colorPressed; - this.colorDisabled = colorDisabled; this.colorNormalf = new float[]{ColorUtils.getRed(colorNormal) / 255f, ColorUtils.getGreen(colorNormal) / 255f, ColorUtils.getBlue(colorNormal) / 255f, ColorUtils.getAlpha(colorNormal) / 255f}; this.colorHoveredf = new float[]{ColorUtils.getRed(colorHovered) / 255f, ColorUtils.getGreen(colorHovered) / 255f, ColorUtils.getBlue(colorHovered) / 255f, ColorUtils.getAlpha(colorHovered) / 255f}; this.colorPressedf = new float[]{ColorUtils.getRed(colorPressed) / 255f, ColorUtils.getGreen(colorPressed) / 255f, ColorUtils.getBlue(colorPressed) / 255f, ColorUtils.getAlpha(colorPressed) / 255f}; - this.colorDisabledf = new float[]{ColorUtils.getRed(colorDisabled) / 255f, ColorUtils.getGreen(colorDisabled) / 255f, ColorUtils.getBlue(colorDisabled) / 255f, ColorUtils.getAlpha(colorDisabled) / 255f}; } - /** <h1>Create a new ColorPalette.</h1> + + /** + * <h1>Create a new ColorPalette.</h1> * This color palette is used with animations, and the elements like BasicButton, BasicElement, and more. * <br> This method takes {@link OneColor} in ARGB format. - * @param colorNormal the color of the element when it is not hovered or pressed. + * + * @param colorNormal the color of the element when it is not hovered or pressed. * @param colorHovered the color of the element when it is hovered. * @param colorPressed the color of the element when it is pressed. */ public ColorPalette(OneColor colorNormal, OneColor colorHovered, OneColor colorPressed) { - this(colorNormal.getRGB(), colorHovered.getRGB(), colorPressed.getRGB(), colorPressed.getRGB()); + this(colorNormal.getRGB(), colorHovered.getRGB(), colorPressed.getRGB()); } - /** <h1>Create a new ColorPalette.</h1> + /** + * <h1>Create a new ColorPalette.</h1> * This color palette is used with animations, and the elements like BasicButton, BasicElement, and more. * <br> This method takes {@link Color} in ARGB format. Disabled color is made from a darker version of the clicked color. - * @param colorNormal the color of the element when it is not hovered or pressed. + * + * @param colorNormal the color of the element when it is not hovered or pressed. * @param colorHovered the color of the element when it is hovered. * @param colorPressed the color of the element when it is pressed. */ public ColorPalette(Color colorNormal, Color colorHovered, Color colorPressed) { - this(colorNormal.getRGB(), colorHovered.getRGB(), colorPressed.getRGB(), colorPressed.darker().getRGB()); + this(colorNormal.getRGB(), colorHovered.getRGB(), colorPressed.getRGB()); } - /** <h1>Create a new ColorPalette.</h1> + /** + * <h1>Create a new ColorPalette.</h1> * This color palette is used with animations, and the elements like BasicButton, BasicElement, and more. * <br> This method takes {@link Color} in ARGB format. - * @param colorNormal the color of the element when it is not hovered or pressed. - * @param colorHovered the color of the element when it is hovered. - * @param colorPressed the color of the element when it is pressed. + * + * @param colorNormal the color of the element when it is not hovered or pressed. + * @param colorHovered the color of the element when it is hovered. + * @param colorPressed the color of the element when it is pressed. * @param colorDisabled the color of the element when it is disabled. */ public ColorPalette(Color colorNormal, Color colorHovered, Color colorPressed, Color colorDisabled) { - this(colorNormal.getRGB(), colorHovered.getRGB(), colorPressed.getRGB(), colorDisabled.getRGB()); + this(colorNormal.getRGB(), colorHovered.getRGB(), colorPressed.getRGB()); } - /** <h1>Create a new ColorPalette.</h1> + /** + * <h1>Create a new ColorPalette.</h1> * This color palette is used with animations, and the elements like BasicButton, BasicElement, and more. * <br> This method takes float arrays of the color between 0f and 1f, in [R, G, B, A] format. - * @param colorNormal the color of the element when it is not hovered or pressed. + * + * @param colorNormal the color of the element when it is not hovered or pressed. * @param colorHovered the color of the element when it is hovered. * @param colorPressed the color of the element when it is pressed. */ @@ -130,51 +122,51 @@ public class ColorPalette { this.colorNormalf = colorNormal; this.colorHoveredf = colorHovered; this.colorPressedf = colorPressed; - this.colorDisabledf = colorDisabled; this.colorNormal = ColorUtils.getColor(colorNormal[0], colorNormal[1], colorNormal[2], colorNormal[3]); this.colorHovered = ColorUtils.getColor(colorHovered[0], colorHovered[1], colorHovered[2], colorHovered[3]); this.colorPressed = ColorUtils.getColor(colorPressed[0], colorPressed[1], colorPressed[2], colorPressed[3]); - this.colorDisabled = ColorUtils.getColor(colorDisabled[0], colorDisabled[1], colorDisabled[2], colorDisabled[3]); } - /** Return the color of the element when it is not hovered or pressed in ARGB format. */ + /** + * Return the color of the element when it is not hovered or pressed in ARGB format. + */ public int getNormalColor() { return colorNormal; } - /** Return the color of the element when it is hovered in ARGB format. */ + /** + * Return the color of the element when it is hovered in ARGB format. + */ public int getHoveredColor() { return colorHovered; } - /** Return the color of the element when it is pressed in ARGB format. */ - public int getDisabledColor() { - return colorDisabled; - } - /** Return the color of the element when it is pressed in ARGB format. */ + /** + * Return the color of the element when it is pressed in ARGB format. + */ public int getPressedColor() { return colorPressed; } - /** Return the color of the element when it is not hovered or pressed in a float array (r,g,b,a). */ + /** + * Return the color of the element when it is not hovered or pressed in a float array (r,g,b,a). + */ public float[] getNormalColorf() { return colorNormalf; } - /** Return the color of the element when it is hovered in a float array (r,g,b,a). */ + /** + * Return the color of the element when it is hovered in a float array (r,g,b,a). + */ public float[] getHoveredColorf() { return colorHoveredf; } - /** Return the color of the element when it is pressed in a float array (r,g,b,a). */ + /** + * Return the color of the element when it is pressed in a float array (r,g,b,a). + */ public float[] getPressedColorf() { return colorPressedf; } - - /** Return the color of the element when it is disabled in a float array (r,g,b,a). */ - public float[] getDisabledColorf() { - return colorDisabledf; - } - } |