From da5bbd2b2260772610729d0a1e195806876748d4 Mon Sep 17 00:00:00 2001 From: Glavo Date: Tue, 18 Nov 2025 16:35:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=92=AD=E6=94=BE=E8=BF=87=E6=B8=A1=E5=8A=A8?= =?UTF-8?q?=E7=94=BB=E6=97=B6=E7=BC=93=E5=AD=98=E8=8A=82=E7=82=B9=E8=87=B3?= =?UTF-8?q?=E4=BD=8D=E5=9B=BE=20(#4815)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmcl/ui/animation/TransitionPane.java | 24 +++++++++++++++++++ .../hmcl/ui/versions/InstallerListPage.java | 3 ++- .../hmcl/ui/versions/ModListPage.java | 3 ++- .../hmcl/ui/versions/SchematicsPage.java | 3 ++- .../hmcl/ui/versions/WorldListPage.java | 3 ++- 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/TransitionPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/TransitionPane.java index 05219e988..57a031d24 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/TransitionPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/TransitionPane.java @@ -20,6 +20,7 @@ package org.jackhuang.hmcl.ui.animation; import javafx.animation.Animation; import javafx.animation.Interpolator; import javafx.application.Platform; +import javafx.scene.CacheHint; import javafx.scene.Node; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; @@ -74,6 +75,15 @@ public class TransitionPane extends StackPane { setMouseTransparent(true); transition.init(this, previousNode, newView); + CacheHint cacheHint = newView instanceof Cacheable cacheable + ? cacheable.getCacheHint(transition) + : null; + + if (cacheHint != null) { + newView.setCache(true); + newView.setCacheHint(cacheHint); + } + // runLater or "init" will not work Platform.runLater(() -> { Animation newAnimation = transition.animate( @@ -84,6 +94,10 @@ public class TransitionPane extends StackPane { newAnimation.setOnFinished(e -> { setMouseTransparent(false); getChildren().remove(previousNode); + + if (cacheHint != null) { + newView.setCache(false); + } }); FXUtils.playAnimation(this, "transition_pane", newAnimation); }); @@ -103,4 +117,14 @@ public class TransitionPane extends StackPane { return null; } } + + /// Marks a node as cacheable as a bitmap during animation. + public interface Cacheable { + /// @return the [cache hint][CacheHint] to use when caching this node during the given animation, + /// or `null` to not cache it. + default @Nullable CacheHint getCacheHint(AnimationProducer animationProducer) { + // https://github.com/HMCL-dev/HMCL/issues/4789 + return animationProducer == ContainerAnimations.SLIDE_UP_FADE_IN ? CacheHint.SPEED : null; + } + } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/InstallerListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/InstallerListPage.java index 2f487ff1d..6897b1c28 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/InstallerListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/InstallerListPage.java @@ -29,6 +29,7 @@ import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.task.TaskExecutor; import org.jackhuang.hmcl.task.TaskListener; import org.jackhuang.hmcl.ui.*; +import org.jackhuang.hmcl.ui.animation.TransitionPane; import org.jackhuang.hmcl.ui.download.UpdateInstallerWizardProvider; import org.jackhuang.hmcl.util.TaskCancellationAction; import org.jackhuang.hmcl.util.io.FileUtils; @@ -42,7 +43,7 @@ import java.util.concurrent.CompletableFuture; import static org.jackhuang.hmcl.ui.FXUtils.runInFX; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; -public class InstallerListPage extends ListPageBase implements VersionPage.VersionLoadable { +public class InstallerListPage extends ListPageBase implements VersionPage.VersionLoadable, TransitionPane.Cacheable { private Profile profile; private String versionId; private Version version; diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPage.java index b826216c9..61706ddf1 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPage.java @@ -34,6 +34,7 @@ import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.ListPageBase; +import org.jackhuang.hmcl.ui.animation.TransitionPane; import org.jackhuang.hmcl.ui.construct.MessageDialogPane; import org.jackhuang.hmcl.ui.construct.PageAware; import org.jackhuang.hmcl.util.TaskCancellationAction; @@ -49,7 +50,7 @@ import java.util.concurrent.locks.ReentrantLock; import static org.jackhuang.hmcl.util.logging.Logger.LOG; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; -public final class ModListPage extends ListPageBase implements VersionPage.VersionLoadable, PageAware { +public final class ModListPage extends ListPageBase implements VersionPage.VersionLoadable, PageAware, TransitionPane.Cacheable { private final BooleanProperty modded = new SimpleBooleanProperty(this, "modded", false); private final ReentrantLock lock = new ReentrantLock(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/SchematicsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/SchematicsPage.java index 8c529b80d..3946f4a2b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/SchematicsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/SchematicsPage.java @@ -37,6 +37,7 @@ import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.*; +import org.jackhuang.hmcl.ui.animation.TransitionPane; import org.jackhuang.hmcl.ui.construct.*; import org.jackhuang.hmcl.util.Lang; import org.jackhuang.hmcl.util.StringUtils; @@ -60,7 +61,7 @@ import static org.jackhuang.hmcl.util.logging.Logger.LOG; /** * @author Glavo */ -public final class SchematicsPage extends ListPageBase implements VersionPage.VersionLoadable { +public final class SchematicsPage extends ListPageBase implements VersionPage.VersionLoadable, TransitionPane.Cacheable { private static String translateAuthorName(String author) { if (I18n.isUseChinese() && "hsds".equals(author)) { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListPage.java index e39162f31..f91d11ac3 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListPage.java @@ -27,6 +27,7 @@ import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.*; +import org.jackhuang.hmcl.ui.animation.TransitionPane; import org.jackhuang.hmcl.util.io.FileUtils; import java.io.IOException; @@ -41,7 +42,7 @@ import java.util.stream.Stream; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.logging.Logger.LOG; -public final class WorldListPage extends ListPageBase implements VersionPage.VersionLoadable { +public final class WorldListPage extends ListPageBase implements VersionPage.VersionLoadable, TransitionPane.Cacheable { private final BooleanProperty showAll = new SimpleBooleanProperty(this, "showAll", false); private Path savesDir;