Skip to content

Commit 75c4fb6

Browse files
authored
优化更多界面的动画 (#4790)
1 parent 44869da commit 75c4fb6

8 files changed

Lines changed: 83 additions & 63 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.jackhuang.hmcl.task.TaskExecutor;
5050
import org.jackhuang.hmcl.ui.account.AccountListPage;
5151
import org.jackhuang.hmcl.ui.animation.AnimationUtils;
52+
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
5253
import org.jackhuang.hmcl.ui.animation.Motion;
5354
import org.jackhuang.hmcl.ui.construct.*;
5455
import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
@@ -91,7 +92,7 @@ public final class Controllers {
9192

9293
private static Scene scene;
9394
private static Stage stage;
94-
private static Lazy<VersionPage> versionPage = new Lazy<>(VersionPage::new);
95+
private static VersionPage versionPage;
9596
private static Lazy<GameListPage> gameListPage = new Lazy<>(() -> {
9697
GameListPage gameListPage = new GameListPage();
9798
gameListPage.selectedProfileProperty().bindBidirectional(Profiles.selectedProfileProperty());
@@ -128,7 +129,18 @@ public static Stage getStage() {
128129

129130
// FXThread
130131
public static VersionPage getVersionPage() {
131-
return versionPage.get();
132+
if (versionPage == null) {
133+
versionPage = new VersionPage();
134+
}
135+
return versionPage;
136+
}
137+
138+
@FXThread
139+
public static void prepareVersionPage() {
140+
if (versionPage == null) {
141+
LOG.info("Prepare the version page");
142+
versionPage = FXUtils.prepareNode(new VersionPage());
143+
}
132144
}
133145

134146
// FXThread
@@ -521,7 +533,11 @@ public static TaskExecutorDialogPane taskDialog(Task<?> task, String title, Task
521533
}
522534

523535
public static void navigate(Node node) {
524-
decorator.navigate(node);
536+
decorator.navigate(node, ContainerAnimations.NAVIGATION, Motion.SHORT4, Motion.EASE);
537+
}
538+
539+
public static void navigateForward(Node node) {
540+
decorator.navigate(node, ContainerAnimations.FORWARD, Motion.SHORT4, Motion.EASE);
525541
}
526542

527543
public static void showToast(String content) {

HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/ContainerAnimations.java

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
*/
1818
package org.jackhuang.hmcl.ui.animation;
1919

20-
import javafx.animation.Interpolator;
21-
import javafx.animation.KeyFrame;
22-
import javafx.animation.KeyValue;
23-
import javafx.animation.Timeline;
20+
import javafx.animation.*;
2421
import javafx.scene.Node;
2522
import javafx.scene.layout.Pane;
2623
import javafx.util.Duration;
24+
import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage;
2725

2826
public enum ContainerAnimations implements TransitionPane.AnimationProducer {
2927
NONE {
@@ -199,6 +197,56 @@ public Timeline animate(
199197
);
200198
}
201199
},
200+
201+
NAVIGATION {
202+
@Override
203+
public void init(TransitionPane container, Node previousNode, Node nextNode) {
204+
}
205+
206+
@Override
207+
public Animation animate(Pane container, Node previousNode, Node nextNode, Duration duration, Interpolator interpolator) {
208+
Timeline timeline = new Timeline();
209+
if (previousNode instanceof TransitionPane.EmptyPane) {
210+
return timeline;
211+
}
212+
213+
Duration halfDuration = duration.divide(2);
214+
215+
timeline.getKeyFrames().add(new KeyFrame(Duration.ZERO,
216+
new KeyValue(previousNode.opacityProperty(), 1, interpolator)));
217+
timeline.getKeyFrames().add(new KeyFrame(halfDuration,
218+
new KeyValue(previousNode.opacityProperty(), 0, interpolator)));
219+
if (previousNode instanceof DecoratorAnimatedPage prevPage) {
220+
Node left = prevPage.getLeft();
221+
Node center = prevPage.getCenter();
222+
223+
timeline.getKeyFrames().add(new KeyFrame(Duration.ZERO,
224+
new KeyValue(left.translateXProperty(), 0, interpolator),
225+
new KeyValue(center.translateXProperty(), 0, interpolator)));
226+
timeline.getKeyFrames().add(new KeyFrame(halfDuration,
227+
new KeyValue(left.translateXProperty(), -30, interpolator),
228+
new KeyValue(center.translateXProperty(), 30, interpolator)));
229+
}
230+
231+
timeline.getKeyFrames().add(new KeyFrame(halfDuration,
232+
new KeyValue(nextNode.opacityProperty(), 0, interpolator)));
233+
timeline.getKeyFrames().add(new KeyFrame(duration,
234+
new KeyValue(nextNode.opacityProperty(), 1, interpolator)));
235+
if (nextNode instanceof DecoratorAnimatedPage nextPage) {
236+
Node left = nextPage.getLeft();
237+
Node center = nextPage.getCenter();
238+
239+
timeline.getKeyFrames().add(new KeyFrame(halfDuration,
240+
new KeyValue(left.translateXProperty(), -30, interpolator),
241+
new KeyValue(center.translateXProperty(), 30, interpolator)));
242+
timeline.getKeyFrames().add(new KeyFrame(duration,
243+
new KeyValue(left.translateXProperty(), 0, interpolator),
244+
new KeyValue(center.translateXProperty(), 0, interpolator)));
245+
}
246+
247+
return timeline;
248+
}
249+
}
202250
;
203251

204252
protected static void reset(Node node) {

HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.jackhuang.hmcl.ui.FXUtils;
5252
import org.jackhuang.hmcl.ui.account.AddAuthlibInjectorServerPane;
5353
import org.jackhuang.hmcl.ui.animation.*;
54+
import org.jackhuang.hmcl.ui.animation.TransitionPane.AnimationProducer;
5455
import org.jackhuang.hmcl.ui.construct.DialogAware;
5556
import org.jackhuang.hmcl.ui.construct.DialogCloseEvent;
5657
import org.jackhuang.hmcl.ui.construct.Navigator;
@@ -364,57 +365,8 @@ private Image loadDefaultBackgroundImage() {
364365

365366
// ==== Navigation ====
366367

367-
private static final TransitionPane.AnimationProducer ANIMATION = (Pane container,
368-
Node previousNode, Node nextNode,
369-
Duration duration,
370-
Interpolator interpolator) -> {
371-
Timeline timeline = new Timeline();
372-
if (previousNode instanceof TransitionPane.EmptyPane) {
373-
return timeline;
374-
}
375-
376-
Duration halfDuration = duration.divide(2);
377-
378-
List<KeyFrame> keyFrames = new ArrayList<>();
379-
380-
keyFrames.add(new KeyFrame(Duration.ZERO,
381-
new KeyValue(previousNode.opacityProperty(), 1, interpolator)));
382-
keyFrames.add(new KeyFrame(halfDuration,
383-
new KeyValue(previousNode.opacityProperty(), 0, interpolator)));
384-
if (previousNode instanceof DecoratorAnimatedPage prevPage) {
385-
Node left = prevPage.getLeft();
386-
Node center = prevPage.getCenter();
387-
388-
keyFrames.add(new KeyFrame(Duration.ZERO,
389-
new KeyValue(left.translateXProperty(), 0, interpolator),
390-
new KeyValue(center.translateXProperty(), 0, interpolator)));
391-
keyFrames.add(new KeyFrame(halfDuration,
392-
new KeyValue(left.translateXProperty(), -30, interpolator),
393-
new KeyValue(center.translateXProperty(), 30, interpolator)));
394-
}
395-
396-
keyFrames.add(new KeyFrame(halfDuration,
397-
new KeyValue(nextNode.opacityProperty(), 0, interpolator)));
398-
keyFrames.add(new KeyFrame(duration,
399-
new KeyValue(nextNode.opacityProperty(), 1, interpolator)));
400-
if (nextNode instanceof DecoratorAnimatedPage nextPage) {
401-
Node left = nextPage.getLeft();
402-
Node center = nextPage.getCenter();
403-
404-
keyFrames.add(new KeyFrame(halfDuration,
405-
new KeyValue(left.translateXProperty(), -30, interpolator),
406-
new KeyValue(center.translateXProperty(), 30, interpolator)));
407-
keyFrames.add(new KeyFrame(duration,
408-
new KeyValue(left.translateXProperty(), 0, interpolator),
409-
new KeyValue(center.translateXProperty(), 0, interpolator)));
410-
}
411-
412-
timeline.getKeyFrames().setAll(keyFrames);
413-
return timeline;
414-
};
415-
416-
public void navigate(Node node) {
417-
navigator.navigate(node, ANIMATION);
368+
public void navigate(Node node, AnimationProducer animationProducer, Duration duration, Interpolator interpolator) {
369+
navigator.navigate(node, animationProducer, duration, interpolator);
418370
}
419371

420372
private void close() {
@@ -586,7 +538,8 @@ public void startWizard(WizardProvider wizardProvider) {
586538
public void startWizard(WizardProvider wizardProvider, String category) {
587539
FXUtils.checkFxUserThread();
588540

589-
navigator.navigate(new DecoratorWizardDisplayer(wizardProvider, category), ContainerAnimations.FADE);
541+
navigator.navigate(new DecoratorWizardDisplayer(wizardProvider, category),
542+
ContainerAnimations.FORWARD, Motion.SHORT4, Motion.EASE);
590543
}
591544

592545
// ==== Authlib Injector DnD ====

HMCL/src/main/java/org/jackhuang/hmcl/ui/main/JavaManagementPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void onAddJava() {
123123
}
124124

125125
void onShowRestoreJavaPage() {
126-
Controllers.navigate(new JavaRestorePage(ConfigHolder.globalConfig().getDisabledJava()));
126+
Controllers.navigateForward(new JavaRestorePage(ConfigHolder.globalConfig().getDisabledJava()));
127127
}
128128

129129
private void onAddJavaBinary(Path file) {

HMCL/src/main/java/org/jackhuang/hmcl/ui/main/RootPage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ protected Skin(RootPage control) {
161161
String currentId = getSkinnable().getMainPage().getCurrentGame();
162162
return Lang.indexWhere(list, instance -> instance.getId().equals(currentId));
163163
}, it -> getSkinnable().getMainPage().getProfile().setSelectedVersion(it.getId()));
164+
if (AnimationUtils.isAnimationEnabled()) {
165+
FXUtils.prepareOnMouseEnter(gameListItem, Controllers::prepareVersionPage);
166+
}
164167

165168
// third item in left sidebar
166169
AdvancedListItem gameItem = new AdvancedListItem();

HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public void checkUpdates() {
244244
} else if (result.isEmpty()) {
245245
Controllers.dialog(i18n("mods.check_updates.empty"));
246246
} else {
247-
Controllers.navigate(new ModUpdatesPage(modManager, result));
247+
Controllers.navigateForward(new ModUpdatesPage(modManager, result));
248248
}
249249
})
250250
.withStagesHint(Collections.singletonList("mods.check_updates")),

HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public VersionSettingsPage(boolean globalSetting) {
461461
if (advancedVersionSettingPage == null)
462462
advancedVersionSettingPage = new AdvancedVersionSettingPage(profile, versionId, lastVersionSetting);
463463

464-
Controllers.navigate(advancedVersionSettingPage);
464+
Controllers.navigateForward(advancedVersionSettingPage);
465465
}
466466
});
467467
showAdvancedSettingPane.setRight(button);

HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ public void reveal() {
9191
}
9292

9393
public void showManagePage() {
94-
Controllers.navigate(new WorldManagePage(world, backupsDir));
94+
Controllers.navigateForward(new WorldManagePage(world, backupsDir));
9595
}
9696
}

0 commit comments

Comments
 (0)