| 1 | package net.minecraft.client.gui.screens.multiplayer;
|
| 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.StringWidget;
|
| 7 | import net.minecraft.client.gui.layouts.FrameLayout;
|
| 8 | import net.minecraft.client.gui.layouts.LinearLayout;
|
| 9 | import net.minecraft.client.gui.screens.ConnectScreen;
|
| 10 | import net.minecraft.client.gui.screens.Screen;
|
| 11 | import net.minecraft.network.Connection;
|
| 12 | import net.minecraft.network.chat.CommonComponents;
|
| 13 | import net.minecraft.network.chat.Component;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public class ServerReconfigScreen extends Screen {
|
| 17 | private static final int DISCONNECT_TIME = 600;
|
| 18 | private final Connection connection;
|
| 19 | private Button disconnectButton;
|
| 20 | private int delayTicker;
|
| 21 | private final LinearLayout layout = LinearLayout.vertical();
|
| 22 |
|
| 23 | public ServerReconfigScreen(final Component title, final Connection connection) {
|
| 24 | super(title);
|
| 25 | this.connection = connection;
|
| 26 | }
|
| 27 |
|
| 28 | @Override
|
| 29 | public boolean shouldCloseOnEsc() {
|
| 30 | return false;
|
| 31 | }
|
| 32 |
|
| 33 | @Override
|
| 34 | protected void init() {
|
| 35 | this.layout.defaultCellSetting().alignHorizontallyCenter().padding(10);
|
| 36 | this.layout.addChild(new StringWidget(this.title, this.font));
|
| 37 | this.disconnectButton = this.layout
|
| 38 | .addChild(Button.builder(CommonComponents.GUI_DISCONNECT, b -> this.connection.disconnect(ConnectScreen.ABORT_CONNECTION)).build());
|
| 39 | this.disconnectButton.active = false;
|
| 40 | this.layout.arrangeElements();
|
| 41 | this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
|
| 42 | this.repositionElements();
|
| 43 | }
|
| 44 |
|
| 45 | @Override
|
| 46 | protected void repositionElements() {
|
| 47 | FrameLayout.centerInRectangle(this.layout, this.getRectangle());
|
| 48 | }
|
| 49 |
|
| 50 | @Override
|
| 51 | public void tick() {
|
| 52 | super.tick();
|
| 53 | this.delayTicker++;
|
| 54 | if (this.delayTicker == 600) {
|
| 55 | this.disconnectButton.active = true;
|
| 56 | }
|
| 57 |
|
| 58 | if (this.connection.isConnected()) {
|
| 59 | this.connection.tick();
|
| 60 | } else {
|
| 61 | this.connection.handleDisconnection();
|
| 62 | }
|
| 63 | }
|
| 64 | }
|
| 65 |
|