DisconnectedScreen.java

net.minecraft.client.gui.screens.DisconnectedScreen

信息

  • 全限定名:net.minecraft.client.gui.screens.DisconnectedScreen
  • 类型:public class
  • 包:net.minecraft.client.gui.screens
  • 源码路径:src/main/java/net/minecraft/client/gui/screens/DisconnectedScreen.java
  • 起始行号:L16
  • 继承:Screen
  • 职责:

    TODO

字段/常量

  • TO_SERVER_LIST

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L17
    • 说明:

      TODO

  • TO_TITLE

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L18
    • 说明:

      TODO

  • REPORT_TO_SERVER_TITLE

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L19
    • 说明:

      TODO

  • OPEN_REPORT_DIR_TITLE

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L20
    • 说明:

      TODO

  • parent

    • 类型: Screen
    • 修饰符: private final
    • 源码定位: L21
    • 说明:

      TODO

  • details

    • 类型: DisconnectionDetails
    • 修饰符: private final
    • 源码定位: L22
    • 说明:

      TODO

  • buttonText

    • 类型: Component
    • 修饰符: private final
    • 源码定位: L23
    • 说明:

      TODO

  • layout

    • 类型: LinearLayout
    • 修饰符: private final
    • 源码定位: L24
    • 说明:

      TODO

内部类/嵌套类型

构造器

public DisconnectedScreen(Screen parent, Component title, Component reason) @ L26

  • 构造器名:DisconnectedScreen
  • 源码定位:L26
  • 修饰符:public

参数:

  • parent: Screen
  • title: Component
  • reason: Component

说明:

TODO

public DisconnectedScreen(Screen parent, Component title, Component reason, Component buttonText) @ L30

  • 构造器名:DisconnectedScreen
  • 源码定位:L30
  • 修饰符:public

参数:

  • parent: Screen
  • title: Component
  • reason: Component
  • buttonText: Component

说明:

TODO

public DisconnectedScreen(Screen parent, Component title, DisconnectionDetails details) @ L34

  • 构造器名:DisconnectedScreen
  • 源码定位:L34
  • 修饰符:public

参数:

  • parent: Screen
  • title: Component
  • details: DisconnectionDetails

说明:

TODO

public DisconnectedScreen(Screen parent, Component title, DisconnectionDetails details, Component buttonText) @ L38

  • 构造器名:DisconnectedScreen
  • 源码定位:L38
  • 修饰符:public

参数:

  • parent: Screen
  • title: Component
  • details: DisconnectionDetails
  • buttonText: Component

说明:

TODO

方法

下面的方法块按源码顺序生成。

protected void init() @ L45

  • 方法名:init
  • 源码定位:L45
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

protected void repositionElements() @ L76

  • 方法名:repositionElements
  • 源码定位:L76
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

public Component getNarrationMessage() @ L81

  • 方法名:getNarrationMessage
  • 源码定位:L81
  • 返回类型:Component
  • 修饰符:public

参数:

说明:

TODO

public boolean shouldCloseOnEsc() @ L86

  • 方法名:shouldCloseOnEsc
  • 源码定位:L86
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class DisconnectedScreen extends Screen {
    private static final Component TO_SERVER_LIST = Component.translatable("gui.toMenu");
    private static final Component TO_TITLE = Component.translatable("gui.toTitle");
    private static final Component REPORT_TO_SERVER_TITLE = Component.translatable("gui.report_to_server");
    private static final Component OPEN_REPORT_DIR_TITLE = Component.translatable("gui.open_report_dir");
    private final Screen parent;
    private final DisconnectionDetails details;
    private final Component buttonText;
    private final LinearLayout layout = LinearLayout.vertical();
 
    public DisconnectedScreen(Screen parent, Component title, Component reason) {
        this(parent, title, new DisconnectionDetails(reason));
    }
 
    public DisconnectedScreen(Screen parent, Component title, Component reason, Component buttonText) {
        this(parent, title, new DisconnectionDetails(reason), buttonText);
    }
 
    public DisconnectedScreen(Screen parent, Component title, DisconnectionDetails details) {
        this(parent, title, details, TO_SERVER_LIST);
    }
 
    public DisconnectedScreen(Screen parent, Component title, DisconnectionDetails details, Component buttonText) {
        super(title);
        this.parent = parent;
        this.details = details;
        this.buttonText = buttonText;
    }
 
    @Override
    protected void init() {
        this.layout.defaultCellSetting().alignHorizontallyCenter().padding(10);
        this.layout.addChild(new StringWidget(this.title, this.font));
        this.layout.addChild(new MultiLineTextWidget(this.details.reason(), this.font).setMaxWidth(this.width - 50).setCentered(true));
        this.layout.defaultCellSetting().padding(2);
        this.details
            .bugReportLink()
            .ifPresent(
                bugReportLink -> this.layout
                    .addChild(Button.builder(REPORT_TO_SERVER_TITLE, ConfirmLinkScreen.confirmLink(this, bugReportLink, false)).width(200).build())
            );
        this.details
            .report()
            .ifPresent(
                report -> this.layout
                    .addChild(Button.builder(OPEN_REPORT_DIR_TITLE, button -> Util.getPlatform().openPath(report.getParent())).width(200).build())
            );
        Button backButton;
        if (this.minecraft.allowsMultiplayer()) {
            backButton = Button.builder(this.buttonText, button -> this.minecraft.setScreen(this.parent)).width(200).build();
        } else {
            backButton = Button.builder(TO_TITLE, button -> this.minecraft.setScreen(new TitleScreen())).width(200).build();
        }
 
        this.layout.addChild(backButton);
        this.layout.arrangeElements();
        this.layout.visitWidgets(this::addRenderableWidget);
        this.repositionElements();
    }
 
    @Override
    protected void repositionElements() {
        FrameLayout.centerInRectangle(this.layout, this.getRectangle());
    }
 
    @Override
    public Component getNarrationMessage() {
        return CommonComponents.joinForNarration(this.title, this.details.reason());
    }
 
    @Override
    public boolean shouldCloseOnEsc() {
        return false;
    }
}

引用的其他类

  • Button

    • 引用位置: 方法调用
    • 关联成员: Button.builder()
  • MultiLineTextWidget

    • 引用位置: 构造调用
    • 关联成员: MultiLineTextWidget()
  • StringWidget

    • 引用位置: 构造调用
    • 关联成员: StringWidget()
  • FrameLayout

    • 引用位置: 方法调用
    • 关联成员: FrameLayout.centerInRectangle()
  • LinearLayout

    • 引用位置: 字段/方法调用
    • 关联成员: LinearLayout.vertical()
  • ConfirmLinkScreen

    • 引用位置: 方法调用
    • 关联成员: ConfirmLinkScreen.confirmLink()
  • Screen

    • 引用位置: 参数/字段/继承
  • TitleScreen

    • 引用位置: 构造调用
    • 关联成员: TitleScreen()
  • DisconnectionDetails

    • 引用位置: 参数/字段/构造调用
    • 关联成员: DisconnectionDetails()
  • CommonComponents

    • 引用位置: 方法调用
    • 关联成员: CommonComponents.joinForNarration()
  • Component

    • 引用位置: 参数/字段/方法调用/返回值
    • 关联成员: Component.translatable()
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.getPlatform()