SocialInteractionsScreen.java

net.minecraft.client.gui.screens.social.SocialInteractionsScreen

信息

  • 全限定名:net.minecraft.client.gui.screens.social.SocialInteractionsScreen
  • 类型:public class
  • 包:net.minecraft.client.gui.screens.social
  • 源码路径:src/main/java/net/minecraft/client/gui/screens/social/SocialInteractionsScreen.java
  • 起始行号:L32
  • 继承:Screen
  • 职责:

    TODO

字段/常量

  • TITLE

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L33
    • 说明:

      TODO

  • BACKGROUND_SPRITE

    • 类型: Identifier
    • 修饰符: private static final
    • 源码定位: L34
    • 说明:

      TODO

  • SEARCH_SPRITE

    • 类型: Identifier
    • 修饰符: private static final
    • 源码定位: L35
    • 说明:

      TODO

  • TAB_ALL

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L36
    • 说明:

      TODO

  • TAB_HIDDEN

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L37
    • 说明:

      TODO

  • TAB_BLOCKED

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L38
    • 说明:

      TODO

  • TAB_ALL_SELECTED

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L39
    • 说明:

      TODO

  • TAB_HIDDEN_SELECTED

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L40
    • 说明:

      TODO

  • TAB_BLOCKED_SELECTED

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L41
    • 说明:

      TODO

  • SEARCH_HINT

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L42
    • 说明:

      TODO

  • EMPTY_SEARCH

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L43
    • 说明:

      TODO

  • EMPTY_HIDDEN

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L44
    • 说明:

      TODO

  • EMPTY_BLOCKED

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L45
    • 说明:

      TODO

  • BLOCKING_HINT

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L46
    • 说明:

      TODO

  • BG_BORDER_SIZE

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L47
    • 说明:

      TODO

  • BG_WIDTH

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L48
    • 说明:

      TODO

  • SEARCH_HEIGHT

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L49
    • 说明:

      TODO

  • MARGIN_Y

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L50
    • 说明:

      TODO

  • SEARCH_START

    • 类型: int
    • 修饰符: public static final
    • 源码定位: L51
    • 说明:

      TODO

  • LIST_START

    • 类型: int
    • 修饰符: public static final
    • 源码定位: L52
    • 说明:

      TODO

  • IMAGE_WIDTH

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L53
    • 说明:

      TODO

  • BUTTON_HEIGHT

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L54
    • 说明:

      TODO

  • ITEM_HEIGHT

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L55
    • 说明:

      TODO

  • layout

    • 类型: HeaderAndFooterLayout
    • 修饰符: private final
    • 源码定位: L56
    • 说明:

      TODO

  • lastScreen

    • 类型: Screen
    • 修饰符: private final
    • 源码定位: L57
    • 说明:

      TODO

  • socialInteractionsPlayerList

    • 类型: SocialInteractionsPlayerList
    • 修饰符: private
    • 源码定位: L58
    • 说明:

      TODO

  • searchBox

    • 类型: EditBox
    • 修饰符: private
    • 源码定位: L59
    • 说明:

      TODO

  • lastSearch

    • 类型: String
    • 修饰符: private
    • 源码定位: L60
    • 说明:

      TODO

  • page

    • 类型: SocialInteractionsScreen.Page
    • 修饰符: private
    • 源码定位: L61
    • 说明:

      TODO

  • allButton

    • 类型: Button
    • 修饰符: private
    • 源码定位: L62
    • 说明:

      TODO

  • hiddenButton

    • 类型: Button
    • 修饰符: private
    • 源码定位: L63
    • 说明:

      TODO

  • blockedButton

    • 类型: Button
    • 修饰符: private
    • 源码定位: L64
    • 说明:

      TODO

  • blockingHintButton

    • 类型: Button
    • 修饰符: private
    • 源码定位: L65
    • 说明:

      TODO

  • serverLabel

    • 类型: Component
    • 修饰符: private
    • 源码定位: L66
    • 说明:

      TODO

  • playerCount

    • 类型: int
    • 修饰符: private
    • 源码定位: L67
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.screens.social.SocialInteractionsScreen.Page
    • 类型: enum
    • 修饰符: public static
    • 源码定位: L310
    • 说明:

      TODO

构造器

public SocialInteractionsScreen() @ L69

  • 构造器名:SocialInteractionsScreen
  • 源码定位:L69
  • 修饰符:public

参数:

说明:

TODO

public SocialInteractionsScreen(Screen lastScreen) @ L73

  • 构造器名:SocialInteractionsScreen
  • 源码定位:L73
  • 修饰符:public

