| 1 | package net.minecraft.client.gui.screens;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.Blaze3D;
|
| 4 | import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
|
| 5 | import java.net.URI;
|
| 6 | import net.fabricmc.api.EnvType;
|
| 7 | import net.fabricmc.api.Environment;
|
| 8 | import net.minecraft.ChatFormatting;
|
| 9 | import net.minecraft.client.Minecraft;
|
| 10 | import net.minecraft.client.gui.components.MultiLineTextWidget;
|
| 11 | import net.minecraft.client.gui.components.StringWidget;
|
| 12 | import net.minecraft.client.gui.layouts.LinearLayout;
|
| 13 | import net.minecraft.network.chat.CommonComponents;
|
| 14 | import net.minecraft.network.chat.Component;
|
| 15 | import org.jspecify.annotations.Nullable;
|
| 16 |
|
| 17 | @Environment(EnvType.CLIENT)
|
| 18 | public class PrivacyConfirmLinkScreen extends ConfirmLinkScreen {
|
| 19 | private static final Component TITLE = Component.translatable("gui.privacy_link.title").withStyle(style -> style.withColor(-256).withUnderlined(true));
|
| 20 | private static final Component MESSAGE = Component.translatable("gui.privacy_link.message");
|
| 21 | private final Component urlComponent;
|
| 22 |
|
| 23 | public PrivacyConfirmLinkScreen(final BooleanConsumer callback, final URI url) {
|
| 24 | super(callback, TITLE, MESSAGE, url, CommonComponents.GUI_CANCEL, true);
|
| 25 | this.urlComponent = Component.literal(url.toString()).withStyle(ChatFormatting.WHITE);
|
| 26 | }
|
| 27 |
|
| 28 | @Override
|
| 29 | protected void init() {
|
| 30 | this.layout.defaultCellSetting().alignHorizontallyCenter();
|
| 31 | this.layout.addChild(new MultiLineTextWidget(this.title, this.font).setMaxWidth(this.width - 50).setMaxRows(4).setCentered(true));
|
| 32 | this.layout.addChild(new MultiLineTextWidget(MESSAGE, this.font).setMaxWidth(this.width - 50).setMaxRows(15).setCentered(true));
|
| 33 | this.addAdditionalText();
|
| 34 | LinearLayout buttonLayout = this.layout.addChild(LinearLayout.horizontal().spacing(4));
|
| 35 | buttonLayout.defaultCellSetting().paddingTop(16);
|
| 36 | this.addButtons(buttonLayout);
|
| 37 | this.layout.visitWidgets(this::addRenderableWidget);
|
| 38 | this.repositionElements();
|
| 39 | }
|
| 40 |
|
| 41 | @Override
|
| 42 | protected void addAdditionalText() {
|
| 43 | this.layout.addChild(new StringWidget(this.urlComponent, this.font));
|
| 44 | }
|
| 45 |
|
| 46 | public static void confirmLinkNow(final @Nullable Screen parentScreen, final URI uri) {
|
| 47 | Minecraft minecraft = Minecraft.getInstance();
|
| 48 | minecraft.gui.setScreen(new PrivacyConfirmLinkScreen(shouldOpen -> {
|
| 49 | if (shouldOpen) {
|
| 50 | Blaze3D.openUri(uri);
|
| 51 | }
|
| 52 |
|
| 53 | minecraft.gui.setScreen(parentScreen);
|
| 54 | }, uri));
|
| 55 | }
|
| 56 | }
|
| 57 |
|