| 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.gui.Font;
|
| 6 | import net.minecraft.client.gui.components.FocusableTextWidget;
|
| 7 | import net.minecraft.client.gui.components.MultiLineTextWidget;
|
| 8 | import net.minecraft.client.gui.components.tabs.Tab;
|
| 9 | import net.minecraft.client.gui.layouts.FrameLayout;
|
| 10 | import net.minecraft.client.gui.layouts.Layout;
|
| 11 | import net.minecraft.client.gui.layouts.LayoutElement;
|
| 12 | import net.minecraft.network.chat.Component;
|
| 13 |
|
| 14 | @Environment(EnvType.CLIENT)
|
| 15 | public abstract class AbstractFriendsTab implements Tab {
|
| 16 | static final int SPACING = 8;
|
| 17 | static final int SCROLLBAR_SPACING = 2;
|
| 18 | static final int LIST_MARGIN = 8;
|
| 19 | protected final int width;
|
| 20 | protected int height;
|
| 21 |
|
| 22 | public AbstractFriendsTab(final int width, final int height) {
|
| 23 | this.width = width;
|
| 24 | this.height = height;
|
| 25 | }
|
| 26 |
|
| 27 | protected int getListContentWidth() {
|
| 28 | return this.width - 16;
|
| 29 | }
|
| 30 |
|
| 31 | abstract void rearrangeElements();
|
| 32 |
|
| 33 | protected abstract Layout entriesContainer();
|
| 34 |
|
| 35 | final void disable() {
|
| 36 | this.entriesContainer().visitWidgets(widget -> {
|
| 37 | if (widget instanceof AbstractFriendsEntryContainerWidget entry) {
|
| 38 | entry.disable();
|
| 39 | }
|
| 40 | });
|
| 41 | }
|
| 42 |
|
| 43 | void setHeight(final int height) {
|
| 44 | this.height = height;
|
| 45 | this.rearrangeElements();
|
| 46 | }
|
| 47 |
|
| 48 | FrameLayout createCenteredFrame(final LayoutElement child, final int frameWidth, final int frameHeight) {
|
| 49 | FrameLayout frameLayout = new FrameLayout(frameWidth, frameHeight);
|
| 50 | frameLayout.defaultChildLayoutSetting().alignHorizontallyCenter().alignVerticallyMiddle();
|
| 51 | frameLayout.addChild(child);
|
| 52 | return frameLayout;
|
| 53 | }
|
| 54 |
|
| 55 | FocusableTextWidget createText(final Component message, final Font font, final int maxWidth) {
|
| 56 | return FocusableTextWidget.builder(message, font).maxWidth(maxWidth).alwaysShowBorder(false).backgroundFill(FocusableTextWidget.BackgroundFill.NEVER).build();
|
| 57 | }
|
| 58 |
|
| 59 | MultiLineTextWidget createCenteredText(final Component message, final Font font, final int maxWidth) {
|
| 60 | return this.createText(message, font, maxWidth).setCentered(true);
|
| 61 | }
|
| 62 | }
|
| 63 |
|