diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldInfoPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldInfoPage.java index d7ab4e186..a8d7e2c5b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldInfoPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldInfoPage.java @@ -1,3 +1,20 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2024 huangyuhui and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.jackhuang.hmcl.ui.versions; import com.github.steveice10.opennbt.tag.builtin.*; @@ -10,11 +27,14 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Pos; import javafx.scene.control.Label; +import javafx.scene.control.ProgressIndicator; import javafx.scene.control.ScrollPane; import javafx.scene.layout.BorderPane; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import org.jackhuang.hmcl.game.World; +import org.jackhuang.hmcl.task.Schedulers; +import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.construct.ComponentList; import org.jackhuang.hmcl.ui.construct.DoubleValidator; @@ -32,22 +52,36 @@ import static org.jackhuang.hmcl.util.logging.Logger.LOG; import static org.jackhuang.hmcl.util.i18n.I18n.formatDateTime; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; +/** + * @author Glavo + */ public final class WorldInfoPage extends StackPane implements DecoratorPage { private final World world; - private final CompoundTag levelDat; - private final CompoundTag dataTag; + private CompoundTag levelDat; - private final ObjectProperty stateProperty = new SimpleObjectProperty<>(); + private final ObjectProperty stateProperty; - public WorldInfoPage(World world) throws IOException { + public WorldInfoPage(World world) { this.world = world; - this.levelDat = world.readLevelDat(); - this.dataTag = levelDat.get("Data"); + this.stateProperty = new SimpleObjectProperty<>(State.fromTitle(i18n("world.info.title", world.getWorldName()))); + this.getChildren().add(new ProgressIndicator()); + Task.supplyAsync(world::readLevelDat) + .whenComplete(Schedulers.javafx(), ((result, exception) -> { + if (exception == null) { + this.levelDat = result; + loadWorldInfo(); + } else { + LOG.warning("Failed to load level.dat", exception); + this.getChildren().setAll(new Label(i18n("world.info.failed"))); + } + })).start(); + } + + private void loadWorldInfo() { + CompoundTag dataTag = levelDat.get("Data"); CompoundTag worldGenSettings = dataTag.get("WorldGenSettings"); - stateProperty.set(State.fromTitle(i18n("world.info.title", world.getWorldName()))); - ScrollPane scrollPane = new ScrollPane(); scrollPane.setFitToHeight(true); scrollPane.setFitToWidth(true); @@ -483,7 +517,6 @@ public final class WorldInfoPage extends StackPane implements DecoratorPage { Tag z = listTag.get(2); if (x instanceof DoubleTag && y instanceof DoubleTag && z instanceof DoubleTag) { - //noinspection MalformedFormatString return this == OVERWORLD ? String.format("(%.2f, %.2f, %.2f)", x.getValue(), y.getValue(), z.getValue()) : String.format("%s (%.2f, %.2f, %.2f)", name, x.getValue(), y.getValue(), z.getValue()); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListItem.java index 5f98c2255..933bb0887 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldListItem.java @@ -102,10 +102,6 @@ public class WorldListItem extends Control { } public void showInfo() { - try { - Controllers.navigate(new WorldInfoPage(world)); - } catch (Exception e) { - // TODO - } + Controllers.navigate(new WorldInfoPage(world)); } } diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 90fd793e5..82fc17d1c 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -1010,6 +1010,7 @@ world.info.difficulty.peaceful=Peaceful world.info.difficulty.easy=Easy world.info.difficulty.normal=Normal world.info.difficulty.hard=Hard +world.info.failed=Failed to read the world info world.info.game_version=Game Version world.info.last_played=Last Played world.info.generate_features=Generate Structures diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 5687f8b5c..fe57454e0 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -870,6 +870,7 @@ world.info.difficulty.peaceful=和平 world.info.difficulty.easy=簡單 world.info.difficulty.normal=普通 world.info.difficulty.hard=困難 +world.info.failed=讀取世界資訊失敗 world.info.game_version=遊戲版本 world.info.last_played=上一次遊戲時間 world.info.generate_features=生成建築 diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index c378a1c7b..184a89472 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -874,6 +874,7 @@ world.info.difficulty.peaceful=和平 world.info.difficulty.easy=简单 world.info.difficulty.normal=普通 world.info.difficulty.hard=困难 +world.info.failed=读取世界信息失败 world.info.game_version=游戏版本 world.info.last_played=上一次游戏时间 world.info.generate_features=生成建筑