Skip to content

Commit 96113ac

Browse files
authored
fix: benchmark toast resizing (#99)
Line wrap the content if it doesn't fit.
1 parent 7746c93 commit 96113ac

1 file changed

Lines changed: 38 additions & 5 deletions

File tree

src/main/java/me/contaria/seedqueue/gui/wall/SeedQueueBenchmarkToast.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package me.contaria.seedqueue.gui.wall;
22

33
import me.contaria.speedrunapi.util.TextUtil;
4+
import net.minecraft.client.font.TextRenderer;
45
import net.minecraft.client.toast.Toast;
56
import net.minecraft.client.toast.ToastManager;
67
import net.minecraft.client.util.math.MatrixStack;
8+
import net.minecraft.text.StringRenderable;
79
import net.minecraft.text.Text;
810
import net.minecraft.util.Util;
911

12+
import java.util.List;
13+
1014
public class SeedQueueBenchmarkToast implements Toast {
1115
private final SeedQueueWallScreen wall;
1216
private final Text title;
@@ -21,10 +25,6 @@ public SeedQueueBenchmarkToast(SeedQueueWallScreen wall) {
2125

2226
@Override
2327
public Visibility draw(MatrixStack matrices, ToastManager manager, long startTime) {
24-
manager.getGame().getTextureManager().bindTexture(TOASTS_TEX);
25-
manager.drawTexture(matrices, 0, 0, 0, 0, this.getWidth(), this.getHeight());
26-
manager.getGame().textRenderer.draw(matrices, this.title, 7.0f, 7.0f, 0xFFFF00 | 0xFF000000);
27-
2828
this.finished |= !this.wall.isBenchmarking();
2929

3030
if (this.finished && !this.fadeOut && !this.wall.showFinishedBenchmarkResults) {
@@ -33,7 +33,40 @@ public Visibility draw(MatrixStack matrices, ToastManager manager, long startTim
3333

3434
double time = (this.finished ? this.wall.benchmarkFinish : Util.getMeasuringTimeMs()) - this.wall.benchmarkStart;
3535
double rps = Math.round(this.wall.benchmarkedSeeds / (time / 10000.0)) / 10.0;
36-
manager.getGame().textRenderer.draw(matrices, TextUtil.translatable("seedqueue.menu.benchmark.result", this.wall.benchmarkedSeeds, Math.round(time / 1000.0), rps), 7.0f, 18.0f, -1);
36+
37+
TextRenderer textRenderer = manager.getGame().textRenderer;
38+
39+
StringRenderable full = TextUtil.translatable(
40+
"seedqueue.menu.benchmark.result",
41+
this.wall.benchmarkedSeeds,
42+
Math.round(time / 1000.0),
43+
rps
44+
);
45+
46+
List<StringRenderable> lines = textRenderer.wrapLines(full, this.getWidth() - 12);
47+
48+
manager.getGame().getTextureManager().bindTexture(TOASTS_TEX);
49+
50+
// Top of the toast texture
51+
manager.drawTexture(matrices, 0, 0, 0, 0, this.getWidth(), 16);
52+
53+
// Center
54+
int textureY = 16;
55+
for (int i = 0; i < lines.size(); i++) {
56+
manager.drawTexture(matrices, 0, textureY, 0, 16, this.getWidth(), textRenderer.fontHeight + 2);
57+
textureY += textRenderer.fontHeight + 2;
58+
}
59+
60+
// Bottom
61+
manager.drawTexture(matrices, 0, textureY, 0, 28, this.getWidth(), 4);
62+
63+
textRenderer.draw(matrices, this.title, 7.0f, 7.0f, 0xFFFF00 | 0xFF000000);
64+
65+
float currentY = 18.0f;
66+
for (StringRenderable line : lines) {
67+
textRenderer.draw(matrices, line, 7.0f, currentY, -1);
68+
currentY += textRenderer.fontHeight + 2;
69+
}
3770

3871
return this.fadeOut ? Visibility.HIDE : Visibility.SHOW;
3972
}

0 commit comments

Comments
 (0)