RealmsInviteScreen.java

com.mojang.realmsclient.gui.screens.configuration.RealmsInviteScreen

信息

  • 全限定名:com.mojang.realmsclient.gui.screens.configuration.RealmsInviteScreen
  • 类型:public class
  • 包:com.mojang.realmsclient.gui.screens.configuration
  • 源码路径:src/main/java/com/mojang/realmsclient/gui/screens/configuration/RealmsInviteScreen.java
  • 起始行号:L21
  • 继承:RealmsScreen
  • 职责:

    TODO

字段/常量

  • TITLE

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

      TODO

  • NAME_LABEL

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

      TODO

  • INVITING_PLAYER_TEXT

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

      TODO

  • NO_SUCH_PLAYER_ERROR_TEXT

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

      TODO

  • DUPLICATE_PLAYER_TEXT

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

      TODO

  • layout

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

      TODO

  • profileName

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

      TODO

  • inviteButton

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

      TODO

  • serverData

    • 类型: RealmsServer
    • 修饰符: private final
    • 源码定位: L30
    • 说明:

      TODO

  • configureScreen

    • 类型: RealmsConfigureWorldScreen
    • 修饰符: private final
    • 源码定位: L31
    • 说明:

      TODO

  • message

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

      TODO

内部类/嵌套类型

构造器

public RealmsInviteScreen(RealmsConfigureWorldScreen configureScreen, RealmsServer serverData) @ L34

  • 构造器名:RealmsInviteScreen
  • 源码定位:L34
  • 修饰符:public

参数:

  • configureScreen: RealmsConfigureWorldScreen
  • serverData: RealmsServer

说明:

TODO

方法

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

public void init() @ L40

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

参数:

说明:

TODO

protected void repositionElements() @ L52

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

参数:

说明:

TODO

protected void setInitialFocus() @ L57

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

参数:

说明:

TODO

private void onInvite() @ L64

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

参数:

说明:

TODO

private void showMessage(Component message) @ L90

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

参数:

  • message: Component

说明:

TODO

public void onClose() @ L95

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

参数:

说明:

TODO

public void extractRenderState(GuiGraphicsExtractor graphics, int xm, int ym, float a) @ L100

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

参数:

  • graphics: GuiGraphicsExtractor
  • xm: int
  • ym: int
  • a: float

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class RealmsInviteScreen extends RealmsScreen {
    private static final Component TITLE = Component.translatable("mco.configure.world.buttons.invite");
    private static final Component NAME_LABEL = Component.translatable("mco.configure.world.invite.profile.name").withColor(-6250336);
    private static final Component INVITING_PLAYER_TEXT = Component.translatable("mco.configure.world.players.inviting").withColor(-6250336);
    private static final Component NO_SUCH_PLAYER_ERROR_TEXT = Component.translatable("mco.configure.world.players.error").withColor(-65536);
    private static final Component DUPLICATE_PLAYER_TEXT = Component.translatable("mco.configure.world.players.invite.duplicate").withColor(-65536);
    private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
    private @Nullable EditBox profileName;
    private @Nullable Button inviteButton;
    private final RealmsServer serverData;
    private final RealmsConfigureWorldScreen configureScreen;
    private @Nullable Component message;
 
    public RealmsInviteScreen(RealmsConfigureWorldScreen configureScreen, RealmsServer serverData) {
        super(TITLE);
        this.configureScreen = configureScreen;
        this.serverData = serverData;
    }
 
    @Override
    public void init() {
        this.layout.addTitleHeader(TITLE, this.font);
        LinearLayout content = this.layout.addToContents(LinearLayout.vertical().spacing(8));
        this.profileName = new EditBox(this.minecraft.font, 200, 20, Component.translatable("mco.configure.world.invite.profile.name"));
        content.addChild(CommonLayouts.labeledElement(this.font, this.profileName, NAME_LABEL));
        this.inviteButton = content.addChild(Button.builder(TITLE, button -> this.onInvite()).width(200).build());
        this.layout.addToFooter(Button.builder(CommonComponents.GUI_BACK, button -> this.onClose()).width(200).build());
        this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
        this.repositionElements();
    }
 
    @Override
    protected void repositionElements() {
        this.layout.arrangeElements();
    }
 
    @Override
    protected void setInitialFocus() {
        if (this.profileName != null) {
            this.setInitialFocus(this.profileName);
        }
    }
 
    private void onInvite() {
        if (this.inviteButton != null && this.profileName != null) {
            if (StringUtil.isBlank(this.profileName.getValue())) {
                this.showMessage(NO_SUCH_PLAYER_ERROR_TEXT);
            } else if (this.serverData.players.stream().anyMatch(player -> player.name.equalsIgnoreCase(this.profileName.getValue()))) {
                this.showMessage(DUPLICATE_PLAYER_TEXT);
            } else {
                long serverId = this.serverData.id;
                String name = this.profileName.getValue().trim();
                this.inviteButton.active = false;
                this.profileName.setEditable(false);
                this.showMessage(INVITING_PLAYER_TEXT);
                CompletableFuture.<Boolean>supplyAsync(() -> this.configureScreen.invitePlayer(serverId, name), Util.ioPool()).thenAcceptAsync(success -> {
                    if (success) {
                        this.minecraft.setScreen(this.configureScreen);
                    } else {
                        this.showMessage(NO_SUCH_PLAYER_ERROR_TEXT);
                    }
 
                    this.profileName.setEditable(true);
                    this.inviteButton.active = true;
                }, this.screenExecutor);
            }
        }
    }
 
    private void showMessage(Component message) {
        this.message = message;
        this.minecraft.getNarrator().saySystemNow(message);
    }
 
    @Override
    public void onClose() {
        this.minecraft.setScreen(this.configureScreen);
    }
 
    @Override
    public void extractRenderState(GuiGraphicsExtractor graphics, int xm, int ym, float a) {
        super.extractRenderState(graphics, xm, ym, a);
        if (this.message != null && this.inviteButton != null) {
            graphics.centeredText(this.font, this.message, this.width / 2, this.inviteButton.getY() + this.inviteButton.getHeight() + 8, -1);
        }
    }
}

引用的其他类

  • RealmsServer

    • 引用位置: 参数/字段
  • RealmsConfigureWorldScreen

    • 引用位置: 参数/字段
  • GuiGraphicsExtractor

    • 引用位置: 参数
  • Button

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

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

    • 引用位置: 方法调用
    • 关联成员: CommonLayouts.labeledElement()
  • HeaderAndFooterLayout

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

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

    • 引用位置: 参数/字段/方法调用
    • 关联成员: Component.translatable()
  • RealmsScreen

    • 引用位置: 继承
  • StringUtil

    • 引用位置: 方法调用
    • 关联成员: StringUtil.isBlank()
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.ioPool()