参数:

  • lastScreen: Screen

说明:

TODO

方法

下面的方法块按源码顺序生成。

private int windowHeight() @ L79

  • 方法名:windowHeight
  • 源码定位:L79
  • 返回类型:int
  • 修饰符:private

参数:

说明:

TODO

private int listEnd() @ L83

  • 方法名:listEnd
  • 源码定位:L83
  • 返回类型:int
  • 修饰符:private

参数:

说明:

TODO

private int marginX() @ L87

  • 方法名:marginX
  • 源码定位:L87
  • 返回类型:int
  • 修饰符:private

参数:

说明:

TODO

public Component getNarrationMessage() @ L91

  • 方法名:getNarrationMessage
  • 源码定位:L91
  • 返回类型:Component
  • 修饰符:public

参数:

说明:

TODO

protected void init() @ L98

  • 方法名:init
  • 源码定位:L98
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

public void added() @ L152

  • 方法名:added
  • 源码定位:L152
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

protected void repositionElements() @ L159

  • 方法名:repositionElements
  • 源码定位:L159
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

protected void setInitialFocus() @ L173

  • 方法名:setInitialFocus
  • 源码定位:L173
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

public void onClose() @ L178

  • 方法名:onClose
  • 源码定位:L178
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

private void showPage(SocialInteractionsScreen.Page page) @ L183

  • 方法名:showPage
  • 源码定位:L183
  • 返回类型:void
  • 修饰符:private

参数:

  • page: SocialInteractionsScreen.Page

说明:

TODO

public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L227

  • 方法名:extractBackground
  • 源码定位:L227
  • 返回类型:void
  • 修饰符:public

参数:

  • graphics: GuiGraphicsExtractor
  • mouseX: int
  • mouseY: int
  • a: float

说明:

TODO

public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L235

  • 方法名:extractRenderState
  • 源码定位:L235
  • 返回类型:void
  • 修饰符:public

参数:

  • graphics: GuiGraphicsExtractor
  • mouseX: int
  • mouseY: int
  • a: float

说明:

TODO

public boolean keyPressed(KeyEvent event) @ L256

  • 方法名:keyPressed
  • 源码定位:L256
  • 返回类型:boolean
  • 修饰符:public

参数:

  • event: KeyEvent

说明:

TODO

public boolean isPauseScreen() @ L266

  • 方法名:isPauseScreen
  • 源码定位:L266
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

private void checkSearchStringUpdate(String searchText) @ L271

  • 方法名:checkSearchStringUpdate
  • 源码定位:L271
  • 返回类型:void
  • 修饰符:private

参数:

  • searchText: String

说明:

TODO

private void updateServerLabel(Minecraft minecraft) @ L280

  • 方法名:updateServerLabel
  • 源码定位:L280
  • 返回类型:void
  • 修饰符:private

参数:

  • minecraft: Minecraft

说明:

TODO

public void onAddPlayer(PlayerInfo info) @ L301

  • 方法名:onAddPlayer
  • 源码定位:L301
  • 返回类型:void
  • 修饰符:public

参数:

  • info: PlayerInfo

说明:

TODO

public void onRemovePlayer(UUID id) @ L305

  • 方法名:onRemovePlayer
  • 源码定位:L305
  • 返回类型:void
  • 修饰符:public

