mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-19 00:36:10 -04:00
feat(download): add import local modpack file button in modpack download page.
This commit is contained in:
parent
fa1c11db5c
commit
5c9deb129d
@ -17,8 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.ui.construct;
|
package org.jackhuang.hmcl.ui.construct;
|
||||||
|
|
||||||
|
import com.jfoenix.controls.JFXListView;
|
||||||
import javafx.css.PseudoClass;
|
import javafx.css.PseudoClass;
|
||||||
import javafx.scene.control.ListCell;
|
import javafx.scene.control.ListCell;
|
||||||
|
import javafx.scene.layout.Region;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
import org.jackhuang.hmcl.ui.FXUtils;
|
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 container = new StackPane();
|
||||||
private final StackPane root = new StackPane();
|
private final StackPane root = new StackPane();
|
||||||
|
|
||||||
public MDListCell() {
|
public MDListCell(JFXListView<T> listView) {
|
||||||
setText(null);
|
setText(null);
|
||||||
setGraphic(null);
|
setGraphic(null);
|
||||||
|
|
||||||
root.getStyleClass().add("md-list-cell");
|
root.getStyleClass().add("md-list-cell");
|
||||||
RipplerContainer ripplerContainer = new RipplerContainer(container);
|
RipplerContainer ripplerContainer = new RipplerContainer(container);
|
||||||
root.getChildren().setAll(ripplerContainer);
|
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
|
@Override
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.ui.download;
|
package org.jackhuang.hmcl.ui.download;
|
||||||
|
|
||||||
|
import com.jfoenix.controls.JFXButton;
|
||||||
import javafx.beans.property.ReadOnlyObjectProperty;
|
import javafx.beans.property.ReadOnlyObjectProperty;
|
||||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
@ -79,7 +80,17 @@ public class DownloadPage extends BorderPane implements DecoratorPage {
|
|||||||
public DownloadPage() {
|
public DownloadPage() {
|
||||||
newGameTab.setNodeSupplier(() -> new VersionsPage(versionPageNavigator, i18n("install.installer.choose", i18n("install.installer.game")), "", DownloadProviders.getDownloadProvider(),
|
newGameTab.setNodeSupplier(() -> new VersionsPage(versionPageNavigator, i18n("install.installer.choose", i18n("install.installer.game")), "", DownloadProviders.getDownloadProvider(),
|
||||||
"game", versionPageNavigator::onGameSelected));
|
"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));
|
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")));
|
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));
|
// customizationTab.setNodeSupplier(() -> new ModDownloadListPage(CurseModManager.SECTION_CUSTOMIZATION, this::download));
|
||||||
|
@ -101,7 +101,7 @@ public class FeedbackPage extends VBox {
|
|||||||
JFXListView<FeedbackResponse> listView = new JFXListView<>();
|
JFXListView<FeedbackResponse> listView = new JFXListView<>();
|
||||||
spinnerPane.setContent(listView);
|
spinnerPane.setContent(listView);
|
||||||
Bindings.bindContent(listView.getItems(), feedbacks);
|
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 TwoLineListItem content = new TwoLineListItem();
|
||||||
private final JFXButton likeButton = new JFXButton();
|
private final JFXButton likeButton = new JFXButton();
|
||||||
private final JFXButton unlikeButton = new JFXButton();
|
private final JFXButton unlikeButton = new JFXButton();
|
||||||
|
@ -30,6 +30,7 @@ import javafx.event.ActionEvent;
|
|||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.Control;
|
import javafx.scene.control.Control;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.Skin;
|
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.SpinnerPane;
|
||||||
import org.jackhuang.hmcl.ui.construct.TwoLineListItem;
|
import org.jackhuang.hmcl.ui.construct.TwoLineListItem;
|
||||||
import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
|
import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
|
||||||
|
import org.jackhuang.hmcl.util.AggregatedObservableList;
|
||||||
import org.jackhuang.hmcl.util.StringUtils;
|
import org.jackhuang.hmcl.util.StringUtils;
|
||||||
import org.jackhuang.hmcl.util.i18n.I18n;
|
import org.jackhuang.hmcl.util.i18n.I18n;
|
||||||
import org.jackhuang.hmcl.util.javafx.BindingMapping;
|
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 final DownloadPage.DownloadCallback callback;
|
||||||
private boolean searchInitialized = false;
|
private boolean searchInitialized = false;
|
||||||
protected final BooleanProperty supportChinese = new SimpleBooleanProperty();
|
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 ListProperty<String> downloadSources = new SimpleListProperty<>(this, "downloadSources", FXCollections.observableArrayList());
|
||||||
protected final StringProperty downloadSource = new SimpleStringProperty();
|
protected final StringProperty downloadSource = new SimpleStringProperty();
|
||||||
private final WeakListenerHolder listenerHolder = new WeakListenerHolder();
|
private final WeakListenerHolder listenerHolder = new WeakListenerHolder();
|
||||||
@ -104,6 +107,10 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP
|
|||||||
this.versionSelection = versionSelection;
|
this.versionSelection = versionSelection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ObservableList<Node> getActions() {
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadVersion(Profile profile, String version) {
|
public void loadVersion(Profile profile, String version) {
|
||||||
this.version.set(new Profile.ProfileVersion(profile, 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 static class ModDownloadListPageSkin extends SkinBase<DownloadListPage> {
|
||||||
|
private final AggregatedObservableList<Node> actions = new AggregatedObservableList<>();
|
||||||
|
|
||||||
protected ModDownloadListPageSkin(DownloadListPage control) {
|
protected ModDownloadListPageSkin(DownloadListPage control) {
|
||||||
super(control);
|
super(control);
|
||||||
@ -315,7 +323,11 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP
|
|||||||
searchButton.setText(i18n("search"));
|
searchButton.setText(i18n("search"));
|
||||||
searchButton.getStyleClass().add("jfx-button-raised");
|
searchButton.getStyleClass().add("jfx-button-raised");
|
||||||
searchButton.setButtonType(JFXButton.ButtonType.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);
|
GridPane.setColumnSpan(searchBox, 4);
|
||||||
searchBox.setAlignment(Pos.CENTER_RIGHT);
|
searchBox.setAlignment(Pos.CENTER_RIGHT);
|
||||||
searchPane.addRow(rowIndex++, searchBox);
|
searchPane.addRow(rowIndex++, searchBox);
|
||||||
|
@ -102,7 +102,7 @@ class ModListPageSkin extends SkinBase<ModListPage> {
|
|||||||
center.getStyleClass().add("large-spinner-pane");
|
center.getStyleClass().add("large-spinner-pane");
|
||||||
center.loadingProperty().bind(skinnable.loadingProperty());
|
center.loadingProperty().bind(skinnable.loadingProperty());
|
||||||
|
|
||||||
listView.setCellFactory(x -> new ModInfoListCell());
|
listView.setCellFactory(x -> new ModInfoListCell(listView));
|
||||||
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
||||||
Bindings.bindContent(listView.getItems(), skinnable.getItems());
|
Bindings.bindContent(listView.getItems(), skinnable.getItems());
|
||||||
|
|
||||||
@ -263,7 +263,9 @@ class ModListPageSkin extends SkinBase<ModListPage> {
|
|||||||
JFXButton revealButton = new JFXButton();
|
JFXButton revealButton = new JFXButton();
|
||||||
BooleanProperty booleanProperty;
|
BooleanProperty booleanProperty;
|
||||||
|
|
||||||
ModInfoListCell() {
|
ModInfoListCell(JFXListView<ModInfoObject> listView) {
|
||||||
|
super(listView);
|
||||||
|
|
||||||
HBox container = new HBox(8);
|
HBox container = new HBox(8);
|
||||||
container.setPickOnBounds(false);
|
container.setPickOnBounds(false);
|
||||||
container.setAlignment(Pos.CENTER_LEFT);
|
container.setAlignment(Pos.CENTER_LEFT);
|
||||||
|
@ -38,7 +38,7 @@ public final class CurseModManager {
|
|||||||
pair("gameId", "432"),
|
pair("gameId", "432"),
|
||||||
pair("gameVersion", gameVersion),
|
pair("gameVersion", gameVersion),
|
||||||
pair("index", Integer.toString(pageOffset)),
|
pair("index", Integer.toString(pageOffset)),
|
||||||
pair("pageSize", "25"),
|
pair("pageSize", "50"),
|
||||||
pair("searchFilter", searchFilter),
|
pair("searchFilter", searchFilter),
|
||||||
pair("sectionId", Integer.toString(section)),
|
pair("sectionId", Integer.toString(section)),
|
||||||
pair("sort", Integer.toString(sort))
|
pair("sort", Integer.toString(sort))
|
||||||
|
@ -41,7 +41,7 @@ public final class Modrinth {
|
|||||||
Map<String, String> query = mapOf(
|
Map<String, String> query = mapOf(
|
||||||
pair("query", searchFilter),
|
pair("query", searchFilter),
|
||||||
pair("offset", Integer.toString(pageOffset)),
|
pair("offset", Integer.toString(pageOffset)),
|
||||||
pair("limit", "25")
|
pair("limit", "50")
|
||||||
);
|
);
|
||||||
if (StringUtils.isNotBlank(gameVersion)) {
|
if (StringUtils.isNotBlank(gameVersion)) {
|
||||||
query.put("version", "versions=" + gameVersion);
|
query.put("version", "versions=" + gameVersion);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user