feat(download): resourcepack game version selection.

This commit is contained in:
huanghongxun 2021-10-10 22:32:59 +08:00
parent 86734d2f5f
commit 9b0c0d1870
2 changed files with 35 additions and 24 deletions

View File

@ -93,7 +93,7 @@ public class DownloadPage extends DecoratorAnimatedPage implements DecoratorPage
return page;
}));
modTab.setNodeSupplier(loadVersionFor(() -> new ModDownloadListPage((profile, version, file) -> download(profile, version, file, "mods"), true)));
resourcePackTab.setNodeSupplier(loadVersionFor(() -> new DownloadListPage(CurseForgeRemoteModRepository.RESOURCE_PACKS, (profile, version, file) -> download(profile, version, file, "resourcepacks"))));
resourcePackTab.setNodeSupplier(loadVersionFor(() -> new DownloadListPage(CurseForgeRemoteModRepository.RESOURCE_PACKS, (profile, version, file) -> download(profile, version, file, "resourcepacks"), true)));
customizationTab.setNodeSupplier(loadVersionFor(() -> new DownloadListPage(CurseForgeRemoteModRepository.CUSTOMIZATIONS)));
worldTab.setNodeSupplier(loadVersionFor(() -> new DownloadListPage(CurseForgeRemoteModRepository.WORLDS)));
tab = new TabHeader(newGameTab, modpackTab, modTab, resourcePackTab, worldTab);
@ -193,24 +193,26 @@ public class DownloadPage extends DecoratorAnimatedPage implements DecoratorPage
}
private void loadVersions(Profile profile) {
WeakListenerHolder listenerHolder = new WeakListenerHolder();
listenerHolder = new WeakListenerHolder();
runInFX(() -> {
if (profile == Profiles.getSelectedProfile()) {
if (modTab.isInitialized()) {
modTab.getNode().loadVersion(profile, null);
}
if (modpackTab.isInitialized()) {
modpackTab.getNode().loadVersion(profile, null);
}
if (resourcePackTab.isInitialized()) {
resourcePackTab.getNode().loadVersion(profile, null);
}
if (customizationTab.isInitialized()) {
customizationTab.getNode().loadVersion(profile, null);
}
if (worldTab.isInitialized()) {
worldTab.getNode().loadVersion(profile, null);
}
listenerHolder.add(FXUtils.onWeakChangeAndOperate(profile.selectedVersionProperty(), version -> {
if (modTab.isInitialized()) {
modTab.getNode().loadVersion(profile, null);
}
if (modpackTab.isInitialized()) {
modpackTab.getNode().loadVersion(profile, null);
}
if (resourcePackTab.isInitialized()) {
resourcePackTab.getNode().loadVersion(profile, null);
}
if (customizationTab.isInitialized()) {
customizationTab.getNode().loadVersion(profile, null);
}
if (worldTab.isInitialized()) {
worldTab.getNode().loadVersion(profile, null);
}
}));
}
});
}

View File

@ -238,19 +238,28 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP
{
int rowIndex = 0;
if (control.versionSelection && control.downloadSources.getSize() > 1) {
if (control.versionSelection) {
JFXComboBox<String> versionsComboBox = new JFXComboBox<>();
versionsComboBox.setMaxWidth(Double.MAX_VALUE);
Bindings.bindContent(versionsComboBox.getItems(), control.versions);
selectedItemPropertyFor(versionsComboBox).bindBidirectional(control.selectedVersion);
JFXComboBox<String> downloadSourceComboBox = new JFXComboBox<>();
downloadSourceComboBox.setMaxWidth(Double.MAX_VALUE);
downloadSourceComboBox.getItems().setAll(control.downloadSources.get());
downloadSourceComboBox.setConverter(stringConverter(I18n::i18n));
selectedItemPropertyFor(downloadSourceComboBox).bindBidirectional(control.downloadSource);
searchPane.addRow(rowIndex, new Label(i18n("version")), versionsComboBox);
searchPane.addRow(rowIndex++, new Label(i18n("version")), versionsComboBox, new Label(i18n("settings.launcher.download_source")), downloadSourceComboBox);
if (control.downloadSources.getSize() > 1) {
JFXComboBox<String> downloadSourceComboBox = new JFXComboBox<>();
downloadSourceComboBox.setMaxWidth(Double.MAX_VALUE);
downloadSourceComboBox.getItems().setAll(control.downloadSources.get());
downloadSourceComboBox.setConverter(stringConverter(I18n::i18n));
selectedItemPropertyFor(downloadSourceComboBox).bindBidirectional(control.downloadSource);
searchPane.add(new Label(i18n("settings.launcher.download_source")), 2, rowIndex);
searchPane.add(downloadSourceComboBox, 3, rowIndex);
} else {
GridPane.setColumnSpan(versionsComboBox, 3);
}
rowIndex++;
}
JFXTextField nameField = new JFXTextField();