| 1 | package net.minecraft.client.gui.screens;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.gui.components.Button;
|
| 6 | import net.minecraft.client.gui.components.MultiLineTextWidget;
|
| 7 | import net.minecraft.client.gui.components.StringWidget;
|
| 8 | import net.minecraft.client.gui.layouts.FrameLayout;
|
| 9 | import net.minecraft.client.gui.layouts.LinearLayout;
|
| 10 | import net.minecraft.client.input.KeyEvent;
|
| 11 | import net.minecraft.network.chat.CommonComponents;
|
| 12 | import net.minecraft.network.chat.Component;
|
| 13 | import net.minecraft.util.CommonLinks;
|
| 14 | import org.jspecify.annotations.Nullable;
|
| 15 |
|
| 16 | @Environment(EnvType.CLIENT)
|
| 17 | public class FileFixerAbortedScreen extends Screen {
|
| 18 | protected final LinearLayout layout = LinearLayout.vertical().spacing(8);
|
| 19 | private final Component message;
|
| 20 | protected @Nullable Button backButton;
|
| 21 | protected @Nullable Button reportBugButton;
|
| 22 | protected final Runnable callback;
|
| 23 |
|
| 24 | public FileFixerAbortedScreen(final Runnable callback, final Component message) {
|
| 25 | super(Component.translatable("upgradeWorld.aborted.title"));
|
| 26 | this.callback = callback;
|
| 27 | this.message = message;
|
| 28 | }
|
| 29 |
|
| 30 | @Override
|
| 31 | public Component getNarrationMessage() {
|
| 32 | return CommonComponents.joinForNarration(super.getNarrationMessage(), this.message);
|
| 33 | }
|
| 34 |
|
| 35 | @Override
|
| 36 | protected void init() {
|
| 37 | super.init();
|
| 38 | this.layout.defaultCellSetting().alignHorizontallyCenter();
|
| 39 | this.layout.addChild(new StringWidget(this.title, this.font));
|
| 40 | this.layout.addChild(new MultiLineTextWidget(this.message, this.font).setMaxWidth(this.width - 50).setMaxRows(15).setCentered(true));
|
| 41 | LinearLayout buttonLayout = this.layout.addChild(LinearLayout.horizontal().spacing(4));
|
| 42 | buttonLayout.defaultCellSetting().paddingTop(16);
|
| 43 | this.addButtons(buttonLayout);
|
| 44 | this.layout.visitWidgets(this::addRenderableWidget);
|
| 45 | this.repositionElements();
|
| 46 | }
|
| 47 |
|
| 48 | @Override
|
| 49 | protected void repositionElements() {
|
| 50 | this.layout.arrangeElements();
|
| 51 | FrameLayout.centerInRectangle(this.layout, this.getRectangle());
|
| 52 | }
|
| 53 |
|
| 54 | protected void addButtons(final LinearLayout buttonLayout) {
|
| 55 | this.backButton = buttonLayout.addChild(Button.builder(CommonComponents.GUI_BACK, var1 -> this.callback.run()).build());
|
| 56 | this.reportBugButton = buttonLayout.addChild(
|
| 57 | Button.builder(Component.translatable("upgradeWorld.aborted.reportBug"), ConfirmLinkScreen.confirmLink(this, CommonLinks.SNAPSHOT_BUGS_FEEDBACK, true))
|
| 58 | .build()
|
| 59 | );
|
| 60 | }
|
| 61 |
|
| 62 | @Override
|
| 63 | public boolean shouldCloseOnEsc() {
|
| 64 | return false;
|
| 65 | }
|
| 66 |
|
| 67 | @Override
|
| 68 | public boolean keyPressed(final KeyEvent event) {
|
| 69 | if (event.isEscape()) {
|
| 70 | this.callback.run();
|
| 71 | return true;
|
| 72 | } else {
|
| 73 | return super.keyPressed(event);
|
| 74 | }
|
| 75 | }
|
| 76 | }
|
| 77 |
|