Skip to content
Draft
Show file tree
Hide file tree
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 @@ -22,7 +22,7 @@
import javafx.scene.control.Skin;
import javafx.stage.FileChooser;
import org.jackhuang.hmcl.game.World;
import org.jackhuang.hmcl.mod.Datapack;
import org.jackhuang.hmcl.mod.DataPack;
import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.ui.Controllers;
Expand All @@ -44,45 +44,45 @@
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> implements WorldManagePage.WorldRefreshable {
public final class DataPackListPage extends ListPageBase<DataPackListPageSkin.DataPackInfoObject> implements WorldManagePage.WorldRefreshable {
private final World world;
private final Datapack datapack;
private final DataPack dataPack;
final BooleanProperty readOnly;

public DatapackListPage(WorldManagePage worldManagePage) {
public DataPackListPage(WorldManagePage worldManagePage) {
world = worldManagePage.getWorld();
datapack = new Datapack(world.getFile().resolve("datapacks"));
setItems(MappedObservableList.create(datapack.getPacks(), DatapackListPageSkin.DatapackInfoObject::new));
dataPack = new DataPack(world.getFile().resolve("datapacks"));
setItems(MappedObservableList.create(dataPack.getPacks(), DataPackListPageSkin.DataPackInfoObject::new));
readOnly = worldManagePage.readOnlyProperty();
FXUtils.applyDragListener(this, it -> Objects.equals("zip", FileUtils.getExtension(it)),
this::installMultiDatapack, this::refresh);
this::installMultiDataPack, this::refresh);

refresh();
}

private void installMultiDatapack(List<Path> datapackPath) {
datapackPath.forEach(this::installSingleDatapack);
private void installMultiDataPack(List<Path> dataPackPath) {
dataPackPath.forEach(this::installSingleDataPack);
if (readOnly.get()) {
Controllers.showToast(i18n("datapack.reload.toast"));
}
}

private void installSingleDatapack(Path datapack) {
private void installSingleDataPack(Path dataPack) {
try {
this.datapack.installPack(datapack, world.getGameVersion());
this.dataPack.installPack(dataPack, world.getGameVersion());
} catch (IOException | IllegalArgumentException e) {
LOG.warning("Unable to parse datapack file " + datapack, e);
LOG.warning("Unable to parse datapack file " + dataPack, e);
}
}

@Override
protected Skin<?> createDefaultSkin() {
return new DatapackListPageSkin(this);
return new DataPackListPageSkin(this);
}

public void refresh() {
setLoading(true);
Task.runAsync(datapack::loadFromDir)
Task.runAsync(dataPack::loadFromDir)
.withRunAsync(Schedulers.javafx(), () -> setLoading(false))
.start();
}
Expand All @@ -94,42 +94,42 @@ public void add() {
List<Path> res = FileUtils.toPaths(chooser.showOpenMultipleDialog(Controllers.getStage()));

if (res != null) {
installMultiDatapack(res);
installMultiDataPack(res);
}

datapack.loadFromDir();
dataPack.loadFromDir();
}

void removeSelected(ObservableList<DatapackListPageSkin.DatapackInfoObject> selectedItems) {
void removeSelected(ObservableList<DataPackListPageSkin.DataPackInfoObject> selectedItems) {
selectedItems.stream()
.map(DatapackListPageSkin.DatapackInfoObject::getPackInfo)
.map(DataPackListPageSkin.DataPackInfoObject::getPackInfo)
.forEach(pack -> {
try {
datapack.deletePack(pack);
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.getId() + "\"", e);
}
});
}

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

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

void openDataPackFolder() {
FXUtils.openFolder(datapack.getPath());
FXUtils.openFolder(dataPack.getPath());
}

@NotNull Predicate<DatapackListPageSkin.DatapackInfoObject> updateSearchPredicate(String queryString) {
@NotNull Predicate<DataPackListPageSkin.DataPackInfoObject> updateSearchPredicate(String queryString) {
if (queryString.isBlank()) {
return dataPack -> true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.util.Duration;
import org.jackhuang.hmcl.mod.Datapack;
import org.jackhuang.hmcl.mod.DataPack;
import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.FXUtils;
Expand All @@ -67,16 +67,16 @@
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;

final class DatapackListPageSkin extends SkinBase<DatapackListPage> {
final class DataPackListPageSkin extends SkinBase<DataPackListPage> {

private final TransitionPane toolbarPane;
private final HBox searchBar;
private final HBox normalToolbar;
private final HBox selectingToolbar;
InvalidationListener updateBarByStateWeakListener;

private final JFXListView<DatapackInfoObject> listView;
private final FilteredList<DatapackInfoObject> filteredList;
private final JFXListView<DataPackInfoObject> listView;
private final FilteredList<DataPackInfoObject> filteredList;

private final BooleanProperty isSearching = new SimpleBooleanProperty(false);
private final BooleanProperty isSelecting = new SimpleBooleanProperty(false);
Expand All @@ -85,7 +85,7 @@ final class DatapackListPageSkin extends SkinBase<DatapackListPage> {
private static final AtomicInteger lastShiftClickIndex = new AtomicInteger(-1);
final Consumer<Integer> toggleSelect;

DatapackListPageSkin(DatapackListPage skinnable) {
DataPackListPageSkin(DataPackListPage skinnable) {
super(skinnable);

StackPane pane = new StackPane();
Expand Down Expand Up @@ -181,7 +181,7 @@ final class DatapackListPageSkin extends SkinBase<DatapackListPage> {
ComponentList.setVgrow(center, Priority.ALWAYS);
center.loadingProperty().bind(skinnable.loadingProperty());

listView.setCellFactory(x -> new DatapackInfoListCell(listView, getSkinnable().readOnly));
listView.setCellFactory(x -> new DataPackInfoListCell(listView, getSkinnable().readOnly));
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
this.listView.setItems(filteredList);

Expand Down Expand Up @@ -216,13 +216,13 @@ private void changeToolbar(HBox newToolbar) {
}
}

static class DatapackInfoObject extends RecursiveTreeObject<DatapackInfoObject> {
static class DataPackInfoObject extends RecursiveTreeObject<DataPackInfoObject> {
private final BooleanProperty activeProperty;
private final Datapack.Pack packInfo;
private final DataPack.Pack packInfo;

private SoftReference<CompletableFuture<Image>> iconCache;

DatapackInfoObject(Datapack.Pack packInfo) {
DataPackInfoObject(DataPack.Pack packInfo) {
this.packInfo = packInfo;
this.activeProperty = packInfo.activeProperty();
}
Expand All @@ -235,7 +235,7 @@ String getSubtitle() {
return packInfo.getDescription().toString();
}

Datapack.Pack getPackInfo() {
DataPack.Pack getPackInfo() {
return packInfo;
}

Expand Down Expand Up @@ -270,7 +270,7 @@ Image loadIcon() {
}
}

public void loadIcon(ImageContainer imageContainer, @Nullable WeakReference<ObjectProperty<DatapackInfoObject>> current) {
public void loadIcon(ImageContainer imageContainer, @Nullable WeakReference<ObjectProperty<DataPackInfoObject>> current) {
SoftReference<CompletableFuture<Image>> iconCache = this.iconCache;
CompletableFuture<Image> imageFuture;
if (iconCache != null && (imageFuture = iconCache.get()) != null) {
Expand All @@ -286,7 +286,7 @@ public void loadIcon(ImageContainer imageContainer, @Nullable WeakReference<Obje
imageContainer.setImage(FXUtils.newBuiltinImage("/assets/img/unknown_pack.png"));
imageFuture.thenAcceptAsync(image -> {
if (current != null) {
ObjectProperty<DatapackInfoObject> infoObjectProperty = current.get();
ObjectProperty<DataPackInfoObject> infoObjectProperty = current.get();
if (infoObjectProperty == null || infoObjectProperty.get() != this) {
// The current ListCell has already switched to another object
return;
Expand All @@ -298,13 +298,13 @@ public void loadIcon(ImageContainer imageContainer, @Nullable WeakReference<Obje
}
}

private final class DatapackInfoListCell extends MDListCell<DatapackInfoObject> {
private final class DataPackInfoListCell extends MDListCell<DataPackInfoObject> {
final JFXCheckBox checkBox = new JFXCheckBox();
ImageContainer imageContainer = new ImageContainer(32);
final TwoLineListItem content = new TwoLineListItem();
BooleanProperty booleanProperty;

DatapackInfoListCell(JFXListView<DatapackInfoObject> listView, BooleanProperty isReadOnlyProperty) {
DataPackInfoListCell(JFXListView<DataPackInfoObject> listView, BooleanProperty isReadOnlyProperty) {
super(listView);

HBox container = new HBox(8);
Expand All @@ -326,7 +326,7 @@ private final class DatapackInfoListCell extends MDListCell<DatapackInfoObject>
}

@Override
protected void updateControl(DatapackInfoObject dataItem, boolean empty) {
protected void updateControl(DataPackInfoObject dataItem, boolean empty) {
if (empty) return;
content.setTitle(dataItem.getTitle());
content.setSubtitle(dataItem.getSubtitle());
Expand All @@ -338,7 +338,7 @@ protected void updateControl(DatapackInfoObject dataItem, boolean empty) {
}
}

public void handleSelect(DatapackInfoListCell cell, MouseEvent mouseEvent) {
public void handleSelect(DataPackInfoListCell cell, MouseEvent mouseEvent) {
if (cell.isEmpty()) {
mouseEvent.consume();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public final class WorldManagePage extends DecoratorAnimatedPage implements Deco
private final TabHeader header = new TabHeader(transitionPane);
private final TabHeader.Tab<WorldInfoPage> worldInfoTab = new TabHeader.Tab<>("worldInfoPage");
private final TabHeader.Tab<WorldBackupsPage> worldBackupsTab = new TabHeader.Tab<>("worldBackupsPage");
private final TabHeader.Tab<DatapackListPage> datapackTab = new TabHeader.Tab<>("datapackListPage");
private final TabHeader.Tab<DataPackListPage> dataPackTab = new TabHeader.Tab<>("dataPackListPage");

public WorldManagePage(World world, Profile profile, String instanceId) {
this.world = world;
Expand All @@ -86,7 +86,7 @@ public WorldManagePage(World world, Profile profile, String instanceId) {

worldInfoTab.setNodeSupplier(() -> new WorldInfoPage(this));
worldBackupsTab.setNodeSupplier(() -> new WorldBackupsPage(this));
datapackTab.setNodeSupplier(() -> new DatapackListPage(this));
dataPackTab.setNodeSupplier(() -> new DataPackListPage(this));

this.state = new SimpleObjectProperty<>(new State(i18n("world.manage.title", StringUtils.parseColorEscapes(world.getWorldName())), null, true, true, true));

Expand Down Expand Up @@ -218,9 +218,9 @@ private AdvancedListBox getTabBar() {
tabBar.addNavigationDrawerTab(getSkinnable().header, getSkinnable().worldInfoTab, i18n("world.info"), SVG.INFO, SVG.INFO_FILL)
.addNavigationDrawerTab(getSkinnable().header, getSkinnable().worldBackupsTab, i18n("world.backup"), SVG.ARCHIVE, SVG.ARCHIVE_FILL);

if (getSkinnable().world.supportDatapacks()) {
getSkinnable().header.getTabs().add(getSkinnable().datapackTab);
tabBar.addNavigationDrawerTab(getSkinnable().header, getSkinnable().datapackTab, i18n("world.datapack"), SVG.EXTENSION, SVG.EXTENSION_FILL);
if (getSkinnable().world.supportDataPacks()) {
getSkinnable().header.getTabs().add(getSkinnable().dataPackTab);
tabBar.addNavigationDrawerTab(getSkinnable().header, getSkinnable().dataPackTab, i18n("world.datapack"), SVG.EXTENSION, SVG.EXTENSION_FILL);
}
}

Expand Down
16 changes: 8 additions & 8 deletions HMCL/src/main/resources/assets/lang/I18N.properties
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ extension.ps1=Windows PowerShell Script
extension.sh=Shell Script
extension.command=macOS Shell Script

extension.datapack=Datapack Archive
extension.datapack=Data Pack Archive
extension.mod=Mod File
extension.modloader.installer=Mod Loader Installer
extension.resourcepack=Resource Pack Archive
Expand Down Expand Up @@ -698,7 +698,7 @@ game.version=Game Instance

help=Help
help.doc=Hello Minecraft! Launcher Documentation
help.detail=For datapack and modpack makers.
help.detail=For data pack and modpack makers.

input.email=The username must be an email address.
input.number=The input must be numbers.
Expand Down Expand Up @@ -984,7 +984,7 @@ modrinth.category.colored-lighting=Colored Lighting
modrinth.category.combat=Combat
modrinth.category.core-shaders=Core Shaders
modrinth.category.cursed=Cursed
modrinth.category.datapack=Datapack
modrinth.category.datapack=Data Pack
modrinth.category.decoration=Decoration
modrinth.category.economy=Economy
modrinth.category.entities=Entities
Expand Down Expand Up @@ -1127,11 +1127,11 @@ nbt.open.failed=Failed to open file
nbt.save.failed=Failed to save file
nbt.title=View File - %s

datapack=Datapacks
datapack=Data Packs
datapack.add=Add
datapack.add.title=Choose datapack archive you want to add
datapack.reload.toast=Minecraft is running, please use the /reload command to reload the data pack
datapack.title=World [%s] - Datapacks
datapack.add.title=Choose data pack archive you want to add
datapack.reload.toast=Minecraft is running. Use /reload command to reload data packs
datapack.title=World [%s] - Data Packs

web.failed=Failed to load page
web.open_in_browser=Do you want to open this address in a browser:\n%s
Expand Down Expand Up @@ -1161,7 +1161,7 @@ world.duplicate.failed.empty_name=Name cannot be empty
world.duplicate.failed.invalid_name=Name contains invalid characters
world.duplicate.failed=Failed to duplicate the world
world.duplicate.success.toast=Successfully duplicated the world
world.datapack=Datapacks
world.datapack=Data Packs
world.datetime=Last played on %s
world.delete=Delete the World
world.delete.failed=Failed to delete world.\n%s
Expand Down
2 changes: 1 addition & 1 deletion HMCLCore/src/main/java/org/jackhuang/hmcl/game/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public boolean isLocked() {
return isLocked(getSessionLockFile());
}

public boolean supportDatapacks() {
public boolean supportDataPacks() {
return getGameVersion() != null && getGameVersion().isAtLeast("1.13", "17w43a");
}

Expand Down
Loading
Loading