EditWorldScreen.java
net.minecraft.client.gui.screens.worldselection.EditWorldScreen
信息
- 全限定名:net.minecraft.client.gui.screens.worldselection.EditWorldScreen
- 类型:public class
- 包:net.minecraft.client.gui.screens.worldselection
- 源码路径:src/main/java/net/minecraft/client/gui/screens/worldselection/EditWorldScreen.java
- 起始行号:L41
- 继承:Screen
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L42 - 说明:
TODO
- 类型:
-
NAME_LABEL- 类型:
Component - 修饰符:
private static final - 源码定位:
L43 - 说明:
TODO
- 类型:
-
RESET_ICON_BUTTON- 类型:
Component - 修饰符:
private static final - 源码定位:
L44 - 说明:
TODO
- 类型:
-
FOLDER_BUTTON- 类型:
Component - 修饰符:
private static final - 源码定位:
L45 - 说明:
TODO
- 类型:
-
BACKUP_BUTTON- 类型:
Component - 修饰符:
private static final - 源码定位:
L46 - 说明:
TODO
- 类型:
-
BACKUP_FOLDER_BUTTON- 类型:
Component - 修饰符:
private static final - 源码定位:
L47 - 说明:
TODO
- 类型:
-
OPTIMIZE_BUTTON- 类型:
Component - 修饰符:
private static final - 源码定位:
L48 - 说明:
TODO
- 类型:
-
OPTIMIZE_TITLE- 类型:
Component - 修饰符:
private static final - 源码定位:
L49 - 说明:
TODO
- 类型:
-
OPTIMIZE_DESCRIPTION- 类型:
Component - 修饰符:
private static final - 源码定位:
L50 - 说明:
TODO
- 类型:
-
OPTIMIZE_CONFIRMATION- 类型:
Component - 修饰符:
private static final - 源码定位:
L51 - 说明:
TODO
- 类型:
-
SAVE_BUTTON- 类型:
Component - 修饰符:
private static final - 源码定位:
L52 - 说明:
TODO
- 类型:
-
DEFAULT_WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L53 - 说明:
TODO
- 类型:
-
VERTICAL_SPACING- 类型:
int - 修饰符:
private static final - 源码定位:
L54 - 说明:
TODO
- 类型:
-
HALF_WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L55 - 说明:
TODO
- 类型:
-
layout- 类型:
LinearLayout - 修饰符:
private final - 源码定位:
L56 - 说明:
TODO
- 类型:
-
callback- 类型:
BooleanConsumer - 修饰符:
private final - 源码定位:
L57 - 说明:
TODO
- 类型:
-
levelAccess- 类型:
LevelStorageSource.LevelStorageAccess - 修饰符:
private final - 源码定位:
L58 - 说明:
TODO
- 类型:
-
nameEdit- 类型:
EditBox - 修饰符:
private final - 源码定位:
L59 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
private EditWorldScreen(Minecraft minecraft, LevelStorageSource.LevelStorageAccess levelAccess, String name, BooleanConsumer callback) @ L66
- 构造器名:EditWorldScreen
- 源码定位:L66
- 修饰符:private
参数:
- minecraft: Minecraft
- levelAccess: LevelStorageSource.LevelStorageAccess
- name: String
- callback: BooleanConsumer
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static EditWorldScreen create(Minecraft minecraft, LevelStorageSource.LevelStorageAccess levelAccess, BooleanConsumer callback) @ L61
- 方法名:create
- 源码定位:L61
- 返回类型:EditWorldScreen
- 修饰符:public static
参数:
- minecraft: Minecraft
- levelAccess: LevelStorageSource.LevelStorageAccess
- callback: BooleanConsumer
说明:
TODO
protected void setInitialFocus() @ L134
- 方法名:setInitialFocus
- 源码定位:L134
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
protected void init() @ L139
- 方法名:init
- 源码定位:L139
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
protected void repositionElements() @ L144
- 方法名:repositionElements
- 源码定位:L144
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
public boolean keyPressed(KeyEvent event) @ L150
- 方法名:keyPressed
- 源码定位:L150
- 返回类型:boolean
- 修饰符:public
参数:
- event: KeyEvent
说明:
TODO
public void onClose() @ L161
- 方法名:onClose
- 源码定位:L161
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
private void onRename(String newName) @ L166
- 方法名:onRename
- 源码定位:L166
- 返回类型:void
- 修饰符:private
参数:
- newName: String
说明:
TODO
public static CompletableFuture<Boolean> conditionallyMakeBackupAndShowToast(boolean createBackup, LevelStorageSource.LevelStorageAccess access) @ L177
- 方法名:conditionallyMakeBackupAndShowToast
- 源码定位:L177
- 返回类型:CompletableFuture
- 修饰符:public static
参数:
- createBackup: boolean
- access: LevelStorageSource.LevelStorageAccess
说明:
TODO
public static CompletableFuture<Boolean> makeBackupAndShowToast(LevelStorageSource.LevelStorageAccess access) @ L181
- 方法名:makeBackupAndShowToast
- 源码定位:L181
- 返回类型:CompletableFuture
- 修饰符:public static
参数:
- access: LevelStorageSource.LevelStorageAccess
说明:
TODO
public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L208
- 方法名:extractRenderState
- 源码定位:L208
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class EditWorldScreen extends Screen {
private static final Logger LOGGER = LogUtils.getLogger();
private static final Component NAME_LABEL = Component.translatable("selectWorld.enterName").withStyle(ChatFormatting.GRAY);
private static final Component RESET_ICON_BUTTON = Component.translatable("selectWorld.edit.resetIcon");
private static final Component FOLDER_BUTTON = Component.translatable("selectWorld.edit.openFolder");
private static final Component BACKUP_BUTTON = Component.translatable("selectWorld.edit.backup");
private static final Component BACKUP_FOLDER_BUTTON = Component.translatable("selectWorld.edit.backupFolder");
private static final Component OPTIMIZE_BUTTON = Component.translatable("selectWorld.edit.optimize");
private static final Component OPTIMIZE_TITLE = Component.translatable("optimizeWorld.confirm.title");
private static final Component OPTIMIZE_DESCRIPTION = Component.translatable("optimizeWorld.confirm.description");
private static final Component OPTIMIZE_CONFIRMATION = Component.translatable("optimizeWorld.confirm.proceed");
private static final Component SAVE_BUTTON = Component.translatable("selectWorld.edit.save");
private static final int DEFAULT_WIDTH = 200;
private static final int VERTICAL_SPACING = 4;
private static final int HALF_WIDTH = 98;
private final LinearLayout layout = LinearLayout.vertical().spacing(5);
private final BooleanConsumer callback;
private final LevelStorageSource.LevelStorageAccess levelAccess;
private final EditBox nameEdit;
public static EditWorldScreen create(Minecraft minecraft, LevelStorageSource.LevelStorageAccess levelAccess, BooleanConsumer callback) throws IOException {
LevelSummary summary = levelAccess.fixAndGetSummary();
return new EditWorldScreen(minecraft, levelAccess, summary.getLevelName(), callback);
}
private EditWorldScreen(Minecraft minecraft, LevelStorageSource.LevelStorageAccess levelAccess, String name, BooleanConsumer callback) {
super(Component.translatable("selectWorld.edit.title"));
this.callback = callback;
this.levelAccess = levelAccess;
Font font = minecraft.font;
this.layout.addChild(new SpacerElement(200, 20));
this.layout.addChild(new StringWidget(NAME_LABEL, font));
this.nameEdit = this.layout.addChild(new EditBox(font, 200, 20, NAME_LABEL));
this.nameEdit.setValue(name);
LinearLayout bottomButtonRow = LinearLayout.horizontal().spacing(4);
Button renameButton = bottomButtonRow.addChild(Button.builder(SAVE_BUTTON, button -> this.onRename(this.nameEdit.getValue())).width(98).build());
bottomButtonRow.addChild(Button.builder(CommonComponents.GUI_CANCEL, button -> this.onClose()).width(98).build());
this.nameEdit.setResponder(newName -> renameButton.active = !StringUtil.isBlank(newName));
this.layout.addChild(Button.builder(RESET_ICON_BUTTON, button -> {
levelAccess.getIconFile().ifPresent(p -> FileUtils.deleteQuietly(p.toFile()));
button.active = false;
}).width(200).build()).active = levelAccess.getIconFile().filter(x$0 -> Files.isRegularFile(x$0)).isPresent();
this.layout
.addChild(Button.builder(FOLDER_BUTTON, button -> Util.getPlatform().openPath(levelAccess.getLevelPath(LevelResource.ROOT))).width(200).build());
this.layout
.addChild(
Button.builder(
BACKUP_BUTTON, button -> makeBackupAndShowToast(levelAccess).thenAcceptAsync(success -> this.callback.accept(!success), minecraft)
)
.width(200)
.build()
);
this.layout.addChild(Button.builder(BACKUP_FOLDER_BUTTON, button -> {
LevelStorageSource levelSource = minecraft.getLevelSource();
Path path = levelSource.getBackupPath();
try {
FileUtil.createDirectoriesSafe(path);
} catch (IOException var5x) {
throw new RuntimeException(var5x);
}
Util.getPlatform().openPath(path);
}).width(200).build());
this.layout
.addChild(
Button.builder(
OPTIMIZE_BUTTON,
button -> minecraft.setScreen(
new BackupConfirmScreen(
() -> minecraft.setScreen(this),
(backup, eraseCache) -> conditionallyMakeBackupAndShowToast(backup, levelAccess)
.thenAcceptAsync(
var4x -> minecraft.setScreen(
OptimizeWorldScreen.create(minecraft, this.callback, minecraft.getFixerUpper(), levelAccess, eraseCache)
),
minecraft
),
OPTIMIZE_TITLE,
OPTIMIZE_DESCRIPTION,
OPTIMIZE_CONFIRMATION,
true
)
)
)
.width(200)
.build()
);
this.layout.addChild(new SpacerElement(200, 20));
this.layout.addChild(bottomButtonRow);
this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
}
@Override
protected void setInitialFocus() {
this.setInitialFocus(this.nameEdit);
}
@Override
protected void init() {
this.repositionElements();
}
@Override
protected void repositionElements() {
this.layout.arrangeElements();
FrameLayout.centerInRectangle(this.layout, this.getRectangle());
}
@Override
public boolean keyPressed(KeyEvent event) {
if (this.nameEdit.isFocused() && event.isConfirmation()) {
this.onRename(this.nameEdit.getValue());
this.onClose();
return true;
} else {
return super.keyPressed(event);
}
}
@Override
public void onClose() {
this.callback.accept(false);
}
private void onRename(String newName) {
try {
this.levelAccess.renameLevel(newName);
} catch (NbtException | ReportedNbtException | IOException var3) {
LOGGER.error("Failed to access world '{}'", this.levelAccess.getLevelId(), var3);
SystemToast.onWorldAccessFailure(this.minecraft, this.levelAccess.getLevelId());
}
this.callback.accept(true);
}
public static CompletableFuture<Boolean> conditionallyMakeBackupAndShowToast(boolean createBackup, LevelStorageSource.LevelStorageAccess access) {
return createBackup ? makeBackupAndShowToast(access) : CompletableFuture.completedFuture(false);
}
public static CompletableFuture<Boolean> makeBackupAndShowToast(LevelStorageSource.LevelStorageAccess access) {
Minecraft minecraft = Minecraft.getInstance();
minecraft.setScreenAndShow(
GenericWaitingScreen.createWaitingWithoutButton(
Component.translatable("selectWorld.waitingForBackup.title"),
Component.translatable("selectWorld.waitingForBackup.message").withStyle(ChatFormatting.GRAY)
)
);
return CompletableFuture.<Long>supplyAsync(() -> {
try {
return access.makeWorldBackup();
} catch (IOException var2) {
throw new RuntimeException(var2);
}
}, Util.backgroundExecutor()).thenApplyAsync(size -> {
Component title = Component.translatable("selectWorld.edit.backupCreated", access.getLevelId());
Component message = Component.translatable("selectWorld.edit.backupSize", Mth.ceil(size.longValue() / 1048576.0));
minecraft.getToastManager().addToast(SystemToast.multiline(minecraft, SystemToast.SystemToastId.WORLD_BACKUP, title, message));
return true;
}, minecraft).exceptionallyAsync(exception -> {
Component title = Component.translatable("selectWorld.edit.backupFailed");
Component message = Component.literal(exception.getMessage());
minecraft.getToastManager().addToast(SystemToast.multiline(minecraft, SystemToast.SystemToastId.WORLD_BACKUP, title, message));
return false;
}, minecraft);
}
@Override
public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
super.extractRenderState(graphics, mouseX, mouseY, a);
graphics.centeredText(this.font, this.title, this.width / 2, 15, -1);
}
}引用的其他类
-
- 引用位置:
参数/方法调用 - 关联成员:
Minecraft.getInstance()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Button.builder()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
EditBox()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
StringWidget()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SystemToast.multiline(), SystemToast.onWorldAccessFailure()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
FrameLayout.centerInRectangle()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
LinearLayout.horizontal(), LinearLayout.vertical()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
SpacerElement()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
BackupConfirmScreen()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
GenericWaitingScreen.createWaitingWithoutButton()
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
OptimizeWorldScreen.create()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Component.literal(), Component.translatable()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
FileUtil.createDirectoriesSafe()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Mth.ceil()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
StringUtil.isBlank()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.backgroundExecutor(), Util.getPlatform()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置: