| 1 | package net.minecraft.client.gui.screens.worldselection;
|
| 2 |
|
| 3 | import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
|
| 4 | import java.util.Collection;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.client.gui.components.Button;
|
| 8 | import net.minecraft.client.gui.components.MultiLineTextWidget;
|
| 9 | import net.minecraft.client.gui.components.StringWidget;
|
| 10 | import net.minecraft.client.gui.layouts.FrameLayout;
|
| 11 | import net.minecraft.client.gui.layouts.GridLayout;
|
| 12 | import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
|
| 13 | import net.minecraft.client.gui.layouts.LayoutSettings;
|
| 14 | import net.minecraft.client.gui.screens.Screen;
|
| 15 | import net.minecraft.client.gui.screens.worldselection.ConfirmExperimentalFeaturesScreen.DetailsScreen.PackList;
|
| 16 | import net.minecraft.network.chat.CommonComponents;
|
| 17 | import net.minecraft.network.chat.Component;
|
| 18 | import net.minecraft.server.packs.repository.Pack;
|
| 19 | import org.jspecify.annotations.Nullable;
|
| 20 |
|
| 21 | @Environment(EnvType.CLIENT)
|
| 22 | public class ConfirmExperimentalFeaturesScreen extends Screen {
|
| 23 | private static final Component TITLE = Component.translatable("selectWorld.experimental.title");
|
| 24 | private static final Component MESSAGE = Component.translatable("selectWorld.experimental.message");
|
| 25 | private static final Component DETAILS_BUTTON = Component.translatable("selectWorld.experimental.details");
|
| 26 | private static final int COLUMN_SPACING = 10;
|
| 27 | private static final int DETAILS_BUTTON_WIDTH = 100;
|
| 28 | private final BooleanConsumer callback;
|
| 29 | private final Collection<Pack> enabledPacks;
|
| 30 | private final GridLayout layout = new GridLayout().columnSpacing(10).rowSpacing(20);
|
| 31 |
|
| 32 | public ConfirmExperimentalFeaturesScreen(final Collection<Pack> enabledPacks, final BooleanConsumer callback) {
|
| 33 | super(TITLE);
|
| 34 | this.enabledPacks = enabledPacks;
|
| 35 | this.callback = callback;
|
| 36 | }
|
| 37 |
|
| 38 | @Override
|
| 39 | public Component getNarrationMessage() {
|
| 40 | return CommonComponents.joinForNarration(super.getNarrationMessage(), MESSAGE);
|
| 41 | }
|
| 42 |
|
| 43 | @Override
|
| 44 | protected void init() {
|
| 45 | super.init();
|
| 46 | GridLayout.RowHelper helper = this.layout.createRowHelper(2);
|
| 47 | LayoutSettings centered = helper.newCellSettings().alignHorizontallyCenter();
|
| 48 | helper.addChild(new StringWidget(this.title, this.font), 2, centered);
|
| 49 | MultiLineTextWidget messageLabel = helper.addChild(new MultiLineTextWidget(MESSAGE, this.font).setCentered(true), 2, centered);
|
| 50 | messageLabel.setMaxWidth(310);
|
| 51 | helper.addChild(
|
| 52 | Button.builder(DETAILS_BUTTON, var1x -> this.minecraft.gui.setScreen(new ConfirmExperimentalFeaturesScreen.DetailsScreen())).width(100).build(), 2, centered
|
| 53 | );
|
| 54 | helper.addChild(Button.builder(CommonComponents.GUI_PROCEED, button -> this.callback.accept(true)).build());
|
| 55 | helper.addChild(Button.builder(CommonComponents.GUI_BACK, button -> this.callback.accept(false)).build());
|
| 56 | this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
|
| 57 | this.layout.arrangeElements();
|
| 58 | this.repositionElements();
|
| 59 | }
|
| 60 |
|
| 61 | @Override
|
| 62 | protected void repositionElements() {
|
| 63 | FrameLayout.alignInRectangle(this.layout, 0, 0, this.width, this.height, 0.5F, 0.5F);
|
| 64 | }
|
| 65 |
|
| 66 | @Override
|
| 67 | public void onClose() {
|
| 68 | this.callback.accept(false);
|
| 69 | }
|
| 70 |
|
| 71 | @Environment(EnvType.CLIENT)
|
| 72 | private class DetailsScreen extends Screen {
|
| 73 | private static final Component TITLE = Component.translatable("selectWorld.experimental.details.title");
|
| 74 | private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
|
| 75 | private PackList/* @Nullable */ list;
|
| 76 |
|
| 77 | private DetailsScreen() {
|
| 78 | super(TITLE);
|
| 79 | }
|
| 80 |
|
| 81 | @Override
|
| 82 | protected void init() {
|
| 83 | this.layout.addTitleHeader(TITLE, this.font);
|
| 84 | this.list = this.layout.addToContents(new PackList(this, this.minecraft, ConfirmExperimentalFeaturesScreen.this.enabledPacks));
|
| 85 | this.layout.addToFooter(Button.builder(CommonComponents.GUI_BACK, button -> this.onClose()).build());
|
| 86 | this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
|
| 87 | this.repositionElements();
|
| 88 | }
|
| 89 |
|
| 90 | @Override
|
| 91 | protected void repositionElements() {
|
| 92 | if (this.list != null) {
|
| 93 | this.list.updateSize(this.width, this.layout);
|
| 94 | }
|
| 95 |
|
| 96 | this.layout.arrangeElements();
|
| 97 | }
|
| 98 |
|
| 99 | @Override
|
| 100 | public void onClose() {
|
| 101 | this.minecraft.gui.setScreen(ConfirmExperimentalFeaturesScreen.this);
|
| 102 | }
|
| 103 | }
|
| 104 | }
|
| 105 |
|