diff options
6 files changed, 140 insertions, 37 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index 6c37229..67bb3ad 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -2,6 +2,8 @@ package cc.polyfrost.oneconfig.gui; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.core.OneColor; +import cc.polyfrost.oneconfig.gui.animations.Animation; +import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad; import cc.polyfrost.oneconfig.gui.elements.BasicElement; import cc.polyfrost.oneconfig.gui.elements.ColorSelector; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; @@ -26,7 +28,6 @@ public class OneConfigGui extends UScreen { private final SideBar sideBar = new SideBar(); protected Page currentPage; protected Page prevPage; - private float pageProgress = -224f; private final TextInputField textInputField = new TextInputField(248, 40, "Search...", false, false, SVGs.MAGNIFYING_GLASS_BOLD); private final ArrayList<Page> previousPages = new ArrayList<>(); private final ArrayList<Page> nextPages = new ArrayList<>(); @@ -40,6 +41,7 @@ public class OneConfigGui extends UScreen { private long time = -1L; private long deltaTime = 17L; public boolean allowClose = true; + private Animation animation; public OneConfigGui() { INSTANCE = this; @@ -54,9 +56,10 @@ public class OneConfigGui extends UScreen { public static OneConfigGui create() { try { - return instanceToRestore == null ? new OneConfigGui() : instanceToRestore; + //return instanceToRestore == null ? new OneConfigGui() : instanceToRestore; + return new OneConfigGui(); } finally { - if (instanceToRestore != null) INSTANCE = instanceToRestore; + //if (instanceToRestore != null) INSTANCE = instanceToRestore; instanceToRestore = null; } } @@ -138,17 +141,15 @@ public class OneConfigGui extends UScreen { } ScissorManager.scissor(vg, x + 224, y + 88, 1056, 698); - if (prevPage != null) { - pageProgress = MathUtils.easeInOutCirc(50, pageProgress, 832 - pageProgress, 600); - prevPage.scrollWithDraw(vg, (int) (x - pageProgress), y + 72); - RenderManager.drawLine(vg, (int) (x - pageProgress + 1055), y + 72, (int) (x - pageProgress + 1057), y + 800, 2, OneConfigConfig.GRAY_700); // TODO might remove this - currentPage.scrollWithDraw(vg, (int) (x - pageProgress + 1056), y + 72); - if (pageProgress > 830f) { // this number is the 'snap' point of the page + if (prevPage != null && animation != null) { + float pageProgress = animation.get(deltaTime); + prevPage.scrollWithDraw(vg, (int) (x + pageProgress), y + 72); + currentPage.scrollWithDraw(vg, (int) (x - 1904 + pageProgress), y + 72); + if (animation.isFinished()) { prevPage = null; - pageProgress = -224f; } } else { - currentPage.scrollWithDraw(vg, (int) (x - pageProgress), y + 72); + currentPage.scrollWithDraw(vg, x + 224, y + 72); } ScissorManager.clearScissors(vg); @@ -196,6 +197,9 @@ public class OneConfigGui extends UScreen { } public void openPage(@NotNull Page page, boolean addToPrevious) { + openPage(page, new EaseInOutQuad(300, 224, 2128, false), true); + } + public void openPage(@NotNull Page page, Animation animation, boolean addToPrevious) { if (page == currentPage) return; currentPage.finishUpAndClose(); if (!page.isBase()) { @@ -221,6 +225,7 @@ public class OneConfigGui extends UScreen { prevPage = currentPage; } currentPage = page; + this.animation = animation; } /** @@ -255,11 +260,13 @@ public class OneConfigGui extends UScreen { public String getSearchValue() { return textInputField.getInput(); } - public long getDeltaTime() { return deltaTime; } + public static long getDeltaTimeNullSafe() { + return OneConfigGui.INSTANCE == null ? 17 : OneConfigGui.INSTANCE.getDeltaTime(); + } @Override public boolean doesGuiPauseGame() { return false; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index c9699f7..6ddda29 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -1,13 +1,17 @@ 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.elements.BasicButton; import cc.polyfrost.oneconfig.gui.pages.CreditsPage; import cc.polyfrost.oneconfig.gui.pages.ModsPage; +import cc.polyfrost.oneconfig.libs.universal.UMinecraft; 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.GuiUtils; +import cc.polyfrost.oneconfig.utils.MathUtils; import java.util.ArrayList; @@ -30,6 +34,9 @@ public class SideBar { private final BasicButton HUDButton = new BasicButton(192, SIZE_36, "Edit HUD", SVGs.NOTE_PENCIL_BOLD, null, ALIGNMENT_LEFT, SECONDARY); private final BasicButton CloseButton = new BasicButton(192, SIZE_36, "Close", SVGs.X_CIRCLE_BOLD, null, ALIGNMENT_LEFT, SECONDARY_DESTRUCTIVE); + private int selected = 2; + private Animation moveAnimation = null; + public SideBar() { buttons.get(0).setClickAction(new CreditsPage()); buttons.get(2).setClickAction(new ModsPage()); @@ -38,6 +45,21 @@ public class SideBar { } public void draw(long vg, int x, int y) { + for (BasicButton button : buttons) { + if (!button.isClicked()) continue; + if (button.equals(buttons.get(selected))) break; + buttons.get(selected).setColorPalette(TERTIARY); + moveAnimation = new EaseInOutQuart(300, buttons.get(selected).x, button.x, false); + selected = buttons.indexOf(button); + } + if (moveAnimation != null) { + RenderManager.drawRoundedRect(vg, x + 16, moveAnimation.get(), 192, 36, OneConfigConfig.PRIMARY_600, 12); + if (moveAnimation.isFinished()) { + moveAnimation = null; + buttons.get(selected).setColorPalette(PRIMARY); + } + } + buttons.get(0).draw(vg, x + 16, y + 80); buttons.get(1).draw(vg, x + 16, y + 116); RenderManager.drawText(vg, "MOD CONFIG", x + 16, y + 178, OneConfigConfig.WHITE, 12, Fonts.SEMIBOLD); @@ -51,16 +73,5 @@ public class SideBar { buttons.get(8).draw(vg, x + 16, y + 448); HUDButton.draw(vg, x + 16, y + 704); CloseButton.draw(vg, x + 16, y + 748); - - for (BasicButton button : buttons) { - if (button.isClicked()) { - button.setColorPalette(PRIMARY); - for (BasicButton button1 : buttons) { - if (button.equals(button1)) continue; - button1.setColorPalette(TERTIARY); - } - break; - } - } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java new file mode 100644 index 0000000..894be2a --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java @@ -0,0 +1,49 @@ +package cc.polyfrost.oneconfig.gui.animations; + +import cc.polyfrost.oneconfig.gui.OneConfigGui; + +public abstract class Animation { + private final int duration; + private final float start; + private final float change; + private long timePassed = 0; + + /** + * @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 Animation(int duration, float start, float end, boolean reverse) { + this.duration = duration; + this.start = start; + if (!reverse) this.change = end - start; + else this.change = start - end; + } + + /** + * @param deltaTime The time since the last frame + * @return The new value + */ + public float get(long deltaTime) { + timePassed += deltaTime; + if (timePassed >= duration) return start + change; + return animate(timePassed, duration, start, change); + } + + /** + * @return The new value + */ + public float get() { + return get(OneConfigGui.getDeltaTimeNullSafe()); + } + + /** + * @return If the animation is finished or not + */ + public boolean isFinished() { + return timePassed >= duration; + } + + protected abstract float animate(long timePassed, int 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 new file mode 100644 index 0000000..df0ad68 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java @@ -0,0 +1,23 @@ +package cc.polyfrost.oneconfig.gui.animations; + +public class EaseInOutQuad 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 EaseInOutQuad(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(long timePassed, int duration, float start, float change) { + if ((timePassed /= (double) 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 new file mode 100644 index 0000000..cb69e64 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java @@ -0,0 +1,23 @@ +package cc.polyfrost.oneconfig.gui.animations; + +public class EaseInOutQuart 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 EaseInOutQuart(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(long timePassed, int duration, float start, float change) { + if ((timePassed /= (double) 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/utils/MathUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java index 79634da..c4beb82 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java @@ -25,21 +25,11 @@ public final class MathUtils { } /** - * taken from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a> + * Adapted from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a> */ - public static float easeInOutCirc(float t, float b, float c, float d) { - c *= OneConfigGui.INSTANCE == null ? 16 : OneConfigGui.INSTANCE.getDeltaTime(); - if ((t /= d / 2) < 1) return -c / 2 * ((float) Math.sqrt(1 - t * t) - 1) + b; - return c / 2 * ((float) Math.sqrt(1 - (t -= 2) * t) + 1) + b; - } - - /** - * taken from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a> - */ - public static float easeInOutQuad(float t, float b, float c, float d) { - c *= OneConfigGui.INSTANCE == null ? 16 : OneConfigGui.INSTANCE.getDeltaTime(); - if ((t /= d / 2) < 1) return c / 2 * t * t + b; - return -c / 2 * ((--t) * (t - 2) - 1) + b; + public static float easeInOutCirc(float time, float beginning, float change, float duration) { + if ((time /= duration / 2) < 1) return -change / 2 * ((float) Math.sqrt(1 - time * time) - 1) + beginning; + return change / 2 * ((float) Math.sqrt(1 - (time -= 2) * time) + 1) + beginning; } public static float map(float value, float start1, float stop1, float start2, float stop2) { |