mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-16 15:26:27 -04: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.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -77,8 +78,8 @@ public class VersionPage extends Control implements DecoratorPage {
|
|||||||
{
|
{
|
||||||
Profiles.registerVersionsListener(this::loadVersions);
|
Profiles.registerVersionsListener(this::loadVersions);
|
||||||
|
|
||||||
listView.getSelectionModel().selectedItemProperty().addListener((a, b, newValue) -> {
|
listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
if (newValue != null)
|
if (newValue != null && !Objects.equals(oldValue, newValue))
|
||||||
loadVersion(newValue, profile);
|
loadVersion(newValue, profile);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -107,19 +108,21 @@ public class VersionPage extends Control implements DecoratorPage {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadVersion(String version, Profile profile) {
|
public void setVersion(String version, Profile profile) {
|
||||||
listView.getSelectionModel().select(version);
|
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadVersion(String version, Profile profile) {
|
||||||
|
setVersion(version, profile);
|
||||||
|
listView.getSelectionModel().select(version);
|
||||||
|
|
||||||
versionSettingsPage.loadVersion(profile, version);
|
versionSettingsPage.loadVersion(profile, version);
|
||||||
loading.set(true);
|
|
||||||
|
|
||||||
CompletableFuture.allOf(
|
CompletableFuture.allOf(
|
||||||
modListPage.loadVersion(profile, version),
|
modListPage.loadVersion(profile, version),
|
||||||
installerListPage.loadVersion(profile, version),
|
installerListPage.loadVersion(profile, version),
|
||||||
worldListPage.loadVersion(profile, version))
|
worldListPage.loadVersion(profile, version));
|
||||||
.whenCompleteAsync((result, exception) -> loading.set(false), Platform::runLater);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onNavigated(Navigator.NavigationEvent event) {
|
private void onNavigated(Navigator.NavigationEvent event) {
|
||||||
|
@ -136,7 +136,8 @@ public class Versions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void modifyGameSettings(Profile profile, String version) {
|
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());
|
Controllers.navigate(Controllers.getVersionPage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user