参数:

  • id: UUID

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class SocialInteractionsScreen extends Screen {
    private static final Component TITLE = Component.translatable("gui.socialInteractions.title");
    private static final Identifier BACKGROUND_SPRITE = Identifier.withDefaultNamespace("social_interactions/background");
    private static final Identifier SEARCH_SPRITE = Identifier.withDefaultNamespace("icon/search");
    private static final Component TAB_ALL = Component.translatable("gui.socialInteractions.tab_all");
    private static final Component TAB_HIDDEN = Component.translatable("gui.socialInteractions.tab_hidden");
    private static final Component TAB_BLOCKED = Component.translatable("gui.socialInteractions.tab_blocked");
    private static final Component TAB_ALL_SELECTED = TAB_ALL.plainCopy().withStyle(ChatFormatting.UNDERLINE);
    private static final Component TAB_HIDDEN_SELECTED = TAB_HIDDEN.plainCopy().withStyle(ChatFormatting.UNDERLINE);
    private static final Component TAB_BLOCKED_SELECTED = TAB_BLOCKED.plainCopy().withStyle(ChatFormatting.UNDERLINE);
    private static final Component SEARCH_HINT = Component.translatable("gui.socialInteractions.search_hint").withStyle(EditBox.SEARCH_HINT_STYLE);
    private static final Component EMPTY_SEARCH = Component.translatable("gui.socialInteractions.search_empty").withStyle(ChatFormatting.GRAY);
    private static final Component EMPTY_HIDDEN = Component.translatable("gui.socialInteractions.empty_hidden").withStyle(ChatFormatting.GRAY);
    private static final Component EMPTY_BLOCKED = Component.translatable("gui.socialInteractions.empty_blocked").withStyle(ChatFormatting.GRAY);
    private static final Component BLOCKING_HINT = Component.translatable("gui.socialInteractions.blocking_hint");
    private static final int BG_BORDER_SIZE = 8;
    private static final int BG_WIDTH = 236;
    private static final int SEARCH_HEIGHT = 16;
    private static final int MARGIN_Y = 64;
    public static final int SEARCH_START = 72;
    public static final int LIST_START = 88;
    private static final int IMAGE_WIDTH = 238;
    private static final int BUTTON_HEIGHT = 20;
    private static final int ITEM_HEIGHT = 36;
    private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
    private final @Nullable Screen lastScreen;
    private @Nullable SocialInteractionsPlayerList socialInteractionsPlayerList;
    private EditBox searchBox;
    private String lastSearch = "";
    private SocialInteractionsScreen.Page page = SocialInteractionsScreen.Page.ALL;
    private Button allButton;
    private Button hiddenButton;
    private Button blockedButton;
    private Button blockingHintButton;
    private @Nullable Component serverLabel;
    private int playerCount;
 
    public SocialInteractionsScreen() {
        this(null);
    }
 
    public SocialInteractionsScreen(@Nullable Screen lastScreen) {
        super(TITLE);
        this.lastScreen = lastScreen;
        this.updateServerLabel(Minecraft.getInstance());
    }
 
    private int windowHeight() {
        return Math.max(52, this.height - 128 - 16);
    }
 
    private int listEnd() {
        return 80 + this.windowHeight() - 8;
    }
 
    private int marginX() {
        return (this.width - 238) / 2;
    }
 
    @Override
    public Component getNarrationMessage() {
        return (Component)(this.serverLabel != null
            ? CommonComponents.joinForNarration(super.getNarrationMessage(), this.serverLabel)
            : super.getNarrationMessage());
    }
 
    @Override
    protected void init() {
        this.layout.addTitleHeader(TITLE, this.font);
        this.socialInteractionsPlayerList = new SocialInteractionsPlayerList(this, this.minecraft, this.width, this.listEnd() - 88, 88, 36);
        int buttonWidth = this.socialInteractionsPlayerList.getRowWidth() / 3;
        int buttonLeft = this.socialInteractionsPlayerList.getRowLeft();
        int buttonRight = this.socialInteractionsPlayerList.getRowRight();
        this.allButton = this.addRenderableWidget(
            Button.builder(TAB_ALL, button -> this.showPage(SocialInteractionsScreen.Page.ALL)).bounds(buttonLeft, 45, buttonWidth, 20).build()
        );
        this.hiddenButton = this.addRenderableWidget(
            Button.builder(TAB_HIDDEN, button -> this.showPage(SocialInteractionsScreen.Page.HIDDEN))
                .bounds((buttonLeft + buttonRight - buttonWidth) / 2 + 1, 45, buttonWidth, 20)
                .build()
        );
        this.blockedButton = this.addRenderableWidget(
            Button.builder(TAB_BLOCKED, button -> this.showPage(SocialInteractionsScreen.Page.BLOCKED))
                .bounds(buttonRight - buttonWidth + 1, 45, buttonWidth, 20)
                .build()
        );
        String oldEdit = this.searchBox != null ? this.searchBox.getValue() : "";
        this.searchBox = this.addRenderableWidget(
            new EditBox(this.font, this.marginX() + 28, 74, 200, 15, SEARCH_HINT) {
                {
                    Objects.requireNonNull(SocialInteractionsScreen.this);
                }
 
                @Override
                protected MutableComponent createNarrationMessage() {
                    return !SocialInteractionsScreen.this.searchBox.getValue().isEmpty()
                            && SocialInteractionsScreen.this.socialInteractionsPlayerList.isEmpty()
                        ? super.createNarrationMessage().append(", ").append(SocialInteractionsScreen.EMPTY_SEARCH)
                        : super.createNarrationMessage();
                }
            }
        );
        this.searchBox.setMaxLength(16);
        this.searchBox.setVisible(true);
        this.searchBox.setTextColor(-1);
        this.searchBox.setValue(oldEdit);
        this.searchBox.setHint(SEARCH_HINT);
        this.searchBox.setResponder(this::checkSearchStringUpdate);
        this.blockingHintButton = this.addRenderableWidget(
            Button.builder(BLOCKING_HINT, ConfirmLinkScreen.confirmLink(this, CommonLinks.BLOCKING_HELP))
                .bounds(this.width / 2 - 100, 64 + this.windowHeight(), 200, 20)
                .build()
        );
        this.addWidget(this.socialInteractionsPlayerList);
        this.showPage(this.page);
        this.layout.addToFooter(Button.builder(CommonComponents.GUI_DONE, button -> this.onClose()).width(200).build());
        this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
        this.repositionElements();
    }
 
    @Override
    public void added() {
        if (this.socialInteractionsPlayerList != null) {
            this.socialInteractionsPlayerList.refreshHasDraftReport();
        }
    }
 
    @Override
    protected void repositionElements() {
        this.layout.arrangeElements();
        this.socialInteractionsPlayerList.updateSizeAndPosition(this.width, this.listEnd() - 88, 88);
        this.searchBox.setPosition(this.marginX() + 28, 74);
        int buttonLeft = this.socialInteractionsPlayerList.getRowLeft();
        int buttonRight = this.socialInteractionsPlayerList.getRowRight();
        int buttonWidth = this.socialInteractionsPlayerList.getRowWidth() / 3;
        this.allButton.setPosition(buttonLeft, 45);
        this.hiddenButton.setPosition((buttonLeft + buttonRight - buttonWidth) / 2 + 1, 45);
        this.blockedButton.setPosition(buttonRight - buttonWidth + 1, 45);
        this.blockingHintButton.setPosition(this.width / 2 - 100, 64 + this.windowHeight());
    }
 
    @Override
    protected void setInitialFocus() {
        this.setInitialFocus(this.searchBox);
    }
 
    @Override
    public void onClose() {
        this.minecraft.setScreen(this.lastScreen);
    }
 
    private void showPage(SocialInteractionsScreen.Page page) {
        this.page = page;
        this.allButton.setMessage(TAB_ALL);
        this.hiddenButton.setMessage(TAB_HIDDEN);
        this.blockedButton.setMessage(TAB_BLOCKED);
        boolean isEmpty = false;
        switch (page) {
            case ALL:
                this.allButton.setMessage(TAB_ALL_SELECTED);
                Collection<UUID> onlinePlayerIds = this.minecraft.player.connection.getOnlinePlayerIds();
                this.socialInteractionsPlayerList.updatePlayerList(onlinePlayerIds, this.socialInteractionsPlayerList.scrollAmount(), true);
                break;
            case HIDDEN:
                this.hiddenButton.setMessage(TAB_HIDDEN_SELECTED);
                Set<UUID> hiddenPlayers = this.minecraft.getPlayerSocialManager().getHiddenPlayers();
                isEmpty = hiddenPlayers.isEmpty();
                this.socialInteractionsPlayerList.updatePlayerList(hiddenPlayers, this.socialInteractionsPlayerList.scrollAmount(), false);
                break;
            case BLOCKED:
                this.blockedButton.setMessage(TAB_BLOCKED_SELECTED);
                PlayerSocialManager socialManager = this.minecraft.getPlayerSocialManager();
                Set<UUID> blockedPlayers = this.minecraft
                    .player
                    .connection
                    .getOnlinePlayerIds()
                    .stream()
                    .filter(socialManager::isBlocked)
                    .collect(Collectors.toSet());
                isEmpty = blockedPlayers.isEmpty();
                this.socialInteractionsPlayerList.updatePlayerList(blockedPlayers, this.socialInteractionsPlayerList.scrollAmount(), false);
        }
 
        GameNarrator narrator = this.minecraft.getNarrator();
        if (!this.searchBox.getValue().isEmpty() && this.socialInteractionsPlayerList.isEmpty() && !this.searchBox.isFocused()) {
            narrator.saySystemNow(EMPTY_SEARCH);
        } else if (isEmpty) {
            if (page == SocialInteractionsScreen.Page.HIDDEN) {
                narrator.saySystemNow(EMPTY_HIDDEN);
            } else if (page == SocialInteractionsScreen.Page.BLOCKED) {
                narrator.saySystemNow(EMPTY_BLOCKED);
            }
        }
    }
 
    @Override
    public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
        super.extractBackground(graphics, mouseX, mouseY, a);
        int marginX = this.marginX() + 3;
        graphics.blitSprite(RenderPipelines.GUI_TEXTURED, BACKGROUND_SPRITE, marginX, 64, 236, this.windowHeight() + 16);
        graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SEARCH_SPRITE, marginX + 10, 76, 12, 12);
    }
 
    @Override
    public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
        super.extractRenderState(graphics, mouseX, mouseY, a);
        this.updateServerLabel(this.minecraft);
        if (this.serverLabel != null) {
            graphics.text(this.minecraft.font, this.serverLabel, this.marginX() + 8, 35, -1);
        }
 
        if (!this.socialInteractionsPlayerList.isEmpty()) {
            this.socialInteractionsPlayerList.extractRenderState(graphics, mouseX, mouseY, a);
        } else if (!this.searchBox.getValue().isEmpty()) {
            graphics.centeredText(this.minecraft.font, EMPTY_SEARCH, this.width / 2, (72 + this.listEnd()) / 2, -1);
        } else if (this.page == SocialInteractionsScreen.Page.HIDDEN) {
            graphics.centeredText(this.minecraft.font, EMPTY_HIDDEN, this.width / 2, (72 + this.listEnd()) / 2, -1);
        } else if (this.page == SocialInteractionsScreen.Page.BLOCKED) {
            graphics.centeredText(this.minecraft.font, EMPTY_BLOCKED, this.width / 2, (72 + this.listEnd()) / 2, -1);
        }
 
        this.blockingHintButton.visible = this.page == SocialInteractionsScreen.Page.BLOCKED;
    }
 
    @Override
    public boolean keyPressed(KeyEvent event) {
        if (!this.searchBox.isFocused() && this.minecraft.options.keySocialInteractions.matches(event)) {
            this.onClose();
            return true;
        } else {
            return super.keyPressed(event);
        }
    }
 
    @Override
    public boolean isPauseScreen() {
        return false;
    }
 
    private void checkSearchStringUpdate(String searchText) {
        searchText = searchText.toLowerCase(Locale.ROOT);
        if (!searchText.equals(this.lastSearch)) {
            this.socialInteractionsPlayerList.setFilter(searchText);
            this.lastSearch = searchText;
            this.showPage(this.page);
        }
    }
 
    private void updateServerLabel(Minecraft minecraft) {
        int playerCount = minecraft.getConnection().getOnlinePlayers().size();
        if (this.playerCount != playerCount) {
            String serverName = "";
            ServerData currentServer = minecraft.getCurrentServer();
            if (minecraft.isLocalServer()) {
                serverName = minecraft.getSingleplayerServer().getMotd();
            } else if (currentServer != null) {
                serverName = currentServer.name;
            }
 
            if (playerCount > 1) {
                this.serverLabel = Component.translatable("gui.socialInteractions.server_label.multiple", serverName, playerCount);
            } else {
                this.serverLabel = Component.translatable("gui.socialInteractions.server_label.single", serverName, playerCount);
            }
 
            this.playerCount = playerCount;
        }
    }
 
    public void onAddPlayer(PlayerInfo info) {
        this.socialInteractionsPlayerList.addPlayer(info, this.page);
    }
 
    public void onRemovePlayer(UUID id) {
        this.socialInteractionsPlayerList.removePlayer(id);
    }
 
    @OnlyIn(Dist.CLIENT)
    public static enum Page {
        ALL,
        HIDDEN,
        BLOCKED;
    }
}

