diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-03 18:13:50 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-03 18:13:50 +0200 |
commit | 91da97c6843b76829a6b8cf1321f3d38f4e8893b (patch) | |
tree | dc7b3dda3ee8ef5ebb88d13c3511b51b7668e002 /src/main/java/cc/polyfrost/oneconfig | |
parent | 5771df1bb5d2bb18507badd68ed3e0718cbb9abc (diff) | |
download | OneConfig-91da97c6843b76829a6b8cf1321f3d38f4e8893b.tar.gz OneConfig-91da97c6843b76829a6b8cf1321f3d38f4e8893b.tar.bz2 OneConfig-91da97c6843b76829a6b8cf1321f3d38f4e8893b.zip |
color anims start
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig')
8 files changed, 88 insertions, 38 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java new file mode 100644 index 0000000..420f1d0 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java @@ -0,0 +1,49 @@ +package cc.polyfrost.oneconfig.gui.animations; + +import cc.polyfrost.oneconfig.utils.color.ColorPalette; + +public class ColorAnimation { + private ColorPalette palette; + /** + * 0 = nothing + * 1 = hovered + * 2 = pressed + * 3 = color palette changed + */ + private int prevState = 0; + private Animation redAnimation; + private Animation greenAnimation; + private Animation blueAnimation; + private Animation alphaAnimation; + + public ColorAnimation(ColorPalette palette) { + this.palette = palette; + redAnimation = new DummyAnimation(palette.getNormalColorf()[0]); + greenAnimation = new DummyAnimation(palette.getNormalColorf()[1]); + blueAnimation = new DummyAnimation(palette.getNormalColorf()[2]); + alphaAnimation = new DummyAnimation(palette.getNormalColorf()[3]); + } + + public int getColor(boolean hovered, boolean pressed) { + int state = pressed ? 2 : hovered ? 1 : 0; + if (state != prevState) { + float[] newColors = pressed ? palette.getPressedColorf() : hovered ? palette.getHoveredColorf() : palette.getNormalColorf(); + redAnimation = new EaseInOutQuad(100, redAnimation.get(), newColors[0], false); + greenAnimation = new EaseInOutQuad(100, greenAnimation.get(), newColors[1], false); + blueAnimation = new EaseInOutQuad(100, blueAnimation.get(), newColors[2], false); + alphaAnimation = new EaseInOutQuad(100, alphaAnimation.get(), newColors[3], false); + prevState = state; + return ((int) (alphaAnimation.get(0) * 255) << 24) | ((int) (redAnimation.get(0) * 255) << 16) | ((int) (greenAnimation.get(0) * 255) << 8) | ((int) (blueAnimation.get(0) * 255)); + } + return ((int) (alphaAnimation.get() * 255) << 24) | ((int) (redAnimation.get() * 255) << 16) | ((int) (greenAnimation.get() * 255) << 8) | ((int) (blueAnimation.get() * 255)); + } + + public ColorPalette getPalette() { + return palette; + } + + public void setPalette(ColorPalette palette) { + this.palette = palette; + prevState = 3; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java index 6343123..bc97aca 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java @@ -10,6 +10,6 @@ public class DummyAnimation extends Animation{ @Override protected float animate(float timePassed, float duration, float start, float change) { - return change; + return 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 2ce7e98..bc2bcae 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -2,14 +2,13 @@ package cc.polyfrost.oneconfig.gui.elements; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; import cc.polyfrost.oneconfig.gui.pages.Page; 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.color.ColorPalette; -import cc.polyfrost.oneconfig.utils.color.ColorUtils; import org.jetbrains.annotations.NotNull; -import org.lwjgl.input.Mouse; public class BasicButton extends BasicElement { @@ -34,10 +33,6 @@ public class BasicButton extends BasicElement { private Page page; private Runnable runnable; - public BasicButton(int width, int size, String text, int align, @NotNull ColorPalette colorPalette) { - this(width, size, text, null, null, align, colorPalette); - } - public BasicButton(int width, int size, String text, SVGs icon1, SVGs icon2, int align, @NotNull ColorPalette colorPalette) { super(width, 32, colorPalette, true); if (text != null) this.text = text; @@ -59,16 +54,8 @@ public class BasicButton extends BasicElement { this(width, size, null, icon, null, align, colorPalette); } - public void setToggleable(boolean state) { - this.toggleable = state; - } - - public void setClickAction(Page page) { - this.page = page; - } - - public void setClickAction(Runnable runnable) { - this.runnable = runnable; + public BasicButton(int width, int size, String text, int align, @NotNull ColorPalette colorPalette) { + this(width, size, text, null, null, align, colorPalette); } @Override @@ -130,14 +117,16 @@ public class BasicButton extends BasicElement { @Override public void onClick() { - if (this.page != null) { + if (this.page != null && OneConfigGui.INSTANCE != null) { OneConfigGui.INSTANCE.openPage(page); } else if (this.runnable != null) { runnable.run(); } + if (toggleable && toggled) colorPalette = ColorPalette.PRIMARY; + else if (toggleable) colorPalette = ColorPalette.SECONDARY; } - @Override + /*@Override public void update(int x, int y) { super.update(x, y); if (hoverFx && !disabled) { @@ -152,6 +141,18 @@ public class BasicButton extends BasicElement { } else if (hoverFx) { currentColor = colorPalette.getNormalColor(); } + }*/ + + public void setToggleable(boolean state) { + this.toggleable = state; + } + + public void setClickAction(Page page) { + this.page = page; + } + + public void setClickAction(Runnable runnable) { + this.runnable = runnable; } public Page getPage() { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java index 93e2c07..c146742 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java @@ -1,10 +1,10 @@ package cc.polyfrost.oneconfig.gui.elements; -import cc.polyfrost.oneconfig.lwjgl.RenderManager; -import cc.polyfrost.oneconfig.utils.color.ColorPalette; -import cc.polyfrost.oneconfig.utils.color.ColorUtils; +import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.color.ColorPalette; import org.jetbrains.annotations.NotNull; +import org.lwjgl.input.Mouse; public class BasicElement { protected int width, height; @@ -12,12 +12,14 @@ public class BasicElement { protected int hitBoxX, hitBoxY; protected boolean hoverFx; protected boolean hovered = false; + protected boolean pressed = false; protected boolean clicked = false; protected boolean toggled = false; protected boolean disabled = false; public int currentColor; protected final float radius; private boolean block = false; + protected ColorAnimation colorAnimation; public BasicElement(int width, int height, @NotNull ColorPalette colorPalette, boolean hoverFx) { this(width, height, colorPalette, hoverFx, 12f); @@ -29,6 +31,7 @@ public class BasicElement { this.colorPalette = colorPalette; this.hoverFx = hoverFx; this.radius = radius; + this.colorAnimation = new ColorAnimation(colorPalette); } public BasicElement(int width, int height, boolean hoverFx) { @@ -37,23 +40,22 @@ public class BasicElement { public void draw(long vg, int x, int y) { - RenderManager.drawRoundedRect(vg, x, y, width, height, currentColor, radius); - - update(x, y); - if (hoverFx) { - currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked); - } } public void update(int x, int y) { if (disabled) { hovered = false; + pressed = false; clicked = false; return; } hovered = InputUtils.isAreaHovered(x - hitBoxX, y - hitBoxY, width + hitBoxX, height + hitBoxY); + pressed = hovered && Mouse.isButtonDown(0); clicked = InputUtils.isClicked(block) && hovered; + if (hoverFx) currentColor = colorAnimation.getColor(hovered, pressed); + else currentColor = colorAnimation.getColor(false, false); + if (clicked) { toggled = !toggled; onClick(); @@ -84,6 +86,7 @@ public class BasicElement { public void setColorPalette(ColorPalette colorPalette) { this.colorPalette = colorPalette; + this.colorAnimation.setPalette(colorPalette); } public int getWidth() { 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 c32f58e..e67c8ef 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -207,7 +207,7 @@ public class ColorSelector { default: case 0: case 2: - buttons.get(mode).currentColor = OneConfigConfig.TRANSPARENT; + //buttons.get(mode).currentColor = OneConfigConfig.TRANSPARENT; topSlider.setImage(Images.HUE_GRADIENT); RenderManager.drawHSBBox(vg, x + 16, y + 120, 384, 288, color.getRGBMax(true)); @@ -222,7 +222,7 @@ public class ColorSelector { } break; case 1: - buttons.get(1).currentColor = OneConfigConfig.TRANSPARENT; + //buttons.get(1).currentColor = OneConfigConfig.TRANSPARENT; topSlider.setImage(null); RenderManager.drawRoundImage(vg, Images.COLOR_WHEEL, x + 64, y + 120, 288, 288, 144f); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java index d5e8895..ad3e998 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java @@ -51,8 +51,8 @@ public class ModCard extends BasicElement { RenderManager.drawSvg(vg, SVGs.BOX, x + 98, y + 19, 48, 48); } favoriteHitbox.update(x + 212, y + 87); - favoriteHitbox.currentColor = ColorUtils.getColor(favoriteHitbox.currentColor, favoriteHitbox.colorPalette, favoriteHitbox.hovered, favoriteHitbox.clicked); - RenderManager.drawRoundedRectVaried(vg, x + 212, y + 87, 32, 32, favoriteHitbox.currentColor, 0f, 0f, 12f, 0f); + //favoriteHitbox.currentColor = ColorUtils.getColor(favoriteHitbox.currentColor, favoriteHitbox.colorPalette, favoriteHitbox.hovered, favoriteHitbox.clicked); + //RenderManager.drawRoundedRectVaried(vg, x + 212, y + 87, 32, 32, favoriteHitbox.currentColor, 0f, 0f, 12f, 0f); favorite = favoriteHitbox.isToggled(); RenderManager.drawText(vg, modData.name, x + 12, y + 103, OneConfigConfig.WHITE, 14f, Fonts.MEDIUM); if (favorite) { 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 5926b30..7754912 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 @@ -15,7 +15,7 @@ import java.lang.reflect.Field; public class ConfigDualOption extends BasicOption { private Animation posAnimation; - private Animation sizeAnimation; + private Animation sizeAnimation = new DummyAnimation(124); private final String left, right; public ConfigDualOption(Field field, Object parent, String name, int size, String[] options) { @@ -35,10 +35,7 @@ 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); - } + if (posAnimation == null) posAnimation = new DummyAnimation(toggled ? 356 : 228); } catch (IllegalAccessException ignored) { } if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java b/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java index 26be1b6..08d1796 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/color/ColorPalette.java @@ -29,7 +29,7 @@ public class ColorPalette { * <h1>Tertiary Color Scheme</h1> Normal: Transparent (Text=White 90%),<br> Hover: Transparent (Text=White 100%),<br> Clicked: Transparent (Text=White 80%) * <h2>NOTICE this returns the text colors as it is always transparent.</h2> */ - public static final ColorPalette TERTIARY = new ColorPalette(WHITE_90, WHITE, WHITE_80); + public static final ColorPalette TERTIARY = new ColorPalette(WHITE_80, WHITE, WHITE_80); /** * <h1>Primary Destructive Color Scheme</h1> Normal: Error 700,<br> Hover: Error 600,<br> Clicked: Error 600 (80%) */ |