GenericWaitingScreen.java

net.minecraft.client.gui.screens.GenericWaitingScreen

信息

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

    TODO

字段/常量

  • TITLE_Y

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

      TODO

  • MESSAGE_Y

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

      TODO

  • MESSAGE_MAX_WIDTH

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

      TODO

  • showLoadingDots

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

      TODO

  • messageText

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

      TODO

  • buttonLabel

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

      TODO

  • buttonCallback

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

      TODO

  • showButton

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

      TODO

  • closeOnEscape

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

      TODO

  • message

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

      TODO

  • button

    • 类型: Button
    • 修饰符: private
    • 源码定位: L27
    • 说明:

      TODO

  • disableButtonTicks

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

      TODO

内部类/嵌套类型

构造器

protected GenericWaitingScreen(Component title, boolean showLoadingDots, Component messageText, Component buttonLabel, Runnable buttonCallback, int disableButtonTicks, boolean showButton, boolean closeOnEscape) @ L42

  • 构造器名:GenericWaitingScreen
  • 源码定位:L42
  • 修饰符:protected

参数:

  • title: Component
  • showLoadingDots: boolean
  • messageText: Component
  • buttonLabel: Component
  • buttonCallback: Runnable
  • disableButtonTicks: int
  • showButton: boolean
  • closeOnEscape: boolean

说明:

TODO

方法

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

public static GenericWaitingScreen createWaitingWithoutButton(Component title, Component messageText) @ L30

  • 方法名:createWaitingWithoutButton
  • 源码定位:L30
  • 返回类型:GenericWaitingScreen
  • 修饰符:public static

参数:

  • title: Component
  • messageText: Component

说明:

TODO

public static GenericWaitingScreen createWaiting(Component title, Component buttonLabel, Runnable buttonCallback) @ L34

  • 方法名:createWaiting
  • 源码定位:L34
  • 返回类型:GenericWaitingScreen
  • 修饰符:public static

参数:

  • title: Component
  • buttonLabel: Component
  • buttonCallback: Runnable

说明:

TODO

public static GenericWaitingScreen createCompleted(Component title, Component messageText, Component buttonLabel, Runnable buttonCallback) @ L38

  • 方法名:createCompleted
  • 源码定位:L38
  • 返回类型:GenericWaitingScreen
  • 修饰符:public static

参数:

  • title: Component
  • messageText: Component
  • buttonLabel: Component
  • buttonCallback: Runnable

说明:

TODO

protected void init() @ L63

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

参数:

说明:

TODO

public void tick() @ L78

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

参数:

说明:

TODO

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

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

参数:

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

说明:

TODO

public boolean shouldCloseOnEsc() @ L104

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

参数:

说明:

TODO

public void onClose() @ L109

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

参数:

说明:

TODO

public Component getNarrationMessage() @ L114

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

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class GenericWaitingScreen extends Screen {
    private static final int TITLE_Y = 80;
    private static final int MESSAGE_Y = 120;
    private static final int MESSAGE_MAX_WIDTH = 360;
    private final boolean showLoadingDots;
    private final Component messageText;
    private final Component buttonLabel;
    private final Runnable buttonCallback;
    private final boolean showButton;
    private final boolean closeOnEscape;
    private final MultiLineLabel message;
    private @Nullable Button button;
    private int disableButtonTicks;
 
    public static GenericWaitingScreen createWaitingWithoutButton(Component title, Component messageText) {
        return new GenericWaitingScreen(title, true, messageText, Component.empty(), () -> {}, 0, false, false);
    }
 
    public static GenericWaitingScreen createWaiting(Component title, Component buttonLabel, Runnable buttonCallback) {
        return new GenericWaitingScreen(title, true, Component.empty(), buttonLabel, buttonCallback, 0, true, false);
    }
 
    public static GenericWaitingScreen createCompleted(Component title, Component messageText, Component buttonLabel, Runnable buttonCallback) {
        return new GenericWaitingScreen(title, false, messageText, buttonLabel, buttonCallback, 20, true, true);
    }
 
    protected GenericWaitingScreen(
        Component title,
        boolean showLoadingDots,
        Component messageText,
        Component buttonLabel,
        Runnable buttonCallback,
        int disableButtonTicks,
        boolean showButton,
        boolean closeOnEscape
    ) {
        super(title);
        this.showLoadingDots = showLoadingDots;
        this.messageText = messageText;
        this.buttonLabel = buttonLabel;
        this.buttonCallback = buttonCallback;
        this.disableButtonTicks = disableButtonTicks;
        this.showButton = showButton;
        this.closeOnEscape = closeOnEscape;
        this.message = MultiLineLabel.create(this.font, messageText, 360);
    }
 
    @Override
    protected void init() {
        super.init();
        int buttonWidth = 150;
        int buttonHeight = 20;
        int lineCount = this.message.getLineCount() + 1;
        int messageButtonSpacing = Math.max(lineCount, 5) * 9;
        int buttonY = Math.min(120 + messageButtonSpacing, this.height - 40);
        if (this.showButton) {
            this.button = this.addRenderableWidget(
                Button.builder(this.buttonLabel, b -> this.onClose()).bounds((this.width - 150) / 2, buttonY, 150, 20).build()
            );
        }
    }
 
    @Override
    public void tick() {
        if (this.disableButtonTicks > 0) {
            this.disableButtonTicks--;
        }
 
        if (this.button != null) {
            this.button.active = this.disableButtonTicks == 0;
        }
    }
 
    @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, 80, -1);
        int messageY = 120;
        if (this.showLoadingDots) {
            String loadingDots = LoadingDotsText.get(Util.getMillis());
            graphics.centeredText(this.font, loadingDots, this.width / 2, messageY, -6250336);
            messageY += 9 + 3;
        }
 
        this.message.visitLines(TextAlignment.CENTER, this.width / 2, messageY, 9, textRenderer);
    }
 
    @Override
    public boolean shouldCloseOnEsc() {
        return this.closeOnEscape && this.button != null && this.button.active;
    }
 
    @Override
    public void onClose() {
        this.buttonCallback.run();
    }
 
    @Override
    public Component getNarrationMessage() {
        return CommonComponents.joinForNarration(this.title, this.messageText);
    }
}

引用的其他类

  • GuiGraphicsExtractor

    • 引用位置: 参数
  • Button

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

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

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

    • 引用位置: 继承
  • CommonComponents

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

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

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