From 981127c3553e1ee3b3853f8e91d11fd7e344c112 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Wed, 1 Sep 2021 01:26:06 +0800 Subject: [PATCH] feat: set background to translucent white to make texts easier to read. --- .../main/java/org/jackhuang/hmcl/ui/FXUtils.java | 14 +++++++------- .../hmcl/ui/account/AccountListPage.java | 7 +++++-- .../hmcl/ui/decorator/DecoratorSkin.java | 16 ++++++++++++++-- .../jackhuang/hmcl/ui/download/DownloadPage.java | 2 +- .../hmcl/ui/main/LauncherSettingsPage.java | 2 +- .../jackhuang/hmcl/ui/versions/GameListPage.java | 4 +--- .../jackhuang/hmcl/ui/versions/VersionPage.java | 2 +- 7 files changed, 30 insertions(+), 17 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java index 8ddc24616..f47ca51ac 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java @@ -18,10 +18,7 @@ package org.jackhuang.hmcl.ui; import com.jfoenix.controls.*; -import javafx.animation.Interpolator; -import javafx.animation.KeyFrame; -import javafx.animation.KeyValue; -import javafx.animation.Timeline; +import javafx.animation.*; import javafx.application.Platform; import javafx.beans.InvalidationListener; import javafx.beans.Observable; @@ -324,16 +321,19 @@ public final class FXUtils { node.getProperties().put(animationKey, timeline); } - public static void playAnimation(Node node, String animationKey, Duration duration, WritableValue property, T from, T to, Interpolator interpolator) { + public static Animation playAnimation(Node node, String animationKey, Duration duration, WritableValue property, T from, T to, Interpolator interpolator) { if (from == null) from = property.getValue(); if (duration == null || Objects.equals(duration, Duration.ZERO) || Objects.equals(from, to)) { playAnimation(node, animationKey, null); property.setValue(to); + return null; } else { - playAnimation(node, animationKey, new Timeline( + Timeline timeline = new Timeline( new KeyFrame(Duration.ZERO, new KeyValue(property, from, interpolator)), new KeyFrame(duration, new KeyValue(property, to, interpolator)) - )); + ); + playAnimation(node, animationKey, timeline); + return timeline; } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountListPage.java index 74932bbf8..dc2f46553 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountListPage.java @@ -27,7 +27,10 @@ import javafx.scene.control.SkinBase; import javafx.scene.layout.BorderPane; import javafx.scene.layout.VBox; import org.jackhuang.hmcl.auth.Account; -import org.jackhuang.hmcl.ui.*; +import org.jackhuang.hmcl.ui.Controllers; +import org.jackhuang.hmcl.ui.FXUtils; +import org.jackhuang.hmcl.ui.ListPageBase; +import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.construct.AdvancedListBox; import org.jackhuang.hmcl.ui.decorator.DecoratorPage; import org.jackhuang.hmcl.util.javafx.MappedObservableList; @@ -37,7 +40,7 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.javafx.ExtendedProperties.createSelectedItemPropertyFor; public class AccountListPage extends ListPageBase implements DecoratorPage { - private final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(State.fromTitle(i18n("account.manage"), 200)); + private final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(State.fromTitle(i18n("account.manage"), -1)); private final ListProperty accounts = new SimpleListProperty<>(this, "accounts", FXCollections.observableArrayList()); private final ObjectProperty selectedAccount; diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorSkin.java index f47fc57ea..e782b8576 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorSkin.java @@ -19,6 +19,7 @@ package org.jackhuang.hmcl.ui.decorator; import com.jfoenix.controls.JFXButton; import com.jfoenix.svg.SVGGlyph; +import javafx.animation.Animation; import javafx.beans.binding.Bindings; import javafx.collections.ListChangeListener; import javafx.css.PseudoClass; @@ -177,8 +178,19 @@ public class DecoratorSkin extends SkinBase { navBarPane.getChildren().setAll(node); } - FXUtils.playAnimation(leftPane, "animation", - s.isAnimate() ? Duration.millis(160) : null, leftPane.prefWidthProperty(), null, s.getLeftPaneWidth(), FXUtils.SINE); + if (s.getLeftPaneWidth() >= 0) { + leftPane.prefWidthProperty().unbind(); + FXUtils.playAnimation(leftPane, "animation", + s.isAnimate() ? Duration.millis(160) : null, leftPane.prefWidthProperty(), null, s.getLeftPaneWidth(), FXUtils.SINE); + } else { + Animation animation = FXUtils.playAnimation(leftPane, "animation1", + s.isAnimate() ? Duration.millis(160) : null, leftPane.prefWidthProperty(), null, container.getWidth(), FXUtils.SINE); + if (animation != null) { + animation.setOnFinished(action -> { + leftPane.prefWidthProperty().bind(container.widthProperty()); + }); + } + } }); titleBar.setCenter(navBarPane); titleBar.setRight(buttonsContainerPlaceHolder); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadPage.java index 150158c3e..2402d3a85 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadPage.java @@ -50,7 +50,7 @@ import static org.jackhuang.hmcl.ui.versions.VersionPage.wrap; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public class DownloadPage extends BorderPane implements DecoratorPage { - private final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(DecoratorPage.State.fromTitle(i18n("download"), 200)); + private final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(DecoratorPage.State.fromTitle(i18n("download"), -1)); private final TabHeader tab; private final TabHeader.Tab modTab = new TabHeader.Tab<>("modTab"); private final TabHeader.Tab modpackTab = new TabHeader.Tab<>("modpackTab"); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/LauncherSettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/LauncherSettingsPage.java index 425b29598..f4ae91479 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/LauncherSettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/LauncherSettingsPage.java @@ -35,7 +35,7 @@ import static org.jackhuang.hmcl.ui.versions.VersionPage.wrap; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public class LauncherSettingsPage extends BorderPane implements DecoratorPage { - private final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(State.fromTitle(i18n("settings"), 200)); + private final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(State.fromTitle(i18n("settings"), -1)); private final TabHeader tab; private final TabHeader.Tab gameTab = new TabHeader.Tab<>("versionSettingsPage"); private final TabHeader.Tab settingsTab = new TabHeader.Tab<>("settingsPage"); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameListPage.java index e5d23d17f..0199c83bf 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameListPage.java @@ -54,7 +54,7 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.javafx.ExtendedProperties.createSelectedItemPropertyFor; public class GameListPage extends ListPageBase implements DecoratorPage { - private final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(State.fromTitle(i18n("version.manage"))); + private final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(State.fromTitle(i18n("version.manage"), -1)); private final ListProperty profiles = new SimpleListProperty<>(FXCollections.observableArrayList()); @SuppressWarnings("FieldCanBeLocal") private final ObservableList profileListItems; @@ -243,8 +243,6 @@ public class GameListPage extends ListPageBase implements Decorato public GameListSkin() { super(GameList.this); - - state.set(State.fromTitle(i18n("version.manage"), 200)); } @Override diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java index d7ef3cb8b..2f69851e1 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java @@ -358,7 +358,7 @@ public class VersionPage extends Control implements DecoratorPage, ModDownloadPa } control.state.bind(Bindings.createObjectBinding(() -> - State.fromTitle(i18n("version.manage.manage.title", getSkinnable().getVersion()), 200), + State.fromTitle(i18n("version.manage.manage.title", getSkinnable().getVersion()), -1), getSkinnable().version)); //control.transitionPane.getStyleClass().add("gray-background");