Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.ui.WeakListenerHolder;
import org.jackhuang.hmcl.ui.construct.*;
import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
Expand Down Expand Up @@ -254,62 +255,64 @@ protected ModDownloadListPageSkin(DownloadListPage control) {

BorderPane pane = new BorderPane();

GridPane searchPane = new GridPane();
VBox searchPane = new VBox(8);
pane.setTop(searchPane);
searchPane.getStyleClass().addAll("card");
BorderPane.setMargin(searchPane, new Insets(10, 10, 0, 10));

ColumnConstraints nameColumn = new ColumnConstraints();
nameColumn.setMinWidth(USE_PREF_SIZE);
ColumnConstraints column1 = new ColumnConstraints();
column1.setHgrow(Priority.ALWAYS);
ColumnConstraints column2 = new ColumnConstraints();
column2.setHgrow(Priority.ALWAYS);
searchPane.getColumnConstraints().setAll(nameColumn, column1, nameColumn, column2);

searchPane.setHgap(16);
searchPane.setVgap(10);
searchPane.setMaxWidth(Double.MAX_VALUE);

{
int rowIndex = 0;

if (control.versionSelection) {
searchPane.addRow(rowIndex);
int columns = 0;
Node lastNode = null;

JFXComboBox<String> versionsComboBox = new JFXComboBox<>();
versionsComboBox.setMaxWidth(Double.MAX_VALUE);
Bindings.bindContent(versionsComboBox.getItems(), control.versions);
selectedItemPropertyFor(versionsComboBox).bindBidirectional(control.selectedVersion);
BooleanProperty isExpanded = new SimpleBooleanProperty(false);

searchPane.add(new Label(i18n("version")), columns++, rowIndex);
searchPane.add(lastNode = versionsComboBox, columns++, rowIndex);

if (columns == 2) {
GridPane.setColumnSpan(lastNode, 3);
}

rowIndex++;
}
HBox rowBox1 = new HBox(16);
rowBox1.setAlignment(Pos.CENTER_LEFT);
rowBox1.setMaxWidth(Double.MAX_VALUE);

JFXTextField nameField = new JFXTextField();
HBox.setHgrow(nameField, Priority.ALWAYS);
nameField.setMaxWidth(Double.MAX_VALUE);
nameField.setPromptText(getSkinnable().supportChinese.get() ? i18n("search.hint.chinese") : i18n("search.hint.english"));
if (getSkinnable().supportChinese.get()) {
FXUtils.installFastTooltip(nameField, i18n("search.hint.chinese"));
} else {
FXUtils.installFastTooltip(nameField, i18n("search.hint.english"));
}

JFXButton btnExpand = FXUtils.newToggleButton4(SVG.ARROW_DROP_DOWN);
btnExpand.setOnAction(e -> {
isExpanded.set(!isExpanded.get());
btnExpand.setGraphic(isExpanded.get() ? SVG.ARROW_DROP_UP.createIcon() : SVG.ARROW_DROP_DOWN.createIcon());
});

if (control.versionSelection) {
JFXComboBox<String> versionsComboBox = new JFXComboBox<>();
versionsComboBox.setPrefWidth(200);
Bindings.bindContent(versionsComboBox.getItems(), control.versions);
selectedItemPropertyFor(versionsComboBox).bindBidirectional(control.selectedVersion);
rowBox1.getChildren().addAll(new Label(i18n("version")), versionsComboBox, new Label(i18n("mods.name")), nameField, btnExpand);
} else {
rowBox1.getChildren().addAll(new Label(i18n("mods.name")), nameField, btnExpand);
}

searchPane.getChildren().add(rowBox1);

HBox rowBox2 = new HBox(16);
rowBox2.setAlignment(Pos.CENTER_LEFT);
rowBox2.setMaxWidth(Double.MAX_VALUE);

rowBox2.visibleProperty().bind(isExpanded);
rowBox2.managedProperty().bind(isExpanded);

JFXComboBox<String> gameVersionField = new JFXComboBox<>();
gameVersionField.setMaxWidth(Double.MAX_VALUE);
gameVersionField.setPrefWidth(100);
gameVersionField.setEditable(true);
gameVersionField.getItems().setAll(GameVersionNumber.getDefaultGameVersions());
Label lblGameVersion = new Label(i18n("world.game_version"));
searchPane.addRow(rowIndex++, new Label(i18n("mods.name")), nameField, lblGameVersion, gameVersionField);
lblGameVersion.setMinWidth(USE_PREF_SIZE);

ObjectBinding<Boolean> hasVersion = BindingMapping.of(getSkinnable().instanceReference)
.map(instanceReference -> instanceReference.instanceId() == null);
.map(instanceReference -> instanceReference.instanceId() == null);
lblGameVersion.managedProperty().bind(hasVersion);
lblGameVersion.visibleProperty().bind(hasVersion);
gameVersionField.managedProperty().bind(hasVersion);
Expand All @@ -325,6 +328,7 @@ protected ModDownloadListPageSkin(DownloadListPage control) {
});

StackPane categoryStackPane = new StackPane();
categoryStackPane.setPrefWidth(100);
JFXComboBox<CategoryIndented> categoryComboBox = new JFXComboBox<>();
categoryComboBox.getItems().setAll(CategoryIndented.ALL);
categoryStackPane.getChildren().setAll(categoryComboBox);
Expand Down Expand Up @@ -354,14 +358,23 @@ protected ModDownloadListPageSkin(DownloadListPage control) {
});