引用的其他类

  • Minecraft

    • 引用位置: 参数/方法调用
    • 关联成员: Minecraft.getInstance()
  • GuiGraphicsExtractor

    • 引用位置: 参数
  • Button

    • 引用位置: 字段/方法调用
    • 关联成员: Button.builder()
  • EditBox

    • 引用位置: 字段/构造调用
    • 关联成员: EditBox()
  • HeaderAndFooterLayout

    • 引用位置: 字段/构造调用
    • 关联成员: HeaderAndFooterLayout()
  • ConfirmLinkScreen

    • 引用位置: 方法调用
    • 关联成员: ConfirmLinkScreen.confirmLink()
  • Screen

    • 引用位置: 参数/字段/继承
  • SocialInteractionsPlayerList

    • 引用位置: 字段/构造调用
    • 关联成员: SocialInteractionsPlayerList()
  • KeyEvent

    • 引用位置: 参数
  • PlayerInfo

    • 引用位置: 参数
  • CommonComponents

    • 引用位置: 方法调用
    • 关联成员: CommonComponents.joinForNarration()
  • Component

    • 引用位置: 字段/方法调用/返回值
    • 关联成员: Component.translatable()
  • Identifier

    • 引用位置: 字段/方法调用
    • 关联成员: Identifier.withDefaultNamespace()