| 1 | package net.minecraft.client.gui.screens.friends;
|
| 2 |
|
| 3 | import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
|
| 4 | import java.net.URI;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.client.gui.GuiGraphicsExtractor;
|
| 8 | import net.minecraft.client.gui.components.FocusableTextWidget;
|
| 9 | import net.minecraft.client.gui.layouts.LayoutElement;
|
| 10 | import net.minecraft.client.gui.layouts.LinearLayout;
|
| 11 | import net.minecraft.client.gui.screens.ConfirmScreen;
|
| 12 | import net.minecraft.client.gui.screens.PrivacyConfirmLinkScreen;
|
| 13 | import net.minecraft.client.renderer.RenderPipelines;
|
| 14 | import net.minecraft.network.chat.Component;
|
| 15 | import net.minecraft.network.chat.ClickEvent.OpenUrl;
|
| 16 | import net.minecraft.resources.Identifier;
|
| 17 |
|
| 18 | @Environment(EnvType.CLIENT)
|
| 19 | public class FriendsListConfirmScreen extends ConfirmScreen {
|
| 20 | private static final Identifier BACKGROUND_SPRITE = Identifier.withDefaultNamespace("friends/background_dark");
|
| 21 | private static final Component USAGE_FOCUSED = Component.translatable("narration.link.usage.focused");
|
| 22 | private static final Component USAGE_HOVERED = Component.translatable("narration.link.usage.hovered");
|
| 23 | private static final int PANEL_PADDING = 10;
|
| 24 | private static final int BG_BORDER_WIDTH = 8;
|
| 25 |
|
| 26 | public FriendsListConfirmScreen(
|
| 27 | final BooleanConsumer callback, final Component title, final Component message, final Component yesButton, final Component noButton
|
| 28 | ) {
|
| 29 | super(callback, title, message, yesButton, noButton);
|
| 30 | }
|
| 31 |
|
| 32 | @Override
|
| 33 | protected LayoutElement addMessage() {
|
| 34 | LinearLayout content = LinearLayout.vertical();
|
| 35 | content.defaultCellSetting().alignHorizontallyCenter().alignVerticallyMiddle().padding(10, 5, 10, 5);
|
| 36 | FocusableTextWidget focusable = FocusableTextWidget.builder(this.message, this.font)
|
| 37 | .maxWidth(this.width - 180)
|
| 38 | .alwaysShowBorder(false)
|
| 39 | .backgroundFill(FocusableTextWidget.BackgroundFill.NEVER)
|
| 40 | .build();
|
| 41 | focusable.setMaxRows(15);
|
| 42 | focusable.setComponentClickHandler(style -> {
|
| 43 | if (style.getClickEvent() instanceof OpenUrl(URI uri)) {
|
| 44 | PrivacyConfirmLinkScreen.confirmLinkNow(this, uri);
|
| 45 | }
|
| 46 | });
|
| 47 | focusable.setNarrateMessage(false);
|
| 48 | focusable.setUsageNarration(USAGE_FOCUSED, USAGE_HOVERED);
|
| 49 | content.addChild(focusable);
|
| 50 | return content;
|
| 51 | }
|
| 52 |
|
| 53 | @Override
|
| 54 | public void extractBackground(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
|
| 55 | super.extractBackground(graphics, mouseX, mouseY, a);
|
| 56 | graphics.blitSprite(
|
| 57 | RenderPipelines.GUI_TEXTURED,
|
| 58 | BACKGROUND_SPRITE,
|
| 59 | this.layout.getX() - 10 - 8,
|
| 60 | this.layout.getY() - 10 - 8,
|
| 61 | this.layout.getWidth() + 20 + 16 + 1,
|
| 62 | this.layout.getHeight() + 20 + 16 + 1
|
| 63 | );
|
| 64 | }
|
| 65 | }
|
| 66 |
|