| 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.Checkbox;
|
| 6 | import net.minecraft.client.gui.components.FittingMultiLineTextWidget;
|
| 7 | import net.minecraft.client.gui.components.StringWidget;
|
| 8 | import net.minecraft.client.gui.layouts.FrameLayout;
|
| 9 | import net.minecraft.client.gui.layouts.Layout;
|
| 10 | import net.minecraft.client.gui.layouts.LinearLayout;
|
| 11 | import net.minecraft.client.gui.screens.Screen;
|
| 12 | import net.minecraft.network.chat.Component;
|
| 13 | import org.jspecify.annotations.Nullable;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public abstract class WarningScreen extends Screen {
|
| 17 | private static final int MESSAGE_PADDING = 100;
|
| 18 | private final Component message;
|
| 19 | private final @Nullable Component check;
|
| 20 | private final Component narration;
|
| 21 | protected @Nullable Checkbox stopShowing;
|
| 22 | private @Nullable FittingMultiLineTextWidget messageWidget;
|
| 23 | private final FrameLayout layout;
|
| 24 |
|
| 25 | protected WarningScreen(final Component title, final Component message, final Component narration) {
|
| 26 | this(title, message, null, narration);
|
| 27 | }
|
| 28 |
|
| 29 | protected WarningScreen(final Component title, final Component message, final @Nullable Component check, final Component narration) {
|
| 30 | super(title);
|
| 31 | this.message = message;
|
| 32 | this.check = check;
|
| 33 | this.narration = narration;
|
| 34 | this.layout = new FrameLayout(0, 0, this.width, this.height);
|
| 35 | }
|
| 36 |
|
| 37 | protected abstract Layout addFooterButtons();
|
| 38 |
|
| 39 | @Override
|
| 40 | protected void init() {
|
| 41 | LinearLayout content = this.layout.addChild(LinearLayout.vertical().spacing(8));
|
| 42 | content.defaultCellSetting().alignHorizontallyCenter();
|
| 43 | content.addChild(new StringWidget(this.getTitle(), this.font));
|
| 44 | this.messageWidget = content.addChild(new FittingMultiLineTextWidget(0, 0, this.width - 100, this.height - 100, this.message, this.font), s -> s.padding(12));
|
| 45 | LinearLayout footer = content.addChild(LinearLayout.vertical().spacing(8));
|
| 46 | footer.defaultCellSetting().alignHorizontallyCenter();
|
| 47 | if (this.check != null) {
|
| 48 | this.stopShowing = footer.addChild(Checkbox.builder(this.check, this.font).build());
|
| 49 | }
|
| 50 |
|
| 51 | footer.addChild(this.addFooterButtons());
|
| 52 | this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
|
| 53 | this.repositionElements();
|
| 54 | }
|
| 55 |
|
| 56 | @Override
|
| 57 | protected void repositionElements() {
|
| 58 | if (this.messageWidget != null) {
|
| 59 | this.messageWidget.setWidth(this.width - 100);
|
| 60 | this.messageWidget.setHeight(this.height - 100);
|
| 61 | this.messageWidget.minimizeHeight();
|
| 62 | }
|
| 63 |
|
| 64 | this.layout.arrangeElements();
|
| 65 | FrameLayout.centerInRectangle(this.layout, this.getRectangle());
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | public Component getNarrationMessage() {
|
| 70 | return this.narration;
|
| 71 | }
|
| 72 | }
|
| 73 |
|