diff options
16 files changed, 112 insertions, 220 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java index 10c9a6b..4ae11da 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java @@ -16,11 +16,6 @@ public enum OptionType { /** * Type: int */ - UNI_SELECTOR, - /** - * Type: String - * Normal: 1x and 2x, Secure and Mutliline: 2x only - */ TEXT, /** * Type: int or float diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java index f495ecd..531c374 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java @@ -146,9 +146,6 @@ public class Config { case DUAL_OPTION: options.add(new ConfigDualOption(field, instance, option.name(), option.size(), option.options())); break; - case UNI_SELECTOR: - options.add(new ConfigUniSelector(field, instance, option.name(), option.size(), option.options())); - break; case DROPDOWN: options.add(new ConfigDropdown(field, instance, option.name(), option.size(), option.options())); break; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index 02cb5de..655b824 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -59,8 +59,9 @@ public class SideBar { } if (moveAnimation != null) { RenderManager.drawRoundedRect(vg, x + 16, moveAnimation.get(), 192, sizeAnimation.get(), OneConfigConfig.PRIMARY_600, 12); - if (moveAnimation.isFinished()) { + if (moveAnimation.isFinished() && sizeAnimation.isFinished()) { moveAnimation = null; + sizeAnimation = 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 ebb9145..9e2c238 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java @@ -7,6 +7,7 @@ public abstract class Animation { private final float start; private final float change; private float timePassed = 0; + protected final boolean reverse; /** * @param duration The duration of the animation @@ -23,6 +24,7 @@ public abstract class Animation { } this.start = start; this.change = end - start; + this.reverse = reverse; } /** @@ -49,5 +51,12 @@ public abstract class Animation { return timePassed >= duration; } + /** + * @return If the animation is reversed + */ + public boolean isReversed() { + return reverse; + } + protected abstract float animate(float timePassed, float duration, float start, float change); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java new file mode 100644 index 0000000..6343123 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java @@ -0,0 +1,15 @@ +package cc.polyfrost.oneconfig.gui.animations; + +public class DummyAnimation extends Animation{ + /** + * @param value The value that is returned + */ + public DummyAnimation(float value) { + super(value, value, value, false); + } + + @Override + protected float animate(float timePassed, float duration, float start, float change) { + return change; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseOutQuad.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseOutQuad.java new file mode 100644 index 0000000..6cc97bf --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseOutQuad.java @@ -0,0 +1,22 @@ +package cc.polyfrost.oneconfig.gui.animations; + +public class EaseOutQuad 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 EaseOutQuad(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) { + return -change * (timePassed /= duration) * (timePassed - 2) + 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 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); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java index fdb5292..4a3cfa6 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -1,5 +1,8 @@ package cc.polyfrost.oneconfig.gui.pages; +import cc.polyfrost.oneconfig.gui.animations.Animation; +import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad; +import cc.polyfrost.oneconfig.gui.animations.EaseOutQuad; import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.MathUtils; @@ -9,7 +12,7 @@ import org.lwjgl.input.Mouse; * A page is a 1056x728 rectangle of the GUI. It is the main content of the gui, and can be switched back and forwards easily. All the content of OneConfig is in a page. */ public abstract class Page { - private float currentScroll = 0f; + private Animation scrollAnimation; private float scrollTarget; protected final String title; @@ -35,20 +38,24 @@ public abstract class Page { public void scrollWithDraw(long vg, int x, int y) { // TODO scroll bar int maxScroll = getMaxScrollHeight(); int scissorOffset = drawStatic(vg, x, y); + float scroll = scrollAnimation == null ? scrollTarget : scrollAnimation.get(); Scissor scissor = ScissorManager.scissor(vg, x, y + scissorOffset, x + 1056, y + 728 - scissorOffset); + int dWheel = Mouse.getDWheel(); + if (dWheel != 0) { + scrollTarget += dWheel; + + if (scrollTarget > 0f) scrollTarget = 0f; + else if (scrollTarget < -maxScroll + 728) scrollTarget = -maxScroll + 728; + + scrollAnimation = new EaseOutQuad(150, scroll, scrollTarget, false); + } else if (scrollAnimation != null && scrollAnimation.isFinished()) scrollAnimation = null; if (maxScroll <= 728) { draw(vg, x, y); ScissorManager.resetScissor(vg, scissor); return; } - draw(vg, x, (int) (y + currentScroll)); - int dWheel = Mouse.getDWheel(); - scrollTarget += dWheel; - - if (scrollTarget > 0f) scrollTarget = 0f; - else if (scrollTarget < -maxScroll + 728) scrollTarget = -maxScroll + 728; + draw(vg, x, (int) (y + scroll)); - currentScroll = MathUtils.easeOut(currentScroll, scrollTarget, 50f); ScissorManager.resetScissor(vg, scissor); } diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java index b805fb9..6ce55f4 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java @@ -93,87 +93,6 @@ public class TestConfig extends Config { ) public static boolean switchTest2; - - @Option( - name = "Test option", - subcategory = "Test", - options = {"Hello", "World", "Fish", "Cat"}, - type = OptionType.UNI_SELECTOR - ) - public static int switchTest3; - - @Option( - name = "Test option", - subcategory = "Test", - options = {"Hello", "World", "Fish", "Cat"}, - type = OptionType.UNI_SELECTOR, - size = 2 - ) - public static int uniSelector1; - - @Option( - name = "Test option", - subcategory = "Test", - options = {"Hello", "World", "Fish", "Cat"}, - type = OptionType.UNI_SELECTOR, - size = 2 - ) - public static int uniSelector2; - - @Option( - name = "Test option", - subcategory = "Test", - options = {"Hello", "World", "Fish", "Cat"}, - type = OptionType.UNI_SELECTOR, - size = 2 - ) - public static int uniSelector3; - - @Option( - name = "Test option", - subcategory = "Test", - options = {"Hello", "World", "Fish", "Cat"}, - type = OptionType.UNI_SELECTOR, - size = 2 - ) - public static int uniSelector4; - - @Option( - name = "Test option", - subcategory = "Test", - options = {"Hello", "World", "Fish", "Cat"}, - type = OptionType.UNI_SELECTOR, - size = 2 - ) - public static int uniSelector5; - - @Option( - name = "Test option", - subcategory = "Test", - options = {"Hello", "World", "Fish", "Cat"}, - type = OptionType.UNI_SELECTOR, - size = 2 - ) - public static int uniSelector6; - - @Option( - name = "Test option", - subcategory = "Test", - options = {"Hello", "World", "Fish", "Cat"}, - type = OptionType.UNI_SELECTOR, - size = 2 - ) - public static int uniSelector7; - - @Option( - name = "Arrow Uniselect (1x)", - subcategory = "Test", - options = {"Option", "World", "Fish"}, - type = OptionType.UNI_SELECTOR, - size = 2 - ) - public static int uniSelector8; - @ConfigPage( name = "Test Page", location = PageLocation.TOP diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java index c4beb82..630390b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/MathUtils.java @@ -11,6 +11,7 @@ public final class MathUtils { return number < min ? min : Math.min(number, max); } + @Deprecated public static float easeOut(float current, float goal, float speed) { float deltaTime = OneConfigGui.INSTANCE == null ? 16 : OneConfigGui.INSTANCE.getDeltaTime(); if (Math.round(Math.abs(goal - current) * 100) > 0) { @@ -20,18 +21,6 @@ public final class MathUtils { } } - public static float easeInQuad(float current) { - return current * current; - } - - /** - * Adapted from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a> - */ - 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) { return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1)); } |