From 53c63db1501e082a8d92dcbcabe5557a83e70308 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Wed, 4 Aug 2021 01:29:07 +0800 Subject: [PATCH] fix: ModListPage not loading mods. --- .../java/org/jackhuang/hmcl/ui/FXUtils.java | 7 +- .../hmcl/ui/construct/SpinnerPane.java | 4 +- .../hmcl/ui/construct/TabControl.java | 49 ++++++----- .../hmcl/ui/construct/TabHeader.java | 20 ++--- .../hmcl/ui/decorator/DecoratorTabPage.java | 18 ++-- .../hmcl/ui/versions/InstallerListPage.java | 7 +- .../hmcl/ui/versions/ModDownloadListPage.java | 3 +- .../hmcl/ui/versions/ModListPage.java | 20 ++--- .../hmcl/ui/versions/VersionPage.java | 82 +++++++++++-------- .../hmcl/ui/versions/VersionSettingsPage.java | 3 +- .../hmcl/ui/versions/WorldListPage.java | 6 +- 11 files changed, 118 insertions(+), 101 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 b9cad02c2..ff8dd080c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java @@ -114,13 +114,14 @@ public final class FXUtils { return onWeakChange(value, consumer); } - public static WeakInvalidationListener observeWeak(Runnable runnable, Observable... observables) { - WeakInvalidationListener listener = new WeakInvalidationListener(observable -> runnable.run()); + public static InvalidationListener observeWeak(Runnable runnable, Observable... observables) { + InvalidationListener originalListener = observable -> runnable.run(); + WeakInvalidationListener listener = new WeakInvalidationListener(originalListener); for (Observable observable : observables) { observable.addListener(listener); } runnable.run(); - return listener; + return originalListener; } public static void runLaterIf(BooleanSupplier condition, Runnable runnable) { 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 0bcde0259..68671de95 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 @@ -19,7 +19,7 @@ package org.jackhuang.hmcl.ui.construct; import com.jfoenix.controls.JFXSpinner; import javafx.beans.DefaultProperty; -import javafx.beans.WeakInvalidationListener; +import javafx.beans.InvalidationListener; import javafx.beans.property.*; import javafx.scene.Node; import javafx.scene.control.Control; @@ -94,7 +94,7 @@ public class SpinnerPane extends Control { private final StackPane failedPane = new StackPane(); private final Label failedReasonLabel = new Label(); @SuppressWarnings("FieldCanBeLocal") // prevent from gc. - private final WeakInvalidationListener observer; + private final InvalidationListener observer; protected Skin(SpinnerPane control) { super(control); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TabControl.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TabControl.java index f4fd58746..89a6e6cb7 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TabControl.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TabControl.java @@ -27,9 +27,9 @@ import javafx.scene.control.SingleSelectionModel; import java.util.function.Supplier; public interface TabControl { - ObservableList getTabs(); + ObservableList> getTabs(); - class TabControlSelectionModel extends SingleSelectionModel { + class TabControlSelectionModel extends SingleSelectionModel> { private final TabControl tabHeader; public TabControlSelectionModel(final TabControl t) { @@ -39,9 +39,9 @@ public interface TabControl { this.tabHeader = t; // watching for changes to the items list content - final ListChangeListener itemsContentObserver = c -> { + final ListChangeListener> itemsContentObserver = c -> { while (c.next()) { - for (Tab tab : c.getRemoved()) { + for (Tab tab : c.getRemoved()) { if (tab != null && !tabHeader.getTabs().contains(tab)) { if (tab.isSelected()) { tab.setSelected(false); @@ -117,29 +117,29 @@ public interface TabControl { } } - @Override protected Tab getModelItem(int index) { - final ObservableList items = tabHeader.getTabs(); + @Override protected Tab getModelItem(int index) { + final ObservableList> items = tabHeader.getTabs(); if (items == null) return null; if (index < 0 || index >= items.size()) return null; return items.get(index); } @Override protected int getItemCount() { - final ObservableList items = tabHeader.getTabs(); + final ObservableList> items = tabHeader.getTabs(); return items == null ? 0 : items.size(); } - private Tab findNearestAvailableTab(int tabIndex, boolean doSelect) { + private Tab findNearestAvailableTab(int tabIndex, boolean doSelect) { // we always try to select the nearest, non-disabled // tab from the position of the closed tab. final int tabCount = getItemCount(); int i = 1; - Tab bestTab = null; + Tab bestTab = null; while (true) { // look leftwards int downPos = tabIndex - i; if (downPos >= 0) { - Tab _tab = getModelItem(downPos); + Tab _tab = getModelItem(downPos); if (_tab != null) { bestTab = _tab; break; @@ -153,7 +153,7 @@ public interface TabControl { // the removed tabs position). int upPos = tabIndex + i - 1; if (upPos < tabCount) { - Tab _tab = getModelItem(upPos); + Tab _tab = getModelItem(upPos); if (_tab != null) { bestTab = _tab; break; @@ -174,12 +174,12 @@ public interface TabControl { } } - class Tab { + class Tab { private final StringProperty id = new SimpleStringProperty(this, "id"); private final StringProperty text = new SimpleStringProperty(this, "text"); private final ReadOnlyBooleanWrapper selected = new ReadOnlyBooleanWrapper(this, "selected"); - private final ObjectProperty node = new SimpleObjectProperty<>(this, "node"); - private Supplier nodeSupplier; + private final ObjectProperty node = new SimpleObjectProperty<>(this, "node"); + private Supplier nodeSupplier; public Tab(String id) { setId(id); @@ -190,11 +190,11 @@ public interface TabControl { setText(text); } - public Supplier getNodeSupplier() { + public Supplier getNodeSupplier() { return nodeSupplier; } - public void setNodeSupplier(Supplier nodeSupplier) { + public void setNodeSupplier(Supplier nodeSupplier) { this.nodeSupplier = nodeSupplier; } @@ -234,16 +234,27 @@ public interface TabControl { this.selected.set(selected); } - public Node getNode() { + public T getNode() { return node.get(); } - public ObjectProperty nodeProperty() { + public ObjectProperty nodeProperty() { return node; } - public void setNode(Node node) { + public void setNode(T node) { this.node.set(node); } + + public boolean initializeIfNeeded() { + if (getNode() == null) { + if (getNodeSupplier() == null) { + return false; + } + setNode(getNodeSupplier().get()); + return true; + } + return false; + } } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TabHeader.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TabHeader.java index 87528564b..0bacedcb4 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TabHeader.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TabHeader.java @@ -41,32 +41,32 @@ import org.jackhuang.hmcl.util.javafx.MappedObservableList; public class TabHeader extends Control implements TabControl { - public TabHeader(Tab... tabs) { + public TabHeader(Tab... tabs) { getStyleClass().setAll("tab-header"); if (tabs != null) { getTabs().addAll(tabs); } } - private ObservableList tabs = FXCollections.observableArrayList(); + private ObservableList> tabs = FXCollections.observableArrayList(); private ObjectProperty side = new SimpleObjectProperty<>(Side.TOP); @Override - public ObservableList getTabs() { + public ObservableList> getTabs() { return tabs; } - private final ObjectProperty> selectionModel = new SimpleObjectProperty<>(this, "selectionModel", new TabControlSelectionModel(this)); + private final ObjectProperty>> selectionModel = new SimpleObjectProperty<>(this, "selectionModel", new TabControlSelectionModel(this)); - public SingleSelectionModel getSelectionModel() { + public SingleSelectionModel> getSelectionModel() { return selectionModel.get(); } - public ObjectProperty> selectionModelProperty() { + public ObjectProperty>> selectionModelProperty() { return selectionModel; } - public void setSelectionModel(SingleSelectionModel selectionModel) { + public void setSelectionModel(SingleSelectionModel> selectionModel) { this.selectionModel.set(selectionModel); } @@ -104,7 +104,7 @@ public class TabHeader extends Control implements TabControl { private final HeaderContainer header; private boolean isSelectingTab = false; - private Tab selectedTab; + private Tab selectedTab; protected TabHeaderSkin(TabHeader control) { super(control); @@ -537,12 +537,12 @@ public class TabHeader extends Control implements TabControl { protected class TabHeaderContainer extends StackPane { - private final Tab tab; + private final Tab tab; private final Label tabText; private final BorderPane inner; private final JFXRippler rippler; - public TabHeaderContainer(Tab tab) { + public TabHeaderContainer(Tab tab) { this.tab = tab; tabText = new Label(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorTabPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorTabPage.java index 07c5e9060..325edd269 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorTabPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorTabPage.java @@ -32,9 +32,7 @@ public abstract class DecoratorTabPage extends DecoratorTransitionPage implement public DecoratorTabPage() { getSelectionModel().selectedItemProperty().addListener((a, b, newValue) -> { - if (newValue.getNode() == null && newValue.getNodeSupplier() != null) { - newValue.setNode(newValue.getNodeSupplier().get()); - } + newValue.initializeIfNeeded(); if (newValue.getNode() != null) { onNavigating(getCurrentPage()); if (getCurrentPage() != null) getCurrentPage().fireEvent(new Navigator.NavigationEvent(null, getCurrentPage(), Navigation.NavigationDirection.NEXT, Navigator.NavigationEvent.NAVIGATING)); @@ -45,31 +43,31 @@ public abstract class DecoratorTabPage extends DecoratorTransitionPage implement }); } - public DecoratorTabPage(TabHeader.Tab... tabs) { + public DecoratorTabPage(TabHeader.Tab... tabs) { this(); if (tabs != null) { getTabs().addAll(tabs); } } - private ObservableList tabs = FXCollections.observableArrayList(); + private ObservableList> tabs = FXCollections.observableArrayList(); @Override - public ObservableList getTabs() { + public ObservableList> getTabs() { return tabs; } - private final ObjectProperty> selectionModel = new SimpleObjectProperty<>(this, "selectionModel", new TabControl.TabControlSelectionModel(this)); + private final ObjectProperty>> selectionModel = new SimpleObjectProperty<>(this, "selectionModel", new TabControl.TabControlSelectionModel(this)); - public SingleSelectionModel getSelectionModel() { + public SingleSelectionModel> getSelectionModel() { return selectionModel.get(); } - public ObjectProperty> selectionModelProperty() { + public ObjectProperty>> selectionModelProperty() { return selectionModel; } - public void setSelectionModel(SingleSelectionModel selectionModel) { + public void setSelectionModel(SingleSelectionModel> selectionModel) { this.selectionModel.set(selectionModel); } } 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 179d54b44..495e66dc9 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 @@ -44,7 +44,7 @@ import java.util.function.Function; import static org.jackhuang.hmcl.ui.FXUtils.runInFX; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; -public class InstallerListPage extends ListPageBase { +public class InstallerListPage extends ListPageBase implements VersionPage.VersionLoadable { private Profile profile; private String versionId; private Version version; @@ -62,13 +62,14 @@ public class InstallerListPage extends ListPageBase { return new InstallerListPageSkin(); } - public CompletableFuture loadVersion(Profile profile, String versionId) { + @Override + public void loadVersion(Profile profile, String versionId) { this.profile = profile; this.versionId = versionId; this.version = profile.getRepository().getVersion(versionId); this.gameVersion = null; - return CompletableFuture.supplyAsync(() -> { + CompletableFuture.supplyAsync(() -> { gameVersion = GameVersion.minecraftVersion(profile.getRepository().getVersionJar(version)).orElse(null); return LibraryAnalyzer.analyze(profile.getRepository().getResolvedPreservingPatchesVersion(versionId)); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModDownloadListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModDownloadListPage.java index cddcae903..3114d4b04 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModDownloadListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModDownloadListPage.java @@ -47,7 +47,7 @@ import java.util.stream.Collectors; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; -public class ModDownloadListPage extends Control implements DecoratorPage { +public class ModDownloadListPage extends Control implements DecoratorPage, VersionPage.VersionLoadable { protected final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(); private final BooleanProperty loading = new SimpleBooleanProperty(false); private final BooleanProperty failed = new SimpleBooleanProperty(false); @@ -66,6 +66,7 @@ public class ModDownloadListPage extends Control implements DecoratorPage { this.callback = callback; } + @Override public void loadVersion(Profile profile, String version) { this.version.set(new Profile.ProfileVersion(profile, version)); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPage.java index d68d4b034..50b1f2c10 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPage.java @@ -32,7 +32,6 @@ import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.ListPageBase; -import org.jackhuang.hmcl.ui.construct.TabHeader; import org.jackhuang.hmcl.util.Logging; import org.jackhuang.hmcl.util.io.FileUtils; @@ -50,16 +49,13 @@ import java.util.stream.Collectors; import static org.jackhuang.hmcl.ui.FXUtils.runInFX; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; -public final class ModListPage extends ListPageBase { +public final class ModListPage extends ListPageBase implements VersionPage.VersionLoadable { private final BooleanProperty modded = new SimpleBooleanProperty(this, "modded", false); - private TabHeader.Tab tab; private ModManager modManager; private LibraryAnalyzer libraryAnalyzer; - public ModListPage(TabHeader.Tab tab) { - this.tab = tab; - + public ModListPage() { FXUtils.applyDragListener(this, it -> Arrays.asList("jar", "zip", "litemod").contains(FileUtils.getExtension(it)), mods -> { mods.forEach(it -> { try { @@ -81,10 +77,11 @@ public final class ModListPage extends ListPageBase loadVersion(Profile profile, String id) { + @Override + public void loadVersion(Profile profile, String id) { libraryAnalyzer = LibraryAnalyzer.analyze(profile.getRepository().getResolvedPreservingPatchesVersion(id)); modded.set(libraryAnalyzer.hasModLoader()); - return loadMods(profile.getRepository().getModManager(id)); + loadMods(profile.getRepository().getModManager(id)); } private CompletableFuture loadMods(ModManager modManager) { @@ -99,13 +96,10 @@ public final class ModListPage extends ListPageBase { + }, Schedulers.defaultScheduler()).whenCompleteAsync((list, exception) -> { loadingProperty().set(false); if (exception == null) - getProperties().put(ModListPage.class, FXUtils.onWeakChangeAndOperate(tab.selectedProperty(), newValue -> { - if (newValue) - itemsProperty().setAll(list.stream().map(ModListPageSkin.ModInfoObject::new).sorted().collect(Collectors.toList())); - })); + itemsProperty().setAll(list.stream().map(ModListPageSkin.ModInfoObject::new).sorted().collect(Collectors.toList())); else getProperties().remove(ModListPage.class); }, Platform::runLater); 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 654f05263..133d7ea38 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 @@ -48,41 +48,45 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.nio.file.Path; import java.util.Optional; -import java.util.concurrent.CompletableFuture; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public class VersionPage extends Control implements DecoratorPage, ModDownloadPage.DownloadCallback { private final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(); private final BooleanProperty loading = new SimpleBooleanProperty(); - private final TabHeader.Tab versionSettingsTab = new TabHeader.Tab("versionSettingsTab"); - private final VersionSettingsPage versionSettingsPage = new VersionSettingsPage(); - private final TabHeader.Tab modListTab = new TabHeader.Tab("modListTab"); - private final ModListPage modListPage = new ModListPage(modListTab); - private final TabHeader.Tab curseModListTab = new TabHeader.Tab("modListTab"); - private final ModDownloadListPage curseModListPage = new ModDownloadListPage(CurseModManager.SECTION_MOD, this); - private final TabHeader.Tab installerListTab = new TabHeader.Tab("installerListTab"); - private final InstallerListPage installerListPage = new InstallerListPage(); - private final TabHeader.Tab worldListTab = new TabHeader.Tab("worldList"); - private final WorldListPage worldListPage = new WorldListPage(); + private final TabHeader tab; + private final TabHeader.Tab versionSettingsTab = new TabHeader.Tab<>("versionSettingsTab"); + private final TabHeader.Tab modListTab = new TabHeader.Tab<>("modListTab"); + private final TabHeader.Tab curseModListTab = new TabHeader.Tab<>("modListTab"); + private final TabHeader.Tab installerListTab = new TabHeader.Tab<>("installerListTab"); + private final TabHeader.Tab worldListTab = new TabHeader.Tab<>("worldList"); private final TransitionPane transitionPane = new TransitionPane(); - private final ObjectProperty selectedTab = new SimpleObjectProperty<>(); private final BooleanProperty currentVersionUpgradable = new SimpleBooleanProperty(); private final ObjectProperty version = new SimpleObjectProperty<>(); private String preferredVersionName = null; { - versionSettingsTab.setNode(versionSettingsPage); - modListTab.setNode(modListPage); - curseModListTab.setNode(curseModListPage); - installerListTab.setNode(installerListPage); - worldListTab.setNode(worldListPage); + versionSettingsTab.setNodeSupplier(VersionSettingsPage::new); + modListTab.setNodeSupplier(ModListPage::new); + curseModListTab.setNodeSupplier(() -> new ModDownloadListPage(CurseModManager.SECTION_MOD, this)); + installerListTab.setNodeSupplier(InstallerListPage::new); + worldListTab.setNodeSupplier(WorldListPage::new); + + tab = new TabHeader(versionSettingsTab, modListTab, curseModListTab, installerListTab, worldListTab); addEventHandler(Navigator.NavigationEvent.NAVIGATED, this::onNavigated); - selectedTab.set(versionSettingsTab); - FXUtils.onChangeAndOperate(selectedTab, newValue -> { + tab.getSelectionModel().select(versionSettingsTab); + FXUtils.onChangeAndOperate(tab.getSelectionModel().selectedItemProperty(), newValue -> { + if (newValue.initializeIfNeeded()) { + if (this.version.get() != null) { + if (newValue.getNode() instanceof VersionLoadable) { + ((VersionLoadable) newValue.getNode()).loadVersion(version.get().getProfile(), version.get().getVersion()); + } + } + } + transitionPane.setContent(newValue.getNode(), ContainerAnimations.FADE.getAnimationProducer()); }); } @@ -103,14 +107,17 @@ public class VersionPage extends Control implements DecoratorPage, ModDownloadPa setVersion(version, profile); preferredVersionName = version; - versionSettingsPage.loadVersion(profile, version); - curseModListPage.loadVersion(profile, version); + if (versionSettingsTab.getNode() != null) + versionSettingsTab.getNode().loadVersion(profile, version); + if (modListTab.getNode() != null) + modListTab.getNode().loadVersion(profile, version); + if (curseModListTab.getNode() != null) + curseModListTab.getNode().loadVersion(profile, version); + if (installerListTab.getNode() != null) + installerListTab.getNode().loadVersion(profile, version); + if (worldListTab.getNode() != null) + worldListTab.getNode().loadVersion(profile, version); currentVersionUpgradable.set(profile.getRepository().isModpack(version)); - - CompletableFuture.allOf( - modListPage.loadVersion(profile, version), - installerListPage.loadVersion(profile, version), - worldListPage.loadVersion(profile, version)); } private void onNavigated(Navigator.NavigationEvent event) { @@ -269,40 +276,40 @@ public class VersionPage extends Control implements DecoratorPage, ModDownloadPa versionSettingsItem.setTitle(i18n("settings")); versionSettingsItem.setLeftGraphic(wrap(SVG.gearOutline(null, 20, 20))); versionSettingsItem.setActionButtonVisible(false); - versionSettingsItem.activeProperty().bind(control.selectedTab.isEqualTo(control.versionSettingsTab)); - versionSettingsItem.setOnAction(e -> control.selectedTab.set(control.versionSettingsTab)); + versionSettingsItem.activeProperty().bind(control.tab.getSelectionModel().selectedItemProperty().isEqualTo(control.versionSettingsTab)); + versionSettingsItem.setOnAction(e -> control.tab.getSelectionModel().select(control.versionSettingsTab)); AdvancedListItem modListItem = new AdvancedListItem(); modListItem.getStyleClass().add("navigation-drawer-item"); modListItem.setTitle(i18n("mods")); modListItem.setLeftGraphic(wrap(SVG.puzzle(null, 20, 20))); modListItem.setActionButtonVisible(false); - modListItem.activeProperty().bind(control.selectedTab.isEqualTo(control.modListTab)); - modListItem.setOnAction(e -> control.selectedTab.set(control.modListTab)); + modListItem.activeProperty().bind(control.tab.getSelectionModel().selectedItemProperty().isEqualTo(control.modListTab)); + modListItem.setOnAction(e -> control.tab.getSelectionModel().select(control.modListTab)); AdvancedListItem curseModListItem = new AdvancedListItem(); curseModListItem.getStyleClass().add("navigation-drawer-item"); curseModListItem.setTitle(i18n("mods.download")); curseModListItem.setLeftGraphic(wrap(SVG.fire(null, 20, 20))); curseModListItem.setActionButtonVisible(false); - curseModListItem.activeProperty().bind(control.selectedTab.isEqualTo(control.curseModListTab)); - curseModListItem.setOnAction(e -> control.selectedTab.set(control.curseModListTab)); + curseModListItem.activeProperty().bind(control.tab.getSelectionModel().selectedItemProperty().isEqualTo(control.curseModListTab)); + curseModListItem.setOnAction(e -> control.tab.getSelectionModel().select(control.curseModListTab)); AdvancedListItem installerListItem = new AdvancedListItem(); installerListItem.getStyleClass().add("navigation-drawer-item"); installerListItem.setTitle(i18n("settings.tabs.installers")); installerListItem.setLeftGraphic(wrap(SVG.cube(null, 20, 20))); installerListItem.setActionButtonVisible(false); - installerListItem.activeProperty().bind(control.selectedTab.isEqualTo(control.installerListTab)); - installerListItem.setOnAction(e -> control.selectedTab.set(control.installerListTab)); + installerListItem.activeProperty().bind(control.tab.getSelectionModel().selectedItemProperty().isEqualTo(control.installerListTab)); + installerListItem.setOnAction(e -> control.tab.getSelectionModel().select(control.installerListTab)); AdvancedListItem worldListItem = new AdvancedListItem(); worldListItem.getStyleClass().add("navigation-drawer-item"); worldListItem.setTitle(i18n("world")); worldListItem.setLeftGraphic(wrap(SVG.gamepad(null, 20, 20))); worldListItem.setActionButtonVisible(false); - worldListItem.activeProperty().bind(control.selectedTab.isEqualTo(control.worldListTab)); - worldListItem.setOnAction(e -> control.selectedTab.set(control.worldListTab)); + worldListItem.activeProperty().bind(control.tab.getSelectionModel().selectedItemProperty().isEqualTo(control.worldListTab)); + worldListItem.setOnAction(e -> control.tab.getSelectionModel().select(control.worldListTab)); AdvancedListBox sideBar = new AdvancedListBox() .add(versionSettingsItem) @@ -403,4 +410,7 @@ public class VersionPage extends Control implements DecoratorPage, ModDownloadPa return stackPane; } + interface VersionLoadable { + void loadVersion(Profile profile, String version); + } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java index da2a3fa5b..3730836ed 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java @@ -67,7 +67,7 @@ import static org.jackhuang.hmcl.ui.FXUtils.newImage; import static org.jackhuang.hmcl.ui.FXUtils.stringConverter; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; -public final class VersionSettingsPage extends StackPane implements DecoratorPage { +public final class VersionSettingsPage extends StackPane implements DecoratorPage, VersionPage.VersionLoadable { private final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(new State("", null, false, false, false)); private VersionSetting lastVersionSetting = null; @@ -168,6 +168,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag advancedSettingsPane.disableProperty().bind(chkEnableSpecificSettings.selectedProperty().not()); } + @Override public void loadVersion(Profile profile, String versionId) { this.profile = profile; this.versionId = versionId; 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 30ccc54d1..fe155a75f 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 @@ -47,7 +47,7 @@ import java.util.stream.Stream; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; -public class WorldListPage extends ListPageBase { +public class WorldListPage extends ListPageBase implements VersionPage.VersionLoadable { private final BooleanProperty showAll = new SimpleBooleanProperty(this, "showAll", false); private Path savesDir; @@ -74,11 +74,11 @@ public class WorldListPage extends ListPageBase { return new WorldListPageSkin(); } - public CompletableFuture loadVersion(Profile profile, String id) { + public void loadVersion(Profile profile, String id) { this.profile = profile; this.id = id; this.savesDir = profile.getRepository().getRunDirectory(id).toPath().resolve("saves"); - return refresh(); + refresh(); } public CompletableFuture refresh() {