From 05562b5c2aef9a71ced1ac6f524a6583970bcb12 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Sat, 18 Sep 2021 02:57:03 +0800 Subject: [PATCH] feat: unify look. --- .../org/jackhuang/hmcl/ui/InstallerItem.java | 24 ++++++++++------- .../org/jackhuang/hmcl/ui/ListPageBase.java | 18 ++++++++++--- .../hmcl/ui/ToolbarListPageSkin.java | 26 +++++++++---------- .../hmcl/ui/download/InstallersPage.java | 19 ++++++++------ .../hmcl/ui/versions/GameListItemSkin.java | 8 +++--- .../hmcl/ui/versions/InstallerListPage.java | 2 +- .../hmcl/ui/versions/ModListPageSkin.java | 3 ++- .../hmcl/ui/versions/WorldListItemSkin.java | 9 ++++--- .../hmcl/ui/versions/WorldListPage.java | 7 ++--- 9 files changed, 67 insertions(+), 49 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java index 3e49109cd..4109eb7d9 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java @@ -18,13 +18,13 @@ package org.jackhuang.hmcl.ui; import com.jfoenix.controls.JFXButton; -import com.jfoenix.effects.JFXDepthManager; import javafx.beans.binding.Bindings; import javafx.beans.property.*; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Cursor; +import javafx.scene.Node; import javafx.scene.control.Control; import javafx.scene.control.Label; import javafx.scene.control.Skin; @@ -37,6 +37,7 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import org.jackhuang.hmcl.download.LibraryAnalyzer; import org.jackhuang.hmcl.setting.Theme; +import org.jackhuang.hmcl.ui.construct.RipplerContainer; import org.jackhuang.hmcl.util.i18n.I18n; import static org.jackhuang.hmcl.download.LibraryAnalyzer.LibraryType.*; @@ -153,24 +154,29 @@ public class InstallerItem extends Control { super(control); HBox hbox = new HBox(); - getChildren().setAll(hbox); - JFXDepthManager.setDepth(hbox, 1); - - hbox.getStyleClass().add("card"); + hbox.getStyleClass().add("md-list-cell"); + hbox.setPadding(new Insets(8)); + RipplerContainer container = new RipplerContainer(hbox); + getChildren().setAll(container); hbox.setAlignment(Pos.CENTER_LEFT); if (control.imageUrl != null) { - hbox.getChildren().add(FXUtils.limitingSize(new ImageView(new Image(control.imageUrl, 32, 32, true, true)), 32, 32)); + ImageView view = new ImageView(new Image(control.imageUrl, 32, 32, true, true)); + Node node = FXUtils.limitingSize(view, 32, 32); + node.setMouseTransparent(true); + hbox.getChildren().add(node); } Label nameLabel = new Label(); + nameLabel.setMouseTransparent(true); hbox.getChildren().add(nameLabel); nameLabel.setPrefWidth(80); nameLabel.textProperty().set(I18n.hasKey("install.installer." + control.id) ? i18n("install.installer." + control.id) : control.id); HBox.setMargin(nameLabel, new Insets(0, 4, 0, 4)); Label label = new Label(); + label.setMouseTransparent(true); hbox.getChildren().add(label); label.setMaxWidth(Double.MAX_VALUE); HBox.setHgrow(label, Priority.ALWAYS); @@ -213,11 +219,11 @@ public class InstallerItem extends Control { FXUtils.onChangeAndOperate(arrowButton.visibleProperty(), clickable -> { if (clickable) { - hbox.onMouseClickedProperty().bind(control.action); + container.onMouseClickedProperty().bind(control.action); hbox.setCursor(Cursor.HAND); } else { - hbox.onMouseClickedProperty().unbind(); - hbox.onMouseClickedProperty().set(null); + container.onMouseClickedProperty().unbind(); + container.onMouseClickedProperty().set(null); hbox.setCursor(Cursor.DEFAULT); } }); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ListPageBase.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ListPageBase.java index e1340d132..8fb03664a 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ListPageBase.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ListPageBase.java @@ -17,10 +17,7 @@ */ package org.jackhuang.hmcl.ui; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.ListProperty; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleListProperty; +import javafx.beans.property.*; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.control.Control; @@ -28,6 +25,7 @@ import javafx.scene.control.Control; public class ListPageBase extends Control { private final ListProperty items = new SimpleListProperty<>(this, "items", FXCollections.observableArrayList()); private final BooleanProperty loading = new SimpleBooleanProperty(this, "loading", false); + private final StringProperty failedReason = new SimpleStringProperty(this, "failed"); public ObservableList getItems() { return items.get(); @@ -52,4 +50,16 @@ public class ListPageBase extends Control { public BooleanProperty loadingProperty() { return loading; } + + public String getFailedReason() { + return failedReason.get(); + } + + public StringProperty failedReasonProperty() { + return failedReason; + } + + public void setFailedReason(String failedReason) { + this.failedReason.set(failedReason); + } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ToolbarListPageSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ToolbarListPageSkin.java index 0033552bd..2b44849d0 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ToolbarListPageSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ToolbarListPageSkin.java @@ -22,14 +22,16 @@ import com.jfoenix.controls.JFXScrollPane; import com.jfoenix.effects.JFXDepthManager; import javafx.beans.binding.Bindings; import javafx.geometry.Insets; +import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.control.ScrollPane; import javafx.scene.control.SkinBase; -import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; +import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import org.jackhuang.hmcl.setting.Theme; +import org.jackhuang.hmcl.ui.construct.ComponentList; import org.jackhuang.hmcl.ui.construct.SpinnerPane; import java.util.List; @@ -40,43 +42,39 @@ public abstract class ToolbarListPageSkin super(skinnable); SpinnerPane spinnerPane = new SpinnerPane(); + spinnerPane.loadingProperty().bind(skinnable.loadingProperty()); + spinnerPane.failedReasonProperty().bind(skinnable.failedReasonProperty()); spinnerPane.getStyleClass().add("large-spinner-pane"); - BorderPane root = new BorderPane(); + ComponentList root = new ComponentList(); + root.getStyleClass().add("no-padding"); + StackPane.setMargin(root, new Insets(10)); List toolbarButtons = initializeToolbar(skinnable); if (!toolbarButtons.isEmpty()) { HBox toolbar = new HBox(); - toolbar.getStyleClass().add("jfx-tool-bar-second"); + toolbar.setAlignment(Pos.CENTER_LEFT); JFXDepthManager.setDepth(toolbar, 1); toolbar.setPickOnBounds(false); toolbar.getChildren().setAll(toolbarButtons); - root.setTop(toolbar); + root.getContent().add(toolbar); } { ScrollPane scrollPane = new ScrollPane(); + ComponentList.setVgrow(scrollPane, Priority.ALWAYS); scrollPane.setFitToWidth(true); VBox content = new VBox(); - content.setSpacing(10); - content.setPadding(new Insets(10)); Bindings.bindContent(content.getChildren(), skinnable.itemsProperty()); scrollPane.setContent(content); JFXScrollPane.smoothScrolling(scrollPane); - root.setCenter(scrollPane); + root.getContent().add(scrollPane); } - FXUtils.onChangeAndOperate(skinnable.loadingProperty(), loading -> { - if (loading) { - spinnerPane.showSpinner(); - } else { - spinnerPane.hideSpinner(); - } - }); spinnerPane.setContent(root); getChildren().setAll(spinnerPane); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java index 6cf3d312e..46fc97ab2 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java @@ -36,6 +36,7 @@ import org.jackhuang.hmcl.download.RemoteVersion; import org.jackhuang.hmcl.game.HMCLGameRepository; import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.InstallerItem; +import org.jackhuang.hmcl.ui.construct.ComponentList; import org.jackhuang.hmcl.ui.construct.MessageDialogPane; import org.jackhuang.hmcl.ui.construct.RequiredValidator; import org.jackhuang.hmcl.ui.construct.Validator; @@ -139,22 +140,24 @@ public class InstallersPage extends Control implements WizardPage { BorderPane root = new BorderPane(); root.setPadding(new Insets(16)); - VBox list = new VBox(8); + ComponentList list = new ComponentList(); + list.getStyleClass().add("no-padding"); root.setCenter(list); { HBox versionNamePane = new HBox(8); versionNamePane.setAlignment(Pos.CENTER_LEFT); - versionNamePane.getStyleClass().add("card"); - versionNamePane.setStyle("-fx-padding: 20 8 20 16"); - - versionNamePane.getChildren().add(new Label(i18n("archive.name"))); + versionNamePane.setPadding(new Insets(20, 8, 20, 16)); control.txtName.setMaxWidth(300); - versionNamePane.getChildren().add(control.txtName); - list.getChildren().add(versionNamePane); + versionNamePane.getChildren().setAll(new Label(i18n("archive.name")), control.txtName); + list.getContent().add(versionNamePane); + } + + { + VBox libraryPane = new VBox(control.group.getLibraries()); + list.getContent().add(libraryPane); } - list.getChildren().addAll(control.group.getLibraries()); { JFXButton installButton = new JFXButton(i18n("button.install")); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameListItemSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameListItemSkin.java index d0d675eaf..61dbb48df 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameListItemSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameListItemSkin.java @@ -20,7 +20,6 @@ package org.jackhuang.hmcl.ui.versions; import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXPopup; import com.jfoenix.controls.JFXRadioButton; -import com.jfoenix.effects.JFXDepthManager; import javafx.geometry.Pos; import javafx.scene.Cursor; import javafx.scene.control.SkinBase; @@ -33,6 +32,7 @@ import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.construct.IconedMenuItem; import org.jackhuang.hmcl.ui.construct.MenuSeparator; import org.jackhuang.hmcl.ui.construct.PopupMenu; +import org.jackhuang.hmcl.ui.construct.RipplerContainer; import org.jackhuang.hmcl.util.Lazy; import static org.jackhuang.hmcl.ui.FXUtils.runInFX; @@ -109,11 +109,11 @@ public class GameListItemSkin extends SkinBase { root.setRight(right); - root.getStyleClass().add("card"); + root.getStyleClass().add("md-list-cell"); root.setStyle("-fx-padding: 8 8 8 0"); - JFXDepthManager.setDepth(root, 1); - getChildren().setAll(root); + RipplerContainer container = new RipplerContainer(root); + getChildren().setAll(container); root.setCursor(Cursor.HAND); root.setOnMouseClicked(e -> { 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 4639d5a5f..98aa1c24b 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 @@ -174,7 +174,7 @@ public class InstallerListPage extends ListPageBase implements Ve @Override protected List initializeToolbar(InstallerListPage skinnable) { return Collections.singletonList( - createToolbarButton(i18n("install.installer.install_offline"), SVG::plus, skinnable::installOffline)); + createToolbarButton2(i18n("install.installer.install_offline"), SVG::plus, skinnable::installOffline)); } } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java index f3d31765d..13be7811f 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java @@ -114,6 +114,7 @@ class ModListPageSkin extends SkinBase { label.prefWidthProperty().bind(pane.widthProperty().add(-100)); FXUtils.onChangeAndOperate(skinnable.moddedProperty(), modded -> { + if (modded) pane.getChildren().setAll(root); else pane.getChildren().setAll(label); }); @@ -281,7 +282,7 @@ class ModListPageSkin extends SkinBase { container.getChildren().setAll(checkBox, content, revealButton, infoButton); - StackPane.setMargin(container, new Insets(10, 16, 10, 16)); + StackPane.setMargin(container, new Insets(8)); getContainer().getChildren().setAll(container); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListItemSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListItemSkin.java index f3139940a..322cad69f 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListItemSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListItemSkin.java @@ -19,6 +19,7 @@ package org.jackhuang.hmcl.ui.versions; import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXPopup; +import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.SkinBase; import javafx.scene.image.ImageView; @@ -30,6 +31,7 @@ import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.construct.IconedMenuItem; import org.jackhuang.hmcl.ui.construct.PopupMenu; +import org.jackhuang.hmcl.ui.construct.RipplerContainer; import org.jackhuang.hmcl.ui.construct.TwoLineListItem; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; @@ -42,6 +44,7 @@ public class WorldListItemSkin extends SkinBase { BorderPane root = new BorderPane(); HBox center = new HBox(); + center.setMouseTransparent(true); center.setSpacing(8); center.setAlignment(Pos.CENTER_LEFT); @@ -82,9 +85,9 @@ public class WorldListItemSkin extends SkinBase { right.getChildren().add(btnManage); root.setRight(right); - root.getStyleClass().add("card"); - root.setStyle("-fx-padding: 8 8 8 0"); + root.getStyleClass().add("md-list-cell"); + root.setPadding(new Insets(8)); - getChildren().setAll(root); + getChildren().setAll(new RipplerContainer(root)); } } 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 bce0f6bba..4f84e63a7 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 @@ -25,7 +25,6 @@ import javafx.scene.Node; import javafx.stage.FileChooser; import org.jackhuang.hmcl.game.World; import org.jackhuang.hmcl.setting.Profile; -import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.*; @@ -161,14 +160,12 @@ public class WorldListPage extends ListPageBase implements Versio @Override protected List initializeToolbar(WorldListPage skinnable) { JFXCheckBox chkShowAll = new JFXCheckBox(); - chkShowAll.getStyleClass().add("jfx-tool-bar-checkbox"); - chkShowAll.textFillProperty().bind(Theme.foregroundFillBinding()); chkShowAll.setText(i18n("world.show_all")); chkShowAll.selectedProperty().bindBidirectional(skinnable.showAllProperty()); return Arrays.asList(chkShowAll, - createToolbarButton(i18n("button.refresh"), SVG::refresh, skinnable::refresh), - createToolbarButton(i18n("world.add"), SVG::plus, skinnable::add)); + createToolbarButton2(i18n("button.refresh"), SVG::refresh, skinnable::refresh), + createToolbarButton2(i18n("world.add"), SVG::plus, skinnable::add)); } } }