RestrictionsScreen.java

net.minecraft.client.gui.screens.multiplayer.RestrictionsScreen

信息

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

    TODO

字段/常量

  • TITLE

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

      TODO

  • previousScreen

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

      TODO

  • chatAbilities

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

      TODO

  • layout

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

      TODO

  • bodyScroll

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

      TODO

内部类/嵌套类型

构造器

public RestrictionsScreen(Screen previousScreen, ChatAbilities chatAbilities) @ L34

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

参数:

  • previousScreen: Screen
  • chatAbilities: ChatAbilities

说明:

TODO

方法

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

protected void init() @ L40

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

参数:

说明:

TODO

private static Component createPermissionStatus(ChatAbilities abilities, Permission permission, String permissionId) @ L94

  • 方法名:createPermissionStatus
  • 源码定位:L94
  • 返回类型:Component
  • 修饰符:private static

参数:

  • abilities: ChatAbilities
  • permission: Permission
  • permissionId: String

说明:

TODO

public void onClose() @ L102

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

参数:

说明:

TODO

protected void repositionElements() @ L107

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

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class RestrictionsScreen extends Screen {
    private static final Component TITLE = Component.translatable("restrictions_screen.title");
    private final Screen previousScreen;
    private final ChatAbilities chatAbilities;
    private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
    private @Nullable ScrollableLayout bodyScroll;
 
    public RestrictionsScreen(Screen previousScreen, ChatAbilities chatAbilities) {
        super(TITLE);
        this.previousScreen = previousScreen;
        this.chatAbilities = chatAbilities;
    }
 
    @Override
    protected void init() {
        this.layout.addToHeader(new StringWidget(TITLE, this.font), LayoutSettings::alignHorizontallyCenter);
        LinearLayout body = LinearLayout.vertical();
        body.defaultCellSetting().alignHorizontallyCenter();
        int textBoxWidth = 250;
        this.chatAbilities
            .restrictions()
            .forEach(
                restriction -> {
                    body.addChild(
                        FocusableTextWidget.builder(
                                ComponentUtils.mergeStyles(restriction.display(), Style.EMPTY.withBold(true).withColor(ChatFormatting.RED)), this.font
                            )
                            .maxWidth(250)
                            .alwaysShowBorder(false)
                            .backgroundFill(FocusableTextWidget.BackgroundFill.ON_FOCUS)
                            .build()
                            .setCentered(true)
                    );
                    restriction.action()
                        .ifPresent(
                            action -> body.addChild(
                                Button.builder(action.title(), var2x -> action.runnable().accept(this.minecraft, this.previousScreen)).width(200).build()
                            )
                        );
                }
            );
        if (this.chatAbilities.hasAnyRestrictions()) {
            body.addChild(new SpacerElement(10, 10));
        }
 
        List<Component> permissionEntries = new ArrayList<>();
        permissionEntries.add(createPermissionStatus(this.chatAbilities, Permissions.CHAT_SEND_MESSAGES, "send_messages"));
        permissionEntries.add(createPermissionStatus(this.chatAbilities, Permissions.CHAT_SEND_COMMANDS, "send_commands"));
        permissionEntries.add(createPermissionStatus(this.chatAbilities, Permissions.CHAT_RECEIVE_SYSTEM_MESSAGES, "receive_system_messages"));
        permissionEntries.add(createPermissionStatus(this.chatAbilities, Permissions.CHAT_RECEIVE_PLAYER_MESSAGES, "receive_player_messages"));
        Component message = CommonComponents.joinLines(permissionEntries);
        body.addChild(
            FocusableTextWidget.builder(message, this.font)
                .maxWidth(250)
                .alwaysShowBorder(false)
                .backgroundFill(FocusableTextWidget.BackgroundFill.ON_FOCUS)
                .build()
                .setCentered(true)
        );
        this.bodyScroll = new ScrollableLayout(this.minecraft, body, this.layout.getContentHeight());
        this.layout.addToContents(this.bodyScroll);
        LinearLayout footer = this.layout.addToFooter(LinearLayout.horizontal().spacing(8));
        footer.addChild(Button.builder(CommonComponents.GUI_DONE, var1x -> this.onClose()).width(200).build());
        this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
        this.repositionElements();
    }
 
    private static Component createPermissionStatus(ChatAbilities abilities, Permission permission, String permissionId) {
        boolean isAllowed = abilities.permissions().hasPermission(permission);
        String prefix = "restrictions_screen.permission." + permissionId;
        return isAllowed
            ? Component.translatable(prefix + ".allowed").withStyle(ChatFormatting.GREEN)
            : Component.translatable(prefix + ".denied").withStyle(ChatFormatting.RED);
    }
 
    @Override
    public void onClose() {
        this.minecraft.setScreen(this.previousScreen);
    }
 
    @Override
    protected void repositionElements() {
        this.bodyScroll.arrangeElements();
        this.bodyScroll.setMaxHeight(this.layout.getContentHeight());
        this.layout.arrangeElements();
    }
}

引用的其他类

  • Button

    • 引用位置: 方法调用
    • 关联成员: Button.builder()
  • FocusableTextWidget

    • 引用位置: 方法调用
    • 关联成员: FocusableTextWidget.builder()
  • ScrollableLayout

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

    • 引用位置: 构造调用
    • 关联成员: StringWidget()
  • HeaderAndFooterLayout

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

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

    • 引用位置: 构造调用
    • 关联成员: SpacerElement()
  • Screen

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

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

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

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

    • 引用位置: 方法调用
    • 关联成员: ComponentUtils.mergeStyles()
  • Permission

    • 引用位置: 参数