AlertScreen.java

net.minecraft.client.gui.screens.AlertScreen

信息

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

    TODO

字段/常量

  • LABEL_Y

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

      TODO

  • messageText

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

      TODO

  • message

    • 类型: MultiLineLabel
    • 修饰符: private
    • 源码定位: L18
    • 说明:

      TODO

  • callback

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

      TODO

  • okButton

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

      TODO

  • shouldCloseOnEsc

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

      TODO

内部类/嵌套类型

构造器

public AlertScreen(Runnable callback, Component title, Component messageText) @ L23

  • 构造器名:AlertScreen
  • 源码定位:L23
  • 修饰符:public

参数:

  • callback: Runnable
  • title: Component
  • messageText: Component

说明:

TODO

public AlertScreen(Runnable callback, Component title, Component messageText, Component okButton, boolean shouldCloseOnEsc) @ L27

  • 构造器名:AlertScreen
  • 源码定位:L27
  • 修饰符:public

参数:

  • callback: Runnable
  • title: Component
  • messageText: Component
  • okButton: Component
  • shouldCloseOnEsc: boolean

说明:

TODO

方法

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

public Component getNarrationMessage() @ L35

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

参数:

说明:

TODO

protected void init() @ L40

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

参数:

说明:

TODO

public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L50

  • 方法名:extractRenderState
  • 源码定位:L50
  • 返回类型:void
  • 修饰符:public

参数:

  • graphics: GuiGraphicsExtractor
  • mouseX: int
  • mouseY: int
  • a: float

说明:

TODO

public boolean shouldCloseOnEsc() @ L58

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

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class AlertScreen extends Screen {
    private static final int LABEL_Y = 90;
    private final Component messageText;
    private MultiLineLabel message = MultiLineLabel.EMPTY;
    private final Runnable callback;
    private final Component okButton;
    private final boolean shouldCloseOnEsc;
 
    public AlertScreen(Runnable callback, Component title, Component messageText) {
        this(callback, title, messageText, CommonComponents.GUI_BACK, true);
    }
 
    public AlertScreen(Runnable callback, Component title, Component messageText, Component okButton, boolean shouldCloseOnEsc) {
        super(title);
        this.callback = callback;
        this.messageText = messageText;
        this.okButton = okButton;
        this.shouldCloseOnEsc = shouldCloseOnEsc;
    }
 
    @Override
    public Component getNarrationMessage() {
        return CommonComponents.joinForNarration(super.getNarrationMessage(), this.messageText);
    }
 
    @Override
    protected void init() {
        super.init();
        this.message = MultiLineLabel.create(this.font, this.messageText, this.width - 50);
        int textHeight = this.message.getLineCount() * 9;
        int buttonY = Mth.clamp(90 + textHeight + 12, this.height / 6 + 96, this.height - 24);
        int buttonWidth = 150;
        this.addRenderableWidget(Button.builder(this.okButton, button -> this.callback.run()).bounds((this.width - 150) / 2, buttonY, 150, 20).build());
    }
 
    @Override
    public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
        super.extractRenderState(graphics, mouseX, mouseY, a);
        ActiveTextCollector textRenderer = graphics.textRenderer();
        graphics.centeredText(this.font, this.title, this.width / 2, 70, -1);
        this.message.visitLines(TextAlignment.CENTER, this.width / 2, 90, 9, textRenderer);
    }
 
    @Override
    public boolean shouldCloseOnEsc() {
        return this.shouldCloseOnEsc;
    }
}

引用的其他类

  • GuiGraphicsExtractor

    • 引用位置: 参数
  • Button

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

    • 引用位置: 字段/方法调用
    • 关联成员: MultiLineLabel.create()
  • Screen

    • 引用位置: 继承
  • CommonComponents

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

    • 引用位置: 参数/字段/返回值
  • Mth

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