Implementing AnimationConfig directly
This commit is contained in:
@@ -6,9 +6,6 @@ import org.saturnclient.saturnclient.config.manager.Property;
|
||||
public class AnimationConfig {
|
||||
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
|
||||
public static final Property<Integer> logoDuration = Property.integer(700);
|
||||
|
||||
@@ -23,8 +20,6 @@ public class AnimationConfig {
|
||||
|
||||
public static void init(ConfigManager parent) {
|
||||
config = new ConfigManager(parent, "Animations");
|
||||
|
||||
config.property("Animation Curve", animationCurve);
|
||||
config.property("Logo Duration", logoDuration);
|
||||
|
||||
mainMenu.init("Main Menu");
|
||||
@@ -35,10 +30,12 @@ public class AnimationConfig {
|
||||
// Animation properties
|
||||
public final Property<Integer> duration;
|
||||
public final Property<Integer> stagger;
|
||||
public final Property<Integer> curve;
|
||||
|
||||
public AnimationConfig(boolean enabled, int delay, int stagger) {
|
||||
this.duration = Property.integer(delay);
|
||||
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) {
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
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.Curve;
|
||||
|
||||
public class Element {
|
||||
public int x;
|
||||
@@ -15,7 +11,6 @@ public class Element {
|
||||
public boolean focused;
|
||||
public Animation animation;
|
||||
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 void render(RenderScope renderScope, ElementContext ctx) {
|
||||
@@ -44,7 +39,7 @@ public class Element {
|
||||
|
||||
public void playAnimationFrame(long elapsed) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -84,22 +79,6 @@ public class Element {
|
||||
|
||||
public Element animation(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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,31 @@
|
||||
package org.saturnclient.ui2.anim;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.saturnclient.saturnclient.config.AnimationConfig;
|
||||
import org.saturnclient.ui2.Element;
|
||||
|
||||
public abstract class Animation {
|
||||
public int duration;
|
||||
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) {
|
||||
this.duration = duration;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.saturnclient.ui2.anim;
|
||||
|
||||
import org.saturnclient.saturnclient.config.AnimationConfig;
|
||||
import org.saturnclient.ui2.Element;
|
||||
|
||||
public class Fade extends Animation {
|
||||
@@ -9,6 +10,10 @@ public class Fade extends Animation {
|
||||
super(duration);
|
||||
}
|
||||
|
||||
public Fade(AnimationConfig config) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(double progress, Element element) {
|
||||
element.opacity = Math.max(0.1f, targetOpacity * (float) progress);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.saturnclient.ui2.anim;
|
||||
|
||||
import org.saturnclient.saturnclient.config.AnimationConfig;
|
||||
import org.saturnclient.ui2.Element;
|
||||
|
||||
public class FadeOut extends Animation {
|
||||
@@ -9,6 +10,10 @@ public class FadeOut extends Animation {
|
||||
super(duration);
|
||||
}
|
||||
|
||||
public FadeOut(AnimationConfig config) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(double progress, Element element) {
|
||||
element.opacity = targetOpacity - (float) progress;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.saturnclient.ui2.anim;
|
||||
|
||||
import org.saturnclient.saturnclient.config.AnimationConfig;
|
||||
import org.saturnclient.ui2.Element;
|
||||
|
||||
public class SlideFade extends Animation {
|
||||
@@ -12,6 +13,10 @@ public class SlideFade extends Animation {
|
||||
this.slideY = new SlideY(duration, offset);
|
||||
}
|
||||
|
||||
public SlideFade(AnimationConfig config) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(double progress, Element element) {
|
||||
fade.delay = this.delay;
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
package org.saturnclient.ui2.anim;
|
||||
|
||||
import org.saturnclient.saturnclient.config.AnimationConfig;
|
||||
import org.saturnclient.ui2.Element;
|
||||
|
||||
public class SlideX extends Animation {
|
||||
int offset = 20;
|
||||
int maxOffset = 20;
|
||||
int elementX;
|
||||
double startX;
|
||||
|
||||
public SlideX(AnimationConfig config) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
public SlideX(AnimationConfig config, int offset) {
|
||||
super(config);
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public SlideX(int duration) {
|
||||
super(duration);
|
||||
@@ -14,23 +23,17 @@ public class SlideX extends Animation {
|
||||
public SlideX(int duration, int offset) {
|
||||
super(duration);
|
||||
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
|
||||
public void init(Element element) {
|
||||
element.x -= offset;
|
||||
elementX = element.x;
|
||||
startX = element.x - offset;
|
||||
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;
|
||||
|
||||
import org.saturnclient.saturnclient.config.AnimationConfig;
|
||||
import org.saturnclient.ui2.Element;
|
||||
|
||||
public class SlideY extends Animation {
|
||||
int offset = 20;
|
||||
int maxOffset = 20;
|
||||
double startY;
|
||||
|
||||
public SlideY(AnimationConfig config) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
public SlideY(AnimationConfig config, int offset) {
|
||||
super(config);
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public SlideY(int duration) {
|
||||
super(duration);
|
||||
}
|
||||
|
||||
public SlideY(int duration, int offset) {
|
||||
super(duration);
|
||||
|
||||
this.offset = offset;
|
||||
this.maxOffset = offset;
|
||||
}
|
||||
|
||||
public SlideY(int duration, int offset, int maxOffset) {
|
||||
super(duration);
|
||||
|
||||
this.offset = offset;
|
||||
this.maxOffset = offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user