Reset intro video playback per page
All checks were successful
Build / build (push) Successful in 14m7s

This commit is contained in:
MrSphay
2026-05-09 11:47:34 +02:00
parent cb111e51da
commit 1859e69b01
2 changed files with 30 additions and 9 deletions

View File

@@ -21,6 +21,8 @@ public class FirstTimeScreen extends Screen {
};
private final Rect[] cardRects = new Rect[] { Rect.empty(), Rect.empty(), Rect.empty() };
private long animationStartedAt;
private boolean resetAnimationTimer = true;
public FirstTimeScreen() {
super(Component.literal("Explosion Overhaul Setup"));
@@ -50,8 +52,13 @@ public class FirstTimeScreen extends Screen {
this.cardRects[1] = new Rect(secondX, firstRowY, cardW, cardH + 34);
this.cardRects[2] = new Rect((this.width - cardW) / 2, secondRowY, cardW, cardH + 34);
long elapsed = this.resetAnimationTimer ? 0L : Math.max(0L, System.currentTimeMillis() - this.animationStartedAt);
for (int i = 0; i < CHOICES.length; ++i) {
this.drawChoice(graphics, CHOICES[i], this.cardRects[i], this.cardRects[i].contains(mouseX, mouseY));
this.drawChoice(graphics, CHOICES[i], this.cardRects[i], this.cardRects[i].contains(mouseX, mouseY), elapsed);
}
if (this.resetAnimationTimer) {
this.animationStartedAt = System.currentTimeMillis();
this.resetAnimationTimer = false;
}
}
@@ -77,17 +84,17 @@ public class FirstTimeScreen extends Screen {
this.onClose();
}
private void drawChoice(GuiGraphics graphics, Choice choice, Rect rect, boolean hovered) {
private void drawChoice(GuiGraphics graphics, Choice choice, Rect rect, boolean hovered, long elapsedMillis) {
int imageX = rect.x;
int imageY = rect.y;
int imageW = rect.w;
int imageH = rect.w * FRAME_HEIGHT / FRAME_WIDTH;
graphics.fill(imageX - 6, imageY - 6, imageX + imageW + 6, imageY + imageH + 6, hovered ? BORDER_HOVER : BORDER);
this.drawSheetFrame(graphics, choice.texture, choice.currentFrame(65L), imageX, imageY, imageW, imageH);
this.drawSheetFrame(graphics, choice, choice.currentFrame(elapsedMillis, 65L), imageX, imageY, imageW, imageH);
graphics.drawCenteredString(this.font, Component.literal(choice.label), imageX + imageW / 2, imageY + imageH + 16, 0xFFFFFFFF);
}
private void drawSheetFrame(GuiGraphics graphics, ResourceLocation texture, int frame, int x, int y, int width, int height) {
private void drawSheetFrame(GuiGraphics graphics, Choice choice, int frame, int x, int y, int width, int height) {
int clamped = Math.max(0, Math.min(frame, FRAME_COUNT - 1));
int u = clamped % COLUMNS * FRAME_WIDTH;
int v = clamped / COLUMNS * FRAME_HEIGHT;
@@ -96,7 +103,7 @@ public class FirstTimeScreen extends Screen {
graphics.pose().pushPose();
graphics.pose().translate(x, y, 0.0F);
graphics.pose().scale(scaleX, scaleY, 1.0F);
graphics.blit(texture, 0, 0, (float)u, (float)v, FRAME_WIDTH, FRAME_HEIGHT, FRAME_WIDTH * COLUMNS, FRAME_HEIGHT * ROWS);
graphics.blit(choice.texture, 0, 0, (float)u, (float)v, FRAME_WIDTH, FRAME_HEIGHT, FRAME_WIDTH * COLUMNS, FRAME_HEIGHT * ROWS);
graphics.pose().popPose();
}
@@ -129,9 +136,9 @@ public class FirstTimeScreen extends Screen {
this.mode = mode;
}
private int currentFrame(long frameTimeMillis) {
private int currentFrame(long elapsedMillis, long frameTimeMillis) {
int span = Math.max(1, this.lastFrameExclusive - this.firstFrame);
return this.firstFrame + (int)((System.currentTimeMillis() / frameTimeMillis) % span);
return this.firstFrame + (int)((elapsedMillis / frameTimeMillis) % span);
}
}

View File

@@ -25,6 +25,8 @@ public class GuideSlidesScreen extends Screen {
};
private int slideIndex;
private long slideStartedAt;
private boolean resetSlideTimer = true;
private Rect leftArrow = Rect.empty();
private Rect rightArrow = Rect.empty();
private Rect skipButton = Rect.empty();
@@ -48,7 +50,12 @@ public class GuideSlidesScreen extends Screen {
graphics.fill(imageX - 8, imageY - 8, imageX + imageW + 8, imageY + imageH + 8, 0xFF1E1205);
graphics.fill(imageX - 4, imageY - 4, imageX + imageW + 4, imageY + imageH + 4, 0xFF3D270E);
Slide slide = SLIDES[this.slideIndex];
this.drawSheetFrame(graphics, slide.texture, this.currentFrame(slide.frameCount, 55L), imageX, imageY, imageW, imageH);
int frame = this.resetSlideTimer ? 0 : this.currentFrame(slide.frameCount, 55L);
this.drawSheetFrame(graphics, slide.texture, frame, imageX, imageY, imageW, imageH);
if (this.resetSlideTimer) {
this.slideStartedAt = System.currentTimeMillis();
this.resetSlideTimer = false;
}
int textWidth = Math.min(this.width - 300, 920);
int textY = imageY + imageH + 24;
@@ -81,10 +88,12 @@ public class GuideSlidesScreen extends Screen {
}
if (this.slideIndex > 0 && this.leftArrow.contains(mouseX, mouseY)) {
--this.slideIndex;
this.resetAnimationTimer();
return true;
}
if (this.slideIndex < SLIDES.length - 1 && this.rightArrow.contains(mouseX, mouseY)) {
++this.slideIndex;
this.resetAnimationTimer();
return true;
}
}
@@ -97,6 +106,10 @@ public class GuideSlidesScreen extends Screen {
}
}
private void resetAnimationTimer() {
this.resetSlideTimer = true;
}
private void drawSheetFrame(GuiGraphics graphics, ResourceLocation texture, int frame, int x, int y, int width, int height) {
int clamped = Math.max(0, Math.min(frame, FRAME_COUNT - 1));
int u = clamped % COLUMNS * FRAME_WIDTH;
@@ -112,7 +125,8 @@ public class GuideSlidesScreen extends Screen {
private int currentFrame(int frameCount, long frameTimeMillis) {
int maxFrame = Math.max(1, Math.min(frameCount, FRAME_COUNT));
return (int)((System.currentTimeMillis() / frameTimeMillis) % maxFrame);
long elapsed = Math.max(0L, System.currentTimeMillis() - this.slideStartedAt);
return (int)((elapsed / frameTimeMillis) % maxFrame);
}
private int drawCenteredWrappedText(GuiGraphics graphics, String text, int centerX, int y, int maxWidth, int color) {