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