feat(download): add import local modpack file button in modpack download page.

This commit is contained in:
huanghongxun 2021-09-12 23:38:47 +08:00
parent fa1c11db5c
commit 5c9deb129d
7 changed files with 43 additions and 8 deletions

View File

@ -17,8 +17,10 @@
*/
package org.jackhuang.hmcl.ui.construct;
import com.jfoenix.controls.JFXListView;
import javafx.css.PseudoClass;
import javafx.scene.control.ListCell;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import org.jackhuang.hmcl.ui.FXUtils;
@ -28,13 +30,21 @@ public abstract class MDListCell<T> extends ListCell<T> {
private final StackPane container = new StackPane();
private final StackPane root = new StackPane();
public MDListCell() {
public MDListCell(JFXListView<T> listView) {
setText(null);
setGraphic(null);
root.getStyleClass().add("md-list-cell");
RipplerContainer ripplerContainer = new RipplerContainer(container);
root.getChildren().setAll(ripplerContainer);
Region clippedContainer = (Region) listView.lookup(".clipped-container");
setPrefWidth(0);
if (clippedContainer != null) {
maxWidthProperty().bind(clippedContainer.widthProperty());
prefWidthProperty().bind(clippedContainer.widthProperty());
minWidthProperty().bind(clippedContainer.widthProperty());
}
}
@Override

View File

@ -17,6 +17,7 @@
*/
package org.jackhuang.hmcl.ui.download;
import com.jfoenix.controls.JFXButton;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.scene.Node;
@ -79,7 +80,17 @@ public class DownloadPage extends BorderPane implements DecoratorPage {
public DownloadPage() {
newGameTab.setNodeSupplier(() -> new VersionsPage(versionPageNavigator, i18n("install.installer.choose", i18n("install.installer.game")), "", DownloadProviders.getDownloadProvider(),
"game", versionPageNavigator::onGameSelected));
modpackTab.setNodeSupplier(() -> new DownloadListPage(CurseModManager.SECTION_MODPACK, Versions::downloadModpackImpl));
modpackTab.setNodeSupplier(() -> {
DownloadListPage page = new DownloadListPage(CurseModManager.SECTION_MODPACK, Versions::downloadModpackImpl);
JFXButton installLocalModpackButton = new JFXButton(i18n("install.modpack"));
installLocalModpackButton.setButtonType(JFXButton.ButtonType.RAISED);
installLocalModpackButton.getStyleClass().add("jfx-button-raised");
installLocalModpackButton.setOnAction(e -> Versions.importModpack());
page.getActions().add(installLocalModpackButton);
return page;
});
modTab.setNodeSupplier(() -> new ModDownloadListPage(CurseModManager.SECTION_MOD, (profile, version, file) -> download(profile, version, file, "mods"), true));
resourcePackTab.setNodeSupplier(() -> new DownloadListPage(CurseModManager.SECTION_RESOURCE_PACK, (profile, version, file) -> download(profile, version, file, "resourcepacks")));
// customizationTab.setNodeSupplier(() -> new ModDownloadListPage(CurseModManager.SECTION_CUSTOMIZATION, this::download));

View File

@ -101,7 +101,7 @@ public class FeedbackPage extends VBox {
JFXListView<FeedbackResponse> listView = new JFXListView<>();
spinnerPane.setContent(listView);
Bindings.bindContent(listView.getItems(), feedbacks);
listView.setCellFactory(x -> new MDListCell<FeedbackResponse>() {
listView.setCellFactory(x -> new MDListCell<FeedbackResponse>(listView) {
private final TwoLineListItem content = new TwoLineListItem();
private final JFXButton likeButton = new JFXButton();
private final JFXButton unlikeButton = new JFXButton();

View File

@ -30,6 +30,7 @@ import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.control.Skin;
@ -53,6 +54,7 @@ import org.jackhuang.hmcl.ui.construct.FloatListCell;
import org.jackhuang.hmcl.ui.construct.SpinnerPane;
import org.jackhuang.hmcl.ui.construct.TwoLineListItem;
import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
import org.jackhuang.hmcl.util.AggregatedObservableList;
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.i18n.I18n;
import org.jackhuang.hmcl.util.javafx.BindingMapping;
@ -79,6 +81,7 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP
private final DownloadPage.DownloadCallback callback;
private boolean searchInitialized = false;
protected final BooleanProperty supportChinese = new SimpleBooleanProperty();
private final ObservableList<Node> actions = FXCollections.observableArrayList();
protected final ListProperty<String> downloadSources = new SimpleListProperty<>(this, "downloadSources", FXCollections.observableArrayList());
protected final StringProperty downloadSource = new SimpleStringProperty();
private final WeakListenerHolder listenerHolder = new WeakListenerHolder();
@ -104,6 +107,10 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP
this.versionSelection = versionSelection;
}
public ObservableList<Node> getActions() {
return actions;
}
@Override
public void loadVersion(Profile profile, String version) {
this.version.set(new Profile.ProfileVersion(profile, version));
@ -213,6 +220,7 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP
}
private static class ModDownloadListPageSkin extends SkinBase<DownloadListPage> {
private final AggregatedObservableList<Node> actions = new AggregatedObservableList<>();
protected ModDownloadListPageSkin(DownloadListPage control) {
super(control);
@ -315,7 +323,11 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP
searchButton.setText(i18n("search"));
searchButton.getStyleClass().add("jfx-button-raised");
searchButton.setButtonType(JFXButton.ButtonType.RAISED);
HBox searchBox = new HBox(searchButton);
ObservableList<Node> last = FXCollections.observableArrayList(searchButton);
HBox searchBox = new HBox(8);
actions.appendList(control.actions);
actions.appendList(last);
Bindings.bindContent(searchBox.getChildren(), actions.getAggregatedList());
GridPane.setColumnSpan(searchBox, 4);
searchBox.setAlignment(Pos.CENTER_RIGHT);
searchPane.addRow(rowIndex++, searchBox);

View File

@ -102,7 +102,7 @@ class ModListPageSkin extends SkinBase<ModListPage> {
center.getStyleClass().add("large-spinner-pane");
center.loadingProperty().bind(skinnable.loadingProperty());
listView.setCellFactory(x -> new ModInfoListCell());
listView.setCellFactory(x -> new ModInfoListCell(listView));
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
Bindings.bindContent(listView.getItems(), skinnable.getItems());
@ -263,7 +263,9 @@ class ModListPageSkin extends SkinBase<ModListPage> {
JFXButton revealButton = new JFXButton();
BooleanProperty booleanProperty;
ModInfoListCell() {
ModInfoListCell(JFXListView<ModInfoObject> listView) {
super(listView);
HBox container = new HBox(8);
container.setPickOnBounds(false);
container.setAlignment(Pos.CENTER_LEFT);

View File

@ -38,7 +38,7 @@ public final class CurseModManager {
pair("gameId", "432"),
pair("gameVersion", gameVersion),
pair("index", Integer.toString(pageOffset)),
pair("pageSize", "25"),
pair("pageSize", "50"),
pair("searchFilter", searchFilter),
pair("sectionId", Integer.toString(section)),
pair("sort", Integer.toString(sort))

View File

@ -41,7 +41,7 @@ public final class Modrinth {
Map<String, String> query = mapOf(
pair("query", searchFilter),
pair("offset", Integer.toString(pageOffset)),
pair("limit", "25")
pair("limit", "50")
);
if (StringUtils.isNotBlank(gameVersion)) {
query.put("version", "versions=" + gameVersion);