PauseScreen.java

net.minecraft.client.gui.screens.PauseScreen

信息

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

    TODO

字段/常量

  • DRAFT_REPORT_SPRITE

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

      TODO

  • COLUMNS

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

      TODO

  • MENU_PADDING_TOP

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

      TODO

  • BUTTON_PADDING

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

      TODO

  • BUTTON_WIDTH_FULL

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

      TODO

  • BUTTON_WIDTH_HALF

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

      TODO

  • RETURN_TO_GAME

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

      TODO

  • ADVANCEMENTS

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

      TODO

  • STATS

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

      TODO

  • SEND_FEEDBACK

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

      TODO

  • REPORT_BUGS

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

      TODO

  • FEEDBACK_SUBSCREEN

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

      TODO

  • OPTIONS

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

      TODO

  • SHARE_TO_LAN

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

      TODO

  • PLAYER_REPORTING

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

      TODO

  • GAME

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

      TODO

  • PAUSED

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

      TODO

  • CUSTOM_OPTIONS_TOOLTIP

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

      TODO

  • showPauseMenu

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

      TODO

  • disconnectButton

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

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.screens.PauseScreen.FeedbackSubScreen
    • 类型: class
    • 修饰符: private static
    • 源码定位: L209
    • 说明:

      TODO

构造器

public PauseScreen(boolean showPauseMenu) @ L63

  • 构造器名:PauseScreen
  • 源码定位:L63
  • 修饰符:public

参数:

  • showPauseMenu: boolean

说明:

TODO

方法

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

public boolean showsPauseMenu() @ L68

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

参数:

说明:

TODO

protected void init() @ L72

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

参数:

说明:

TODO

private void createPauseMenu() @ L82

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

参数:

说明:

TODO

private Optional<?extends Holder<Dialog>> getCustomAdditions() @ L125

  • 方法名:getCustomAdditions
  • 源码定位:L125
  • 返回类型:Optional<?extends Holder>
  • 修饰符:private

参数:

说明:

TODO

private static void addFeedbackButtons(Screen screen, GridLayout.RowHelper helper) @ L143

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

参数:

  • screen: Screen
  • helper: GridLayout.RowHelper

说明:

TODO

private void addFeedbackSubscreenAndCustomDialogButtons(Minecraft minecraft, Holder<Dialog> dialog, GridLayout.RowHelper helper) @ L152

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

参数:

  • minecraft: Minecraft
  • dialog: Holder
  • helper: GridLayout.RowHelper

说明:

TODO

public void tick() @ L162

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

参数:

说明:

TODO

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

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

参数:

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

说明:

TODO

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

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

参数:

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

说明:

TODO

public boolean rendersNowPlayingToast() @ L195

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

参数:

说明:

TODO

private Button openScreenButton(Component message, Supplier<Screen> newScreen) @ L200

  • 方法名:openScreenButton
  • 源码定位:L200
  • 返回类型:Button
  • 修饰符:private

参数:

  • message: Component
  • newScreen: Supplier

说明:

TODO

  • 方法名:openLinkButton
  • 源码定位:L204
  • 返回类型:Button
  • 修饰符:private static

