mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-08 11:25:46 -04:00
Downloading snapshot versions
This commit is contained in:
parent
c76bcb5d15
commit
8d1e335abf
@ -64,7 +64,7 @@ public final class DownloadWizardProvider implements WizardProvider {
|
||||
if (settings.containsKey("optifine"))
|
||||
builder.version("optifine", (String) settings.get("optifine"));
|
||||
|
||||
return builder.buildAsync();
|
||||
return builder.buildAsync().finalized((a, b) -> profile.getRepository().refreshVersions());
|
||||
}
|
||||
|
||||
private Task finishModpackInstallingAsync(Map<String, Object> settings) {
|
||||
|
@ -17,17 +17,20 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.ui.download;
|
||||
|
||||
import com.jfoenix.controls.JFXCheckBox;
|
||||
import com.jfoenix.controls.JFXListView;
|
||||
import com.jfoenix.controls.JFXSpinner;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.InvalidationListener;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.jackhuang.hmcl.download.DownloadProvider;
|
||||
import org.jackhuang.hmcl.download.RemoteVersion;
|
||||
import org.jackhuang.hmcl.download.VersionList;
|
||||
import org.jackhuang.hmcl.task.Scheduler;
|
||||
import org.jackhuang.hmcl.task.Schedulers;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
import org.jackhuang.hmcl.download.game.GameRemoteVersionTag;
|
||||
import org.jackhuang.hmcl.download.game.GameVersionList;
|
||||
import org.jackhuang.hmcl.task.TaskExecutor;
|
||||
import org.jackhuang.hmcl.ui.FXUtils;
|
||||
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
|
||||
@ -39,6 +42,7 @@ import org.jackhuang.hmcl.ui.wizard.WizardPage;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class VersionsPage extends StackPane implements WizardPage, Refreshable {
|
||||
private final WizardController controller;
|
||||
@ -54,6 +58,16 @@ public final class VersionsPage extends StackPane implements WizardPage, Refresh
|
||||
private JFXSpinner spinner;
|
||||
@FXML
|
||||
private StackPane failedPane;
|
||||
@FXML
|
||||
private JFXCheckBox chkRelease;
|
||||
@FXML
|
||||
private JFXCheckBox chkSnapshot;
|
||||
@FXML
|
||||
private JFXCheckBox chkOld;
|
||||
@FXML
|
||||
private HBox checkPane;
|
||||
@FXML
|
||||
private VBox centrePane;
|
||||
|
||||
private final TransitionHandler transitionHandler = new TransitionHandler(this);
|
||||
private final VersionList<?> versionList;
|
||||
@ -66,10 +80,20 @@ public final class VersionsPage extends StackPane implements WizardPage, Refresh
|
||||
this.downloadProvider = downloadProvider;
|
||||
this.libraryId = libraryId;
|
||||
this.callback = callback;
|
||||
|
||||
this.versionList = downloadProvider.getVersionListById(libraryId);
|
||||
|
||||
FXUtils.loadFXML(this, "/assets/fxml/download/versions.fxml");
|
||||
|
||||
if (versionList instanceof GameVersionList) {
|
||||
centrePane.getChildren().setAll(checkPane, list);
|
||||
} else
|
||||
centrePane.getChildren().setAll(list);
|
||||
|
||||
InvalidationListener listener = o -> list.getItems().setAll(loadVersions());
|
||||
chkRelease.selectedProperty().addListener(listener);
|
||||
chkSnapshot.selectedProperty().addListener(listener);
|
||||
chkOld.selectedProperty().addListener(listener);
|
||||
|
||||
list.getSelectionModel().selectedItemProperty().addListener((a, b, newValue) -> {
|
||||
controller.getSettings().put(libraryId, newValue.getRemoteVersion().getSelfVersion());
|
||||
callback.run();
|
||||
@ -77,18 +101,35 @@ public final class VersionsPage extends StackPane implements WizardPage, Refresh
|
||||
refresh();
|
||||
}
|
||||
|
||||
private List<VersionsPageItem> loadVersions() {
|
||||
boolean isGameVersionList = versionList instanceof GameVersionList;
|
||||
return versionList.getVersions(gameVersion).stream()
|
||||
.filter(it -> {
|
||||
if (isGameVersionList)
|
||||
switch (((GameRemoteVersionTag) it.getTag()).getType()) {
|
||||
case RELEASE:
|
||||
return chkRelease.isSelected();
|
||||
case SNAPSHOT:
|
||||
return chkSnapshot.isSelected();
|
||||
default:
|
||||
return chkOld.isSelected();
|
||||
}
|
||||
else return true;
|
||||
})
|
||||
.sorted()
|
||||
.map(VersionsPageItem::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
getChildren().setAll(spinner);
|
||||
executor = versionList.refreshAsync(downloadProvider).finalized((variables, isDependentsSucceeded) -> {
|
||||
if (isDependentsSucceeded) {
|
||||
List<VersionsPageItem> items = versionList.getVersions(gameVersion).stream()
|
||||
.sorted(RemoteVersion.RemoteVersionComparator.INSTANCE)
|
||||
.map(VersionsPageItem::new).collect(Collectors.toList());
|
||||
List<VersionsPageItem> items = loadVersions();
|
||||
|
||||
Platform.runLater(() -> {
|
||||
list.getItems().setAll(items);
|
||||
transitionHandler.setContent(list, ContainerAnimations.FADE.getAnimationProducer());
|
||||
transitionHandler.setContent(centrePane, ContainerAnimations.FADE.getAnimationProducer());
|
||||
});
|
||||
} else {
|
||||
Platform.runLater(() -> {
|
||||
|
@ -20,7 +20,9 @@ package org.jackhuang.hmcl.ui.download;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import org.jackhuang.hmcl.Main;
|
||||
import org.jackhuang.hmcl.download.RemoteVersion;
|
||||
import org.jackhuang.hmcl.download.game.GameRemoteVersionTag;
|
||||
import org.jackhuang.hmcl.ui.FXUtils;
|
||||
|
||||
/**
|
||||
@ -38,7 +40,22 @@ public final class VersionsPageItem extends StackPane {
|
||||
|
||||
FXUtils.loadFXML(this, "/assets/fxml/download/versions-list-item.fxml");
|
||||
lblSelfVersion.setText(remoteVersion.getSelfVersion());
|
||||
lblGameVersion.setText(remoteVersion.getGameVersion());
|
||||
|
||||
if (remoteVersion.getTag() instanceof GameRemoteVersionTag) {
|
||||
switch (((GameRemoteVersionTag) remoteVersion.getTag()).getType()) {
|
||||
case RELEASE:
|
||||
lblGameVersion.setText(Main.i18n("version.game.release"));
|
||||
break;
|
||||
case SNAPSHOT:
|
||||
lblGameVersion.setText(Main.i18n("version.game.snapshot"));
|
||||
break;
|
||||
default:
|
||||
lblGameVersion.setText(Main.i18n("version.game.old"));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
lblGameVersion.setText(remoteVersion.getGameVersion());
|
||||
}
|
||||
}
|
||||
|
||||
public RemoteVersion<?> getRemoteVersion() {
|
||||
|
@ -4,13 +4,23 @@
|
||||
<?import com.jfoenix.controls.JFXSpinner?>
|
||||
<?import javafx.scene.layout.StackPane?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import com.jfoenix.controls.JFXCheckBox?>
|
||||
<fx:root xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
type="StackPane"
|
||||
prefHeight="400.0" prefWidth="600.0">
|
||||
<JFXSpinner fx:id="spinner" styleClass="first-spinner" />
|
||||
<JFXListView fx:id="list" styleClass="jfx-list-view">
|
||||
</JFXListView>
|
||||
<VBox fx:id="centrePane">
|
||||
<HBox fx:id="checkPane" spacing="10" style="-fx-padding: 10;">
|
||||
<JFXCheckBox fx:id="chkRelease" text="%version.game.release" selected="true" />
|
||||
<JFXCheckBox fx:id="chkSnapshot" text="%version.game.snapshot" />
|
||||
<JFXCheckBox fx:id="chkOld" text="%version.game.old" />
|
||||
</HBox>
|
||||
<JFXListView fx:id="list" styleClass="jfx-list-view" VBox.vgrow="ALWAYS">
|
||||
</JFXListView>
|
||||
</VBox>
|
||||
<StackPane fx:id="failedPane">
|
||||
<Label onMouseClicked="#onRefresh" style="-fx-text-fill: #0079FF; -fx-font-size: 20;" text="%download.failed.refresh" />
|
||||
</StackPane>
|
||||
|
@ -382,8 +382,7 @@ update.tooltip=Update
|
||||
|
||||
version.cannot_read=Unable to gather the game version. Cannot continue auto-installing.
|
||||
version.forbidden_name=Forbidden name, do not use this.
|
||||
version.game.old_alpha=Old Alpha
|
||||
version.game.old_beta=Beta
|
||||
version.game.old=Old
|
||||
version.game.release=Release
|
||||
version.game.snapshot=Snapshot
|
||||
version.launch=Play
|
||||
|
@ -382,10 +382,9 @@ update.tooltip=更新
|
||||
|
||||
version.cannot_read=读取游戏版本失败,无法进行自动安装
|
||||
version.forbidden_name=此版本名称不受支持,请换一个名字
|
||||
version.game.old_alpha=远古版
|
||||
version.game.old_beta=测试版
|
||||
version.game.old=远古版
|
||||
version.game.release=稳定版
|
||||
version.game.snapshot=快照版
|
||||
version.game.snapshot=测试版
|
||||
version.launch=启动游戏
|
||||
version.launch_script=生成启动脚本
|
||||
version.launch_script.failed=生成启动脚本失败
|
||||
|
@ -78,20 +78,6 @@ public class RemoteVersion<T> implements Comparable<RemoteVersion<T>> {
|
||||
@Override
|
||||
public int compareTo(RemoteVersion<T> o) {
|
||||
// newer versions are smaller than older versions
|
||||
return -selfVersion.compareTo(o.selfVersion);
|
||||
}
|
||||
|
||||
public static class RemoteVersionComparator implements Comparator<RemoteVersion<?>> {
|
||||
|
||||
public static final RemoteVersionComparator INSTANCE = new RemoteVersionComparator();
|
||||
|
||||
private RemoteVersionComparator() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(RemoteVersion<?> o1, RemoteVersion<?> o2) {
|
||||
return -VersionNumber.asVersion(o1.selfVersion).compareTo(VersionNumber.asVersion(o2.selfVersion));
|
||||
}
|
||||
|
||||
return -VersionNumber.asVersion(selfVersion).compareTo(VersionNumber.asVersion(o.selfVersion));
|
||||
}
|
||||
}
|
||||
|
@ -56,10 +56,7 @@ public final class GameVersionList extends VersionList<GameRemoteVersionTag> {
|
||||
|
||||
GameRemoteVersions root = Constants.GSON.fromJson(task.getResult(), GameRemoteVersions.class);
|
||||
for (GameRemoteVersion remoteVersion : root.getVersions()) {
|
||||
Optional<String> gameVersion = VersionNumber.parseVersion(remoteVersion.getGameVersion());
|
||||
if (!gameVersion.isPresent())
|
||||
continue;
|
||||
versions.put(gameVersion.get(), new RemoteVersion<>(
|
||||
versions.put(remoteVersion.getGameVersion(), new RemoteVersionGame(
|
||||
remoteVersion.getGameVersion(),
|
||||
remoteVersion.getGameVersion(),
|
||||
remoteVersion.getUrl(),
|
||||
@ -70,4 +67,14 @@ public final class GameVersionList extends VersionList<GameRemoteVersionTag> {
|
||||
};
|
||||
}
|
||||
|
||||
private static class RemoteVersionGame extends RemoteVersion<GameRemoteVersionTag> {
|
||||
public RemoteVersionGame(String gameVersion, String selfVersion, String url, GameRemoteVersionTag tag) {
|
||||
super(gameVersion, selfVersion, url, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(RemoteVersion<GameRemoteVersionTag> o) {
|
||||
return -getTag().getTime().compareTo(o.getTag().getTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user