| 1 | package net.minecraft.client.gui.components;
|
| 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.screens.social.PlayerSocialManager;
|
| 8 | import net.minecraft.client.renderer.RenderPipelines;
|
| 9 | import net.minecraft.network.chat.Component;
|
| 10 | import net.minecraft.resources.Identifier;
|
| 11 |
|
| 12 | @Environment(EnvType.CLIENT)
|
| 13 | public class FriendsButton extends SpriteIconButton.CenteredIcon {
|
| 14 | private static final Component TOOLTIP = Component.translatable("gui.friends.open.tooltip");
|
| 15 | private static final Component MESSAGE = Component.translatable("gui.friends.open");
|
| 16 | private static final Button.CreateNarration NARRATION = var0 -> Component.translatable("gui.friends.open.narration");
|
| 17 | private static final Identifier[] NOTIFICATION_ICONS = new Identifier[]{
|
| 18 | Identifier.withDefaultNamespace("notification/1"),
|
| 19 | Identifier.withDefaultNamespace("notification/2"),
|
| 20 | Identifier.withDefaultNamespace("notification/3"),
|
| 21 | Identifier.withDefaultNamespace("notification/4"),
|
| 22 | Identifier.withDefaultNamespace("notification/5"),
|
| 23 | Identifier.withDefaultNamespace("notification/more")
|
| 24 | };
|
| 25 | private static final int SPRITE_SIZE = 15;
|
| 26 | private int incomingRequestCount;
|
| 27 |
|
| 28 | public FriendsButton(final int width, final Button.OnPress onPress, final boolean friendsAvailable) {
|
| 29 | super(
|
| 30 | width,
|
| 31 | 20,
|
| 32 | MESSAGE,
|
| 33 | 15,
|
| 34 | 15,
|
| 35 | 0,
|
| 36 | 0,
|
| 37 | new WidgetSprites(Identifier.withDefaultNamespace("friends/friends")),
|
| 38 | onPress,
|
| 39 | friendsAvailable ? TOOLTIP : null,
|
| 40 | NARRATION,
|
| 41 | false
|
| 42 | );
|
| 43 | this.active = friendsAvailable;
|
| 44 | this.refreshIncomingRequestCount();
|
| 45 | }
|
| 46 |
|
| 47 | public void refreshIncomingRequestCount() {
|
| 48 | Minecraft minecraft = Minecraft.getInstance();
|
| 49 | PlayerSocialManager playerSocialManager = minecraft.getPlayerSocialManager();
|
| 50 | if (!playerSocialManager.isFriendListEnabled()) {
|
| 51 | this.incomingRequestCount = 0;
|
| 52 | } else {
|
| 53 | this.incomingRequestCount = playerSocialManager.getIncomingRequests().size();
|
| 54 | }
|
| 55 | }
|
| 56 |
|
| 57 | @Override
|
| 58 | public void extractContents(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
|
| 59 | super.extractContents(graphics, mouseX, mouseY, a);
|
| 60 | if (this.isActive() && this.incomingRequestCount > 0) {
|
| 61 | int iconIndex = Math.min(this.incomingRequestCount, 6) - 1;
|
| 62 | graphics.blitSprite(RenderPipelines.GUI_TEXTURED, NOTIFICATION_ICONS[iconIndex], this.getX() + this.getWidth() - 5, this.getY() - 3, 8, 8, this.alpha);
|
| 63 | }
|
| 64 | }
|
| 65 | }
|
| 66 |
|