aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/gui/animations
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-08-24 22:51:58 +0200
committerGitHub <noreply@github.com>2022-08-24 22:51:58 +0200
commitdaed9569a0f1d2231c4f824f6cffd72d5f8ae8bd (patch)
tree6efee702c616d96e40a3e69ce89425f0936a7598 /src/main/java/cc/polyfrost/oneconfig/gui/animations
parenta76b49be6dbeb0be3f88870e33d3e10e0e7f8e1c (diff)
downloadOneConfig-daed9569a0f1d2231c4f824f6cffd72d5f8ae8bd.tar.gz
OneConfig-daed9569a0f1d2231c4f824f6cffd72d5f8ae8bd.tar.bz2
OneConfig-daed9569a0f1d2231c4f824f6cffd72d5f8ae8bd.zip
Notifs (#111)
* Start on notifications * Finish notifications (pog) * oop * internalizing * misc: set default duration to 4000ms * Scaling notifs stuff Co-authored-by: Wyvest <45589059+Wyvest@users.noreply.github.com>
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/animations')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java24
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/animations/ChainedAnimation.java56
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java37
3 files changed, 110 insertions, 7 deletions
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 4040164..f85132b 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java
@@ -29,11 +29,11 @@ package cc.polyfrost.oneconfig.gui.animations;
import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
public abstract class Animation {
- private final boolean reverse;
- private final float duration;
- private final float start;
- private final float change;
- private float timePassed = 0;
+ protected final boolean reverse;
+ protected final float duration;
+ protected final float start;
+ protected final float change;
+ protected float timePassed = 0;
/**
* @param duration The duration of the animation
@@ -84,5 +84,19 @@ public abstract class Animation {
return reverse;
}
+ /**
+ * @return The start position of the animation
+ */
+ public float getStart() {
+ return start;
+ }
+
+ /**
+ * @return The end position of the animation
+ */
+ public float getEnd() {
+ return start + change;
+ }
+
protected abstract float animate(float x);
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/ChainedAnimation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/ChainedAnimation.java
new file mode 100644
index 0000000..63be4a0
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/ChainedAnimation.java
@@ -0,0 +1,56 @@
+/*
+ * This file is part of OneConfig.
+ * OneConfig - Next Generation Config Library for Minecraft: Java Edition
+ * Copyright (C) 2021, 2022 Polyfrost.
+ * <https://polyfrost.cc> <https://github.com/Polyfrost/>
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * OneConfig is licensed under the terms of version 3 of the GNU Lesser
+ * General Public License as published by the Free Software Foundation, AND
+ * under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
+ * either version 1.0 of the Additional Terms, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License. If not, see <https://www.gnu.org/licenses/>. You should
+ * have also received a copy of the Additional Terms Applicable
+ * to OneConfig, as published by Polyfrost. If not, see
+ * <https://polyfrost.cc/legal/oneconfig/additional-terms>
+ */
+
+package cc.polyfrost.oneconfig.gui.animations;
+
+public class ChainedAnimation extends Animation {
+ private final Animation[] animations;
+ private int currentAnimation = 0;
+ private float value;
+
+ public ChainedAnimation(Animation... animations) {
+ super(1, 0, 0, false);
+ this.animations = animations;
+ }
+
+ @Override
+ public float get(float deltaTime) {
+ if (currentAnimation >= animations.length) return value;
+ value = animations[currentAnimation].get(deltaTime);
+ if (animations[currentAnimation].isFinished()) currentAnimation++;
+ return value;
+ }
+
+ @Override
+ public boolean isFinished() {
+ return currentAnimation >= animations.length;
+ }
+
+ @Override
+ protected float animate(float x) {
+ return 0;
+ }
+}
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 ca9bc17..62cbed7 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java
@@ -26,23 +26,56 @@
package cc.polyfrost.oneconfig.gui.animations;
+import java.util.concurrent.Callable;
+
public class DummyAnimation extends Animation {
protected final float value;
+ protected Callable<Boolean> done = null;
/**
* @param value The value that is returned
+ * @param done A callable that returns if the animation is finished
*/
- public DummyAnimation(float value) {
- super(value, value, value, false);
+ public DummyAnimation(float value, Callable<Boolean> done) {
+ super(0, value, value, false);
+ this.value = value;
+ this.done = done;
+ }
+
+ /**
+ * @param value The value that is returned
+ * @param duration The duration of the animation
+ */
+ public DummyAnimation(float value, float duration) {
+ super(duration, value, value, false);
this.value = value;
}
+ /**
+ * @param value The value that is returned
+ */
+ public DummyAnimation(float value) {
+ this(value, 0);
+ }
+
@Override
public float get(float deltaTime) {
+ timePassed += deltaTime;
return value;
}
@Override
+ public boolean isFinished() {
+ if (done != null) {
+ try {
+ return done.call();
+ } catch (Exception ignored) {
+ }
+ }
+ return super.isFinished();
+ }
+
+ @Override
protected float animate(float x) {
return x;
}