DeathScreen.java

net.minecraft.client.gui.screens.DeathScreen

信息

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

    TODO

字段/常量

  • TITLE_SCALE

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

      TODO

  • DRAFT_REPORT_SPRITE

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

      TODO

  • delayTicker

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

      TODO

  • causeOfDeath

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

      TODO

  • hardcore

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

      TODO

  • player

    • 类型: LocalPlayer
    • 修饰符: private final
    • 源码定位: L31
    • 说明:

      TODO

  • deathScore

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

      TODO

  • exitButtons

    • 类型: List<Button>
    • 修饰符: private final
    • 源码定位: L33
    • 说明:

      TODO

  • exitToTitleButton

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

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.screens.DeathScreen.TitleConfirmScreen
    • 类型: class
    • 修饰符: public static
    • 源码定位: L177
    • 说明:

      TODO

构造器

public DeathScreen(Component causeOfDeath, boolean hardcore, LocalPlayer player) @ L36

  • 构造器名:DeathScreen
  • 源码定位:L36
  • 修饰符:public

参数:

  • causeOfDeath: Component
  • hardcore: boolean
  • player: LocalPlayer

说明:

TODO

方法

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

protected void init() @ L45

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

参数:

说明:

TODO

public boolean shouldCloseOnEsc() @ L66

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

参数:

说明:

TODO

private void handleExitToTitleScreen() @ L71

  • 方法名:handleExitToTitleScreen
  • 源码定位:L71
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

private void exitToTitleScreen() @ L94

  • 方法名:exitToTitleScreen
  • 源码定位:L94
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

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

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

参数:

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

说明:

TODO

private void visitText(ActiveTextCollector output) @ L119

  • 方法名:visitText
  • 源码定位:L119
  • 返回类型:void
  • 修饰符:private

参数:

  • output: ActiveTextCollector

说明:

TODO

public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L132

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

参数:

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

说明:

TODO

private static void extractDeathBackground(GuiGraphicsExtractor graphics, int width, int height) @ L137

  • 方法名:extractDeathBackground
  • 源码定位:L137
  • 返回类型:void
  • 修饰符:private static

参数:

  • graphics: GuiGraphicsExtractor
  • width: int
  • height: int

说明:

TODO

public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) @ L141

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

参数:

  • event: MouseButtonEvent
  • doubleClick: boolean

说明:

TODO

public boolean isPauseScreen() @ L151

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

参数:

说明:

TODO

public boolean isAllowedInPortal() @ L156

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

参数:

说明:

TODO

public void tick() @ L161

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

参数:

说明:

TODO

private void setButtonsActive(boolean isActive) @ L170

  • 方法名:setButtonsActive
  • 源码定位:L170
  • 返回类型:void
  • 修饰符:private

