diff options
author | Roman / Nea <roman.graef@gmail.com> | 2022-07-14 19:57:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-14 19:57:37 +0200 |
commit | 6489385cabc021cc36b487151b5d6c85d7617390 (patch) | |
tree | 37370f9e12f20961cc11f216841ea1420bdcc90b /src/main/java/io | |
parent | 36be173ff0505942fd9b54a39f64b703f1510d9e (diff) | |
download | NotEnoughUpdates-6489385cabc021cc36b487151b5d6c85d7617390.tar.gz NotEnoughUpdates-6489385cabc021cc36b487151b5d6c85d7617390.tar.bz2 NotEnoughUpdates-6489385cabc021cc36b487151b5d6c85d7617390.zip |
Various fixes regarding finalizing the release ig (#186)
* Fix Sign calc not aligning properly with the GuiEditSign
* "Fix" official wiki rendering.
This one didnt receive extensive testing, but so far it works
* Update notification changes
* Dont reset the config lol
Diffstat (limited to 'src/main/java/io')
7 files changed, 94 insertions, 93 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 3ef305f2..76387844 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -34,7 +34,6 @@ import io.github.moulberry.notenoughupdates.listener.NEUEventListener; import io.github.moulberry.notenoughupdates.listener.OldAnimationChecker; import io.github.moulberry.notenoughupdates.listener.RenderListener; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionProfit; -import io.github.moulberry.notenoughupdates.miscfeatures.CookieWarning; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalWishingCompassSolver; import io.github.moulberry.notenoughupdates.miscfeatures.CustomItemEffects; @@ -70,6 +69,7 @@ import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.util.XPInformation; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.IReloadableResourceManager; import net.minecraft.client.settings.KeyBinding; @@ -108,9 +108,9 @@ import java.util.Set; public class NotEnoughUpdates { public static final String MODID = "notenoughupdates"; public static final String VERSION = "2.1.0-REL"; - public static final String PRE_VERSION = "0.0"; - public static final int VERSION_ID = 20100; + public static final int VERSION_ID = 20200; public static final int PRE_VERSION_ID = 0; + public static final int HOTFIX_VERSION_ID = 1; /** * Registers the biomes for the crystal hollows here so optifine knows they exists */ @@ -215,7 +215,8 @@ public class NotEnoughUpdates { )) ) { config = gson.fromJson(reader, NEUConfig.class); - } catch (Exception ignored) { + } catch (Exception exc) { + new RuntimeException("Invalid config file. This will reset the config to default", exc).printStackTrace(); } } @@ -371,11 +372,10 @@ public class NotEnoughUpdates { } } - public void displayLinks(JsonObject update) { + public void displayLinks(JsonObject update, int totalWidth) { String discord_link = update.get("discord_link").getAsString(); String youtube_link = update.get("youtube_link").getAsString(); String twitch_link = update.get("twitch_link").getAsString(); - String update_link = update.get("update_link").getAsString(); String github_link = update.get("github_link").getAsString(); String other_text = update.get("other_text").getAsString(); String other_link = update.get("other_link").getAsString(); @@ -388,8 +388,7 @@ public class NotEnoughUpdates { } ChatComponentText links = new ChatComponentText(""); ChatComponentText separator = new ChatComponentText( - EnumChatFormatting.GRAY + EnumChatFormatting.BOLD.toString() + EnumChatFormatting.STRIKETHROUGH + - (other == null ? "--" : "-")); + EnumChatFormatting.GRAY + EnumChatFormatting.BOLD.toString() + EnumChatFormatting.STRIKETHROUGH + "-"); ChatComponentText discord = new ChatComponentText( EnumChatFormatting.GRAY + "[" + EnumChatFormatting.BLUE + "Discord" + EnumChatFormatting.GRAY + "]"); discord.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, discord_link)); @@ -399,9 +398,6 @@ public class NotEnoughUpdates { ChatComponentText twitch = new ChatComponentText( EnumChatFormatting.GRAY + "[" + EnumChatFormatting.DARK_PURPLE + "Twitch" + EnumChatFormatting.GRAY + "]"); twitch.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, twitch_link)); - ChatComponentText release = new ChatComponentText( - EnumChatFormatting.GRAY + "[" + EnumChatFormatting.GREEN + "Release" + EnumChatFormatting.GRAY + "]"); - release.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, update_link)); ChatComponentText github = new ChatComponentText( EnumChatFormatting.GRAY + "[" + EnumChatFormatting.DARK_PURPLE + "GitHub" + EnumChatFormatting.GRAY + "]"); github.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, github_link)); @@ -413,16 +409,28 @@ public class NotEnoughUpdates { links.appendSibling(separator); links.appendSibling(twitch); links.appendSibling(separator); - links.appendSibling(release); - links.appendSibling(separator); links.appendSibling(github); links.appendSibling(separator); if (other != null) { links.appendSibling(other); links.appendSibling(separator); } - - Minecraft.getMinecraft().thePlayer.addChatMessage(links); + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int missingWidth = Math.max(0, totalWidth - fr.getStringWidth(links.getFormattedText())); + int missingCharsOnEitherSide = missingWidth / fr.getStringWidth(EnumChatFormatting.BOLD + "-") / 2; + StringBuilder sb = new StringBuilder(missingCharsOnEitherSide + 6); + sb.append(EnumChatFormatting.GRAY); + sb.append(EnumChatFormatting.BOLD); + sb.append(EnumChatFormatting.STRIKETHROUGH); + for (int i = 0; i < missingCharsOnEitherSide; i++) { + sb.append("-"); + } + String padding = sb.toString(); + ChatComponentText cp = new ChatComponentText(""); + cp.appendText(padding); + cp.appendSibling(links); + cp.appendText(padding); + Minecraft.getMinecraft().thePlayer.addChatMessage(cp); } @SubscribeEvent diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java index cb8ba6ed..9938403c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.java @@ -44,7 +44,7 @@ public class LinksCommand extends ClientCommandBase { JsonObject update = NotEnoughUpdates.INSTANCE.manager.getJsonFromFile(updateJson); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); - NotEnoughUpdates.INSTANCE.displayLinks(update); + NotEnoughUpdates.INSTANCE.displayLinks(update,0 ); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); } catch (Exception ignored) { } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java index 03f55561..de9c608f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java @@ -215,8 +215,11 @@ public class HTMLInfoPane extends TextInfoPane { } String html; try { - html = wikiModel.render(wiki); - } catch (IOException e) { + if (isOfficialWiki) + html = wiki; + else + html = wikiModel.render(wiki); + } catch (Exception e) { return new HTMLInfoPane(overlay, manager, "error", "error", "Could not render wiki.", false); } try (PrintWriter out = new PrintWriter(new File(manager.configLocation, "debug/html.txt"))) { @@ -330,8 +333,6 @@ public class HTMLInfoPane extends TextInfoPane { .replaceAll("[^a-zA-Z0-9_\\-]", "_"); File output = new File(manager.configLocation, "tmp/" + outputFileName + ".png"); - File outputExt = new File(manager.configLocation, "tmp/" + - outputFileName + "_ext.png"); input.deleteOnExit(); output.deleteOnExit(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java index 8b924d78..26c2d1f9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java @@ -19,6 +19,7 @@ package io.github.moulberry.notenoughupdates.listener; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; @@ -59,6 +60,7 @@ import org.lwjgl.input.Keyboard; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -78,6 +80,37 @@ public class NEUEventListener { this.neu = neu; } + private void displayUpdateMessage(JsonObject updateJson, String updateMessage, String downloadLink) { + int firstWidth = -1; + + for (String line : Iterables.concat(Arrays.asList(updateMessage.split("\n")), Arrays.asList("Download here"))) { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + boolean isDownloadLink = line.equals("Download here"); + int width = fr.getStringWidth(line); + if (firstWidth == -1) { + firstWidth = width; + } + int missingLen = firstWidth - width; + if (missingLen > 0) { + StringBuilder sb = new StringBuilder(missingLen / 4 / 2 +line.length()); + for (int i = 0; i < missingLen / 4 / 2; i++) { /* fr.getCharWidth(' ') == 4 */ + sb.append(" "); + } + sb.append(line); + line = sb.toString(); + } + ChatComponentText cp = new ChatComponentText(line); + if (isDownloadLink) + cp.setChatStyle(Utils.createClickStyle(ClickEvent.Action.OPEN_URL, downloadLink)); + Minecraft.getMinecraft().thePlayer.addChatMessage(cp); + } + neu.displayLinks(updateJson, firstWidth); + NotificationHandler.displayNotification(Arrays.asList( + "§eThere is a new version of NotEnoughUpdates available.", + "§eCheck the chat for more information" + ), true); + } + private void displayUpdateMessageIfOutOfDate() { File repo = neu.manager.repoLocation; if (repo.exists()) { @@ -85,73 +118,31 @@ public class NEUEventListener { try { JsonObject o = neu.manager.getJsonFromFile(updateJson); - String version = o.get("version").getAsString(); - String preVersion = o.get("pre_version").getAsString(); - - boolean shouldUpdate = !NotEnoughUpdates.VERSION.equalsIgnoreCase(version); - boolean shouldPreUpdate = !NotEnoughUpdates.PRE_VERSION.equalsIgnoreCase(preVersion); - - if (o.has("version_id") && o.get("version_id").isJsonPrimitive()) { - int version_id = o.get("version_id").getAsInt(); - shouldUpdate = version_id > NotEnoughUpdates.VERSION_ID; - } - if (o.has("pre_version_id") && o.get("pre_version_id").isJsonPrimitive()) { - int pre_version_id = o.get("pre_version_id").getAsInt(); - shouldPreUpdate = pre_version_id > NotEnoughUpdates.PRE_VERSION_ID; - } - - if (shouldUpdate) { - String update_msg = o.get("update_msg").getAsString(); - - int first_len = -1; - for (String line : update_msg.split("\n")) { - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int len = fr.getStringWidth(line); - if (first_len == -1) { - first_len = len; - } - int missing_len = first_len - len; - if (missing_len > 0) { - StringBuilder sb = new StringBuilder(line); - for (int i = 0; i < missing_len / 8; i++) { - sb.insert(0, " "); - } - line = sb.toString(); - } - line = line.replaceAll("\\{version}", version); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(line)); - } - - neu.displayLinks(o); - - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); - } else if (shouldPreUpdate && NotEnoughUpdates.VERSION_ID == o.get("version").getAsInt()) { - String pre_update_msg = o.get("pre_update_msg").getAsString(); - - int first_len = -1; - for (String line : pre_update_msg.split("\n")) { - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int len = fr.getStringWidth(line); - if (first_len == -1) { - first_len = len; - } - int missing_len = first_len - len; - if (missing_len > 0) { - StringBuilder sb = new StringBuilder(line); - for (int i = 0; i < missing_len / 8; i++) { - sb.insert(0, " "); - } - line = sb.toString(); - } - line = line.replaceAll("\\{pre_version}", preVersion); - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(line)); - } - - neu.displayLinks(o); - - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("")); + int fullReleaseVersion = + o.has("version_id") && o.get("version_id").isJsonPrimitive() ? o.get("version_id").getAsInt() : -1; + int preReleaseVersion = + o.has("version_id") && o.get("version_id").isJsonPrimitive() ? o.get("version_id").getAsInt() : -1; + int hotfixVersion = + o.has("hotfix_id") && o.get("hotfix_id").isJsonPrimitive() ? o.get("hotfix_id").getAsInt() : -1; + + boolean hasFullReleaseAvailableForUpgrade = fullReleaseVersion > NotEnoughUpdates.VERSION_ID; + boolean hasHotfixAvailableForUpgrade = + fullReleaseVersion == NotEnoughUpdates.VERSION_ID && hotfixVersion > NotEnoughUpdates.HOTFIX_VERSION_ID; + boolean hasPreReleaseAvailableForUpdate = + fullReleaseVersion == NotEnoughUpdates.VERSION_ID && preReleaseVersion > NotEnoughUpdates.PRE_VERSION_ID; + + int updateChannel = NotEnoughUpdates.INSTANCE.config.notifications.updateChannel; /* 1 = Full, 2 = Pre */ + if (hasFullReleaseAvailableForUpgrade || (hasHotfixAvailableForUpgrade && updateChannel == 1)) { + displayUpdateMessage(o, o.get("update_msg").getAsString(), o.get("update_link").getAsString()); + } else if (hasPreReleaseAvailableForUpdate && updateChannel == 2) { + displayUpdateMessage(o, o.get("pre_update_msg").getAsString(), o.get("pre_update_link").getAsString()); } - } catch (Exception ignored) { + } catch (Exception e) { + e.printStackTrace(); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( + "§e[NEU] §cThere has been an error checking for updates. Check the log or join the discord for more information.").setChatStyle( + Utils.createClickStyle( + ClickEvent.Action.OPEN_URL, "https://discord.gg/moulberry"))); } } } @@ -274,7 +265,7 @@ public class NEUEventListener { if (!joinedSB) { joinedSB = true; - if (NotEnoughUpdates.INSTANCE.config.notifications.showUpdateMsg) { + if (NotEnoughUpdates.INSTANCE.config.notifications.updateChannel != 0) { displayUpdateMessageIfOutOfDate(); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/SignCalculator.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/SignCalculator.java index f3d4237d..bee0a36f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/SignCalculator.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/SignCalculator.java @@ -58,7 +58,7 @@ public class SignCalculator { getRenderedString(), Minecraft.getMinecraft().fontRendererObj, guiEditSign.width / 2F, - guiEditSign.height / 4F - 120, + 58, false, 0x808080FF ); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java index 08ae5745..b0e4c60b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java @@ -196,8 +196,8 @@ public class Misc { name = "Waypoint Keybind", desc = "Press this keybind to show waypoints to various NPCs" ) - @ConfigEditorKeybind(defaultKey = Keyboard.KEY_N) - public int keybindWaypoint = Keyboard.KEY_N; + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) + public int keybindWaypoint = Keyboard.KEY_NONE; @Expose @ConfigOption( @@ -210,7 +210,7 @@ public class Misc { @Expose @ConfigOption( name = "Warp twice", - desc = "Warp twice when using SHIFT+N to /warp to a waypoint." + desc = "Warp twice when using SHIFT+<waypoint keybind> to /warp to a waypoint." ) @ConfigEditorBoolean public boolean warpTwice = true; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Notifications.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Notifications.java index 353cd36d..e25a535f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Notifications.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Notifications.java @@ -21,6 +21,7 @@ package io.github.moulberry.notenoughupdates.options.seperateSections; import com.google.gson.annotations.Expose; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDropdown; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorSlider; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption; @@ -30,8 +31,8 @@ public class Notifications { name = "Update Messages", desc = "Give a notification in chat whenever a new version of NEU is released" ) - @ConfigEditorBoolean - public boolean showUpdateMsg = true; + @ConfigEditorDropdown(values = {"Off", "Releases", "Pre-Releases"}) + public int updateChannel = 1; @Expose @ConfigOption( |