From 90976cc7e0f52a8d058810df59c520a7e41e4757 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Mon, 20 Sep 2021 13:31:35 +0800 Subject: [PATCH] fix: should not navigate to DownloadPage when clicking GameListItem --- .../org/jackhuang/hmcl/ui/ListPageBase.java | 21 ++++++------- .../hmcl/ui/ToolbarListPageSkin.java | 2 +- .../hmcl/ui/construct/SpinnerPane.java | 30 +++++++++++-------- .../hmcl/ui/versions/GameListPage.java | 2 +- 4 files changed, 31 insertions(+), 24 deletions(-) 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 003f7faad..38911bbdd 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ListPageBase.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ListPageBase.java @@ -20,10 +20,12 @@ package org.jackhuang.hmcl.ui; import javafx.beans.property.*; import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import javafx.event.ActionEvent; +import javafx.event.Event; import javafx.event.EventHandler; import javafx.scene.control.Control; +import static org.jackhuang.hmcl.ui.construct.SpinnerPane.FAILED_ACTION; + public class ListPageBase extends Control { private final ListProperty items = new SimpleListProperty<>(this, "items", FXCollections.observableArrayList()); private final BooleanProperty loading = new SimpleBooleanProperty(this, "loading", false); @@ -65,23 +67,22 @@ public class ListPageBase extends Control { this.failedReason.set(failedReason); } - public final ObjectProperty> onActionProperty() { - return onAction; + public final ObjectProperty> onFailedActionProperty() { + return onFailedAction; } - public final void setOnAction(EventHandler value) { - onActionProperty().set(value); + public final void setOnFailedAction(EventHandler value) { + onFailedActionProperty().set(value); } - public final EventHandler getOnAction() { - return onActionProperty().get(); + public final EventHandler getOnFailedAction() { + return onFailedActionProperty().get(); } - private ObjectProperty> onAction = new SimpleObjectProperty>(this, "onAction") { + private ObjectProperty> onFailedAction = new SimpleObjectProperty>(this, "onFailedAction") { @Override protected void invalidated() { - setEventHandler(ActionEvent.ACTION, get()); + setEventHandler(FAILED_ACTION, get()); } }; - } 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 819aa94a2..d051924c0 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ToolbarListPageSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ToolbarListPageSkin.java @@ -43,7 +43,7 @@ public abstract class ToolbarListPageSkin SpinnerPane spinnerPane = new SpinnerPane(); spinnerPane.loadingProperty().bind(skinnable.loadingProperty()); spinnerPane.failedReasonProperty().bind(skinnable.failedReasonProperty()); - spinnerPane.onActionProperty().bind(skinnable.onActionProperty()); + spinnerPane.onFailedActionProperty().bind(skinnable.onFailedActionProperty()); spinnerPane.getStyleClass().add("large-spinner-pane"); ComponentList root = new ComponentList(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/SpinnerPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/SpinnerPane.java index 7aa7c0045..8035df089 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/SpinnerPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/SpinnerPane.java @@ -21,8 +21,9 @@ import com.jfoenix.controls.JFXSpinner; import javafx.beans.DefaultProperty; import javafx.beans.InvalidationListener; import javafx.beans.property.*; -import javafx.event.ActionEvent; +import javafx.event.Event; import javafx.event.EventHandler; +import javafx.event.EventType; import javafx.scene.Node; import javafx.scene.control.Control; import javafx.scene.control.Label; @@ -88,25 +89,24 @@ public class SpinnerPane extends Control { this.failedReason.set(failedReason); } - public final ObjectProperty> onActionProperty() { - return onAction; + public final ObjectProperty> onFailedActionProperty() { + return onFailedAction; } - public final void setOnAction(EventHandler value) { - onActionProperty().set(value); + public final void setOnFailedAction(EventHandler value) { + onFailedActionProperty().set(value); } - public final EventHandler getOnAction() { - return onActionProperty().get(); + public final EventHandler getOnFailedAction() { + return onFailedActionProperty().get(); } - private ObjectProperty> onAction = new SimpleObjectProperty>(this, "onAction") { + private ObjectProperty> onFailedAction = new SimpleObjectProperty>(this, "onFailedAction") { @Override protected void invalidated() { - setEventHandler(ActionEvent.ACTION, get()); + setEventHandler(FAILED_ACTION, get()); } }; - @Override protected Skin createDefaultSkin() { return new Skin(this); @@ -130,8 +130,12 @@ public class SpinnerPane extends Control { failedPane.getStyleClass().add("notice-pane"); failedPane.getChildren().setAll(failedReasonLabel); failedPane.onMouseClickedProperty().bind( - BindingMapping.of(control.onAction) - .map(actionHandler -> (e -> actionHandler.handle(new ActionEvent())))); + BindingMapping.of(control.onFailedAction) + .map(actionHandler -> (e -> { + if (actionHandler != null) { + actionHandler.handle(new Event(FAILED_ACTION)); + } + }))); FXUtils.onChangeAndOperate(getSkinnable().content, newValue -> { if (newValue == null) { @@ -172,4 +176,6 @@ public class SpinnerPane extends Control { return reason; } } + + public static final EventType FAILED_ACTION = new EventType<>(Event.ANY, "FAILED_ACTION"); } 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 e9a24cf35..38d76b632 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 @@ -180,7 +180,7 @@ public class GameListPage extends ListPageBase implements Decorato Profiles.registerVersionsListener(this::loadVersions); - setOnAction(e -> Controllers.navigate(Controllers.getDownloadPage())); + setOnFailedAction(e -> Controllers.navigate(Controllers.getDownloadPage())); } private void loadVersions(Profile profile) {