Added the ChangelogScreen. New changelog screen done

This commit is contained in:
coolGi
2022-11-18 19:12:25 +10:30
parent 7c5ffe3f10
commit de60b15d2b
5 changed files with 117 additions and 17 deletions
@@ -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();
@@ -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<String> 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<String> 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<ButtonEntry> {
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<ButtonEntry> {
private static final Font textRenderer = Minecraft.getInstance().font;
private final Component text;
private final List<AbstractWidget> 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<? extends GuiEventListener> children() {
return children;
}
#if POST_MC_1_17_1
@Override
public List<? extends NarratableEntry> narratables() {
return children;
}
#endif
}
}
@@ -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
@@ -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
@@ -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