diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-01 20:06:36 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-01 20:06:36 +0200 |
commit | ef98c272d57161ea1de222fe4ee04ee701877b4f (patch) | |
tree | 368d63b62b0cd04b179350d7477eacedf19917be /src/main/java/cc/polyfrost/oneconfig | |
parent | 18ddce4242a5a68bef111f9bce43b6c3f3a45ce6 (diff) | |
download | OneConfig-ef98c272d57161ea1de222fe4ee04ee701877b4f.tar.gz OneConfig-ef98c272d57161ea1de222fe4ee04ee701877b4f.tar.bz2 OneConfig-ef98c272d57161ea1de222fe4ee04ee701877b4f.zip |
sidebar and animation stuff
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig')
8 files changed, 39 insertions, 16 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java index 376f221..faeffff 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java @@ -25,8 +25,10 @@ public class OneConfigConfig extends Config { public static final int BLACK = new Color(0, 0, 0, 255).getRGB(); // Black public static final int GRAY_900 = new Color(13, 14, 15, 255).getRGB(); // Gray 900 + public static final int GRAY_900_80 = new Color(13, 14, 15, 204).getRGB(); // Gray 900 80% public static final int GRAY_800 = new Color(21, 22, 23, 255).getRGB(); // Gray 800 + public static final int GRAY_800_95 = new Color(21, 22, 23, 242).getRGB(); public static final int GRAY_700 = new Color(34, 35, 38, 255).getRGB(); // Gray 700 public static final int GRAY_600 = new Color(42, 44, 48, 255).getRGB(); // Gray 600 public static final int GRAY_500 = new Color(49, 51, 56, 255).getRGB(); // Gray 500 // button sidebar hover, button gray normal diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index 63fbd39..169aef0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -90,7 +90,7 @@ public class OneConfigGui extends UScreen { if (OneConfigConfig.ROUNDED_CORNERS) { RenderManager.drawDropShadow(vg, x, y, 1280, 800, 32, 0, 20); RenderManager.drawRoundedRect(vg, x + 224, y, 1056, 800, OneConfigConfig.GRAY_800, OneConfigConfig.CORNER_RADIUS_WIN); - RenderManager.drawRoundedRect(vg, x, y, 244, 800, OneConfigConfig.GRAY_900_80, OneConfigConfig.CORNER_RADIUS_WIN); + RenderManager.drawRoundedRect(vg, x, y, 244, 800, OneConfigConfig.GRAY_800_95, OneConfigConfig.CORNER_RADIUS_WIN); RenderManager.drawRect(vg, x + 224, y, 20, 800, OneConfigConfig.GRAY_800); } RenderManager.drawLine(vg, x + 224, y + 72, x + 1280, y + 72, 1, OneConfigConfig.GRAY_700); @@ -127,7 +127,7 @@ public class OneConfigGui extends UScreen { if (backArrow.isClicked() && previousPages.size() > 0) { try { nextPages.add(0, currentPage); - openPage(previousPages.get(0), false); + openPage(previousPages.get(0), new EaseInOutQuad(300, 224, 2128, false), true); previousPages.remove(0); } catch (Exception ignored) { } @@ -197,7 +197,7 @@ public class OneConfigGui extends UScreen { } public void openPage(@NotNull Page page, boolean addToPrevious) { - openPage(page, new EaseInOutQuad(300, 224, 2128, false), true); + openPage(page, new EaseInOutQuad(300, 224, 2128, false), addToPrevious); } public void openPage(@NotNull Page page, Animation animation, boolean addToPrevious) { if (page == currentPage) return; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index 7ca3e31..02cb5de 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -3,6 +3,7 @@ package cc.polyfrost.oneconfig.gui; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.gui.animations.Animation; 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; @@ -34,6 +35,7 @@ public class SideBar { private int selected = 2; private Animation moveAnimation = null; + private Animation sizeAnimation = null; public SideBar() { buttons.get(0).setClickAction(new CreditsPage()); @@ -52,10 +54,11 @@ 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); selected = buttons.indexOf(button); } if (moveAnimation != null) { - RenderManager.drawRoundedRect(vg, x + 16, moveAnimation.get(), 192, 36, OneConfigConfig.PRIMARY_600, 12); + RenderManager.drawRoundedRect(vg, x + 16, moveAnimation.get(), 192, sizeAnimation.get(), OneConfigConfig.PRIMARY_600, 12); if (moveAnimation.isFinished()) { moveAnimation = null; buttons.get(selected).setColorPalette(ColorPalette.PRIMARY); 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 834aeb1..d8d672d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java @@ -3,10 +3,10 @@ package cc.polyfrost.oneconfig.gui.animations; import cc.polyfrost.oneconfig.gui.OneConfigGui; public abstract class Animation { - private final int duration; + private final float duration; private final float start; private final float change; - private long timePassed = 0; + private float timePassed = 0; /** * @param duration The duration of the animation @@ -14,7 +14,7 @@ public abstract class Animation { * @param end The end of the animation * @param reverse Reverse the animation */ - public Animation(int duration, float start, float end, boolean reverse) { + public Animation(float duration, float start, float end, boolean reverse) { this.duration = duration; this.start = start; if (!reverse) this.change = end - start; @@ -25,12 +25,10 @@ public abstract class Animation { * @param deltaTime The time since the last frame * @return The new value */ - public float get(long deltaTime) { + public float get(float deltaTime) { timePassed += deltaTime; - if (timePassed >= duration) return start + change; - float value = animate(timePassed, duration, start, change); - System.out.println(value); - return value; + if (timePassed >= duration) timePassed = duration; + return animate(timePassed, duration, start, change); } /** @@ -47,5 +45,5 @@ public abstract class Animation { return timePassed >= duration; } - protected abstract float animate(long timePassed, int duration, float start, float change); + protected abstract float animate(float timePassed, float duration, float start, float change); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java index 14e802f..9af6557 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java @@ -16,7 +16,7 @@ public class EaseInOutQuad extends Animation{ * Adapted from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a> */ @Override - protected float animate(long timePassed, int duration, float start, float change) { + protected float animate(float timePassed, float duration, float start, float change) { if ((timePassed /= duration / 2) < 1) return change / 2 * timePassed * timePassed + start;; return -change / 2 * ((--timePassed) * (timePassed - 2) - 1) + start; } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java index 55c1cad..a21aa73 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java @@ -16,7 +16,7 @@ public class EaseInOutQuart extends Animation{ * Adapted from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a> */ @Override - protected float animate(long timePassed, int duration, float start, float change) { + protected float animate(float timePassed, float duration, float start, float change) { if ((timePassed /= duration / 2) < 1) return change / 2 * timePassed * timePassed * timePassed * timePassed + start; return -change / 2 * ((timePassed -= 2) * timePassed * 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 new file mode 100644 index 0000000..9e77714 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInQuartReversed.java @@ -0,0 +1,20 @@ +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.5f) return (float) (16 * Math.pow(x, 4) * change + start); + return (float) (Math.pow(2 * x - 2, 4) * change + start); + } +} 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 71441e6..2ce7e98 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -75,6 +75,7 @@ public class BasicButton extends BasicElement { public void draw(long vg, int x, int y) { this.x = x; this.y = y; + this.update(x, 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; @@ -123,7 +124,6 @@ public class BasicButton extends BasicElement { if (icon2 != null) RenderManager.drawSvg(vg, icon2, x + contentWidth, middleYIcon, iconSize, iconSize, color); } - this.update(x, y); if (disabled) RenderManager.setAlpha(vg, 1f); } |