From 47efdd4f84cc9a29738fe16d631eb33ee716db61 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Sun, 27 Mar 2022 19:12:44 +0200 Subject: New wiki in wiki renderer (#97) * partly working and pushing cuz jani * way better rendering stuff but still not perfect * finish most of wiki renderer for new wiki * JANI MY FRIEND PLEASE TEST * Windows time :sad: * fix wiki renderer * Some things I forgor * changelog * Better corrupted file handling in graph and added check for crash that I have no idea how it happened. --- .../notenoughupdates/infopanes/HTMLInfoPane.java | 124 ++++++++++++++++++--- 1 file changed, 109 insertions(+), 15 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java') 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 baf88457..e4098f3e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/infopanes/HTMLInfoPane.java @@ -14,6 +14,7 @@ import io.github.moulberry.notenoughupdates.util.AllowEmptyHTMLTag; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.texture.DynamicTexture; @@ -30,10 +31,12 @@ import java.net.URL; import java.net.URLConnection; import java.nio.charset.CharsetEncoder; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import java.util.regex.Pattern; public class HTMLInfoPane extends TextInfoPane { private static final WikiModel wikiModel; @@ -47,6 +50,10 @@ public class HTMLInfoPane extends TextInfoPane { private int imageHeight = 0; private int imageWidth = 0; + private float xMin = 0; + private int mouseOffset = 0; + private boolean selected = false; + private static boolean hasAttemptedDownload = false; /* @@ -61,6 +68,16 @@ public class HTMLInfoPane extends TextInfoPane { conf.addTokenTag("infobox", new IgnoreTag("infobox")); conf.addTokenTag("tabber", new IgnoreTag("tabber")); conf.addTokenTag("kbd", new HTMLTag("kbd")); + conf.addTokenTag("td", new AllowEmptyHTMLTag("td")); + conf.addTokenTag("tbody", new AllowEmptyHTMLTag("tbody")); + conf.addTokenTag("style", new AllowEmptyHTMLTag("style")); + conf.addTokenTag("article", new AllowEmptyHTMLTag("article")); + conf.addTokenTag("section", new AllowEmptyHTMLTag("section")); + conf.addTokenTag("link", new AllowEmptyHTMLTag("link")); + conf.addTokenTag("wbr", new AllowEmptyHTMLTag("wbr")); + conf.addTokenTag("dl", new AllowEmptyHTMLTag("dl")); + conf.addTokenTag("dd", new AllowEmptyHTMLTag("dd")); + conf.addTokenTag("dt", new AllowEmptyHTMLTag("dt")); wikiModel = new WikiModel(conf, "https://hypixel-skyblock.fandom.com/wiki/Special:Filepath/${image}", "https://hypixel-skyblock.fandom.com/wiki/${title}" ) { @@ -101,7 +118,7 @@ public class HTMLInfoPane extends TextInfoPane { ) { return manager.getWebFile(wikiUrl).thenApply(f -> { if (f == null) { - return new HTMLInfoPane(overlay, manager, "error", "error", "Failed to load wiki url: " + wikiUrl); + return new HTMLInfoPane(overlay, manager, "error", "error", "Failed to load wiki url: " + wikiUrl, false); } StringBuilder sb = new StringBuilder(); @@ -114,9 +131,16 @@ public class HTMLInfoPane extends TextInfoPane { sb.append(l).append("\n"); } } catch (IOException e) { - return new HTMLInfoPane(overlay, manager, "error", "error", "Failed to load wiki url: " + wikiUrl); + return new HTMLInfoPane(overlay, manager, "error", "error", "Failed to load wiki url: " + wikiUrl, false); } - return createFromWikiText(overlay, manager, name, f.getName(), sb.toString()); + return createFromWikiText( + overlay, + manager, + name, + f.getName(), + sb.toString(), + wikiUrl.startsWith("https://wiki.hypixel.net/") + ); }); } @@ -126,15 +150,37 @@ public class HTMLInfoPane extends TextInfoPane { * a more permanent solution that can be abstracted to work with arbitrary wiki codes (eg. moulberry.github.io/ * files/neu_help.html). */ + + private static final Pattern replacePattern = Pattern.compile( + "|", + Pattern.DOTALL + ); + public static HTMLInfoPane createFromWikiText( NEUOverlay overlay, NEUManager manager, String name, String filename, - String wiki + String wiki, boolean isOfficialWiki ) { - String[] split = wiki.split(""); - wiki = split[split.length - 1]; //Remove everything before infobox - wiki = wiki.split("")[0]; //Remove navbox - wiki = wiki.split("")[1].split("")[0]; // hide top bar + wiki = wiki.split("
")[0]; // hide giant bottom list + wiki = wiki.split("
")[0]; // hide small bottom category thing + wiki = replacePattern.matcher(wiki).replaceAll(""); + wiki = wiki.replaceAll( + "
", + "" + ); // hide beta box + wiki = wiki.replaceAll("

.*

", ""); // hide title + wiki = wiki.replace("src=\"/", "src=\"https://wiki.hypixel.net/"); + wiki = wiki.replace("\uD83D\uDDF8", "✓"); // replace checkmark with one that renders + wiki = wiki.replace("\uD83E\uDC10", "\u27F5"); // replace left arrow with one that renders + wiki = wiki.replace("\uD83E\uDC12", "\u27F6"); // replace right arrow with one that renders + } else { + String[] split = wiki.split(""); + wiki = split[split.length - 1]; //Remove everything before infobox + wiki = wiki.split("")[0]; //Remove navbox + wiki = wiki.split("
= barX && mouseX <= barWidth && mouseY >= barY && mouseY <= barHeight || selected; + Gui.drawRect(barX, barY, barWidth, barHeight, new Color(255, 255, 255, isHovered ? 150 : 100).getRGB()); + } } else { scrollHeight.setValue(0); @@ -435,6 +508,27 @@ public class HTMLInfoPane extends TextInfoPane { @Override public void mouseInput(int width, int height, int mouseX, int mouseY, boolean mouseDown) { + int paneWidth = (int) (width / 3 * overlay.getWidthMult()); + int rightSide = (int) (width * overlay.getInfoPaneOffsetFactor()); + int leftSide = rightSide - paneWidth; + int imageW = paneWidth - overlay.getBoxPadding() * 2; + float scaleF = IMAGE_WIDTH * ZOOM_FACTOR / (float) imageW; + float xSize = Math.min((paneWidth - overlay.getBoxPadding() * 2f) / imageWidth * scaleF, 1); + float xMax = xMin + xSize; + int barX = (int) (xMin * imageW) + leftSide + overlay.getBoxPadding(); + int barY = height - overlay.getBoxPadding() - 10; + int barWidth = (int) (xMax * imageW) + leftSide + overlay.getBoxPadding(); + int barHeight = height - overlay.getBoxPadding() - 5; + if (!mouseDown) + selected = false; + if (mouseX >= barX && mouseX <= barWidth && mouseY >= barY && mouseY <= barHeight && mouseDown || selected) { + if (!selected) + mouseOffset = mouseX - barX; + xMin = (mouseX - leftSide - overlay.getBoxPadding() / 2f - mouseOffset) / imageWidth * scaleF; + xMin = Math.max(0, xMin); + xMin = Math.min(xMin, 1 - xSize); + selected = true; + } super.mouseInput(width, height, mouseX, mouseY, mouseDown); } -- cgit