参数:

  • screen: Screen
  • message: Component
  • link: URI

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class PauseScreen extends Screen {
    private static final Identifier DRAFT_REPORT_SPRITE = Identifier.withDefaultNamespace("icon/draft_report");
    private static final int COLUMNS = 2;
    private static final int MENU_PADDING_TOP = 50;
    private static final int BUTTON_PADDING = 4;
    private static final int BUTTON_WIDTH_FULL = 204;
    private static final int BUTTON_WIDTH_HALF = 98;
    private static final Component RETURN_TO_GAME = Component.translatable("menu.returnToGame");
    private static final Component ADVANCEMENTS = Component.translatable("gui.advancements");
    private static final Component STATS = Component.translatable("gui.stats");
    private static final Component SEND_FEEDBACK = Component.translatable("menu.sendFeedback");
    private static final Component REPORT_BUGS = Component.translatable("menu.reportBugs");
    private static final Component FEEDBACK_SUBSCREEN = Component.translatable("menu.feedback");
    private static final Component OPTIONS = Component.translatable("menu.options");
    private static final Component SHARE_TO_LAN = Component.translatable("menu.shareToLan");
    private static final Component PLAYER_REPORTING = Component.translatable("menu.playerReporting");
    private static final Component GAME = Component.translatable("menu.game");
    private static final Component PAUSED = Component.translatable("menu.paused");
    private static final Tooltip CUSTOM_OPTIONS_TOOLTIP = Tooltip.create(Component.translatable("menu.custom_options.tooltip"));
    private final boolean showPauseMenu;
    private @Nullable Button disconnectButton;
 
    public PauseScreen(boolean showPauseMenu) {
        super(showPauseMenu ? GAME : PAUSED);
        this.showPauseMenu = showPauseMenu;
    }
 
    public boolean showsPauseMenu() {
        return this.showPauseMenu;
    }
 
    @Override
    protected void init() {
        if (this.showPauseMenu) {
            this.createPauseMenu();
        }
 
        int textWidth = this.font.width(this.title);
        this.addRenderableWidget(new StringWidget(this.width / 2 - textWidth / 2, this.showPauseMenu ? 40 : 10, textWidth, 9, this.title, this.font));
    }
 
    private void createPauseMenu() {
        GridLayout gridLayout = new GridLayout();
        gridLayout.defaultCellSetting().padding(4, 4, 4, 0);
        GridLayout.RowHelper helper = gridLayout.createRowHelper(2);
        helper.addChild(Button.builder(RETURN_TO_GAME, button -> {
            this.minecraft.setScreen(null);
            this.minecraft.mouseHandler.grabMouse();
        }).width(204).build(), 2, gridLayout.newCellSettings().paddingTop(50));
        helper.addChild(this.openScreenButton(ADVANCEMENTS, () -> new AdvancementsScreen(this.minecraft.player.connection.getAdvancements(), this)));
        helper.addChild(this.openScreenButton(STATS, () -> new StatsScreen(this, this.minecraft.player.getStats())));
        Optional<? extends Holder<Dialog>> additions = this.getCustomAdditions();
        if (additions.isEmpty()) {
            addFeedbackButtons(this, helper);
        } else {
            this.addFeedbackSubscreenAndCustomDialogButtons(this.minecraft, (Holder<Dialog>)additions.get(), helper);
        }
 
        helper.addChild(this.openScreenButton(OPTIONS, () -> new OptionsScreen(this, this.minecraft.options, true)));
        if (this.minecraft.hasSingleplayerServer() && !this.minecraft.getSingleplayerServer().isPublished()) {
            helper.addChild(this.openScreenButton(SHARE_TO_LAN, () -> new ShareToLanScreen(this)));
        } else {
            helper.addChild(this.openScreenButton(PLAYER_REPORTING, () -> new SocialInteractionsScreen(this)));
        }
 
        this.disconnectButton = helper.addChild(
            Button.builder(
                    CommonComponents.disconnectButtonLabel(this.minecraft.isLocalServer()),
                    button -> {
                        button.active = false;
                        this.minecraft
                            .getReportingContext()
                            .draftReportHandled(this.minecraft, this, () -> this.minecraft.disconnectFromWorld(ClientLevel.DEFAULT_QUIT_MESSAGE), true);
                    }
                )
                .width(204)
                .build(),
            2
        );
        gridLayout.arrangeElements();
        FrameLayout.alignInRectangle(gridLayout, 0, 0, this.width, this.height, 0.5F, 0.25F);
        gridLayout.visitWidgets(this::addRenderableWidget);
    }
 
    private Optional<? extends Holder<Dialog>> getCustomAdditions() {
        Registry<Dialog> dialogRegistry = this.minecraft.player.connection.registryAccess().lookupOrThrow(Registries.DIALOG);
        Optional<? extends HolderSet<Dialog>> maybeCustomAdditions = dialogRegistry.get(DialogTags.PAUSE_SCREEN_ADDITIONS);
        if (maybeCustomAdditions.isPresent()) {
            HolderSet<Dialog> customAdditions = (HolderSet<Dialog>)maybeCustomAdditions.get();
            if (customAdditions.size() > 0) {
                if (customAdditions.size() == 1) {
                    return Optional.of(customAdditions.get(0));
                }
 
                return dialogRegistry.get(Dialogs.CUSTOM_OPTIONS);
            }
        }
 
        ServerLinks serverLinks = this.minecraft.player.connection.serverLinks();
        return !serverLinks.isEmpty() ? dialogRegistry.get(Dialogs.SERVER_LINKS) : Optional.empty();
    }
 
    private static void addFeedbackButtons(Screen screen, GridLayout.RowHelper helper) {
        helper.addChild(
            openLinkButton(screen, SEND_FEEDBACK, SharedConstants.getCurrentVersion().stable() ? CommonLinks.RELEASE_FEEDBACK : CommonLinks.SNAPSHOT_FEEDBACK)
        );
        helper.addChild(openLinkButton(screen, REPORT_BUGS, CommonLinks.SNAPSHOT_BUGS_FEEDBACK)).active = !SharedConstants.getCurrentVersion()
            .dataVersion()
            .isSideSeries();
    }
 
    private void addFeedbackSubscreenAndCustomDialogButtons(Minecraft minecraft, Holder<Dialog> dialog, GridLayout.RowHelper helper) {
        helper.addChild(this.openScreenButton(FEEDBACK_SUBSCREEN, () -> new PauseScreen.FeedbackSubScreen(this)));
        helper.addChild(
            Button.builder(dialog.value().common().computeExternalTitle(), button -> minecraft.player.connection.showDialog(dialog, this))
                .width(98)
                .tooltip(CUSTOM_OPTIONS_TOOLTIP)
                .build()
        );
    }
 
    @Override
    public void tick() {
        if (this.rendersNowPlayingToast()) {
            NowPlayingToast.tickMusicNotes();
        }
    }
 
    @Override
    public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
        super.extractRenderState(graphics, mouseX, mouseY, a);
        if (this.rendersNowPlayingToast()) {
            NowPlayingToast.extractToast(graphics, this.font);
        }
 
        if (this.showPauseMenu && this.minecraft.getReportingContext().hasDraftReport() && this.disconnectButton != null) {
            graphics.blitSprite(
                RenderPipelines.GUI_TEXTURED,
                DRAFT_REPORT_SPRITE,
                this.disconnectButton.getX() + this.disconnectButton.getWidth() - 17,
                this.disconnectButton.getY() + 3,
                15,
                15
            );
        }
    }
 
    @Override
    public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
        if (this.showPauseMenu) {
            super.extractBackground(graphics, mouseX, mouseY, a);
        }
    }
 
    public boolean rendersNowPlayingToast() {
        Options options = this.minecraft.options;
        return options.musicToast().get().renderInPauseScreen() && options.getFinalSoundSourceVolume(SoundSource.MUSIC) > 0.0F && this.showPauseMenu;
    }
 
    private Button openScreenButton(Component message, Supplier<Screen> newScreen) {
        return Button.builder(message, button -> this.minecraft.setScreen(newScreen.get())).width(98).build();
    }
 
    private static Button openLinkButton(Screen screen, Component message, URI link) {
        return Button.builder(message, ConfirmLinkScreen.confirmLink(screen, link)).width(98).build();
    }
 
    @OnlyIn(Dist.CLIENT)
    private static class FeedbackSubScreen extends Screen {
        private static final Component TITLE = Component.translatable("menu.feedback.title");
        public final Screen parent;
        private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
 
        protected FeedbackSubScreen(Screen parent) {
            super(TITLE);
            this.parent = parent;
        }
 
        @Override
        protected void init() {
            this.layout.addTitleHeader(TITLE, this.font);
            GridLayout buttonContainer = this.layout.addToContents(new GridLayout());
            buttonContainer.defaultCellSetting().padding(4, 4, 4, 0);
            GridLayout.RowHelper helper = buttonContainer.createRowHelper(2);
            PauseScreen.addFeedbackButtons(this, helper);
            this.layout.addToFooter(Button.builder(CommonComponents.GUI_BACK, button -> this.onClose()).width(200).build());
            this.layout.visitWidgets(this::addRenderableWidget);
            this.repositionElements();
        }
 
        @Override
        protected void repositionElements() {
            this.layout.arrangeElements();
        }
 
        @Override
        public void onClose() {
            this.minecraft.setScreen(this.parent);
        }
    }
}

