animation thread
This commit is contained in:
@@ -77,5 +77,7 @@ public class CloaksMenu extends SaturnUi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
draw(modsScroll.setX(rectX + 17).setY(rectY + 10).setWidth(rectWidth - 17).setHeight(rectHeight - 10));
|
draw(modsScroll.setX(rectX + 17).setY(rectY + 10).setWidth(rectWidth - 17).setHeight(rectHeight - 10));
|
||||||
|
|
||||||
|
super.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class MainMenu extends SaturnUi {
|
|||||||
}).setX((width - buttonWidth) / 2).setY((height - buttonHeight) /
|
}).setX((width - buttonWidth) / 2).setY((height - buttonHeight) /
|
||||||
2).setWidth(buttonWidth)
|
2).setWidth(buttonWidth)
|
||||||
.setHeight(buttonHeight)
|
.setHeight(buttonHeight)
|
||||||
.setAnimations(new FadeIn(1)));
|
.setAnimations(new FadeIn(2)));
|
||||||
|
|
||||||
draw(
|
draw(
|
||||||
new SaturnImageButton(Textures.HUD_ICON, 14, 14,
|
new SaturnImageButton(Textures.HUD_ICON, 14, 14,
|
||||||
@@ -40,7 +40,7 @@ public class MainMenu extends SaturnUi {
|
|||||||
.setY((height - buttonHeight) / 2)
|
.setY((height - buttonHeight) / 2)
|
||||||
.setWidth(buttonHeight)
|
.setWidth(buttonHeight)
|
||||||
.setHeight(buttonHeight)
|
.setHeight(buttonHeight)
|
||||||
.setAnimations(new FadeIn(1)));
|
.setAnimations(new FadeIn(2)));
|
||||||
|
|
||||||
draw(
|
draw(
|
||||||
new SaturnImageButton(Textures.COSMETICS, 14, 14,
|
new SaturnImageButton(Textures.COSMETICS, 14, 14,
|
||||||
@@ -51,7 +51,7 @@ public class MainMenu extends SaturnUi {
|
|||||||
.setY((height - buttonHeight) / 2)
|
.setY((height - buttonHeight) / 2)
|
||||||
.setWidth(buttonHeight)
|
.setWidth(buttonHeight)
|
||||||
.setHeight(buttonHeight)
|
.setHeight(buttonHeight)
|
||||||
.setAnimations(new FadeIn(1)));
|
.setAnimations(new FadeIn(2)));
|
||||||
|
|
||||||
int logoSize = 49;
|
int logoSize = 49;
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ public class MainMenu extends SaturnUi {
|
|||||||
.setY((height - 8) / 2 - 23)
|
.setY((height - 8) / 2 - 23)
|
||||||
.setWidth(logoSize)
|
.setWidth(logoSize)
|
||||||
.setHeight(8)
|
.setHeight(8)
|
||||||
.setAnimations(new FadeIn(1)));
|
.setAnimations(new FadeIn(2)));
|
||||||
|
|
||||||
draw(
|
draw(
|
||||||
new SaturnImage(Textures.LOGO)
|
new SaturnImage(Textures.LOGO)
|
||||||
@@ -69,6 +69,8 @@ public class MainMenu extends SaturnUi {
|
|||||||
.setY(height / 2 - logoSize - 24)
|
.setY(height / 2 - logoSize - 24)
|
||||||
.setWidth(logoSize)
|
.setWidth(logoSize)
|
||||||
.setHeight(logoSize)
|
.setHeight(logoSize)
|
||||||
.setAnimations(new Slide(1, 14)));
|
.setAnimations(new Slide(2, 14)));
|
||||||
|
|
||||||
|
super.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ public class SettingsMenu extends SaturnUi {
|
|||||||
.setY(tabsY + 3)
|
.setY(tabsY + 3)
|
||||||
.setWidth(tabSize)
|
.setWidth(tabSize)
|
||||||
.setHeight(tabSize)
|
.setHeight(tabSize)
|
||||||
.setAnimations(new FadeIn(1))
|
.setAnimations(new FadeIn(2))
|
||||||
.setAnimations(new Slide(1, 10)));
|
.setAnimations(new Slide(1, 10)));
|
||||||
|
|
||||||
draw(new SaturnClickableImage(Textures.MODS_TAB, () -> {
|
draw(new SaturnClickableImage(Textures.MODS_TAB, () -> {
|
||||||
@@ -60,7 +60,7 @@ public class SettingsMenu extends SaturnUi {
|
|||||||
.setY(tabsY + 3)
|
.setY(tabsY + 3)
|
||||||
.setWidth(tabSize)
|
.setWidth(tabSize)
|
||||||
.setHeight(tabSize)
|
.setHeight(tabSize)
|
||||||
.setAnimations(new FadeIn(1))
|
.setAnimations(new FadeIn(2))
|
||||||
.setAnimations(new Slide(1, 10)));
|
.setAnimations(new Slide(1, 10)));
|
||||||
|
|
||||||
draw(new SaturnClickableImage(Textures.SEARCH, () -> {
|
draw(new SaturnClickableImage(Textures.SEARCH, () -> {
|
||||||
@@ -70,7 +70,7 @@ public class SettingsMenu extends SaturnUi {
|
|||||||
.setY(tabsY + 3)
|
.setY(tabsY + 3)
|
||||||
.setWidth(tabSize)
|
.setWidth(tabSize)
|
||||||
.setHeight(tabSize)
|
.setHeight(tabSize)
|
||||||
.setAnimations(new FadeIn(1))
|
.setAnimations(new FadeIn(2))
|
||||||
.setAnimations(new Slide(1, 10)));
|
.setAnimations(new Slide(1, 10)));
|
||||||
|
|
||||||
int modX = 0;
|
int modX = 0;
|
||||||
@@ -99,5 +99,7 @@ public class SettingsMenu extends SaturnUi {
|
|||||||
|
|
||||||
draw(modsScroll.setX(modsX + 17).setY(modsY + 10).setWidth(rectWidth - 17).setHeight(rectHeight - 10)
|
draw(modsScroll.setX(modsX + 17).setY(modsY + 10).setWidth(rectWidth - 17).setHeight(rectHeight - 10)
|
||||||
.setAnimations(new Slide(1, 10)));
|
.setAnimations(new Slide(1, 10)));
|
||||||
|
|
||||||
|
super.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,12 @@ package org.saturnclient.ui;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.text.MutableText;
|
import net.minecraft.text.MutableText;
|
||||||
@@ -11,6 +16,8 @@ import net.minecraft.text.Text;
|
|||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class SaturnUi extends Screen {
|
public class SaturnUi extends Screen {
|
||||||
|
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|
||||||
public static MutableText text(String text) {
|
public static MutableText text(String text) {
|
||||||
return Text.literal(text).setStyle(Style.EMPTY.withFont(Identifier.of("saturnclient:panton")));
|
return Text.literal(text).setStyle(Style.EMPTY.withFont(Identifier.of("saturnclient:panton")));
|
||||||
}
|
}
|
||||||
@@ -22,6 +29,12 @@ public class SaturnUi extends Screen {
|
|||||||
super(title);
|
super(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
scheduler.scheduleAtFixedRate(this::saturnTick, 0, 7, TimeUnit.MILLISECONDS);
|
||||||
|
super.init();
|
||||||
|
}
|
||||||
|
|
||||||
public void draw(SaturnWidget widget) {
|
public void draw(SaturnWidget widget) {
|
||||||
synchronized (widgets) {
|
synchronized (widgets) {
|
||||||
widget.init();
|
widget.init();
|
||||||
@@ -38,24 +51,10 @@ public class SaturnUi extends Screen {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.animations != null) {
|
|
||||||
for (SaturnAnimation animation : widget.animations) {
|
|
||||||
if (animation != null && tick - animation.lastTick == animation.delay) {
|
|
||||||
if (animation.run(widget, tick)) {
|
|
||||||
animation = null;
|
|
||||||
} else {
|
|
||||||
animation.lastTick = tick;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isMouseInside = widget.x < mouseX && widget.x + widget.width > mouseX
|
boolean isMouseInside = widget.x < mouseX && widget.x + widget.width > mouseX
|
||||||
&& widget.y < mouseY && widget.y + widget.height > mouseY;
|
&& widget.y < mouseY && widget.y + widget.height > mouseY;
|
||||||
widget.render(context, isMouseInside, mouseX, mouseY);
|
widget.render(context, isMouseInside, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
tick++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -138,4 +137,23 @@ public class SaturnUi extends Screen {
|
|||||||
default -> '\0';
|
default -> '\0';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saturnTick() {
|
||||||
|
synchronized (widgets) {
|
||||||
|
for (SaturnWidget widget : widgets) {
|
||||||
|
if (widget.visible && widget.animations != null) {
|
||||||
|
for (SaturnAnimation animation : widget.animations) {
|
||||||
|
if (animation != null && tick - animation.lastTick == animation.delay) {
|
||||||
|
if (animation.run(widget, tick)) {
|
||||||
|
animation = null;
|
||||||
|
} else {
|
||||||
|
animation.lastTick = tick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tick++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user