| 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.ActiveTextCollector;
|
| 7 | import net.minecraft.client.gui.Font;
|
| 8 | import net.minecraft.client.gui.GuiGraphicsExtractor;
|
| 9 | import net.minecraft.client.gui.components.TabButton;
|
| 10 | import net.minecraft.client.gui.components.WidgetSprites;
|
| 11 | import net.minecraft.client.gui.components.tabs.Tab;
|
| 12 | import net.minecraft.client.gui.components.tabs.TabManager;
|
| 13 | import net.minecraft.client.renderer.RenderPipelines;
|
| 14 | import net.minecraft.resources.Identifier;
|
| 15 |
|
| 16 | @Environment(EnvType.CLIENT)
|
| 17 | class FriendsOverlayTabButton extends TabButton {
|
| 18 | private final WidgetSprites sprites = new WidgetSprites(
|
| 19 | Identifier.withDefaultNamespace("friends/button"),
|
| 20 | Identifier.withDefaultNamespace("friends/button_disabled"),
|
| 21 | Identifier.withDefaultNamespace("friends/button_highlighted"),
|
| 22 | Identifier.withDefaultNamespace("friends/button_highlighted")
|
| 23 | );
|
| 24 | private static final int SELECTED_OFFSET = 1;
|
| 25 | private static final int TEXT_MARGIN = 1;
|
| 26 | private static final int UNDERLINE_HEIGHT = 1;
|
| 27 | private static final int UNDERLINE_MARGIN_X = 4;
|
| 28 | private static final int UNDERLINE_MARGIN_BOTTOM = 2;
|
| 29 |
|
| 30 | public FriendsOverlayTabButton(final TabManager tabManager, final Tab tab, final int width, final int height) {
|
| 31 | super(tabManager, tab, width, height);
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | public void extractWidgetRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
|
| 36 | graphics.blitSprite(
|
| 37 | RenderPipelines.GUI_TEXTURED, this.sprites.get(this.isSelected(), this.isHoveredOrFocused()), this.getX(), this.getY(), this.width, this.height
|
| 38 | );
|
| 39 | Font font = Minecraft.getInstance().font;
|
| 40 | int underlineColor = this.active ? -1 : -6250336;
|
| 41 | if (this.isSelected()) {
|
| 42 | this.renderFocusUnderline(graphics, font, underlineColor);
|
| 43 | }
|
| 44 |
|
| 45 | this.renderLabel(graphics.textRendererForWidget(this, GuiGraphicsExtractor.HoveredTextEffects.NONE));
|
| 46 | this.handleCursor(graphics);
|
| 47 | }
|
| 48 |
|
| 49 | private void renderLabel(final ActiveTextCollector output) {
|
| 50 | int left = this.getX() + 1;
|
| 51 | int top = this.getY() + (this.isSelected() ? 0 : 1);
|
| 52 | int right = this.getX() + this.getWidth() - 1;
|
| 53 | int bottom = this.getY() + this.getHeight();
|
| 54 | output.acceptScrollingWithDefaultCenter(this.getMessage(), left, right, top, bottom);
|
| 55 | }
|
| 56 |
|
| 57 | private void renderFocusUnderline(final GuiGraphicsExtractor graphics, final Font font, final int color) {
|
| 58 | int width = Math.min(font.width(this.getMessage()), this.getWidth() - 4);
|
| 59 | int left = this.getX() + (this.getWidth() - width) / 2;
|
| 60 | int top = this.getY() + this.getHeight() - 2;
|
| 61 | graphics.fill(left, top, left + width, top + 1, color);
|
| 62 | }
|
| 63 | }
|
| 64 |
|