From 83516ba679291456f204dcc604c057ac2bb2cf4f Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Tue, 2 Oct 2018 12:15:52 +0800 Subject: [PATCH] Fix #461 --- HMCL/build.gradle | 4 +++- .../hmcl/ui/construct/Navigator.java | 8 ++++++-- .../hmcl/ui/versions/VersionPage.java | 20 +++++++++++++++++++ build.gradle | 1 + 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/HMCL/build.gradle b/HMCL/build.gradle index 82a8a460d..337b3880e 100644 --- a/HMCL/build.gradle +++ b/HMCL/build.gradle @@ -23,6 +23,8 @@ if (System.getenv("BUILD_NUMBER") != null && System.getenv("BUILD_NUMBER_OFFSET" def versionroot = System.getenv("VERSION_ROOT") ?: "3.2" version = versionroot + '.' + buildnumber +mainClassName = 'org.jackhuang.hmcl.Main' + dependencies { compile project(":HMCLCore") compile rootProject.files("lib/JFoenix.jar") @@ -75,7 +77,7 @@ def repack(File file) { jar { manifest { attributes 'Created-By': 'Copyright(c) 2013-2018 huangyuhui.', - 'Main-Class': 'org.jackhuang.hmcl.Main', + 'Main-Class': mainClassName, 'Multi-Release': 'true', 'Implementation-Version': version } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/Navigator.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/Navigator.java index b6a6931e1..41815563c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/Navigator.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/Navigator.java @@ -83,9 +83,13 @@ public class Navigator extends StackPane { throw new IllegalStateException(); stack.pop(); Node node = stack.peek(); - fireEvent(new NavigationEvent(this, from, NavigationEvent.NAVIGATING)); + NavigationEvent navigating = new NavigationEvent(this, from, NavigationEvent.NAVIGATING); + fireEvent(navigating); + node.fireEvent(navigating); setContent(node); - fireEvent(new NavigationEvent(this, node, NavigationEvent.NAVIGATED)); + NavigationEvent navigated = new NavigationEvent(this, node, NavigationEvent.NAVIGATED); + fireEvent(navigated); + node.fireEvent(navigated); Optional.ofNullable(from.getProperties().get(PROPERTY_DIALOG_CLOSE_HANDLER)) .ifPresent(handler -> from.removeEventHandler(PageCloseEvent.CLOSE, (EventHandler) handler)); 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 d9a1189fe..404867f66 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 @@ -20,6 +20,7 @@ package org.jackhuang.hmcl.ui.versions; import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXPopup; import com.jfoenix.controls.JFXTabPane; +import javafx.application.Platform; import javafx.beans.property.ReadOnlyStringProperty; import javafx.beans.property.ReadOnlyStringWrapper; import javafx.fxml.FXML; @@ -30,6 +31,8 @@ import org.jackhuang.hmcl.download.game.GameAssetIndexDownloadTask; import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.construct.IconedMenuItem; +import org.jackhuang.hmcl.ui.construct.Navigator; +import org.jackhuang.hmcl.ui.construct.PageCloseEvent; import org.jackhuang.hmcl.ui.construct.PopupMenu; import org.jackhuang.hmcl.ui.decorator.DecoratorPage; import org.jackhuang.hmcl.util.io.FileUtils; @@ -99,6 +102,8 @@ public final class VersionPage extends StackPane implements DecoratorPage { FXUtils.installTooltip(btnBrowseMenu, i18n("settings.game.exploration")); FXUtils.installTooltip(btnManagementMenu, i18n("settings.game.management")); FXUtils.installTooltip(btnExport, i18n("modpack.export")); + + setEventHandler(Navigator.NavigationEvent.NAVIGATED, this::onNavigated); } public void load(String id, Profile profile) { @@ -115,6 +120,21 @@ public final class VersionPage extends StackPane implements DecoratorPage { world.loadVersion(profile, id); } + private void onNavigated(Navigator.NavigationEvent event) { + if (this.version == null || this.profile == null) + throw new IllegalStateException(); + + // If we jumped to game list page and deleted this version + // and back to this page, we should return to main page. + if (!this.profile.getRepository().isLoaded() || + !this.profile.getRepository().hasVersion(version)) { + Platform.runLater(() -> fireEvent(new PageCloseEvent())); + return; + } + + load(this.version, this.profile); + } + @FXML private void onBrowseMenu() { browsePopup.show(btnBrowseMenu, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, 0, btnBrowseMenu.getHeight()); diff --git a/build.gradle b/build.gradle index b83739842..bc362b04a 100644 --- a/build.gradle +++ b/build.gradle @@ -32,6 +32,7 @@ buildscript { subprojects { apply plugin: 'java' apply plugin: 'idea' + apply plugin: 'application' repositories { mavenCentral()