feat: download game in download page

This commit is contained in:
huanghongxun
2021-08-29 07:51:09 +08:00
parent fb78b8f573
commit 50ce3617be
8 changed files with 76 additions and 147 deletions

View File

@@ -20,6 +20,7 @@ package org.jackhuang.hmcl.ui.download;
import javafx.beans.binding.Bindings;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.download.LibraryAnalyzer;
import org.jackhuang.hmcl.download.RemoteVersion;
import org.jackhuang.hmcl.game.GameRepository;
@@ -41,7 +42,7 @@ class AdditionalInstallersPage extends InstallersPage {
protected final String gameVersion;
protected final Version version;
public AdditionalInstallersPage(String gameVersion, Version version, WizardController controller, HMCLGameRepository repository, InstallerWizardDownloadProvider downloadProvider) {
public AdditionalInstallersPage(String gameVersion, Version version, WizardController controller, HMCLGameRepository repository, DownloadProvider downloadProvider) {
super(controller, repository, gameVersion, downloadProvider);
this.gameVersion = gameVersion;
this.version = version;

View File

@@ -96,6 +96,11 @@ public class DownloadPage extends BorderPane implements DecoratorPage {
item.setLeftGraphic(wrap(SVG.textureBox(null, 20, 20)));
item.activeProperty().bind(tab.getSelectionModel().selectedItemProperty().isEqualTo(resourcePackTab));
item.setOnAction(e -> tab.getSelectionModel().select(resourcePackTab));
})
.addNavigationDrawerItem(item -> {
item.setTitle(i18n("install.new_game"));
item.setLeftGraphic(wrap(SVG.gamepad(null, 20, 20)));
item.setOnAction(e -> Versions.addNewGame());
});
FXUtils.setLimitWidth(sideBar, 200);
setLeft(sideBar);

View File

@@ -1,72 +0,0 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2020 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.ui.download;
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.download.VersionList;
import java.net.URL;
import java.util.List;
public class InstallerWizardDownloadProvider implements DownloadProvider {
private DownloadProvider fallback;
public InstallerWizardDownloadProvider(DownloadProvider fallback) {
this.fallback = fallback;
}
public void setDownloadProvider(DownloadProvider downloadProvider) {
fallback = downloadProvider;
}
@Override
public String getVersionListURL() {
return fallback.getVersionListURL();
}
@Override
public String getAssetBaseURL() {
return fallback.getAssetBaseURL();
}
@Override
public List<URL> getAssetObjectCandidates(String assetObjectLocation) {
return fallback.getAssetObjectCandidates(assetObjectLocation);
}
@Override
public String injectURL(String baseURL) {
return fallback.injectURL(baseURL);
}
@Override
public List<URL> injectURLWithCandidates(String baseURL) {
return fallback.injectURLWithCandidates(baseURL);
}
@Override
public VersionList<?> getVersionListById(String id) {
return fallback.getVersionListById(id);
}
@Override
public int getConcurrency() {
return fallback.getConcurrency();
}
}

View File

@@ -19,7 +19,8 @@ package org.jackhuang.hmcl.ui.download;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXTextField;
import javafx.beans.property.*;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
@@ -30,6 +31,7 @@ import javafx.scene.control.SkinBase;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.download.RemoteVersion;
import org.jackhuang.hmcl.game.HMCLGameRepository;
import org.jackhuang.hmcl.ui.InstallerItem;
@@ -50,7 +52,7 @@ public class InstallersPage extends Control implements WizardPage {
protected JFXTextField txtName = new JFXTextField();
protected BooleanProperty installable = new SimpleBooleanProperty();
public InstallersPage(WizardController controller, HMCLGameRepository repository, String gameVersion, InstallerWizardDownloadProvider downloadProvider) {
public InstallersPage(WizardController controller, HMCLGameRepository repository, String gameVersion, DownloadProvider downloadProvider) {
this.controller = controller;
txtName.getValidators().addAll(

View File

@@ -18,10 +18,7 @@
package org.jackhuang.hmcl.ui.download;
import javafx.scene.Node;
import org.jackhuang.hmcl.download.ArtifactMalformedException;
import org.jackhuang.hmcl.download.DefaultDependencyManager;
import org.jackhuang.hmcl.download.RemoteVersion;
import org.jackhuang.hmcl.download.VersionMismatchException;
import org.jackhuang.hmcl.download.*;
import org.jackhuang.hmcl.download.fabric.FabricInstallTask;
import org.jackhuang.hmcl.download.game.GameAssetIndexDownloadTask;
import org.jackhuang.hmcl.download.game.LibraryDownloadException;
@@ -57,7 +54,7 @@ public final class UpdateInstallerWizardProvider implements WizardProvider {
private final Version version;
private final String libraryId;
private final String oldLibraryVersion;
private final InstallerWizardDownloadProvider downloadProvider;
private final DownloadProvider downloadProvider;
public UpdateInstallerWizardProvider(@NotNull Profile profile, @NotNull String gameVersion, @NotNull Version version, @NotNull String libraryId, @Nullable String oldLibraryVersion) {
this.profile = profile;
@@ -65,7 +62,7 @@ public final class UpdateInstallerWizardProvider implements WizardProvider {
this.version = version;
this.libraryId = libraryId;
this.oldLibraryVersion = oldLibraryVersion;
this.downloadProvider = new InstallerWizardDownloadProvider(DownloadProviders.getDownloadProvider());
this.downloadProvider = DownloadProviders.getDownloadProvider();
this.dependencyManager = profile.getDependency(downloadProvider);
}

View File

@@ -19,6 +19,7 @@ package org.jackhuang.hmcl.ui.download;
import javafx.scene.Node;
import org.jackhuang.hmcl.download.DefaultDependencyManager;
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.download.GameBuilder;
import org.jackhuang.hmcl.download.RemoteVersion;
import org.jackhuang.hmcl.setting.DownloadProviders;
@@ -35,11 +36,11 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public final class VanillaInstallWizardProvider implements WizardProvider {
private final Profile profile;
private final DefaultDependencyManager dependencyManager;
private final InstallerWizardDownloadProvider downloadProvider;
private final DownloadProvider downloadProvider;
public VanillaInstallWizardProvider(Profile profile) {
this.profile = profile;
this.downloadProvider = new InstallerWizardDownloadProvider(DownloadProviders.getDownloadProvider());
this.downloadProvider = DownloadProviders.getDownloadProvider();
this.dependencyManager = profile.getDependency(downloadProvider);
}

View File

@@ -18,20 +18,18 @@
package org.jackhuang.hmcl.ui.download;
import com.jfoenix.controls.JFXCheckBox;
import com.jfoenix.controls.JFXComboBox;
import com.jfoenix.controls.JFXListView;
import com.jfoenix.controls.JFXSpinner;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.ListCell;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
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.download.fabric.FabricRemoteVersion;
@@ -39,13 +37,13 @@ import org.jackhuang.hmcl.download.forge.ForgeRemoteVersion;
import org.jackhuang.hmcl.download.game.GameRemoteVersion;
import org.jackhuang.hmcl.download.liteloader.LiteLoaderRemoteVersion;
import org.jackhuang.hmcl.download.optifine.OptiFineRemoteVersion;
import org.jackhuang.hmcl.setting.DownloadProviders;
import org.jackhuang.hmcl.task.TaskExecutor;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
import org.jackhuang.hmcl.ui.animation.TransitionPane;
import org.jackhuang.hmcl.ui.construct.FloatListCell;
import org.jackhuang.hmcl.ui.construct.TwoLineListItem;
import org.jackhuang.hmcl.ui.construct.ComponentList;
import org.jackhuang.hmcl.ui.construct.IconedTwoLineListItem;
import org.jackhuang.hmcl.ui.construct.RipplerContainer;
import org.jackhuang.hmcl.ui.wizard.Refreshable;
import org.jackhuang.hmcl.ui.wizard.WizardController;
import org.jackhuang.hmcl.ui.wizard.WizardPage;
@@ -55,7 +53,6 @@ import java.util.Map;
import java.util.logging.Level;
import java.util.stream.Collectors;
import static org.jackhuang.hmcl.ui.FXUtils.stringConverter;
import static org.jackhuang.hmcl.util.Logging.LOG;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
@@ -84,14 +81,14 @@ public final class VersionsPage extends BorderPane implements WizardPage, Refres
@FXML
private HBox checkPane;
@FXML
private VBox centrePane;
private ComponentList centrePane;
@FXML
private JFXComboBox<String> downloadSourceComboBox;
private StackPane center;
private VersionList<?> versionList;
private TaskExecutor executor;
public VersionsPage(WizardController controller, String title, String gameVersion, InstallerWizardDownloadProvider downloadProvider, String libraryId, Runnable callback) {
public VersionsPage(WizardController controller, String title, String gameVersion, DownloadProvider downloadProvider, String libraryId, Runnable callback) {
this.title = title;
this.gameVersion = gameVersion;
this.libraryId = libraryId;
@@ -99,42 +96,38 @@ public final class VersionsPage extends BorderPane implements WizardPage, Refres
FXUtils.loadFXML(this, "/assets/fxml/download/versions.fxml");
downloadSourceComboBox.getItems().setAll(DownloadProviders.providersById.keySet());
downloadSourceComboBox.setConverter(stringConverter(key -> i18n("download.provider." + key)));
downloadSourceComboBox.getSelectionModel().selectedItemProperty().addListener((a, b, newValue) -> {
controller.getSettings().put("downloadProvider", newValue);
downloadProvider.setDownloadProvider(DownloadProviders.getDownloadProviderByPrimaryId(newValue));
versionList = downloadProvider.getVersionListById(libraryId);
if (versionList.hasType()) {
centrePane.getChildren().setAll(checkPane, list);
} else {
centrePane.getChildren().setAll(list);
}
refresh();
});
downloadSourceComboBox.getSelectionModel().select((String)controller.getSettings().getOrDefault("downloadProvider", DownloadProviders.getPrimaryDownloadProviderId()));
versionList = downloadProvider.getVersionListById(libraryId);
if (versionList.hasType()) {
centrePane.getContent().setAll(checkPane, list);
} else {
centrePane.getContent().setAll(list);
}
InvalidationListener listener = o -> list.getItems().setAll(loadVersions());
chkRelease.selectedProperty().addListener(listener);
chkSnapshot.selectedProperty().addListener(listener);
chkOld.selectedProperty().addListener(listener);
list.setCellFactory(listView -> new FloatListCell<RemoteVersion>(list) {
ImageView imageView = new ImageView();
TwoLineListItem content = new TwoLineListItem();
list.setCellFactory(listView -> new ListCell<RemoteVersion>() {
IconedTwoLineListItem content = new IconedTwoLineListItem();
RipplerContainer ripplerContainer = new RipplerContainer(content);
StackPane pane = new StackPane();
{
HBox container = new HBox(12);
container.setPadding(new Insets(0, 0, 0, 6));
container.setAlignment(Pos.CENTER_LEFT);
pane.getChildren().add(container);
container.getChildren().setAll(imageView, content);
pane.getStyleClass().add("md-list-cell");
StackPane.setMargin(content, new Insets(10, 16, 10, 16));
pane.getChildren().setAll(ripplerContainer);
}
@Override
protected void updateControl(RemoteVersion remoteVersion, boolean empty) {
if (empty) return;
public void updateItem(RemoteVersion remoteVersion, boolean empty) {
super.updateItem(remoteVersion, empty);
if (empty) {
setGraphic(null);
return;
}
setGraphic(pane);
content.setTitle(remoteVersion.getSelfVersion());
content.setSubtitle(remoteVersion.getGameVersion());
@@ -142,28 +135,28 @@ public final class VersionsPage extends BorderPane implements WizardPage, Refres
switch (remoteVersion.getVersionType()) {
case RELEASE:
content.setSubtitle(i18n("version.game.release"));
imageView.setImage(new Image("/assets/img/grass.png", 32, 32, false, true));
content.setImage(new Image("/assets/img/grass.png", 32, 32, false, true));
break;
case SNAPSHOT:
content.setSubtitle(i18n("version.game.snapshot"));
imageView.setImage(new Image("/assets/img/command.png", 32, 32, false, true));
content.setImage(new Image("/assets/img/command.png", 32, 32, false, true));
break;
default:
content.setSubtitle(i18n("version.game.old"));
imageView.setImage(new Image("/assets/img/craft_table.png", 32, 32, false, true));
content.setImage(new Image("/assets/img/craft_table.png", 32, 32, false, true));
break;
}
} else if (remoteVersion instanceof LiteLoaderRemoteVersion) {
imageView.setImage(new Image("/assets/img/chicken.png", 32, 32, false, true));
content.setImage(new Image("/assets/img/chicken.png", 32, 32, false, true));
content.setSubtitle(remoteVersion.getGameVersion());
} else if (remoteVersion instanceof OptiFineRemoteVersion) {
imageView.setImage(new Image("/assets/img/command.png", 32, 32, false, true));
content.setImage(new Image("/assets/img/command.png", 32, 32, false, true));
content.setSubtitle(remoteVersion.getGameVersion());
} else if (remoteVersion instanceof ForgeRemoteVersion) {
imageView.setImage(new Image("/assets/img/forge.png", 32, 32, false, true));
content.setImage(new Image("/assets/img/forge.png", 32, 32, false, true));
content.setSubtitle(remoteVersion.getGameVersion());
} else if (remoteVersion instanceof FabricRemoteVersion) {
imageView.setImage(new Image("/assets/img/fabric.png", 32, 32, false, true));
content.setImage(new Image("/assets/img/fabric.png", 32, 32, false, true));
content.setSubtitle(remoteVersion.getGameVersion());
}
}
@@ -175,6 +168,7 @@ public final class VersionsPage extends BorderPane implements WizardPage, Refres
controller.getSettings().put(libraryId, list.getSelectionModel().getSelectedItem());
callback.run();
});
refresh();
}
@@ -215,7 +209,7 @@ public final class VersionsPage extends BorderPane implements WizardPage, Refres
} else {
list.getItems().setAll(items);
}
root.setContent(centrePane, ContainerAnimations.FADE.getAnimationProducer());
root.setContent(center, ContainerAnimations.FADE.getAnimationProducer());
}
});
} else {

View File

@@ -4,38 +4,39 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?>
<?import org.jackhuang.hmcl.ui.animation.TransitionPane?>
<?import org.jackhuang.hmcl.ui.construct.ComponentList?>
<?import java.lang.String?>
<fx:root xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
type="BorderPane"
prefHeight="400.0" prefWidth="600.0">
<top>
<VBox>
<StackPane styleClass="sponsor-pane" onMouseClicked="#onSponsor">
<Label text="%sponsor.bmclapi" />
<StackPane style="-fx-padding: 10 10 0 10;">
<StackPane onMouseClicked="#onSponsor">
<styleClass>
<String fx:value="card-non-transparent" />
<String fx:value="sponsor-pane" />
</styleClass>
<Label text="%sponsor.bmclapi" />
</StackPane>
</StackPane>
<BorderPane style="-fx-padding: 0 16 16 16;">
<left>
<Label text="%settings.launcher.download_source" BorderPane.alignment="CENTER_LEFT" />
</left>
<right>
<JFXComboBox fx:id="downloadSourceComboBox">
</JFXComboBox>
</right>
</BorderPane>
</VBox>
</top>
<center>
<TransitionPane fx:id="root">
<JFXSpinner fx:id="spinner" styleClass="first-spinner" />
<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-float" VBox.vgrow="ALWAYS">
</JFXListView>
</VBox>
<StackPane fx:id="center" style="-fx-padding: 10;">
<ComponentList fx:id="centrePane" styleClass="no-padding">
<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-float" VBox.vgrow="ALWAYS">
</JFXListView>
</ComponentList>
</StackPane>
<StackPane fx:id="failedPane" styleClass="notice-pane">
<Label onMouseClicked="#onRefresh" text="%download.failed.refresh" />
</StackPane>