参数:

  • isActive: boolean

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class DeathScreen extends Screen {
    private static final int TITLE_SCALE = 2;
    private static final Identifier DRAFT_REPORT_SPRITE = Identifier.withDefaultNamespace("icon/draft_report");
    private int delayTicker;
    private final @Nullable Component causeOfDeath;
    private final boolean hardcore;
    private final LocalPlayer player;
    private final Component deathScore;
    private final List<Button> exitButtons = Lists.newArrayList();
    private @Nullable Button exitToTitleButton;
 
    public DeathScreen(@Nullable Component causeOfDeath, boolean hardcore, LocalPlayer player) {
        super(Component.translatable(hardcore ? "deathScreen.title.hardcore" : "deathScreen.title"));
        this.causeOfDeath = causeOfDeath;
        this.hardcore = hardcore;
        this.player = player;
        Component scoreValue = Component.literal(Integer.toString(player.getScore())).withStyle(ChatFormatting.YELLOW);
        this.deathScore = Component.translatable("deathScreen.score.value", scoreValue);
    }
 
    @Override
    protected void init() {
        this.delayTicker = 0;
        this.exitButtons.clear();
        Component message = this.hardcore ? Component.translatable("deathScreen.spectate") : Component.translatable("deathScreen.respawn");
        this.exitButtons.add(this.addRenderableWidget(Button.builder(message, button -> {
            this.player.respawn();
            button.active = false;
        }).bounds(this.width / 2 - 100, this.height / 4 + 72, 200, 20).build()));
        this.exitToTitleButton = this.addRenderableWidget(
            Button.builder(
                    Component.translatable("deathScreen.titleScreen"),
                    button -> this.minecraft.getReportingContext().draftReportHandled(this.minecraft, this, this::handleExitToTitleScreen, true)
                )
                .bounds(this.width / 2 - 100, this.height / 4 + 96, 200, 20)
                .build()
        );
        this.exitButtons.add(this.exitToTitleButton);
        this.setButtonsActive(false);
    }
 
    @Override
    public boolean shouldCloseOnEsc() {
        return false;
    }
 
    private void handleExitToTitleScreen() {
        if (this.hardcore) {
            this.exitToTitleScreen();
        } else {
            ConfirmScreen confirm = new DeathScreen.TitleConfirmScreen(
                result -> {
                    if (result) {
                        this.exitToTitleScreen();
                    } else {
                        this.player.respawn();
                        this.minecraft.setScreen(null);
                    }
                },
                Component.translatable("deathScreen.quit.confirm"),
                CommonComponents.EMPTY,
                Component.translatable("deathScreen.titleScreen"),
                Component.translatable("deathScreen.respawn")
            );
            this.minecraft.setScreen(confirm);
            confirm.setDelay(20);
        }
    }
 
    private void exitToTitleScreen() {
        if (this.minecraft.level != null) {
            this.minecraft.level.disconnect(ClientLevel.DEFAULT_QUIT_MESSAGE);
        }
 
        this.minecraft.disconnectWithSavingScreen();
        this.minecraft.setScreen(new TitleScreen());
    }
 
    @Override
    public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
        super.extractRenderState(graphics, mouseX, mouseY, a);
        this.visitText(graphics.textRenderer(GuiGraphicsExtractor.HoveredTextEffects.TOOLTIP_AND_CURSOR));
        if (this.exitToTitleButton != null && this.minecraft.getReportingContext().hasDraftReport()) {
            graphics.blitSprite(
                RenderPipelines.GUI_TEXTURED,
                DRAFT_REPORT_SPRITE,
                this.exitToTitleButton.getX() + this.exitToTitleButton.getWidth() - 17,
                this.exitToTitleButton.getY() + 3,
                15,
                15
            );
        }
    }
 
    private void visitText(ActiveTextCollector output) {
        ActiveTextCollector.Parameters normalParameters = output.defaultParameters();
        int middleLine = this.width / 2;
        output.defaultParameters(normalParameters.withScale(2.0F));
        output.accept(TextAlignment.CENTER, middleLine / 2, 30, this.title);
        output.defaultParameters(normalParameters);
        if (this.causeOfDeath != null) {
            output.accept(TextAlignment.CENTER, middleLine, 85, this.causeOfDeath);
        }
 
        output.accept(TextAlignment.CENTER, middleLine, 100, this.deathScore);
    }
 
    @Override
    public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
        extractDeathBackground(graphics, this.width, this.height);
    }
 
    private static void extractDeathBackground(GuiGraphicsExtractor graphics, int width, int height) {
        graphics.fillGradient(0, 0, width, height, 1615855616, -1602211792);
    }
 
    @Override
    public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
        ActiveTextCollector.ClickableStyleFinder finder = new ActiveTextCollector.ClickableStyleFinder(this.getFont(), (int)event.x(), (int)event.y());
        this.visitText(finder);
        Style clickedStyle = finder.result();
        return clickedStyle != null && clickedStyle.getClickEvent() instanceof ClickEvent.OpenUrl openUrl
            ? clickUrlAction(this.minecraft, this, openUrl.uri())
            : super.mouseClicked(event, doubleClick);
    }
 
    @Override
    public boolean isPauseScreen() {
        return false;
    }
 
    @Override
    public boolean isAllowedInPortal() {
        return true;
    }
 
    @Override
    public void tick() {
        super.tick();
        this.delayTicker++;
        if (this.delayTicker == 20) {
            this.setButtonsActive(true);
        }
    }
 
    private void setButtonsActive(boolean isActive) {
        for (Button button : this.exitButtons) {
            button.active = isActive;
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    public static class TitleConfirmScreen extends ConfirmScreen {
        public TitleConfirmScreen(BooleanConsumer callback, Component title, Component message, Component yesButton, Component noButton) {
            super(callback, title, message, yesButton, noButton);
        }
 
        @Override
        public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
            DeathScreen.extractDeathBackground(graphics, this.width, this.height);
        }
    }
}

引用的其他类

  • ActiveTextCollector

    • 引用位置: 参数/方法调用/构造调用
    • 关联成员: ActiveTextCollector.ClickableStyleFinder(), ClickableStyleFinder()
  • GuiGraphicsExtractor

    • 引用位置: 参数
  • Button

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

    • 引用位置: 继承
  • TitleScreen

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

    • 引用位置: 参数
  • LocalPlayer

    • 引用位置: 参数/字段
  • Component

    • 引用位置: 参数/字段/方法调用
    • 关联成员: Component.literal(), Component.translatable()
  • Identifier

    • 引用位置: 字段/方法调用
    • 关联成员: Identifier.withDefaultNamespace()