mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-03-07 17:36:52 +08:00
alt: reduce call count of VersionPage.loadVersion
This commit is contained in:
parent
16d92454f4
commit
646bfa5be7
@ -50,6 +50,7 @@ import java.io.File;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -77,8 +78,8 @@ public class VersionPage extends Control implements DecoratorPage {
|
||||
{
|
||||
Profiles.registerVersionsListener(this::loadVersions);
|
||||
|
||||
listView.getSelectionModel().selectedItemProperty().addListener((a, b, newValue) -> {
|
||||
if (newValue != null)
|
||||
listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue != null && !Objects.equals(oldValue, newValue))
|
||||
loadVersion(newValue, profile);
|
||||
});
|
||||
|
||||
@ -107,19 +108,21 @@ public class VersionPage extends Control implements DecoratorPage {
|
||||
});
|
||||
}
|
||||
|
||||
public void loadVersion(String version, Profile profile) {
|
||||
listView.getSelectionModel().select(version);
|
||||
public void setVersion(String version, Profile profile) {
|
||||
this.version = version;
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public void loadVersion(String version, Profile profile) {
|
||||
setVersion(version, profile);
|
||||
listView.getSelectionModel().select(version);
|
||||
|
||||
versionSettingsPage.loadVersion(profile, version);
|
||||
loading.set(true);
|
||||
|
||||
CompletableFuture.allOf(
|
||||
modListPage.loadVersion(profile, version),
|
||||
installerListPage.loadVersion(profile, version),
|
||||
worldListPage.loadVersion(profile, version))
|
||||
.whenCompleteAsync((result, exception) -> loading.set(false), Platform::runLater);
|
||||
worldListPage.loadVersion(profile, version));
|
||||
}
|
||||
|
||||
private void onNavigated(Navigator.NavigationEvent event) {
|
||||
|
@ -136,7 +136,8 @@ public class Versions {
|
||||
}
|
||||
|
||||
public static void modifyGameSettings(Profile profile, String version) {
|
||||
Controllers.getVersionPage().loadVersion(version, profile);
|
||||
Controllers.getVersionPage().setVersion(version, profile);
|
||||
// VersionPage.loadVersion will be invoked after navigation
|
||||
Controllers.navigate(Controllers.getVersionPage());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user