StackPane sortStackPane = new StackPane();
sortStackPane.setPrefWidth(100);
JFXComboBox<RemoteAddonRepository.SortType> sortComboBox = new JFXComboBox<>();
sortStackPane.getChildren().setAll(sortComboBox);
sortComboBox.prefWidthProperty().bind(sortStackPane.widthProperty());
sortComboBox.getStyleClass().add("fit-width");
sortComboBox.setConverter(stringConverter(sortType -> i18n("curse.sort." + sortType.name().toLowerCase(Locale.ROOT))));
sortComboBox.getItems().setAll(RemoteAddonRepository.SortType.values());
sortComboBox.getSelectionModel().select(0);
searchPane.addRow(rowIndex++, new Label(i18n("addon.category")), categoryStackPane, new Label(i18n("search.sort")), sortStackPane);

Label categoryLabel = new Label(i18n("addon.category"));
categoryLabel.setMinWidth(Region.USE_PREF_SIZE);
Label sortLabel = new Label(i18n("search.sort"));
sortLabel.setMinWidth(Region.USE_PREF_SIZE);

rowBox2.getChildren().addAll(lblGameVersion, gameVersionField, categoryLabel, categoryStackPane, sortLabel, sortStackPane);

searchPane.getChildren().add(rowBox2);

IntegerProperty filterID = new SimpleIntegerProperty(this, "Filter ID", 0);
IntegerProperty currentFilterID = new SimpleIntegerProperty(this, "Current Filter ID", -1);
Expand Down Expand Up @@ -393,7 +406,6 @@ protected ModDownloadListPageSkin(DownloadListPage control) {
));

HBox actionsBox = new HBox(8);
GridPane.setColumnSpan(actionsBox, 4);
actionsBox.setAlignment(Pos.CENTER);
{
AggregatedObservableList<Node> actions = new AggregatedObservableList<>();
Expand Down Expand Up @@ -489,7 +501,7 @@ protected ModDownloadListPageSkin(DownloadListPage control) {
Bindings.bindContent(actionsBox.getChildren(), actions.getAggregatedList());
}

searchPane.addRow(rowIndex++, actionsBox);
searchPane.getChildren().add(actionsBox);

FXUtils.onChange(control.downloadSource, v -> searchAction.handle(null));
nameField.setOnAction(searchAction);
Expand Down