diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-02 19:14:51 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-02 19:14:51 +0200 |
commit | 0ad0457dc608ade2cd8ff7e325c009c2847fb711 (patch) | |
tree | a8761d2aef3684de9c10c5345f7e11a3cde245da /src/main/java/cc/polyfrost/oneconfig/gui/elements | |
parent | 4945b1bf585a0a53917917b29f3450002d4e3553 (diff) | |
download | OneConfig-0ad0457dc608ade2cd8ff7e325c009c2847fb711.tar.gz OneConfig-0ad0457dc608ade2cd8ff7e325c009c2847fb711.tar.bz2 OneConfig-0ad0457dc608ade2cd8ff7e325c009c2847fb711.zip |
animations
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/elements')
7 files changed, 48 insertions, 110 deletions
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 8cc8165..c32f58e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -3,6 +3,7 @@ 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.animations.*; import cc.polyfrost.oneconfig.gui.elements.text.NumberInputField; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; import cc.polyfrost.oneconfig.lwjgl.RenderManager; @@ -26,7 +27,9 @@ public class ColorSelector { private int x; private int y; private final OneColor color; - private float percentMove = 0f; + private Animation barMoveAnimation = new DummyAnimation(18); + private Animation barSizeAnimation = new DummyAnimation(124); + private Animation moveAnimation = new DummyAnimation(1); private int mouseX, mouseY; private final ArrayList<BasicElement> buttons = new ArrayList<>(); private final BasicElement closeBtn = new BasicElement(32, 32, false); @@ -50,7 +53,6 @@ public class ColorSelector { private final ColorSlider bottomSlider = new ColorSlider(384, 0, 255, 100); private final Slider speedSlider = new Slider(296, 1, 32, 0); private int mode = 0, prevMode = 0; - private float percentMoveMain = 1f; private boolean dragging, mouseWasDown; @@ -124,8 +126,6 @@ public class ColorSelector { 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) { button.draw(vg, x + i, y + 66); @@ -133,16 +133,16 @@ public class ColorSelector { prevMode = mode; mode = buttons.indexOf(button); setXYFromColor(); - percentMoveMain = 0f; - } - if (percentMove != mode) { - button.currentColor = OneConfigConfig.TRANSPARENT; - drawColorSelector(vg, prevMode, (int) (x + (width * percentMoveMain)), y); + barMoveAnimation = new EaseInOutQuart(200, 18 + prevMode * 128, 18 + mode * 128, false); + barSizeAnimation = new EaseInQuartReversed(200, 124, 186, false); + moveAnimation = new EaseInOutQuad(200, 0, 1, false); } i += 128; } - percentMove = MathUtils.easeOut(percentMove, mode, 100f); - percentMoveMain = MathUtils.clamp(MathUtils.easeOut(percentMoveMain, 1f, 100f)); + float percentMoveMain = moveAnimation.get(); + + RenderManager.drawRoundedRect(vg, x + 16, y + 64, 384, 32, OneConfigConfig.GRAY_500, 12f); + RenderManager.drawRoundedRect(vg, x + barMoveAnimation.get(), y + 66, barSizeAnimation.get(), 28, OneConfigConfig.PRIMARY_600, 10f); RenderManager.drawText(vg, "HSB Box", x + 55, y + 81, OneConfigConfig.WHITE, 12f, Fonts.MEDIUM); RenderManager.drawText(vg, "Color Wheel", x + 172.5f, y + 81, OneConfigConfig.WHITE, 12f, Fonts.MEDIUM); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java index 543a8e0..a3da96e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java @@ -2,20 +2,22 @@ package cc.polyfrost.oneconfig.gui.elements.config; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.gui.animations.Animation; +import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; +import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad; 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.InputUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import cc.polyfrost.oneconfig.utils.color.ColorUtils; -import cc.polyfrost.oneconfig.utils.InputUtils; -import cc.polyfrost.oneconfig.utils.MathUtils; import java.awt.*; import java.lang.reflect.Field; public class ConfigCheckbox extends BasicOption { private int color; - private float percentOn = 0f; + private Animation animation; public ConfigCheckbox(Field field, Object parent, String name, int size) { super(field, parent, name, size); @@ -27,6 +29,7 @@ public class ConfigCheckbox extends BasicOption { boolean toggled = false; try { toggled = (boolean) get(); + if (animation == null) animation = new DummyAnimation(toggled ? 0 : 1); } catch (IllegalAccessException ignored) { } boolean hover = InputUtils.isAreaHovered(x, y + 4, 24, 24); @@ -34,6 +37,7 @@ public class ConfigCheckbox extends BasicOption { boolean clicked = InputUtils.isClicked() && hover; if (clicked && isEnabled()) { toggled = !toggled; + animation = new EaseInOutQuad(100, 0, 1, !toggled); try { set(toggled); } catch (IllegalAccessException e) { @@ -42,12 +46,12 @@ public class ConfigCheckbox extends BasicOption { } } color = ColorUtils.getColor(color, ColorPalette.SECONDARY, hover, false); - if (percentOn != 1f) { // performance + float percentOn = animation.get(); + if (percentOn != 1f) { RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, color, 6f); RenderManager.drawHollowRoundRect(vg, x, y + 4, 23.5f, 23.5f, OneConfigConfig.GRAY_300, 6f, 1f); // the 0.5f is to make it look better ok } RenderManager.drawText(vg, name, x + 32, y + 17, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); - percentOn = MathUtils.clamp(MathUtils.easeOut(percentOn, toggled ? 1f : 0f, 50f)); if (percentOn != 0 && percentOn != 1f) { RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, ColorUtils.setAlpha(OneConfigConfig.PRIMARY_500, (int) (percentOn * 255)), 6f); RenderManager.drawSvg(vg, SVGs.CHECKBOX_TICK, x, y + 4, 24, 24, new Color(1f, 1f, 1f, percentOn).getRGB()); 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 d031e6a..16b1ea2 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 @@ -29,6 +29,11 @@ public class ConfigColorElement extends BasicOption { @Override public void draw(long vg, int x, int y) { + if(!isEnabled()) RenderManager.setAlpha(vg, 0.5f); + hexField.disable(!isEnabled()); + alphaField.disable(!isEnabled()); + element.disable(!isEnabled()); + int x1 = size == 1 ? x : x + 512; OneColor color; try { @@ -81,6 +86,7 @@ public class ConfigColorElement extends BasicOption { color = (OneConfigGui.INSTANCE.getColor()); } setColor(color); + RenderManager.setAlpha(vg, 1f); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java index 76601f7..5926b30 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java @@ -2,6 +2,10 @@ package cc.polyfrost.oneconfig.gui.elements.config; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.gui.animations.Animation; +import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; +import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuart; +import cc.polyfrost.oneconfig.gui.animations.EaseInQuartReversed; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.utils.InputUtils; @@ -10,7 +14,8 @@ import cc.polyfrost.oneconfig.utils.MathUtils; import java.lang.reflect.Field; public class ConfigDualOption extends BasicOption { - private float percentMove = 0f; + private Animation posAnimation; + private Animation sizeAnimation; private final String left, right; public ConfigDualOption(Field field, Object parent, String name, int size, String[] options) { @@ -30,6 +35,10 @@ public class ConfigDualOption extends BasicOption { boolean toggled = false; try { toggled = (boolean) get(); + if (posAnimation == null) { + posAnimation = new EaseInOutQuart(1, 228, 356, !toggled); + sizeAnimation = new EaseInQuartReversed(1, 124, 186, false); + } } catch (IllegalAccessException ignored) { } if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); @@ -37,8 +46,7 @@ public class ConfigDualOption extends BasicOption { boolean hoveredRight = InputUtils.isAreaHovered(x + 354, y, 128, 32) && isEnabled(); RenderManager.drawText(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); RenderManager.drawRoundedRect(vg, x + 226, y, 256, 32, OneConfigConfig.GRAY_600, 12f); - int x1 = (int) (x + 228 + (percentMove * 128)); - RenderManager.drawRoundedRect(vg, x1, y + 2, 124, 28, OneConfigConfig.PRIMARY_600, 10f); + RenderManager.drawRoundedRect(vg, x + posAnimation.get(), y + 2, sizeAnimation.get(), 28, OneConfigConfig.PRIMARY_600, 10f); if (!hoveredLeft && isEnabled()) RenderManager.setAlpha(vg, 0.8f); RenderManager.drawText(vg, left, x + 290 - RenderManager.getTextWidth(vg, left, 12f, Fonts.MEDIUM) / 2, y + 17, OneConfigConfig.WHITE, 12f, Fonts.MEDIUM); if (isEnabled()) RenderManager.setAlpha(vg, 1f); @@ -48,6 +56,8 @@ public class ConfigDualOption extends BasicOption { RenderManager.setAlpha(vg, 1); if ((hoveredLeft && toggled || hoveredRight && !toggled) && InputUtils.isClicked()) { toggled = !toggled; + posAnimation = new EaseInOutQuart(200, 228, 356, !toggled); + sizeAnimation = new EaseInQuartReversed(200, 124, 186, false); try { set(toggled); } catch (IllegalAccessException e) { @@ -55,6 +65,5 @@ public class ConfigDualOption extends BasicOption { e.printStackTrace(); } } - percentMove = MathUtils.clamp(MathUtils.easeOut(percentMove, toggled ? 1f : 0f, 75)); } } 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 08761fb..9a38b98 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 @@ -43,7 +43,7 @@ public class ConfigSlider extends BasicOption { value = MathUtils.map(xCoordinate, x + 352, x + 864, min, max); } else if (inputField.isToggled() || inputField.arrowsClicked()) { value = inputField.getCurrentValue(); - xCoordinate = (int) MathUtils.map(value, min, max, x + 352, x + 864); + xCoordinate = (int) MathUtils.clamp(MathUtils.map(value, min, max, x + 352, x + 864), x + 352, x + 864); } if (dragging && InputUtils.isClicked() || inputField.isToggled() || inputField.arrowsClicked()) { dragging = false; @@ -61,7 +61,7 @@ public class ConfigSlider extends BasicOption { isFloat = false; if (isFloat) value = (float) object; else value = (int) object; - xCoordinate = (int) MathUtils.map(value, min, max, x + 352, x + 864); + xCoordinate = (int) MathUtils.clamp(MathUtils.map(value, min, max, x + 352, x + 864), x + 352, x + 864); } catch (IllegalAccessException ignored) { } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java index 8a0d85e..91271e2 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java @@ -2,6 +2,9 @@ package cc.polyfrost.oneconfig.gui.elements.config; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; +import cc.polyfrost.oneconfig.gui.animations.Animation; +import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; +import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.utils.color.ColorPalette; @@ -14,7 +17,7 @@ import java.lang.reflect.Field; public class ConfigSwitch extends BasicOption { private int colorEnabled; private int colorDisabled; - private float percentOn = 0f; + private Animation animation; public ConfigSwitch(Field field, Object parent, String name, int size) { super(field, parent, name, size); @@ -25,8 +28,10 @@ public class ConfigSwitch extends BasicOption { boolean toggled = false; try { toggled = (boolean) get(); + if (animation == null) animation = new DummyAnimation(toggled ? 0 : 1); } catch (IllegalAccessException ignored) { } + float percentOn = animation.get(); int x2 = x + 3 + (int) (percentOn * 18); boolean hovered = InputUtils.isAreaHovered(x, y, 42, 32); colorDisabled = ColorUtils.getColor(colorDisabled, ColorPalette.SECONDARY, hovered, false); @@ -40,6 +45,7 @@ public class ConfigSwitch extends BasicOption { if (InputUtils.isAreaClicked(x, y, 42, 32) && isEnabled()) { toggled = !toggled; + animation = new EaseInOutQuad(200, 0, 1, !toggled); try { set(toggled); } catch (IllegalAccessException e) { @@ -47,7 +53,6 @@ public class ConfigSwitch extends BasicOption { e.printStackTrace(); } } - percentOn = MathUtils.clamp(MathUtils.easeOut(percentOn, toggled ? 1f : 0f, 75)); RenderManager.setAlpha(vg, 1f); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java deleted file mode 100644 index 698d04b..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java +++ /dev/null @@ -1,86 +0,0 @@ -package cc.polyfrost.oneconfig.gui.elements.config; - -import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.config.interfaces.BasicOption; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.SVGs; -import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; -import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; -import cc.polyfrost.oneconfig.utils.color.ColorUtils; -import cc.polyfrost.oneconfig.utils.InputUtils; -import cc.polyfrost.oneconfig.utils.MathUtils; - -import java.lang.reflect.Field; - -public class ConfigUniSelector extends BasicOption { - private final String[] options; - private float percentMove = 1f; - private int previous = -1; - private int colorLeft; - private int colorRight; - - public ConfigUniSelector(Field field, Object parent, String name, int size, String[] options) { - super(field, parent, name, size); - this.options = options; - } - - @Override - public int getHeight() { - return 32; - } - - @Override - public void draw(long vg, int x, int y) { - int selected = 0; - try { - selected = (int) get(); - } catch (IllegalAccessException ignored) { - } - if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); - String option = options[selected] + " " + (selected + 1) + "/" + options.length; - RenderManager.drawText(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); - - Scissor scissor = ScissorManager.scissor(vg, x + 256, y, 192, 32); - if (previous == -1) { - RenderManager.drawText(vg, option, x + 352 - RenderManager.getTextWidth(vg, option, 14f, Fonts.MEDIUM) / 2f, y + 15, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); - } else { - String prevOption = options[previous] + " " + (previous + 1) + "/" + options.length; - RenderManager.drawText(vg, selected < previous ? prevOption : option, x + 352 - RenderManager.getTextWidth(vg, selected < previous ? prevOption : option, 14f, Fonts.MEDIUM) / 2f + 192 * percentMove, y + 15, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); - RenderManager.drawText(vg, selected < previous ? option : prevOption, x + 352 - RenderManager.getTextWidth(vg, selected < previous ? option : prevOption, 14f, Fonts.MEDIUM) / 2f - 192 * (1 - percentMove), y + 15, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); - } - ScissorManager.resetScissor(vg, scissor); - - boolean hoveredLeft = InputUtils.isAreaHovered(x + 231, y + 7, 18, 18) && selected > 0 && isEnabled(); - boolean hoveredRight = InputUtils.isAreaHovered(x + 455, y + 7, 18, 18) && selected < options.length - 1 && isEnabled(); - colorLeft = ColorUtils.smoothColor(colorLeft, OneConfigConfig.PRIMARY_500, OneConfigConfig.PRIMARY_400, hoveredLeft, 40f); - colorRight = ColorUtils.smoothColor(colorRight, OneConfigConfig.PRIMARY_500, OneConfigConfig.PRIMARY_400, hoveredRight, 40f); - - if (selected <= 0 && isEnabled()) RenderManager.setAlpha(vg, 0.5f); - RenderManager.drawSvg(vg, SVGs.CHEVRON_LEFT, x + 231, y + 7, 18, 18, colorLeft); - if (isEnabled()) RenderManager.setAlpha(vg, selected >= options.length - 1 ? 0.5f : 1f); - RenderManager.drawSvg(vg, SVGs.CHEVRON_RIGHT, x + 455, y + 7, 18, 18, colorRight); - if (isEnabled()) RenderManager.setAlpha(vg, 1f); - - if (hoveredLeft && InputUtils.isClicked()) { - previous = selected; - selected -= 1; - try { - set(selected); - } catch (IllegalAccessException ignored) { - } - percentMove = selected < previous ? 0f : 1f; - } else if (hoveredRight && InputUtils.isClicked()) { - previous = selected; - selected += 1; - try { - set(selected); - } catch (IllegalAccessException ignored) { - } - percentMove = selected < previous ? 0f : 1f; - } - if (previous != -1) percentMove = MathUtils.easeOut(percentMove, selected < previous ? 1f : 0f, 75); - if ((selected < previous ? 1f : 0f) == percentMove) previous = -1; - RenderManager.setAlpha(vg, 1f); - } -} |