Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions src/main/java/me/contaria/seedqueue/customization/Layout.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.io.InputStreamReader;
import java.io.Reader;
import java.math.BigDecimal;
Expand All @@ -21,16 +23,19 @@ public class Layout {
public final Group locked;
public final Group[] preparing;
public final boolean replaceLockedInstances;
@Nullable
public final CustomTextObject[] customTextObjects;

private Layout(@NotNull Group main) {
this(main, null, new Group[0], true);
this(main, null, new Group[0], true, null);
}

private Layout(@NotNull Group main, @Nullable Group locked, Group[] preparing, boolean replaceLockedInstances) {
private Layout(@NotNull Group main, @Nullable Group locked, Group[] preparing, boolean replaceLockedInstances, @Nullable CustomTextObject[] customTextObjects) {
this.main = main;
this.locked = locked;
this.preparing = preparing;
this.replaceLockedInstances = replaceLockedInstances;
this.customTextObjects = customTextObjects;

if (this.main.cosmetic) {
throw new IllegalArgumentException("Main Group may not be cosmetic!");
Expand Down Expand Up @@ -62,6 +67,10 @@ private static int getAsInt(JsonObject jsonObject, String name, int windowSize)
return jsonPrimitive.getAsInt();
}

private static int getColor(JsonObject jsonObject) {
return Integer.parseInt(jsonObject.get("color").getAsString(), 16);
}

private static Layout grid(int rows, int columns, int width, int height) {
return new Layout(Group.grid(rows, columns, 0, 0, width, height, 0, false, true));
}
Expand All @@ -71,7 +80,8 @@ private static Layout fromJson(JsonObject jsonObject) throws JsonParseException
Group.fromJson(jsonObject.getAsJsonObject("main"), SeedQueue.config.rows, SeedQueue.config.columns),
jsonObject.has("locked") ? Group.fromJson(jsonObject.getAsJsonObject("locked")) : null,
jsonObject.has("preparing") ? Group.fromJson(jsonObject.getAsJsonArray("preparing")) : new Group[0],
jsonObject.has("replaceLockedInstances") && jsonObject.get("replaceLockedInstances").getAsBoolean()
jsonObject.has("replaceLockedInstances") && jsonObject.get("replaceLockedInstances").getAsBoolean(),
jsonObject.has("customTextObjects") ? CustomTextObject.fromJson(jsonObject.getAsJsonArray("customTextObjects")) : null
);
}

Expand Down Expand Up @@ -192,4 +202,38 @@ private static Pos fromJson(JsonObject jsonObject) throws JsonParseException {
);
}
}

public static class CustomTextObject {
public final Pos pos;
public final int color;
public final float lineSpacing;
public final boolean shadow;
public final Path path;

CustomTextObject(Pos pos, int color, float lineSpacing, boolean shadow, Path path) {
this.pos = pos;
this.color = color;
this.lineSpacing = lineSpacing;
this.shadow = shadow;
this.path = path;
}

private static CustomTextObject[] fromJson(JsonArray jsonArray) {
CustomTextObject[] textObjects = new CustomTextObject[jsonArray.size()];
for (int i = 0; i < jsonArray.size(); i++) {
textObjects[i] = CustomTextObject.fromJson(jsonArray.get(i).getAsJsonObject());
}
return textObjects;
}

private static CustomTextObject fromJson(JsonObject jsonObject) throws JsonParseException {
return new CustomTextObject(
Pos.fromJson(jsonObject),
getColor(jsonObject),
jsonObject.has("lineSpacing") ? jsonObject.get("lineSpacing").getAsFloat() : 9.0f,
jsonObject.has("shadow") && jsonObject.get("shadow").getAsBoolean(),
Paths.get(jsonObject.get("path").getAsString())
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@
import net.minecraft.client.gui.hud.DebugHud;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.render.BufferBuilderStorage;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.*;
import net.minecraft.client.util.Window;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.sound.SoundEvent;
import net.minecraft.text.LiteralText;
import net.minecraft.text.StringRenderable;
import net.minecraft.util.Identifier;
import org.apache.commons.lang3.ArrayUtils;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;

import java.nio.file.Files;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

public class SeedQueueWallScreen extends Screen {
private static final Set<WorldRenderer> WORLD_RENDERERS = new HashSet<>();
Expand Down Expand Up @@ -156,6 +159,13 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
SeedQueueProfiler.pop();
}

if (this.layout.customTextObjects != null) {
SeedQueueProfiler.swap("draw_text");
for (Layout.CustomTextObject customTextObject : this.layout.customTextObjects) {
this.drawCustomTextObject(matrices, Objects.requireNonNull(customTextObject));
}
}

SeedQueueProfiler.swap("reset");
this.resetViewport();
this.loadPreviewSettings(this.settingsCache, 0);
Expand Down Expand Up @@ -248,6 +258,24 @@ private void drawAnimatedTexture(AnimatedTexture texture, MatrixStack matrices,
RenderSystem.disableBlend();
}

private void drawCustomTextObject(MatrixStack matrices, Layout.CustomTextObject customTextObject) {
assert this.client != null;
try {
List<StringRenderable> lines = Files.readAllLines(customTextObject.path).stream().map(StringRenderable::plain).collect(Collectors.toList());
this.setViewport(customTextObject.pos);
for (int i = 0; i < lines.size(); i++) {
if (customTextObject.shadow) {
this.client.textRenderer.drawWithShadow(matrices, lines.get(i), 0, customTextObject.lineSpacing * i, customTextObject.color);
} else {
this.client.textRenderer.draw(matrices, lines.get(i), 0, customTextObject.lineSpacing * i, customTextObject.color);
}
}
this.resetViewport();
} catch (IOException e) {
SeedQueue.LOGGER.warn("File {} failed to be read", customTextObject.path);
}
}

private boolean playSound(SoundEvent sound) {
// spread out reset sounds over multiple ticks
if (sound == SeedQueueSounds.RESET_INSTANCE) {
Expand Down