| 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 OutgoingEntry extends AbstractFriendsEntryContainerWidget {
|
| 16 | private static final WidgetSprites REVOKE_SPRITE = new WidgetSprites(Identifier.withDefaultNamespace("friends/cancel"));
|
| 17 | private static final Component REVOKE_INVITE = Component.translatable("gui.friends.cancel_request");
|
| 18 | private final SpriteIconButton revokeButton;
|
| 19 |
|
| 20 | public OutgoingEntry(
|
| 21 | final Minecraft minecraft, final FriendsOverlayScreen screen, final PlayerSocialManager.PlayerData playerData, final Runnable revokeAction
|
| 22 | ) {
|
| 23 | super(minecraft, screen, 0, 0, screen.getOverlayWidth() - 16, 28, playerData);
|
| 24 | Button.CreateNarration narration = getSpriteIconNarration(Component.translatable("gui.friends.narration.button.cancel_request", playerData.name()));
|
| 25 | this.revokeButton = SpriteIconButton.builder(REVOKE_INVITE, var2 -> {
|
| 26 | screen.startFriendAction();
|
| 27 | revokeAction.run();
|
| 28 | }, true).size(20, 20).sprite(REVOKE_SPRITE, 12, 12).tooltip(REVOKE_INVITE).narration(narration).switchToLoadingAfterPress().build();
|
| 29 | this.addChild(this.revokeButton);
|
| 30 | }
|
| 31 |
|
| 32 | @Override
|
| 33 | void disable() {
|
| 34 | this.revokeButton.active = false;
|
| 35 | }
|
| 36 |
|
| 37 | @Override
|
| 38 | protected Component getEntryNarration() {
|
| 39 | return Component.translatable("gui.friends.narration.entry.outgoing", this.playerName);
|
| 40 | }
|
| 41 |
|
| 42 | @Override
|
| 43 | protected void extractWidgetRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
|
| 44 | super.extractWidgetRenderState(graphics, mouseX, mouseY, a);
|
| 45 | this.revokeButton
|
| 46 | .setPosition(this.getX() + this.getWidth() - this.revokeButton.getWidth(), this.getY() + (this.getHeight() - this.revokeButton.getHeight()) / 2);
|
| 47 | this.revokeButton.extractRenderState(graphics, mouseX, mouseY, a);
|
| 48 | }
|
| 49 | }
|
| 50 |
|