引用的其他类

  • SharedConstants

    • 引用位置: 方法调用
    • 关联成员: SharedConstants.getCurrentVersion()
  • Minecraft

    • 引用位置: 参数
  • GuiGraphicsExtractor

    • 引用位置: 参数
  • Button

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

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

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

    • 引用位置: 方法调用
    • 关联成员: NowPlayingToast.extractToast(), NowPlayingToast.tickMusicNotes()
  • FrameLayout

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

    • 引用位置: 参数/构造调用
    • 关联成员: GridLayout()
  • HeaderAndFooterLayout

    • 引用位置: 构造调用
    • 关联成员: HeaderAndFooterLayout()
  • ConfirmLinkScreen

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

    • 引用位置: 参数/继承
  • ShareToLanScreen

    • 引用位置: 构造调用
    • 关联成员: ShareToLanScreen()
  • StatsScreen

    • 引用位置: 构造调用
    • 关联成员: StatsScreen()
  • AdvancementsScreen

    • 引用位置: 构造调用
    • 关联成员: AdvancementsScreen()
  • OptionsScreen

    • 引用位置: 构造调用
    • 关联成员: OptionsScreen()
  • SocialInteractionsScreen

    • 引用位置: 构造调用
    • 关联成员: SocialInteractionsScreen()
  • Holder

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

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

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

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

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