Merge branch 'main' of gitlab.com:jeseibel/minecraft-lod-mod
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
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.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.*;
|
||||
|
||||
/**
|
||||
* The screen that pops up if the mod has an update.
|
||||
*
|
||||
* @author coolGi
|
||||
*/
|
||||
// TODO: After finishing the config, rewrite this in openGL as well
|
||||
// TODO: Make this
|
||||
public class ChangelogScreen extends Screen {
|
||||
private Screen parent;
|
||||
private String versionID;
|
||||
private List<String> changelog;
|
||||
private TextArea changelogArea;
|
||||
|
||||
|
||||
public ChangelogScreen(Screen parent, String versionID) {
|
||||
super(translate(ModInfo.ID + ".updater.title"));
|
||||
this.parent = parent;
|
||||
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
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
|
||||
this.addBtn( // Close
|
||||
new Button(5, this.height - 25, 100, 20, translate(ModInfo.ID + ".general.back"), (btn) -> {
|
||||
this.onClose();
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
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()
|
||||
);
|
||||
|
||||
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
|
||||
public void onClose() {
|
||||
Objects.requireNonNull(minecraft).setScreen(this.parent); // Goto the parent screen
|
||||
}
|
||||
|
||||
|
||||
// addRenderableWidget in 1.17 and over
|
||||
// addButton in 1.16 and below
|
||||
private void addBtn(Button button) {
|
||||
#if PRE_MC_1_17_1
|
||||
this.addButton(button);
|
||||
#else
|
||||
this.addRenderableWidget(button);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if PRE_MC_1_19
|
||||
public static net.minecraft.network.chat.TranslatableComponent translate (String str, Object... args) {
|
||||
return new net.minecraft.network.chat.TranslatableComponent(str, args);
|
||||
}
|
||||
#else
|
||||
public static net.minecraft.network.chat.MutableComponent translate (String str, Object... args) {
|
||||
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
|
||||
}
|
||||
}
|
||||
+37
-17
@@ -1,10 +1,12 @@
|
||||
package com.seibel.lod.common.wrappers.gui;
|
||||
package com.seibel.lod.common.wrappers.gui.updater;
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
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;
|
||||
@@ -24,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
|
||||
@@ -48,15 +50,16 @@ public class UpdateModScreen extends Screen {
|
||||
);
|
||||
|
||||
|
||||
// Logo image
|
||||
this.addBtn(new ImageButton(
|
||||
// Where the button is on the screen
|
||||
this.width / 2 - 100, this.height / 2 - 110,
|
||||
this.width / 2 - 65, this.height / 2 - 110,
|
||||
// Width and height of the button
|
||||
200, 100,
|
||||
130, 65,
|
||||
// Offset
|
||||
0, 0,
|
||||
// Some textuary stuff
|
||||
0, logoLocation, 200, 100,
|
||||
0, logoLocation, 130, 65,
|
||||
// Create the button and tell it where to go
|
||||
// For now it goes to the client option by default
|
||||
(buttonWidget) -> System.out.println("Nice, you found an easter egg :)"), // TODO: Add a proper easter egg to pressing the logo (maybe with confetti)
|
||||
@@ -66,27 +69,44 @@ public class UpdateModScreen extends Screen {
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
|
||||
|
||||
this.addBtn(
|
||||
new Button(this.width / 2 - 155, this.height / 2 + 40, 150, 20, translate(ModInfo.ID + ".updater.update"), (btn) -> {
|
||||
this.addBtn(new TexturedButtonWidget(
|
||||
// Where the button is on the screen
|
||||
this.width / 2 - 97, this.height / 2 + 8,
|
||||
// Width and height of the button
|
||||
20, 20,
|
||||
// Offset
|
||||
0, 0,
|
||||
// Some textuary stuff
|
||||
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.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")
|
||||
));
|
||||
|
||||
|
||||
this.addBtn( // Update
|
||||
new Button(this.width / 2 - 75, this.height / 2 + 8, 150, 20, translate(ModInfo.ID + ".updater.update"), (btn) -> {
|
||||
SelfUpdater.deleteOldOnClose = true;
|
||||
SelfUpdater.updateMod();
|
||||
this.onClose();
|
||||
})
|
||||
);
|
||||
this.addBtn(
|
||||
new Button(this.width / 2 + 5, this.height / 2 + 40, 150, 20, translate(ModInfo.ID + ".updater.silent"), (btn) -> {
|
||||
this.addBtn( // Silent update
|
||||
new Button(this.width / 2 - 75, this.height / 2 + 30, 150, 20, translate(ModInfo.ID + ".updater.silent"), (btn) -> {
|
||||
Config.Client.AutoUpdater.promptForUpdate.set(false);
|
||||
SelfUpdater.updateMod();
|
||||
this.onClose();
|
||||
})
|
||||
);
|
||||
this.addBtn(
|
||||
new Button(this.width / 2 - 155, this.height / 2 + 65, 150, 20, translate(ModInfo.ID + ".updater.later"), (btn) -> {
|
||||
this.addBtn( // Later (not now)
|
||||
new Button(this.width / 2 + 2, this.height / 2 + 70, 100, 20, translate(ModInfo.ID + ".updater.later"), (btn) -> {
|
||||
this.onClose();
|
||||
})
|
||||
);
|
||||
this.addBtn(
|
||||
new Button(this.width / 2 + 5, this.height / 2 + 65, 150, 20, translate(ModInfo.ID + ".updater.never"), (btn) -> {
|
||||
this.addBtn( // Never
|
||||
new Button(this.width / 2 - 102, this.height / 2 + 70, 100, 20, translate(ModInfo.ID + ".updater.never"), (btn) -> {
|
||||
Config.Client.AutoUpdater.enableAutoUpdater.set(false);
|
||||
this.onClose();
|
||||
})
|
||||
@@ -100,8 +120,8 @@ public class UpdateModScreen extends Screen {
|
||||
|
||||
|
||||
// Render the text's
|
||||
drawCenteredString(matrices, this.font, translate(ModInfo.ID + ".updater.text1"), this.width / 2, this.height / 2, 0xFFFFFF);
|
||||
drawCenteredString(matrices, this.font, translate(ModInfo.ID + ".updater.text2", ModInfo.VERSION, this.newVersion), this.width / 2, this.height / 2 + 15, 0x52FD52);
|
||||
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, 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
|
||||
+1
-1
Submodule coreSubProjects updated: 0249894386...2ce8692d84
@@ -1,6 +1,6 @@
|
||||
package com.seibel.lod.mixins.client;
|
||||
|
||||
import com.seibel.lod.common.wrappers.gui.UpdateModScreen;
|
||||
import com.seibel.lod.common.wrappers.gui.updater.UpdateModScreen;
|
||||
import com.seibel.lod.core.config.Config;
|
||||
import com.seibel.lod.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.lod.core.jar.installer.ModrinthGetter;
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.seibel.lod.mixins.client;
|
||||
|
||||
import com.seibel.lod.common.wrappers.gui.UpdateModScreen;
|
||||
import com.seibel.lod.common.wrappers.gui.updater.UpdateModScreen;
|
||||
import com.seibel.lod.core.config.Config;
|
||||
import com.seibel.lod.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.lod.core.jar.installer.ModrinthGetter;
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user