Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
680cbb7
feat:分类操作栏,添加功能
Mine-diamond Oct 14, 2025
406b49b
feat:重构datapack类,添加图片显示功能
Mine-diamond Oct 17, 2025
4d515bd
fix:修复逻辑错误
Mine-diamond Oct 17, 2025
88d08fd
fix:优化字段名称
Mine-diamond Oct 18, 2025
97f1a5e
feat: 添加搜索功能
Mine-diamond Oct 18, 2025
23bd43f
feat: 优化代码
Mine-diamond Oct 18, 2025
e51cd07
feat: 改进格式
Mine-diamond Oct 18, 2025
c979031
feat: 优化代码
Mine-diamond Oct 19, 2025
bbcbd03
feat: 优化代码
Mine-diamond Oct 19, 2025
59dbf1c
feat: 优化代码
Mine-diamond Oct 20, 2025
4d2fef0
Update HMCL/src/main/resources/assets/lang/I18N_zh.properties
Mine-diamond Oct 21, 2025
3a38718
fix:修复全选时工具栏闪烁的问题
Mine-diamond Oct 25, 2025
bfc8dae
fix:使用自定义的新的选择逻辑
Mine-diamond Oct 25, 2025
98f6c32
fear:图标显示大小被调整至32×32px
Mine-diamond Oct 25, 2025
23ae2e5
feat: 优化选择逻辑
Mine-diamond Oct 26, 2025
b5ef48b
feat: 优化自定义选择的逻辑
Mine-diamond Oct 27, 2025
d9aae47
feat: 优化代码
Mine-diamond Oct 28, 2025
166fcf3
feat: 优化代码
Mine-diamond Oct 28, 2025
e286591
Merge remote-tracking branch 'upstream/main' into enhance-datapack-page
Mine-diamond Nov 2, 2025
7b2cf4c
Merge branch 'main' into enhance-datapack-page
Mine-diamond Nov 2, 2025
5415065
feat: 更改i18n
Mine-diamond Nov 2, 2025
dfab3fa
feat:应用copilot的建议
Mine-diamond Nov 4, 2025
7093a85
fix style
Mine-diamond Nov 4, 2025
b74f523
feat: 优化代码
Mine-diamond Nov 6, 2025
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 @@ -26,16 +26,21 @@
import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.ListPageBase;
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.io.FileUtils;
import org.jackhuang.hmcl.util.javafx.MappedObservableList;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.regex.Pattern;

import static org.jackhuang.hmcl.util.logging.Logger.LOG;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;

public final class DatapackListPage extends ListPageBase<DatapackListPageSkin.DatapackInfoObject> {
private final Path worldDir;
Expand All @@ -47,17 +52,15 @@ public DatapackListPage(WorldManagePage worldManagePage) {
datapack = new Datapack(worldDir.resolve("datapacks"));
datapack.loadFromDir();

setItems(MappedObservableList.create(datapack.getInfo(), DatapackListPageSkin.DatapackInfoObject::new));
setItems(MappedObservableList.create(datapack.getPacks(), DatapackListPageSkin.DatapackInfoObject::new));

FXUtils.applyDragListener(this, it -> Objects.equals("zip", FileUtils.getExtension(it)),
mods -> mods.forEach(this::installSingleDatapack), this::refresh);
}

private void installSingleDatapack(Path datapack) {
try {
Datapack zip = new Datapack(datapack);
zip.loadFromZip();
zip.installTo(worldDir);
this.datapack.installPack(datapack);
} catch (IOException | IllegalArgumentException e) {
LOG.warning("Unable to parse datapack file " + datapack, e);
}
Expand All @@ -83,8 +86,9 @@ public void add() {
chooser.getExtensionFilters().setAll(new FileChooser.ExtensionFilter(i18n("datapack.extension"), "*.zip"));
List<Path> res = FileUtils.toPaths(chooser.showOpenMultipleDialog(Controllers.getStage()));

if (res != null)
if (res != null) {
res.forEach(this::installSingleDatapack);
}

datapack.loadFromDir();
}
Expand All @@ -97,20 +101,49 @@ void removeSelected(ObservableList<DatapackListPageSkin.DatapackInfoObject> sele
datapack.deletePack(pack);
} catch (IOException e) {
// Fail to remove mods if the game is running or the datapack is absent.
LOG.warning("Failed to delete datapack " + pack);
LOG.warning("Failed to delete datapack \"" + pack.getId() + "\"", e);
}
});
}

void enableSelected(ObservableList<DatapackListPageSkin.DatapackInfoObject> selectedItems) {
selectedItems.stream()
.map(DatapackListPageSkin.DatapackInfoObject::getPackInfo)
.forEach(info -> info.setActive(true));
.forEach(pack -> pack.setActive(true));
}

void disableSelected(ObservableList<DatapackListPageSkin.DatapackInfoObject> selectedItems) {
selectedItems.stream()
.map(DatapackListPageSkin.DatapackInfoObject::getPackInfo)
.forEach(info -> info.setActive(false));
.forEach(pack -> pack.setActive(false));
}

void openDataPackFolder() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉不需要单独做一个这个

FXUtils.openFolder(datapack.getPath());
}

@NotNull Predicate<DatapackListPageSkin.DatapackInfoObject> updateSearchPredicate(String queryString) {
if (queryString.isBlank()) {
return dataPack -> true;
}

final Predicate<String> stringPredicate;
if (queryString.startsWith("regex:")) {
try {
Pattern pattern = Pattern.compile(StringUtils.substringAfter(queryString, "regex:"));
stringPredicate = s -> s != null && pattern.matcher(s).find();
} catch (Exception e) {
return dataPack -> false;
}
} else {
String lowerCaseFilter = queryString.toLowerCase(Locale.ROOT);
stringPredicate = s -> s != null && s.toLowerCase(Locale.ROOT).contains(lowerCaseFilter);
}

return dataPack -> {
String id = dataPack.getPackInfo().getId();
String description = dataPack.getPackInfo().getDescription().toString();
return stringPredicate.test(id) || stringPredicate.test(description);
};
}
}
Loading