From 9fe70c30bd2f1a69b805af23c8f00a9d7b47bb22 Mon Sep 17 00:00:00 2001 From: zbx1425 Date: Sat, 4 Jan 2025 20:43:04 +0800 Subject: [PATCH] Some more tweaks --- src/main/java/appeng/client/guidebook/Guide.java | 9 +++++++++ .../appeng/client/guidebook/compiler/PageCompiler.java | 1 + .../appeng/client/guidebook/layout/flow/LineBuilder.java | 4 ++-- .../java/appeng/client/guidebook/screen/GuideNavBar.java | 2 +- src/main/java/appeng/core/AppEngClient.java | 2 ++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/appeng/client/guidebook/Guide.java b/src/main/java/appeng/client/guidebook/Guide.java index a79af6e171a..0a2177d9af1 100644 --- a/src/main/java/appeng/client/guidebook/Guide.java +++ b/src/main/java/appeng/client/guidebook/Guide.java @@ -29,6 +29,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import net.minecraft.util.profiling.InactiveProfiler; import org.apache.commons.lang3.mutable.MutableBoolean; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -747,4 +748,12 @@ private void registerReloadListener(IEventBus modEventBus) { new ReloadListener(ResourceLocation.fromNamespaceAndPath(defaultNamespace, folder))); }); } + + public void reloadIfNoPages() { + if (pages == null || pages.isEmpty()) { + var reloader = new ReloadListener(ResourceLocation.fromNamespaceAndPath(defaultNamespace, folder)); + pages = reloader.prepare(Minecraft.getInstance().getResourceManager(), InactiveProfiler.INSTANCE); + reloader.apply(pages, Minecraft.getInstance().getResourceManager(), InactiveProfiler.INSTANCE); + } + } } diff --git a/src/main/java/appeng/client/guidebook/compiler/PageCompiler.java b/src/main/java/appeng/client/guidebook/compiler/PageCompiler.java index 15be2e36520..4174a533db0 100644 --- a/src/main/java/appeng/client/guidebook/compiler/PageCompiler.java +++ b/src/main/java/appeng/client/guidebook/compiler/PageCompiler.java @@ -327,6 +327,7 @@ private void compileFlowContent(LytFlowParent layoutParent, MdAstAnyContent cont .replace("\\n", "\n") .replace("\\", " ") ); + text.modifyStyle(style -> style.whiteSpace(WhiteSpaceMode.PRE)); layoutChild = text; } else if (content instanceof MdAstInlineCode astCode) { var text = new LytFlowText(); diff --git a/src/main/java/appeng/client/guidebook/layout/flow/LineBuilder.java b/src/main/java/appeng/client/guidebook/layout/flow/LineBuilder.java index d4f8ff5f859..8831090d81d 100644 --- a/src/main/java/appeng/client/guidebook/layout/flow/LineBuilder.java +++ b/src/main/java/appeng/client/guidebook/layout/flow/LineBuilder.java @@ -209,7 +209,7 @@ private void iterateRuns(CharSequence text, ResolvedTextStyle style, char lastCh var fontScale = style.fontScale(); var lineBuffer = new StringBuilder(); - boolean lastCharWasWhitespace = Character.isWhitespace(lastChar); + boolean lastCharWasWhitespace = Character.isWhitespace(lastChar) && lastChar != '\n'; for (var i = 0; i < text.length(); i++) { char ch = text.charAt(i); @@ -239,7 +239,7 @@ private void iterateRuns(CharSequence text, ResolvedTextStyle style, char lastCh // } } - if (Character.isWhitespace(codePoint)) { + if (Character.isWhitespace(codePoint) && codePoint != '\n') { // Skip if the last one was a space already if (lastCharWasWhitespace && style.whiteSpace().isCollapseWhitespace()) { continue; // White space collapsing diff --git a/src/main/java/appeng/client/guidebook/screen/GuideNavBar.java b/src/main/java/appeng/client/guidebook/screen/GuideNavBar.java index b279c8b16bd..72018e73f33 100644 --- a/src/main/java/appeng/client/guidebook/screen/GuideNavBar.java +++ b/src/main/java/appeng/client/guidebook/screen/GuideNavBar.java @@ -349,7 +349,7 @@ private class Row { private final NavigationNode node; private final LytParagraph paragraph = new LytParagraph(); public final LytFlowSpan span; - private boolean expanded; + private boolean expanded = true; private final Row parent; private boolean hasChildren; public int top; diff --git a/src/main/java/appeng/core/AppEngClient.java b/src/main/java/appeng/core/AppEngClient.java index 33d90f9fb2d..aec85302751 100644 --- a/src/main/java/appeng/core/AppEngClient.java +++ b/src/main/java/appeng/core/AppEngClient.java @@ -147,6 +147,7 @@ public HitResult getCurrentMouseOver() { @Override public void openGuideAtPreviousPage(ResourceLocation initialPage) { try { + guide.reloadIfNoPages(); var screen = GuideScreen.openAtPreviousPage(guide, PageAnchor.page(initialPage), GlobalInMemoryHistory.INSTANCE); @@ -159,6 +160,7 @@ public void openGuideAtPreviousPage(ResourceLocation initialPage) { @Override public void openGuideAtAnchor(PageAnchor anchor) { try { + guide.reloadIfNoPages(); var screen = GuideScreen.openNew(guide, anchor, GlobalInMemoryHistory.INSTANCE); openGuideScreen(screen);