| 1 | package net.minecraft.client.gui.screens;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.Blaze3D;
|
| 4 | import net.fabricmc.api.EnvType;
|
| 5 | import net.fabricmc.api.Environment;
|
| 6 | import net.minecraft.client.gui.components.Button;
|
| 7 | import net.minecraft.client.gui.components.MultiLineTextWidget;
|
| 8 | import net.minecraft.client.gui.components.StringWidget;
|
| 9 | import net.minecraft.client.gui.layouts.FrameLayout;
|
| 10 | import net.minecraft.client.gui.layouts.LinearLayout;
|
| 11 | import net.minecraft.network.DisconnectionDetails;
|
| 12 | import net.minecraft.network.chat.CommonComponents;
|
| 13 | import net.minecraft.network.chat.Component;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public class DisconnectedScreen extends Screen {
|
| 17 | private static final Component TO_SERVER_LIST = Component.translatable("gui.toMenu");
|
| 18 | private static final Component TO_TITLE = Component.translatable("gui.toTitle");
|
| 19 | private static final Component REPORT_TO_SERVER_TITLE = Component.translatable("gui.report_to_server");
|
| 20 | private static final Component OPEN_REPORT_DIR_TITLE = Component.translatable("gui.open_report_dir");
|
| 21 | private final Screen parent;
|
| 22 | private final DisconnectionDetails details;
|
| 23 | private final Component buttonText;
|
| 24 | private final LinearLayout layout = LinearLayout.vertical();
|
| 25 |
|
| 26 | public DisconnectedScreen(final Screen parent, final Component title, final Component reason) {
|
| 27 | this(parent, title, new DisconnectionDetails(reason));
|
| 28 | }
|
| 29 |
|
| 30 | public DisconnectedScreen(final Screen parent, final Component title, final Component reason, final Component buttonText) {
|
| 31 | this(parent, title, new DisconnectionDetails(reason), buttonText);
|
| 32 | }
|
| 33 |
|
| 34 | public DisconnectedScreen(final Screen parent, final Component title, final DisconnectionDetails details) {
|
| 35 | this(parent, title, details, TO_SERVER_LIST);
|
| 36 | }
|
| 37 |
|
| 38 | public DisconnectedScreen(final Screen parent, final Component title, final DisconnectionDetails details, final Component buttonText) {
|
| 39 | super(title);
|
| 40 | this.parent = parent;
|
| 41 | this.details = details;
|
| 42 | this.buttonText = buttonText;
|
| 43 | }
|
| 44 |
|
| 45 | @Override
|
| 46 | protected void init() {
|
| 47 | this.layout.defaultCellSetting().alignHorizontallyCenter().padding(10);
|
| 48 | this.layout.addChild(new StringWidget(this.title, this.font));
|
| 49 | this.layout.addChild(new MultiLineTextWidget(this.details.reason(), this.font).setMaxWidth(this.width - 50).setCentered(true));
|
| 50 | this.layout.defaultCellSetting().padding(2);
|
| 51 | this.details
|
| 52 | .bugReportLink()
|
| 53 | .ifPresent(
|
| 54 | bugReportLink -> this.layout.addChild(Button.builder(REPORT_TO_SERVER_TITLE, ConfirmLinkScreen.confirmLink(this, bugReportLink, false)).width(200).build())
|
| 55 | );
|
| 56 | this.details
|
| 57 | .report()
|
| 58 | .ifPresent(report -> this.layout.addChild(Button.builder(OPEN_REPORT_DIR_TITLE, button -> Blaze3D.openPath(report.getParent())).width(200).build()));
|
| 59 | Button backButton;
|
| 60 | if (this.minecraft.allowsMultiplayer()) {
|
| 61 | backButton = Button.builder(this.buttonText, var1x -> this.minecraft.gui.setScreen(this.parent)).width(200).build();
|
| 62 | } else {
|
| 63 | backButton = Button.builder(TO_TITLE, var1x -> this.minecraft.gui.setScreen(new TitleScreen())).width(200).build();
|
| 64 | }
|
| 65 |
|
| 66 | this.layout.addChild(backButton);
|
| 67 | this.layout.arrangeElements();
|
| 68 | this.layout.visitWidgets(this::addRenderableWidget);
|
| 69 | this.repositionElements();
|
| 70 | }
|
| 71 |
|
| 72 | @Override
|
| 73 | protected void repositionElements() {
|
| 74 | FrameLayout.centerInRectangle(this.layout, this.getRectangle());
|
| 75 | }
|
| 76 |
|
| 77 | @Override
|
| 78 | public Component getNarrationMessage() {
|
| 79 | return CommonComponents.joinForNarration(this.title, this.details.reason());
|
| 80 | }
|
| 81 |
|
| 82 | @Override
|
| 83 | public boolean shouldCloseOnEsc() {
|
| 84 | return false;
|
| 85 | }
|
| 86 | }
|
| 87 |
|