From de60b15d2b2e36c5a987511343129000ec83f59a Mon Sep 17 00:00:00 2001 From: coolGi Date: Fri, 18 Nov 2022 19:12:25 +1030 Subject: [PATCH] Added the ChangelogScreen. New changelog screen done --- .../common/wrappers/gui/ClassicConfigGUI.java | 2 +- .../wrappers/gui/updater/ChangelogScreen.java | 117 ++++++++++++++++-- .../wrappers/gui/updater/UpdateModScreen.java | 11 +- .../lod/mixins/client/MixinMinecraft.java | 2 +- .../lod/mixins/client/MixinMinecraft.java | 2 +- 5 files changed, 117 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/gui/ClassicConfigGUI.java b/common/src/main/java/com/seibel/lod/common/wrappers/gui/ClassicConfigGUI.java index 272a7d12c..c9f557af6 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/gui/ClassicConfigGUI.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/gui/ClassicConfigGUI.java @@ -281,7 +281,7 @@ public abstract class ClassicConfigGUI { drawCenteredString(matrices, font, title, width / 2, 15, 0xFFFFFF); // Render title // Render the tooltip only if it can find a tooltip in the language file - for (AbstractConfigType info : ConfigBase.INSTANCE.entries) { // idk why this is using the normal entries but as long as it works, it works + for (AbstractConfigType info : ConfigBase.INSTANCE.entries) { if (info.getCategory().matches(category) && info.getAppearance().showInGui) { if (list.getHoveredButton(mouseX, mouseY).isPresent()) { AbstractWidget buttonWidget = list.getHoveredButton(mouseX, mouseY).get(); diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/gui/updater/ChangelogScreen.java b/common/src/main/java/com/seibel/lod/common/wrappers/gui/updater/ChangelogScreen.java index cfe32d491..31df00cbe 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/gui/updater/ChangelogScreen.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/gui/updater/ChangelogScreen.java @@ -1,21 +1,35 @@ package com.seibel.lod.common.wrappers.gui.updater; +import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.NativeImage; import com.mojang.blaze3d.vertex.PoseStack; -import com.seibel.lod.common.wrappers.gui.TexturedButtonWidget; +import com.seibel.lod.common.wrappers.gui.ClassicConfigGUI; import com.seibel.lod.core.ModInfo; import com.seibel.lod.core.config.Config; import com.seibel.lod.core.jar.JarUtils; +import com.seibel.lod.core.jar.installer.MarkdownFormatter; +import com.seibel.lod.core.jar.installer.ModrinthGetter; import com.seibel.lod.core.jar.updater.SelfUpdater; import net.minecraft.client.Minecraft; +import net.minecraft.client.StringSplitter; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.ContainerObjectSelectionList; import net.minecraft.client.gui.components.ImageButton; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.FormattedText; +import net.minecraft.network.chat.Style; import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.FormattedCharSequence; -import java.util.Objects; +import java.util.*; /** * The screen that pops up if the mod has an update. @@ -26,13 +40,30 @@ import java.util.Objects; // TODO: Make this public class ChangelogScreen extends Screen { private Screen parent; - private String version; + private String versionID; + private List changelog; + private TextArea changelogArea; - public ChangelogScreen(Screen parent, String version) { + public ChangelogScreen(Screen parent, String versionID) { super(translate(ModInfo.ID + ".updater.title")); this.parent = parent; - this.version = version; + this.versionID = versionID; + + this.changelog = new ArrayList<>(); + // Get the release changelog and split it by the new lines + List unwrappedChangelog = + List.of(new MarkdownFormatter.MinecraftFormat().convertTo( // This formats markdown to minecraft's "ยง" characters + ModrinthGetter.changeLogs.get(versionID) + ).split("\\n")); + // Makes the words wrap around to not go off the screen + for (String str: unwrappedChangelog) { + this.changelog.addAll( + MarkdownFormatter.splitString(str, 75) + ); + } + // Debugging +// System.out.println(this.changelog); } @Override @@ -46,17 +77,29 @@ public class ChangelogScreen extends Screen { }) ); + + this.changelogArea = new TextArea(this.minecraft, this.width*2, this.height, 32, this.height - 32, 10); + for (int i = 0; i < changelog.size(); i++) { + this.changelogArea.addButton(new TextComponent(changelog.get(i))); +// drawString(matrices, this.font, changelog.get(i), this.width / 2 - 175, this.height / 2 - 100 + i*10, 0xFFFFFF); + } + } @Override public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { this.renderBackground(matrices); // Render background + // Set the scroll position to the mouse height relative to the screen + this.changelogArea.setScrollAmount( + ((double) mouseY)/((double) this.height) * this.changelogArea.getMaxScroll() + ); - // Render the text - drawCenteredString(matrices, this.font, new TextComponent("Some changelog thing\nIsn't done yet so pls wait"), this.width / 2, this.height / 2 - 35, 0xFFFFFF); + this.changelogArea.render(matrices, mouseX, mouseY, delta); // Render the changelog super.render(matrices, mouseX, mouseY, delta); // Render the buttons + + drawCenteredString(matrices, font, title, width / 2, 15, 0xFFFFFF); // Render title } @Override @@ -65,8 +108,6 @@ public class ChangelogScreen extends Screen { } - - // addRenderableWidget in 1.17 and over // addButton in 1.16 and below private void addBtn(Button button) { @@ -86,4 +127,62 @@ public class ChangelogScreen extends Screen { return net.minecraft.network.chat.Component.translatable(str, args); } #endif + + + + + + + + + + + public static class TextArea extends ContainerObjectSelectionList { + Font textRenderer; + + public TextArea(Minecraft minecraftClient, int i, int j, int k, int l, int m) { + super(minecraftClient, i, j, k, l, m); + this.centerListVertically = false; + textRenderer = minecraftClient.font; + } + + public void addButton(Component text) { + this.addEntry(ButtonEntry.create(text)); + } + + @Override + public int getRowWidth() { + return 10000; + } + } + + public static class ButtonEntry extends ContainerObjectSelectionList.Entry { + private static final Font textRenderer = Minecraft.getInstance().font; + private final Component text; + private final List children = new ArrayList<>(); + + private ButtonEntry(Component text) { + this.text = text; + } + + public static ButtonEntry create(Component text) { + return new ButtonEntry(text); + } + + @Override + public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + GuiComponent.drawString(matrices, textRenderer, text, 12, y + 5, 0xFFFFFF); + } + + @Override + public List children() { + return children; + } + #if POST_MC_1_17_1 + @Override + public List narratables() { + return children; + } + #endif + } } \ No newline at end of file diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/gui/updater/UpdateModScreen.java b/common/src/main/java/com/seibel/lod/common/wrappers/gui/updater/UpdateModScreen.java index 80d34d081..b91b2ca6d 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/gui/updater/UpdateModScreen.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/gui/updater/UpdateModScreen.java @@ -6,6 +6,7 @@ import com.seibel.lod.common.wrappers.gui.TexturedButtonWidget; import com.seibel.lod.core.ModInfo; import com.seibel.lod.core.config.Config; import com.seibel.lod.core.jar.JarUtils; +import com.seibel.lod.core.jar.installer.ModrinthGetter; import com.seibel.lod.core.jar.updater.SelfUpdater; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.Button; @@ -25,13 +26,13 @@ import java.util.*; // and also maybe add this suggestion https://discord.com/channels/881614130614767666/1035863487110467625/1035949054485594192 public class UpdateModScreen extends Screen { private Screen parent; - private String newVersion; + private String newVersionID; - public UpdateModScreen(Screen parent, String newVersion) { + public UpdateModScreen(Screen parent, String newVersionID) { super(translate(ModInfo.ID + ".updater.title")); this.parent = parent; - this.newVersion = newVersion; + this.newVersionID = newVersionID; } @Override @@ -79,7 +80,7 @@ public class UpdateModScreen extends Screen { 0, new ResourceLocation(ModInfo.ID, "textures/gui/changelog.png"), 20, 20, // Create the button and tell it where to go // For now it goes to the client option by default - (buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(new ChangelogScreen(this, this.newVersion)), // TODO: Add a proper easter egg to pressing the logo (maybe with confetti) + (buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(new ChangelogScreen(this, this.newVersionID)), // TODO: Add a proper easter egg to pressing the logo (maybe with confetti) // Add a title to the button translate(ModInfo.ID + ".updater.title") )); @@ -120,7 +121,7 @@ public class UpdateModScreen extends Screen { // Render the text's drawCenteredString(matrices, this.font, translate(ModInfo.ID + ".updater.text1"), this.width / 2, this.height / 2 - 35, 0xFFFFFF); - drawCenteredString(matrices, this.font, translate(ModInfo.ID + ".updater.text2", ModInfo.VERSION, this.newVersion), this.width / 2, this.height / 2 -20, 0x52FD52); + drawCenteredString(matrices, this.font, translate(ModInfo.ID + ".updater.text2", ModInfo.VERSION, ModrinthGetter.releaseNames.get(this.newVersionID)), this.width / 2, this.height / 2 -20, 0x52FD52); // TODO: add the tooltips for the buttons super.render(matrices, mouseX, mouseY, delta); // Render the buttons diff --git a/fabric/src/main/java/com/seibel/lod/mixins/client/MixinMinecraft.java b/fabric/src/main/java/com/seibel/lod/mixins/client/MixinMinecraft.java index db16cdaa7..6741eec00 100644 --- a/fabric/src/main/java/com/seibel/lod/mixins/client/MixinMinecraft.java +++ b/fabric/src/main/java/com/seibel/lod/mixins/client/MixinMinecraft.java @@ -34,7 +34,7 @@ public class MixinMinecraft if (SelfUpdater.onStart()) { instance.setScreen(new UpdateModScreen( new TitleScreen(false), // We don't want to use the vanilla title screen as it would fade the buttons - ModrinthGetter.getLatestNameForVersion(SingletonInjector.INSTANCE.get(IVersionConstants.class).getMinecraftVersion()) + ModrinthGetter.getLatestIDForVersion(SingletonInjector.INSTANCE.get(IVersionConstants.class).getMinecraftVersion()) )); } else { instance.setScreen(guiScreen); // Sets the screen back to the vanilla screen as if nothing ever happened diff --git a/forge/src/main/java/com/seibel/lod/mixins/client/MixinMinecraft.java b/forge/src/main/java/com/seibel/lod/mixins/client/MixinMinecraft.java index 4afdd056d..1cf4923ab 100644 --- a/forge/src/main/java/com/seibel/lod/mixins/client/MixinMinecraft.java +++ b/forge/src/main/java/com/seibel/lod/mixins/client/MixinMinecraft.java @@ -34,7 +34,7 @@ public class MixinMinecraft if (SelfUpdater.onStart()) { instance.setScreen(new UpdateModScreen( new TitleScreen(false), // We don't want to use the vanilla title screen as it would fade the buttons - ModrinthGetter.getLatestNameForVersion(SingletonInjector.INSTANCE.get(IVersionConstants.class).getMinecraftVersion()) + ModrinthGetter.getLatestIDForVersion(SingletonInjector.INSTANCE.get(IVersionConstants.class).getMinecraftVersion()) )); } else { instance.setScreen(guiScreen); // Sets the screen back to the vanilla screen as if nothing ever happened