| 1 | package net.minecraft.client.gui.screens.friends;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.Minecraft;
|
| 6 | import net.minecraft.client.gui.GuiGraphicsExtractor;
|
| 7 | import net.minecraft.client.gui.components.Button;
|
| 8 | import net.minecraft.client.gui.components.SpriteIconButton;
|
| 9 | import net.minecraft.client.gui.components.WidgetSprites;
|
| 10 | import net.minecraft.client.gui.screens.social.PlayerSocialManager;
|
| 11 | import net.minecraft.network.chat.Component;
|
| 12 | import net.minecraft.resources.Identifier;
|
| 13 |
|
| 14 | @Environment(EnvType.CLIENT)
|
| 15 | class IncomingEntry extends AbstractFriendsEntryContainerWidget {
|
| 16 | private static final WidgetSprites ACCEPT_SPRITE = new WidgetSprites(
|
| 17 | Identifier.withDefaultNamespace("friends/accept"), Identifier.withDefaultNamespace("friends/accept_highlighted")
|
| 18 | );
|
| 19 | private static final WidgetSprites REJECT_SPRITE = new WidgetSprites(
|
| 20 | Identifier.withDefaultNamespace("friends/reject"), Identifier.withDefaultNamespace("friends/reject_highlighted")
|
| 21 | );
|
| 22 | private static final Component ACCEPT_INVITE = Component.translatable("gui.friends.accept");
|
| 23 | private static final Component REJECT_INVITE = Component.translatable("gui.friends.decline");
|
| 24 | private final SpriteIconButton acceptButton;
|
| 25 | private final SpriteIconButton rejectButton;
|
| 26 |
|
| 27 | public IncomingEntry(
|
| 28 | final Minecraft minecraft,
|
| 29 | final FriendsOverlayScreen screen,
|
| 30 | final PlayerSocialManager.PlayerData playerData,
|
| 31 | final Runnable acceptAction,
|
| 32 | final Runnable declineAction
|
| 33 | ) {
|
| 34 | super(minecraft, screen, 0, 0, screen.getOverlayWidth() - 16, 28, playerData);
|
| 35 | Button.CreateNarration acceptNarration = getSpriteIconNarration(Component.translatable("gui.friends.narration.button.accept", playerData.name()));
|
| 36 | Button.CreateNarration rejectNarration = getSpriteIconNarration(Component.translatable("gui.friends.narration.button.decline", playerData.name()));
|
| 37 | this.acceptButton = SpriteIconButton.builder(ACCEPT_INVITE, var2 -> {
|
| 38 | screen.startFriendAction();
|
| 39 | acceptAction.run();
|
| 40 | }, true).size(20, 20).sprite(ACCEPT_SPRITE, 18, 18).tooltip(ACCEPT_INVITE).narration(acceptNarration).switchToLoadingAfterPress().build();
|
| 41 | this.addChild(this.acceptButton);
|
| 42 | this.rejectButton = SpriteIconButton.builder(REJECT_INVITE, var2 -> {
|
| 43 | screen.startFriendAction();
|
| 44 | declineAction.run();
|
| 45 | }, true).size(20, 20).sprite(REJECT_SPRITE, 18, 18).tooltip(REJECT_INVITE).narration(rejectNarration).switchToLoadingAfterPress().build();
|
| 46 | this.addChild(this.rejectButton);
|
| 47 | }
|
| 48 |
|
| 49 | @Override
|
| 50 | void disable() {
|
| 51 | this.acceptButton.active = false;
|
| 52 | this.rejectButton.active = false;
|
| 53 | }
|
| 54 |
|
| 55 | @Override
|
| 56 | protected Component getEntryNarration() {
|
| 57 | return Component.translatable("gui.friends.narration.entry.incoming", this.playerName);
|
| 58 | }
|
| 59 |
|
| 60 | @Override
|
| 61 | protected void extractWidgetRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
|
| 62 | super.extractWidgetRenderState(graphics, mouseX, mouseY, a);
|
| 63 | this.rejectButton
|
| 64 | .setPosition(this.getX() + this.getWidth() - this.rejectButton.getWidth(), this.getY() + (this.getHeight() - this.rejectButton.getHeight()) / 2);
|
| 65 | this.rejectButton.extractRenderState(graphics, mouseX, mouseY, a);
|
| 66 | this.acceptButton
|
| 67 | .setPosition(this.rejectButton.getX() - this.acceptButton.getWidth() - 4, this.getY() + (this.getHeight() - this.acceptButton.getHeight()) / 2);
|
| 68 | this.acceptButton.extractRenderState(graphics, mouseX, mouseY, a);
|
| 69 | }
|
| 70 | }
|
| 71 |
|