Animation stagger and a few slide fixes

This commit is contained in:
2026-02-22 02:19:04 +01:00
parent 265b44187b
commit 53732c5df3
6 changed files with 62 additions and 22 deletions
@@ -43,7 +43,8 @@ public class Element {
public void playAnimationFrame(long elapsed) {
if (this.animation != null && elapsed >= this.animation.delay) {
this.animation.tick(this.curve.apply(Math.min(1.0, (double) elapsed / this.animation.duration)), this);
this.animation.tick(this.curve
.apply(Math.min(1.0, (double) (elapsed - this.animation.delay) / this.animation.duration)), this);
}
}
@@ -11,12 +11,12 @@ public class Fade extends Animation {
@Override
public void tick(double progress, Element element) {
element.opacity = targetOpacity * (float) progress;
element.opacity = Math.max(0.1f, targetOpacity * (float) progress);
}
@Override
public void init(Element element) {
targetOpacity = element.opacity;
element.opacity = 0;
element.opacity = 0.1f;
}
}
@@ -0,0 +1,32 @@
package org.saturnclient.ui2.anim;
import org.saturnclient.ui2.Element;
public class SlideFade extends Animation {
public Fade fade;
public SlideY slideY;
public SlideFade(int duration, int offset) {
super(duration);
this.fade = new Fade(duration);
this.slideY = new SlideY(duration, offset);
}
@Override
public void tick(double progress, Element element) {
fade.delay = this.delay;
fade.duration = this.duration;
slideY.delay = this.delay;
slideY.duration = this.duration;
fade.tick(progress, element);
slideY.tick(progress, element);
}
@Override
public void init(Element element) {
fade.init(element);
slideY.init(element);
}
}
@@ -5,7 +5,7 @@ import org.saturnclient.ui2.Element;
public class SlideY extends Animation {
int offset = 20;
int maxOffset = 20;
int elementY;
double startY;
public SlideY(int duration) {
super(duration);
@@ -24,15 +24,16 @@ public class SlideY extends Animation {
this.offset = offset;
this.maxOffset = offset;
}
@Override
public void tick(double progress, Element element) {
element.y = elementY + (int) (offset * progress);
}
@Override
public void init(Element element) {
element.y -= offset;
elementY = element.y;
startY = element.y - offset;
element.y = (int) startY;
}
@Override
public void tick(double progress, Element element) {
double currentY = startY + offset * progress;
element.y = (int) currentY;
}
}
@@ -30,9 +30,9 @@ public class AnimationStagger extends Element {
public void draw(Element element) {
if (element.animation != null) {
element.animation.delay = delay * (children.size() + 1);
element.animation.delay = delay * children.size();
}
children.add(element);
ElementRenderer.draw(children, element);
}
@Override
@@ -7,7 +7,9 @@ import org.saturnclient.ui2.resources.Textures;
import org.saturnclient.ui2.screens.cosmetics.CloakMenu;
import org.saturnclient.ui2.SaturnScreen;
import org.saturnclient.ui2.anim.Fade;
import org.saturnclient.ui2.anim.SlideFade;
import org.saturnclient.ui2.anim.SlideY;
import org.saturnclient.ui2.elements.AnimationStagger;
import org.saturnclient.ui2.elements.Button;
import org.saturnclient.ui2.elements.ImageTexture;
import org.saturnclient.ui2.elements.TextureButton;
@@ -19,7 +21,7 @@ import net.minecraft.client.gui.screen.world.SelectWorldScreen;
public class TitleMenu extends SaturnScreen {
public TitleMenu() {
super("Tile Menu");
super("Title Menu");
}
@Override
@@ -31,21 +33,25 @@ public class TitleMenu extends SaturnScreen {
draw(new ImageTexture(SaturnClientConfig.getLogo()).dimensions(98, 98).centerOffset(width, height, 0, -82)
.animation(new SlideY(700, -20)));
draw(new Button("SINGLEPLAYER", () -> {
AnimationStagger stagger = new AnimationStagger(120);
stagger.draw(new Button("SINGLEPLAYER", () -> {
client.setScreen(new SelectWorldScreen(new TitleMenu()));
}).scale(0.69f).dimensions(420, 52).centerOffset(width, height, 0, 0));
}).scale(0.69f).dimensions(420, 52).position(0, 0).animation(new SlideFade(1000, -10)));
draw(new Button("MULTIPLAYER", () -> {
stagger.draw(new Button("MULTIPLAYER", () -> {
client.setScreen(new MultiplayerScreen(new TitleMenu()));
}).scale(0.69f).dimensions(420, 52).centerOffset(width, height, 0, 40));
}).scale(0.69f).dimensions(420, 52).position(0, 40).animation(new SlideFade(1000, -10)));
draw(new Button("OPTIONS", () -> {
stagger.draw(new Button("OPTIONS", () -> {
client.setScreen(new OptionsScreen(new TitleMenu(), SaturnClient.client.options));
}).scale(0.69f).dimensions(206, 52).centerOffset(width, height, -73, 80));
}).scale(0.69f).dimensions(206, 52).position(0, 80).animation(new SlideFade(1000, -10)));
draw(new Button("QUIT", () -> {
stagger.draw(new Button("QUIT", () -> {
client.scheduleStop();
}).scale(0.69f).dimensions(206, 52).centerOffset(width, height, 73, 80));
}).scale(0.69f).dimensions(206, 52).position(146, 80).animation(new SlideFade(1000, -10)));
draw(stagger.dimensions(289, 143).centerOffset(width, height, 0, 60));
int s = Fonts.getHeight() + 20;