RealmsCreateRealmScreen.java
com.mojang.realmsclient.gui.screens.RealmsCreateRealmScreen
信息
- 全限定名:com.mojang.realmsclient.gui.screens.RealmsCreateRealmScreen
- 类型:public class
- 包:com.mojang.realmsclient.gui.screens
- 源码路径:src/main/java/com/mojang/realmsclient/gui/screens/RealmsCreateRealmScreen.java
- 起始行号:L25
- 继承:RealmsScreen
- 职责:
TODO
字段/常量
-
CREATE_REALM_TEXT- 类型:
Component - 修饰符:
private static final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
NAME_LABEL- 类型:
Component - 修饰符:
private static final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
DESCRIPTION_LABEL- 类型:
Component - 修饰符:
private static final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
BUTTON_SPACING- 类型:
int - 修饰符:
private static final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
CONTENT_WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
lastScreen- 类型:
RealmsMainScreen - 修饰符:
private final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
layout- 类型:
HeaderAndFooterLayout - 修饰符:
private final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
nameBox- 类型:
EditBox - 修饰符:
private - 源码定位:
L33 - 说明:
TODO
- 类型:
-
descriptionBox- 类型:
EditBox - 修饰符:
private - 源码定位:
L34 - 说明:
TODO
- 类型:
-
createWorldRunnable- 类型:
Runnable - 修饰符:
private final - 源码定位:
L35 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public RealmsCreateRealmScreen(RealmsMainScreen lastScreen, RealmsServer server, boolean isSnapshot) @ L37
- 构造器名:RealmsCreateRealmScreen
- 源码定位:L37
- 修饰符:public
参数:
- lastScreen: RealmsMainScreen
- server: RealmsServer
- isSnapshot: boolean
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void init() @ L43
- 方法名:init
- 源码定位:L43
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
protected void setInitialFocus() @ L61
- 方法名:setInitialFocus
- 源码定位:L61
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
protected void repositionElements() @ L66
- 方法名:repositionElements
- 源码定位:L66
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
private void createWorld(RealmsServer server, boolean initializeSnapshotRealm) @ L71
- 方法名:createWorld
- 源码定位:L71
- 返回类型:void
- 修饰符:private
参数:
- server: RealmsServer
- initializeSnapshotRealm: boolean
说明:
TODO
private static RealmsServer createSnapshotRealm(RealmsServer server) @ L100
- 方法名:createSnapshotRealm
- 源码定位:L100
- 返回类型:RealmsServer
- 修饰符:private static
参数:
- server: RealmsServer
说明:
TODO
private void showResetWorldScreen(RealmsServer server) @ L110
- 方法名:showResetWorldScreen
- 源码定位:L110
- 返回类型:void
- 修饰符:private
参数:
- server: RealmsServer
说明:
TODO
public void onClose() @ L119
- 方法名:onClose
- 源码定位:L119
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class RealmsCreateRealmScreen extends RealmsScreen {
private static final Component CREATE_REALM_TEXT = Component.translatable("mco.selectServer.create");
private static final Component NAME_LABEL = Component.translatable("mco.configure.world.name");
private static final Component DESCRIPTION_LABEL = Component.translatable("mco.configure.world.description");
private static final int BUTTON_SPACING = 10;
private static final int CONTENT_WIDTH = 210;
private final RealmsMainScreen lastScreen;
private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
private EditBox nameBox;
private EditBox descriptionBox;
private final Runnable createWorldRunnable;
public RealmsCreateRealmScreen(RealmsMainScreen lastScreen, RealmsServer server, boolean isSnapshot) {
super(CREATE_REALM_TEXT);
this.lastScreen = lastScreen;
this.createWorldRunnable = () -> this.createWorld(server, isSnapshot);
}
@Override
public void init() {
this.layout.addTitleHeader(this.title, this.font);
LinearLayout content = this.layout.addToContents(LinearLayout.vertical()).spacing(10);
Button createButton = Button.builder(CommonComponents.GUI_CONTINUE, button -> this.createWorldRunnable.run()).build();
createButton.active = false;
this.nameBox = new EditBox(this.font, 210, 20, NAME_LABEL);
this.nameBox.setResponder(value -> createButton.active = !StringUtil.isBlank(value));
this.descriptionBox = new EditBox(this.font, 210, 20, DESCRIPTION_LABEL);
content.addChild(CommonLayouts.labeledElement(this.font, this.nameBox, NAME_LABEL));
content.addChild(CommonLayouts.labeledElement(this.font, this.descriptionBox, DESCRIPTION_LABEL));
LinearLayout bottomButtons = this.layout.addToFooter(LinearLayout.horizontal().spacing(10));
bottomButtons.addChild(createButton);
bottomButtons.addChild(Button.builder(CommonComponents.GUI_BACK, button -> this.onClose()).build());
this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
this.repositionElements();
}
@Override
protected void setInitialFocus() {
this.setInitialFocus(this.nameBox);
}
@Override
protected void repositionElements() {
this.layout.arrangeElements();
}
private void createWorld(RealmsServer server, boolean initializeSnapshotRealm) {
if (!server.isSnapshotRealm() && initializeSnapshotRealm) {
AtomicBoolean canceled = new AtomicBoolean();
this.minecraft.setScreen(new AlertScreen(() -> {
canceled.set(true);
this.lastScreen.resetScreen();
this.minecraft.setScreen(this.lastScreen);
}, Component.translatable("mco.upload.preparing"), Component.empty()));
CompletableFuture.<RealmsServer>supplyAsync(() -> createSnapshotRealm(server), Util.backgroundExecutor()).thenAcceptAsync(snapshotServer -> {
if (!canceled.get()) {
this.showResetWorldScreen(snapshotServer);
}
}, this.minecraft).exceptionallyAsync(ex -> {
this.lastScreen.resetScreen();
Component errorMessage;
if (ex.getCause() instanceof RealmsServiceException realmsServiceException) {
errorMessage = realmsServiceException.realmsError.errorMessage();
} else {
errorMessage = Component.translatable("mco.errorMessage.initialize.failed");
}
this.minecraft.setScreen(new RealmsGenericErrorScreen(errorMessage, this.lastScreen));
return null;
}, this.minecraft);
} else {
this.showResetWorldScreen(server);
}
}
private static RealmsServer createSnapshotRealm(RealmsServer server) {
RealmsClient client = RealmsClient.getOrCreate();
try {
return client.createSnapshotRealm(server.id);
} catch (RealmsServiceException var3) {
throw new RuntimeException(var3);
}
}
private void showResetWorldScreen(RealmsServer server) {
RealmCreationTask realmCreationTask = new RealmCreationTask(server.id, this.nameBox.getValue(), this.descriptionBox.getValue());
RealmsResetWorldScreen resetWorldScreen = RealmsResetWorldScreen.forNewRealm(this, server, realmCreationTask, () -> this.minecraft.execute(() -> {
RealmsMainScreen.refreshServerList();
this.minecraft.setScreen(this.lastScreen);
}));
this.minecraft.setScreen(resetWorldScreen);
}
@Override
public void onClose() {
this.minecraft.setScreen(this.lastScreen);
}
}引用的其他类
-
- 引用位置:
参数/字段/方法调用 - 关联成员:
RealmsMainScreen.refreshServerList()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RealmsClient.getOrCreate()
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
RealmsGenericErrorScreen()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RealmsResetWorldScreen.forNewRealm()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
RealmCreationTask()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Button.builder()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
EditBox()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
CommonLayouts.labeledElement()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
HeaderAndFooterLayout()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
LinearLayout.horizontal(), LinearLayout.vertical()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
AlertScreen()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Component.empty(), Component.translatable()
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
StringUtil.isBlank()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.backgroundExecutor()
- 引用位置: