From 18ddce4242a5a68bef111f9bce43b6c3f3a45ce6 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Wed, 1 Jun 2022 19:27:17 +0200 Subject: more fixes ffs --- .../java/cc/polyfrost/oneconfig/gui/SideBar.java | 2 +- .../oneconfig/gui/animations/Animation.java | 4 +- .../oneconfig/gui/elements/BasicButton.java | 92 +++++++--------------- .../gui/elements/config/ConfigKeyBind.java | 2 +- 4 files changed, 33 insertions(+), 67 deletions(-) (limited to 'src/main/java/cc/polyfrost/oneconfig/gui') 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); } -- cgit