ConfirmScreen.java

net.minecraft.client.gui.screens.ConfirmScreen

信息

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

    TODO

字段/常量

  • message

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

      TODO

  • layout

    • 类型: LinearLayout
    • 修饰符: protected final
    • 源码定位: L19
    • 说明:

      TODO

  • yesButtonComponent

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

      TODO

  • noButtonComponent

    • 类型: Component
    • 修饰符: protected
    • 源码定位: L21
    • 说明:

      TODO

  • yesButton

    • 类型: Button
    • 修饰符: protected
    • 源码定位: L22
    • 说明:

      TODO

  • noButton

    • 类型: Button
    • 修饰符: protected
    • 源码定位: L23
    • 说明:

      TODO

  • delayTicker

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

      TODO

  • callback

    • 类型: BooleanConsumer
    • 修饰符: protected final
    • 源码定位: L25
    • 说明:

      TODO

内部类/嵌套类型

构造器

public ConfirmScreen(BooleanConsumer callback, Component title, Component message) @ L27

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

参数:

  • callback: BooleanConsumer
  • title: Component
  • message: Component

说明:

TODO

public ConfirmScreen(BooleanConsumer callback, Component title, Component message, Component yesButtonComponent, Component noButtonComponent) @ L31

  • 构造器名:ConfirmScreen
  • 源码定位:L31
  • 修饰符:public

参数:

  • callback: BooleanConsumer
  • title: Component
  • message: Component
  • yesButtonComponent: Component
  • noButtonComponent: Component

说明:

TODO

方法

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

public Component getNarrationMessage() @ L39

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

参数:

说明:

TODO

protected void init() @ L44

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

参数:

说明:

TODO

protected void repositionElements() @ L58

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

参数:

说明:

TODO

protected void addAdditionalText() @ L64

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

参数:

说明:

TODO

protected void addButtons(LinearLayout buttonLayout) @ L67

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

参数:

  • buttonLayout: LinearLayout

说明:

TODO

public void setDelay(int delay) @ L72

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

参数:

  • delay: int

说明:

TODO

public void tick() @ L78

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

参数:

说明:

TODO

public boolean shouldCloseOnEsc() @ L87

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

参数:

说明:

TODO

public boolean keyPressed(KeyEvent event) @ L92

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

参数:

  • event: KeyEvent

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class ConfirmScreen extends Screen {
    private final Component message;
    protected final LinearLayout layout = LinearLayout.vertical().spacing(8);
    protected Component yesButtonComponent;
    protected Component noButtonComponent;
    protected @Nullable Button yesButton;
    protected @Nullable Button noButton;
    private int delayTicker;
    protected final BooleanConsumer callback;
 
    public ConfirmScreen(BooleanConsumer callback, Component title, Component message) {
        this(callback, title, message, CommonComponents.GUI_YES, CommonComponents.GUI_NO);
    }
 
    public ConfirmScreen(BooleanConsumer callback, Component title, Component message, Component yesButtonComponent, Component noButtonComponent) {
        super(title);
        this.callback = callback;
        this.message = message;
        this.yesButtonComponent = yesButtonComponent;
        this.noButtonComponent = noButtonComponent;
    }
 
    @Override
    public Component getNarrationMessage() {
        return CommonComponents.joinForNarration(super.getNarrationMessage(), this.message);
    }
 
    @Override
    protected void init() {
        super.init();
        this.layout.defaultCellSetting().alignHorizontallyCenter();
        this.layout.addChild(new StringWidget(this.title, this.font));
        this.layout.addChild(new MultiLineTextWidget(this.message, this.font).setMaxWidth(this.width - 50).setMaxRows(15).setCentered(true));
        this.addAdditionalText();
        LinearLayout buttonLayout = this.layout.addChild(LinearLayout.horizontal().spacing(4));
        buttonLayout.defaultCellSetting().paddingTop(16);
        this.addButtons(buttonLayout);
        this.layout.visitWidgets(this::addRenderableWidget);
        this.repositionElements();
    }
 
    @Override
    protected void repositionElements() {
        this.layout.arrangeElements();
        FrameLayout.centerInRectangle(this.layout, this.getRectangle());
    }
 
    protected void addAdditionalText() {
    }
 
    protected void addButtons(LinearLayout buttonLayout) {
        this.yesButton = buttonLayout.addChild(Button.builder(this.yesButtonComponent, button -> this.callback.accept(true)).build());
        this.noButton = buttonLayout.addChild(Button.builder(this.noButtonComponent, button -> this.callback.accept(false)).build());
    }
 
    public void setDelay(int delay) {
        this.delayTicker = delay;
        this.yesButton.active = false;
        this.noButton.active = false;
    }
 
    @Override
    public void tick() {
        super.tick();
        if (--this.delayTicker == 0) {
            this.yesButton.active = true;
            this.noButton.active = true;
        }
    }
 
    @Override
    public boolean shouldCloseOnEsc() {
        return false;
    }
 
    @Override
    public boolean keyPressed(KeyEvent event) {
        if (this.delayTicker <= 0 && event.isEscape()) {
            this.callback.accept(false);
            return true;
        } else {
            return super.keyPressed(event);
        }
    }
}

引用的其他类

  • Button

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

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

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

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

    • 引用位置: 参数/字段/方法调用
    • 关联成员: LinearLayout.horizontal(), LinearLayout.vertical()
  • Screen

    • 引用位置: 继承
  • KeyEvent

    • 引用位置: 参数
  • CommonComponents

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

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