diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-04 16:57:41 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-04 16:57:41 +0200 |
commit | 140ffd89293cdad8963d1fc80db382dc5681229f (patch) | |
tree | b611edd6a7faac0a7f6f3b1895fa33571b6de0cf /src/main/java/cc/polyfrost/oneconfig/gui | |
parent | 07f04270648ae1e38e4f411898f38b0f067dd308 (diff) | |
download | OneConfig-140ffd89293cdad8963d1fc80db382dc5681229f.tar.gz OneConfig-140ffd89293cdad8963d1fc80db382dc5681229f.tar.bz2 OneConfig-140ffd89293cdad8963d1fc80db382dc5681229f.zip |
animation
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui')
5 files changed, 30 insertions, 35 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index 050d8dd..236733a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -2,8 +2,8 @@ package cc.polyfrost.oneconfig.gui; import cc.polyfrost.oneconfig.config.OneConfigConfig; 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.gui.elements.BasicButton; import cc.polyfrost.oneconfig.gui.pages.CreditsPage; import cc.polyfrost.oneconfig.gui.pages.ModsPage; @@ -56,7 +56,7 @@ public class SideBar { if (button.equals(buttons.get(selected))) break; buttons.get(selected).setColorPalette(ColorPalette.TERTIARY); moveAnimation = new EaseInOutQuart(300, buttons.get(selected).y, button.y, false); - sizeAnimation = new EaseInQuartReversed(300, 36, 54, false); + sizeAnimation = new DummyAnimation(36); selected = buttons.indexOf(button); } if (moveAnimation != null) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutCubic.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutCubic.java new file mode 100644 index 0000000..760f369 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutCubic.java @@ -0,0 +1,23 @@ +package cc.polyfrost.oneconfig.gui.animations; + +public class EaseInOutCubic extends Animation { + + /** + * @param duration The duration of the animation + * @param start The start of the animation + * @param end The end of the animation + * @param reverse Reverse the animation + */ + public EaseInOutCubic(int duration, float start, float end, boolean reverse) { + super(duration, start, end, reverse); + } + + /** + * Adapted from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a> + */ + @Override + protected float animate(float timePassed, float duration, float start, float change) { + if ((timePassed /= duration / 2) < 1) return change / 2 * timePassed * timePassed * timePassed + start; + return change / 2 * ((timePassed -= 2) * timePassed * timePassed + 2) + start; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInQuartReversed.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInQuartReversed.java deleted file mode 100644 index 10bf354..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInQuartReversed.java +++ /dev/null @@ -1,21 +0,0 @@ -package cc.polyfrost.oneconfig.gui.animations; - -public class EaseInQuartReversed extends Animation { - /** - * @param duration The duration of the animation - * @param start The start of the animation - * @param end The end of the animation - * @param reverse Reverse the animation - */ - public EaseInQuartReversed(float duration, float start, float end, boolean reverse) { - super(duration, start, end, reverse); - } - - @Override - protected float animate(float timePassed, float duration, float start, float change) { - float x = timePassed / duration; - if (x < 0.25f) return (float) (128 * Math.pow(x, 4) * change + start); - if (x < 0.75f) return (float) ((-128 * Math.pow(x - 0.5, 4) + 1) * change + start); - return (float) (128 * Math.pow(x - 1, 4) * change + start); - } -} 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 0a48db2..1a53564 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -27,7 +27,6 @@ public class ColorSelector { private int y; private final OneColor color; 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<>(); @@ -127,7 +126,7 @@ public class ColorSelector { RenderManager.drawRoundedRect(vg, x + 16, y + 64, 384, 32, OneConfigConfig.GRAY_500, 12f); if (!barMoveAnimation.isFinished()) - RenderManager.drawRoundedRect(vg, x + barMoveAnimation.get() - (barSizeAnimation.get() - 124) / 2, y + 66, barSizeAnimation.get(0), 28, OneConfigConfig.PRIMARY_600, 10f); + RenderManager.drawRoundedRect(vg, x + barMoveAnimation.get(), y + 66, 124, 28, OneConfigConfig.PRIMARY_600, 10f); else buttons.get(mode).setColorPalette(ColorPalette.PRIMARY); int i = 18; @@ -137,8 +136,7 @@ public class ColorSelector { prevMode = mode; mode = buttons.indexOf(button); setXYFromColor(); - barMoveAnimation = new EaseInOutQuart(300, 18 + prevMode * 128, 18 + mode * 128, false); - barSizeAnimation = new EaseInQuartReversed(300, 124, 186, false); + barMoveAnimation = new EaseInOutCubic(175, 18 + prevMode * 128, 18 + mode * 128, false); moveAnimation = new EaseInOutQuad(300, 0, 1, false); for (BasicElement button1 : buttons) button1.setColorPalette(ColorPalette.TERTIARY); } 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 1331f3f..7a458c8 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,10 +2,7 @@ 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.gui.animations.*; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.utils.InputUtils; @@ -15,7 +12,6 @@ import java.lang.reflect.Field; public class ConfigDualOption extends BasicOption { private Animation posAnimation; - private Animation sizeAnimation = new DummyAnimation(124); private final String left, right; public ConfigDualOption(Field field, Object parent, String name, int size, String[] options) { @@ -43,7 +39,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); - RenderManager.drawRoundedRect(vg, x + posAnimation.get() - (sizeAnimation.get() - 124) / 2f, y + 2, sizeAnimation.get(0), 28, OneConfigConfig.PRIMARY_600, 10f); + RenderManager.drawRoundedRect(vg, x + posAnimation.get(), y + 2, 124, 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); @@ -53,8 +49,7 @@ public class ConfigDualOption extends BasicOption { RenderManager.setAlpha(vg, 1); if ((hoveredLeft && toggled || hoveredRight && !toggled) && InputUtils.isClicked()) { toggled = !toggled; - posAnimation = new EaseInOutQuart(300, 228, 356, !toggled); - sizeAnimation = new EaseInQuartReversed(300, 124, 186, false); + posAnimation = new EaseInOutCubic(175, 228, 356, !toggled); try { set(toggled); } catch (IllegalAccessException e) { |