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 e879ead17..3bdfdf3b1 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java @@ -18,7 +18,10 @@ package org.jackhuang.hmcl.ui; import com.jfoenix.controls.*; -import javafx.animation.*; +import javafx.animation.Interpolator; +import javafx.animation.KeyFrame; +import javafx.animation.KeyValue; +import javafx.animation.Timeline; import javafx.application.Platform; import javafx.beans.InvalidationListener; import javafx.beans.property.Property; @@ -26,7 +29,6 @@ import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.beans.value.WeakChangeListener; import javafx.beans.value.WritableValue; -import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; import javafx.geometry.Insets; import javafx.geometry.Pos; @@ -34,8 +36,6 @@ import javafx.scene.Node; import javafx.scene.control.*; import javafx.scene.image.Image; import javafx.scene.image.ImageView; -import javafx.scene.input.MouseEvent; -import javafx.scene.input.ScrollEvent; import javafx.scene.input.TransferMode; import javafx.scene.layout.Region; import javafx.scene.layout.StackPane; @@ -43,7 +43,6 @@ import javafx.scene.shape.Rectangle; import javafx.util.Callback; import javafx.util.Duration; import javafx.util.StringConverter; -import org.jackhuang.hmcl.util.Lang; import org.jackhuang.hmcl.util.Logging; import org.jackhuang.hmcl.util.ResourceNotFoundError; import org.jackhuang.hmcl.util.i18n.I18n; @@ -61,12 +60,9 @@ import java.lang.reflect.Method; import java.net.URI; import java.util.List; import java.util.Objects; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicReference; import java.util.function.BooleanSupplier; import java.util.function.Consumer; import java.util.function.Function; -import java.util.function.Supplier; import java.util.logging.Level; import java.util.stream.Collectors; @@ -443,72 +439,6 @@ public final class FXUtils { comboBox.getSelectionModel().selectedIndexProperty().removeListener(listener); } - public static void smoothScrolling(ListView listView) { - listView.skinProperty().addListener(o -> { - ScrollBar bar = (ScrollBar) listView.lookup(".scroll-bar"); - Node virtualFlow = listView.lookup(".virtual-flow"); - double[] frictions = new double[]{0.99, 0.1, 0.05, 0.04, 0.03, 0.02, 0.01, 0.04, 0.01, 0.008, 0.008, 0.008, 0.008, 0.0006, 0.0005, 0.00003, 0.00001}; - double[] pushes = new double[]{1}; - double[] derivatives = new double[frictions.length]; - - Timeline timeline = new Timeline(); - bar.addEventHandler(MouseEvent.DRAG_DETECTED, e -> timeline.stop()); - - EventHandler scrollEventHandler = event -> { - if (event.getEventType() == ScrollEvent.SCROLL) { - int direction = event.getDeltaY() > 0 ? -1 : 1; - for (int i = 0; i < pushes.length; ++i) - derivatives[i] += direction * pushes[i]; - if (timeline.getStatus() == Animation.Status.STOPPED) - timeline.play(); - event.consume(); - } - }; - - bar.addEventHandler(ScrollEvent.ANY, scrollEventHandler); - virtualFlow.setOnScroll(scrollEventHandler); - - timeline.getKeyFrames().add(new KeyFrame(Duration.millis(3), event -> { - for (int i = 0; i < derivatives.length; ++i) - derivatives[i] *= frictions[i]; - for (int i = 1; i < derivatives.length; ++i) - derivatives[i] += derivatives[i - 1]; - double dy = derivatives[derivatives.length - 1]; - double height = listView.getLayoutBounds().getHeight(); - bar.setValue(Lang.clamp(0, bar.getValue() + dy / height, 1)); - if (Math.abs(dy) < 0.001) - timeline.stop(); - listView.requestLayout(); - })); - timeline.setCycleCount(Animation.INDEFINITE); - }); - } - - public static T runInUIThread(Supplier supplier) { - if (javafx.application.Platform.isFxApplicationThread()) { - return supplier.get(); - } else { - CountDownLatch doneLatch = new CountDownLatch(1); - AtomicReference reference = new AtomicReference<>(); - Platform.runLater(() -> { - try { - reference.set(supplier.get()); - } finally { - doneLatch.countDown(); - } - - }); - - try { - doneLatch.await(); - } catch (InterruptedException var3) { - Thread.currentThread().interrupt(); - } - - return reference.get(); - } - } - /** * Suppress IllegalArgumentException since the url is supposed to be correct definitely. * @param url the url of image. The image resource should be a file within the jar. diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java index 534022c20..77fad1055 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SVG.java @@ -37,7 +37,7 @@ public final class SVG { SVGPath path = new SVGPath(); path.getStyleClass().add("svg"); path.setContent(d); - path.fillProperty().bind(fill); + if (fill != null) path.fillProperty().bind(fill); if (width < 0 || height < 0) { StackPane pane = new StackPane(path); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/MainPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/MainPage.java index 507c24157..2ad1fc248 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/MainPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/MainPage.java @@ -174,7 +174,7 @@ public final class MainPage extends StackPane implements DecoratorPage { menuButton.setOnMouseClicked(e -> onMenu()); menuButton.setClip(new Rectangle(211, -100, 100, 200)); StackPane graphic = new StackPane(); - Node svg = SVG.triangle(Theme.whiteFillBinding(), 10, 10); + Node svg = SVG.triangle(Theme.foregroundFillBinding(), 10, 10); StackPane.setAlignment(svg, Pos.CENTER_RIGHT); graphic.getChildren().setAll(svg); graphic.setTranslateX(12); 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 d85cd8f7d..80100cee5 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 @@ -17,16 +17,17 @@ */ package org.jackhuang.hmcl.ui.versions; -import com.jfoenix.controls.*; +import com.jfoenix.controls.JFXButton; +import com.jfoenix.controls.JFXListCell; +import com.jfoenix.controls.JFXListView; +import com.jfoenix.controls.JFXPopup; import javafx.application.Platform; import javafx.beans.property.*; -import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.*; import javafx.scene.input.MouseButton; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; -import javafx.scene.layout.StackPane; import javafx.util.Callback; import org.jackhuang.hmcl.game.HMCLGameRepository; import org.jackhuang.hmcl.game.Version; @@ -244,7 +245,6 @@ public class VersionPage extends Control implements DecoratorPage { }, listViewItemPopup)) ); - FXUtils.smoothScrolling(control.listView); control.listView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); control.listView.setCellFactory(new Callback, ListCell>() { @Override @@ -318,7 +318,7 @@ public class VersionPage extends Control implements DecoratorPage { ); JFXButton upgradeButton = new JFXButton(); - upgradeButton.setGraphic(SVG.update(Theme.whiteFillBinding(), 20, 20)); + upgradeButton.setGraphic(SVG.update(null, 20, 20)); upgradeButton.getStyleClass().add("jfx-decorator-button"); upgradeButton.ripplerFillProperty().bind(Theme.whiteFillBinding()); upgradeButton.setOnAction(event -> control.updateGame()); @@ -326,14 +326,14 @@ public class VersionPage extends Control implements DecoratorPage { FXUtils.installFastTooltip(upgradeButton, i18n("version.update")); JFXButton testGameButton = new JFXButton(); - testGameButton.setGraphic(SVG.launch(Theme.whiteFillBinding(), 20, 20)); + testGameButton.setGraphic(SVG.launch(null, 20, 20)); testGameButton.getStyleClass().add("jfx-decorator-button"); testGameButton.ripplerFillProperty().bind(Theme.whiteFillBinding()); testGameButton.setOnAction(event -> control.testGame()); FXUtils.installFastTooltip(testGameButton, i18n("version.launch.test")); JFXButton browseMenuButton = new JFXButton(); - browseMenuButton.setGraphic(SVG.folderOpen(Theme.whiteFillBinding(), 20, 20)); + browseMenuButton.setGraphic(SVG.folderOpen(null, 20, 20)); browseMenuButton.getStyleClass().add("jfx-decorator-button"); browseMenuButton.ripplerFillProperty().bind(Theme.whiteFillBinding()); browseMenuButton.setOnAction(event -> browsePopup.show(browseMenuButton, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, 0, browseMenuButton.getHeight())); @@ -342,7 +342,7 @@ public class VersionPage extends Control implements DecoratorPage { JFXButton managementMenuButton = new JFXButton(); FXUtils.setLimitWidth(managementMenuButton, 40); FXUtils.setLimitHeight(managementMenuButton, 40); - managementMenuButton.setGraphic(SVG.wrench(Theme.whiteFillBinding(), 20, 20)); + managementMenuButton.setGraphic(SVG.wrench(null, 20, 20)); managementMenuButton.getStyleClass().add("jfx-decorator-button"); managementMenuButton.ripplerFillProperty().bind(Theme.whiteFillBinding()); managementMenuButton.setOnAction(event -> managementPopup.show(managementMenuButton, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, 0, managementMenuButton.getHeight())); diff --git a/HMCL/src/main/resources/assets/css/root.css b/HMCL/src/main/resources/assets/css/root.css index d7b8e74a1..80104e071 100644 --- a/HMCL/src/main/resources/assets/css/root.css +++ b/HMCL/src/main/resources/assets/css/root.css @@ -393,6 +393,10 @@ -fx-cursor: hand; } +.jfx-tool-bar .jfx-decorator-button .svg { + -fx-fill: -fx-base-text-fill; +} + .jfx-tool-bar Label { -fx-text-fill: WHITE; } @@ -687,7 +691,6 @@ } .jfx-list-view-float { - -fx-padding: 5; -fx-background-insets: 0.0; -jfx-cell-horizontal-margin: 0.0; -jfx-cell-vertical-margin: 5.0; @@ -1108,10 +1111,6 @@ -fx-decorator-color: -fx-base-color; } -.jfx-decorator .jfx-decorator-buttons-container { - -fx-background-color: -fx-decorator-color; -} - .jfx-decorator-drawer { -fx-background-color: rgba(244, 244, 244, 0.5); }