Implementing AnimationConfig directly
This commit is contained in:
@@ -6,9 +6,6 @@ import org.saturnclient.saturnclient.config.manager.Property;
|
|||||||
public class AnimationConfig {
|
public class AnimationConfig {
|
||||||
public static ConfigManager config;
|
public static ConfigManager config;
|
||||||
|
|
||||||
// Animation curve
|
|
||||||
public static final Property<Integer> animationCurve = Property.select(1, "Ease In Out Cubic", "Ease Out Cubic", "Ease In Out Back");
|
|
||||||
|
|
||||||
// Logo duration
|
// Logo duration
|
||||||
public static final Property<Integer> logoDuration = Property.integer(700);
|
public static final Property<Integer> logoDuration = Property.integer(700);
|
||||||
|
|
||||||
@@ -23,8 +20,6 @@ public class AnimationConfig {
|
|||||||
|
|
||||||
public static void init(ConfigManager parent) {
|
public static void init(ConfigManager parent) {
|
||||||
config = new ConfigManager(parent, "Animations");
|
config = new ConfigManager(parent, "Animations");
|
||||||
|
|
||||||
config.property("Animation Curve", animationCurve);
|
|
||||||
config.property("Logo Duration", logoDuration);
|
config.property("Logo Duration", logoDuration);
|
||||||
|
|
||||||
mainMenu.init("Main Menu");
|
mainMenu.init("Main Menu");
|
||||||
@@ -35,10 +30,12 @@ public class AnimationConfig {
|
|||||||
// Animation properties
|
// Animation properties
|
||||||
public final Property<Integer> duration;
|
public final Property<Integer> duration;
|
||||||
public final Property<Integer> stagger;
|
public final Property<Integer> stagger;
|
||||||
|
public final Property<Integer> curve;
|
||||||
|
|
||||||
public AnimationConfig(boolean enabled, int delay, int stagger) {
|
public AnimationConfig(boolean enabled, int delay, int stagger) {
|
||||||
this.duration = Property.integer(delay);
|
this.duration = Property.integer(delay);
|
||||||
this.stagger = Property.integer(stagger);
|
this.stagger = Property.integer(stagger);
|
||||||
|
this.curve = Property.select(1, "Ease In Out Cubic", "Ease Out Cubic", "Ease In Out Back");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(String name) {
|
public void init(String name) {
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
package org.saturnclient.ui2;
|
package org.saturnclient.ui2;
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.config.AnimationConfig;
|
|
||||||
import org.saturnclient.ui2.anim.Animation;
|
import org.saturnclient.ui2.anim.Animation;
|
||||||
import org.saturnclient.ui2.anim.Curve;
|
|
||||||
|
|
||||||
public class Element {
|
public class Element {
|
||||||
public int x;
|
public int x;
|
||||||
@@ -15,7 +11,6 @@ public class Element {
|
|||||||
public boolean focused;
|
public boolean focused;
|
||||||
public Animation animation;
|
public Animation animation;
|
||||||
public float scale = 1.0f;
|
public float scale = 1.0f;
|
||||||
public Function<Double, Double> curve = Curve::easeInOutCubic;
|
|
||||||
public Integer duration = null; // Element duration, will fade out if not null
|
public Integer duration = null; // Element duration, will fade out if not null
|
||||||
|
|
||||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||||
@@ -44,7 +39,7 @@ public class Element {
|
|||||||
|
|
||||||
public void playAnimationFrame(long elapsed) {
|
public void playAnimationFrame(long elapsed) {
|
||||||
if (this.animation != null && elapsed >= this.animation.delay) {
|
if (this.animation != null && elapsed >= this.animation.delay) {
|
||||||
this.animation.tick(this.curve
|
this.animation.tick(this.animation.curve
|
||||||
.apply(Math.min(1.0, (double) (elapsed - this.animation.delay) / this.animation.duration)), this);
|
.apply(Math.min(1.0, (double) (elapsed - this.animation.delay) / this.animation.duration)), this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,22 +79,6 @@ public class Element {
|
|||||||
|
|
||||||
public Element animation(Animation animation) {
|
public Element animation(Animation animation) {
|
||||||
this.animation = animation;
|
this.animation = animation;
|
||||||
switch (AnimationConfig.animationCurve.value) {
|
|
||||||
case 0:
|
|
||||||
this.curve = Curve::easeInOutCubic;
|
|
||||||
case 1:
|
|
||||||
this.curve = Curve::easeOutCubic;
|
|
||||||
case 2:
|
|
||||||
this.curve = Curve::easeInOutBack;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Element animation(Animation animation, Function<Double, Double> curve) {
|
|
||||||
this.animation = animation;
|
|
||||||
this.curve = curve;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,31 @@
|
|||||||
package org.saturnclient.ui2.anim;
|
package org.saturnclient.ui2.anim;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.config.AnimationConfig;
|
||||||
import org.saturnclient.ui2.Element;
|
import org.saturnclient.ui2.Element;
|
||||||
|
|
||||||
public abstract class Animation {
|
public abstract class Animation {
|
||||||
public int duration;
|
public int duration;
|
||||||
public int delay = 0;
|
public int delay = 0;
|
||||||
|
public Function<Double, Double> curve = Curve::easeInOutCubic;
|
||||||
|
|
||||||
|
Animation(AnimationConfig config) {
|
||||||
|
this.duration = config.duration.value;
|
||||||
|
switch (config.curve.value) {
|
||||||
|
case 0:
|
||||||
|
this.curve = Curve::easeInOutCubic;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
this.curve = Curve::easeOutCubic;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
this.curve = Curve::easeInOutBack;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Animation(int duration) {
|
Animation(int duration) {
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.saturnclient.ui2.anim;
|
package org.saturnclient.ui2.anim;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.config.AnimationConfig;
|
||||||
import org.saturnclient.ui2.Element;
|
import org.saturnclient.ui2.Element;
|
||||||
|
|
||||||
public class Fade extends Animation {
|
public class Fade extends Animation {
|
||||||
@@ -9,6 +10,10 @@ public class Fade extends Animation {
|
|||||||
super(duration);
|
super(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Fade(AnimationConfig config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick(double progress, Element element) {
|
public void tick(double progress, Element element) {
|
||||||
element.opacity = Math.max(0.1f, targetOpacity * (float) progress);
|
element.opacity = Math.max(0.1f, targetOpacity * (float) progress);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.saturnclient.ui2.anim;
|
package org.saturnclient.ui2.anim;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.config.AnimationConfig;
|
||||||
import org.saturnclient.ui2.Element;
|
import org.saturnclient.ui2.Element;
|
||||||
|
|
||||||
public class FadeOut extends Animation {
|
public class FadeOut extends Animation {
|
||||||
@@ -9,6 +10,10 @@ public class FadeOut extends Animation {
|
|||||||
super(duration);
|
super(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FadeOut(AnimationConfig config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick(double progress, Element element) {
|
public void tick(double progress, Element element) {
|
||||||
element.opacity = targetOpacity - (float) progress;
|
element.opacity = targetOpacity - (float) progress;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.saturnclient.ui2.anim;
|
package org.saturnclient.ui2.anim;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.config.AnimationConfig;
|
||||||
import org.saturnclient.ui2.Element;
|
import org.saturnclient.ui2.Element;
|
||||||
|
|
||||||
public class SlideFade extends Animation {
|
public class SlideFade extends Animation {
|
||||||
@@ -12,6 +13,10 @@ public class SlideFade extends Animation {
|
|||||||
this.slideY = new SlideY(duration, offset);
|
this.slideY = new SlideY(duration, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SlideFade(AnimationConfig config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick(double progress, Element element) {
|
public void tick(double progress, Element element) {
|
||||||
fade.delay = this.delay;
|
fade.delay = this.delay;
|
||||||
|
|||||||
@@ -1,11 +1,20 @@
|
|||||||
package org.saturnclient.ui2.anim;
|
package org.saturnclient.ui2.anim;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.config.AnimationConfig;
|
||||||
import org.saturnclient.ui2.Element;
|
import org.saturnclient.ui2.Element;
|
||||||
|
|
||||||
public class SlideX extends Animation {
|
public class SlideX extends Animation {
|
||||||
int offset = 20;
|
int offset = 20;
|
||||||
int maxOffset = 20;
|
double startX;
|
||||||
int elementX;
|
|
||||||
|
public SlideX(AnimationConfig config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SlideX(AnimationConfig config, int offset) {
|
||||||
|
super(config);
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
public SlideX(int duration) {
|
public SlideX(int duration) {
|
||||||
super(duration);
|
super(duration);
|
||||||
@@ -14,23 +23,17 @@ public class SlideX extends Animation {
|
|||||||
public SlideX(int duration, int offset) {
|
public SlideX(int duration, int offset) {
|
||||||
super(duration);
|
super(duration);
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
this.maxOffset = offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SlideX(int duration, int offset, int maxOffset) {
|
|
||||||
super(duration);
|
|
||||||
this.offset = offset;
|
|
||||||
this.maxOffset = maxOffset; // ✅ fixed
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick(double progress, Element element) {
|
|
||||||
element.x = elementX + (int) (offset * progress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Element element) {
|
public void init(Element element) {
|
||||||
element.x -= offset;
|
startX = element.x - offset;
|
||||||
elementX = element.x;
|
element.x = (int) startX;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(double progress, Element element) {
|
||||||
|
double currentX = startX + offset * progress;
|
||||||
|
element.x = (int) currentX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
package org.saturnclient.ui2.anim;
|
|
||||||
|
|
||||||
import org.saturnclient.ui2.Element;
|
|
||||||
|
|
||||||
public class SlideXAbsolute extends Animation {
|
|
||||||
int offset = 20;
|
|
||||||
int maxOffset = 20;
|
|
||||||
int elementX;
|
|
||||||
|
|
||||||
public SlideXAbsolute(int duration) {
|
|
||||||
super(duration);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SlideXAbsolute(int duration, int offset) {
|
|
||||||
super(duration);
|
|
||||||
this.offset = offset;
|
|
||||||
this.maxOffset = offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SlideXAbsolute(int duration, int offset, int maxOffset) {
|
|
||||||
super(duration);
|
|
||||||
this.offset = offset;
|
|
||||||
this.maxOffset = maxOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick(double progress, Element element) {
|
|
||||||
element.x = elementX + (int) (offset * progress);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(Element element) {
|
|
||||||
elementX = element.x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +1,28 @@
|
|||||||
package org.saturnclient.ui2.anim;
|
package org.saturnclient.ui2.anim;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.config.AnimationConfig;
|
||||||
import org.saturnclient.ui2.Element;
|
import org.saturnclient.ui2.Element;
|
||||||
|
|
||||||
public class SlideY extends Animation {
|
public class SlideY extends Animation {
|
||||||
int offset = 20;
|
int offset = 20;
|
||||||
int maxOffset = 20;
|
|
||||||
double startY;
|
double startY;
|
||||||
|
|
||||||
|
public SlideY(AnimationConfig config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SlideY(AnimationConfig config, int offset) {
|
||||||
|
super(config);
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
public SlideY(int duration) {
|
public SlideY(int duration) {
|
||||||
super(duration);
|
super(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SlideY(int duration, int offset) {
|
public SlideY(int duration, int offset) {
|
||||||
super(duration);
|
super(duration);
|
||||||
|
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
this.maxOffset = offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SlideY(int duration, int offset, int maxOffset) {
|
|
||||||
super(duration);
|
|
||||||
|
|
||||||
this.offset = offset;
|
|
||||||
this.maxOffset = offset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user