| 1 | package net.minecraft.client.gui.screens.dialog;
|
| 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.layouts.FrameLayout;
|
| 7 | import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
|
| 8 | import net.minecraft.client.gui.screens.Screen;
|
| 9 | import net.minecraft.network.chat.CommonComponents;
|
| 10 | import net.minecraft.network.chat.Component;
|
| 11 | import org.jspecify.annotations.Nullable;
|
| 12 |
|
| 13 | @Environment(EnvType.CLIENT)
|
| 14 | public class WaitingForResponseScreen extends Screen {
|
| 15 | private static final Component TITLE = Component.translatable("gui.waitingForResponse.title");
|
| 16 | private static final Component[] BUTTON_LABELS = new Component[]{
|
| 17 | Component.empty(),
|
| 18 | Component.translatable("gui.waitingForResponse.button.inactive", 4),
|
| 19 | Component.translatable("gui.waitingForResponse.button.inactive", 3),
|
| 20 | Component.translatable("gui.waitingForResponse.button.inactive", 2),
|
| 21 | Component.translatable("gui.waitingForResponse.button.inactive", 1),
|
| 22 | CommonComponents.GUI_BACK
|
| 23 | };
|
| 24 | private static final int BUTTON_VISIBLE_AFTER = 1;
|
| 25 | private static final int BUTTON_ACTIVE_AFTER = 5;
|
| 26 | private final @Nullable Screen previousScreen;
|
| 27 | private final HeaderAndFooterLayout layout;
|
| 28 | private final Button closeButton;
|
| 29 | private int ticks;
|
| 30 |
|
| 31 | public WaitingForResponseScreen(final @Nullable Screen nextScreen) {
|
| 32 | super(TITLE);
|
| 33 | this.previousScreen = nextScreen;
|
| 34 | this.layout = new HeaderAndFooterLayout(this, 33, 0);
|
| 35 | this.closeButton = Button.builder(CommonComponents.GUI_BACK, button -> this.onClose()).width(200).build();
|
| 36 | }
|
| 37 |
|
| 38 | @Override
|
| 39 | protected void init() {
|
| 40 | super.init();
|
| 41 | this.layout.addTitleHeader(TITLE, this.font);
|
| 42 | this.layout.addToContents(this.closeButton);
|
| 43 | this.closeButton.visible = false;
|
| 44 | this.closeButton.active = false;
|
| 45 | this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
|
| 46 | this.repositionElements();
|
| 47 | }
|
| 48 |
|
| 49 | @Override
|
| 50 | protected void repositionElements() {
|
| 51 | this.layout.arrangeElements();
|
| 52 | FrameLayout.centerInRectangle(this.layout, this.getRectangle());
|
| 53 | }
|
| 54 |
|
| 55 | @Override
|
| 56 | public void tick() {
|
| 57 | super.tick();
|
| 58 | if (!this.closeButton.active) {
|
| 59 | int secondsVisible = this.ticks++ / 20;
|
| 60 | this.closeButton.visible = secondsVisible >= 1;
|
| 61 | this.closeButton.setMessage(BUTTON_LABELS[secondsVisible]);
|
| 62 | if (secondsVisible == 5) {
|
| 63 | this.closeButton.active = true;
|
| 64 | this.triggerImmediateNarration(true);
|
| 65 | }
|
| 66 | }
|
| 67 | }
|
| 68 |
|
| 69 | @Override
|
| 70 | public boolean isPauseScreen() {
|
| 71 | return false;
|
| 72 | }
|
| 73 |
|
| 74 | @Override
|
| 75 | public boolean shouldCloseOnEsc() {
|
| 76 | return this.closeButton.active;
|
| 77 | }
|
| 78 |
|
| 79 | @Override
|
| 80 | public void onClose() {
|
| 81 | this.minecraft.gui.setScreen(this.previousScreen);
|
| 82 | }
|
| 83 |
|
| 84 | public @Nullable Screen previousScreen() {
|
| 85 | return this.previousScreen;
|
| 86 | }
|
| 87 | }
|
| 88 |
|