| 1 | package net.minecraft.client.gui.screens;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.Blaze3D;
|
| 4 | import java.net.URI;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.ChatFormatting;
|
| 8 | import net.minecraft.client.gui.components.Button;
|
| 9 | import net.minecraft.client.gui.components.MultiLineTextWidget;
|
| 10 | import net.minecraft.client.gui.components.StringWidget;
|
| 11 | import net.minecraft.client.gui.layouts.FrameLayout;
|
| 12 | import net.minecraft.client.gui.layouts.GridLayout;
|
| 13 | import net.minecraft.network.chat.CommonComponents;
|
| 14 | import net.minecraft.network.chat.Component;
|
| 15 | import net.minecraft.util.CommonLinks;
|
| 16 |
|
| 17 | @Environment(EnvType.CLIENT)
|
| 18 | public class NoticeWithLinkScreen extends Screen {
|
| 19 | private static final Component SYMLINK_WORLD_TITLE = Component.translatable("symlink_warning.title.world").withStyle(ChatFormatting.BOLD);
|
| 20 | private static final Component SYMLINK_WORLD_MESSAGE_TEXT = Component.translatable(
|
| 21 | "symlink_warning.message.world", Component.translationArg(CommonLinks.SYMLINK_HELP)
|
| 22 | );
|
| 23 | private static final Component SYMLINK_PACK_TITLE = Component.translatable("symlink_warning.title.pack").withStyle(ChatFormatting.BOLD);
|
| 24 | private static final Component SYMLINK_PACK_MESSAGE_TEXT = Component.translatable(
|
| 25 | "symlink_warning.message.pack", Component.translationArg(CommonLinks.SYMLINK_HELP)
|
| 26 | );
|
| 27 | private final Component message;
|
| 28 | private final URI uri;
|
| 29 | private final Runnable onClose;
|
| 30 | private final GridLayout layout = new GridLayout().rowSpacing(10);
|
| 31 |
|
| 32 | public NoticeWithLinkScreen(final Component title, final Component message, final URI uri, final Runnable onClose) {
|
| 33 | super(title);
|
| 34 | this.message = message;
|
| 35 | this.uri = uri;
|
| 36 | this.onClose = onClose;
|
| 37 | }
|
| 38 |
|
| 39 | public static Screen createWorldSymlinkWarningScreen(final Runnable onClose) {
|
| 40 | return new NoticeWithLinkScreen(SYMLINK_WORLD_TITLE, SYMLINK_WORLD_MESSAGE_TEXT, CommonLinks.SYMLINK_HELP, onClose);
|
| 41 | }
|
| 42 |
|
| 43 | public static Screen createPackSymlinkWarningScreen(final Runnable onClose) {
|
| 44 | return new NoticeWithLinkScreen(SYMLINK_PACK_TITLE, SYMLINK_PACK_MESSAGE_TEXT, CommonLinks.SYMLINK_HELP, onClose);
|
| 45 | }
|
| 46 |
|
| 47 | @Override
|
| 48 | protected void init() {
|
| 49 | super.init();
|
| 50 | this.layout.defaultCellSetting().alignHorizontallyCenter();
|
| 51 | GridLayout.RowHelper rowHelper = this.layout.createRowHelper(1);
|
| 52 | rowHelper.addChild(new StringWidget(this.title, this.font));
|
| 53 | rowHelper.addChild(new MultiLineTextWidget(this.message, this.font).setMaxWidth(this.width - 50).setCentered(true));
|
| 54 | int buttonWidth = 120;
|
| 55 | GridLayout buttonGrid = new GridLayout().columnSpacing(5);
|
| 56 | GridLayout.RowHelper buttonRow = buttonGrid.createRowHelper(3);
|
| 57 | buttonRow.addChild(Button.builder(CommonComponents.GUI_OPEN_IN_BROWSER, button -> Blaze3D.openUri(this.uri)).size(120, 20).build());
|
| 58 | buttonRow.addChild(
|
| 59 | Button.builder(CommonComponents.GUI_COPY_LINK_TO_CLIPBOARD, button -> this.minecraft.keyboardHandler.setClipboard(this.uri.toString()))
|
| 60 | .size(120, 20)
|
| 61 | .build()
|
| 62 | );
|
| 63 | buttonRow.addChild(Button.builder(CommonComponents.GUI_BACK, button -> this.onClose()).size(120, 20).build());
|
| 64 | rowHelper.addChild(buttonGrid);
|
| 65 | this.repositionElements();
|
| 66 | this.layout.visitWidgets(this::addRenderableWidget);
|
| 67 | }
|
| 68 |
|
| 69 | @Override
|
| 70 | protected void repositionElements() {
|
| 71 | this.layout.arrangeElements();
|
| 72 | FrameLayout.centerInRectangle(this.layout, this.getRectangle());
|
| 73 | }
|
| 74 |
|
| 75 | @Override
|
| 76 | public Component getNarrationMessage() {
|
| 77 | return CommonComponents.joinForNarration(super.getNarrationMessage(), this.message);
|
| 78 | }
|
| 79 |
|
| 80 | @Override
|
| 81 | public void onClose() {
|
| 82 | this.onClose.run();
|
| 83 | }
|
| 84 | }
|
| 85 |
|