SelectWorldScreen.java

net.minecraft.client.gui.screens.worldselection.SelectWorldScreen

信息

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

    TODO

字段/常量

  • LOGGER

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

      TODO

  • TEST_OPTIONS

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

      TODO

  • lastScreen

    • 类型: Screen
    • 修饰符: protected final
    • 源码定位: L33
    • 说明:

      TODO

  • layout

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

      TODO

  • deleteButton

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

      TODO

  • playWorldButton

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

      TODO

  • editButton

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

      TODO

  • recreateButton

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

      TODO

  • searchBox

    • 类型: EditBox
    • 修饰符: protected
    • 源码定位: L39
    • 说明:

      TODO

  • list

    • 类型: WorldSelectionList
    • 修饰符: private
    • 源码定位: L40
    • 说明:

      TODO

内部类/嵌套类型

构造器

public SelectWorldScreen(Screen lastScreen) @ L42

  • 构造器名:SelectWorldScreen
  • 源码定位:L42
  • 修饰符:public

参数:

  • lastScreen: Screen

说明:

TODO

方法

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

protected void init() @ L47

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

参数:

说明:

TODO

private void createFooterButtons(Consumer<WorldSelectionList.WorldListEntry> joinWorld, WorldSelectionList list) @ L84

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

参数:

  • joinWorld: Consumer<WorldSelectionList.WorldListEntry>
  • list: WorldSelectionList

说明:

TODO

private Button createDebugWorldRecreateButton() @ L115

  • 方法名:createDebugWorldRecreateButton
  • 源码定位:L115
  • 返回类型:Button
  • 修饰符:private

参数:

说明:

TODO

protected void repositionElements() @ L144

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

参数:

说明:

TODO

protected void setInitialFocus() @ L153

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

参数:

说明:

TODO

public void onClose() @ L160

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

参数:

说明:

TODO

public void updateButtonStatus(LevelSummary summary) @ L165

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

参数:

  • summary: LevelSummary

说明:

TODO

public void removed() @ L192

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

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class SelectWorldScreen extends Screen {
    private static final Logger LOGGER = LogUtils.getLogger();
    public static final WorldOptions TEST_OPTIONS = new WorldOptions("test1".hashCode(), true, false);
    protected final Screen lastScreen;
    private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this, 8 + 9 + 8 + 20 + 4, 60);
    private @Nullable Button deleteButton;
    private @Nullable Button playWorldButton;
    private @Nullable Button editButton;
    private @Nullable Button recreateButton;
    protected @Nullable EditBox searchBox;
    private @Nullable WorldSelectionList list;
 
    public SelectWorldScreen(Screen lastScreen) {
        super(Component.translatable("selectWorld.title"));
        this.lastScreen = lastScreen;
    }
 
    @Override
    protected void init() {
        LinearLayout header = this.layout.addToHeader(LinearLayout.vertical().spacing(4));
        header.defaultCellSetting().alignHorizontallyCenter();
        header.addChild(new StringWidget(this.title, this.font));
        LinearLayout subHeader = header.addChild(LinearLayout.horizontal().spacing(4));
        if (SharedConstants.DEBUG_WORLD_RECREATE) {
            subHeader.addChild(this.createDebugWorldRecreateButton());
        }
 
        this.searchBox = subHeader.addChild(
            new EditBox(this.font, this.width / 2 - 100, 22, 200, 20, this.searchBox, Component.translatable("selectWorld.search"))
        );
        this.searchBox.setResponder(value -> {
            if (this.list != null) {
                this.list.updateFilter(value);
            }
        });
        this.searchBox.setHint(Component.translatable("gui.selectWorld.search").setStyle(EditBox.SEARCH_HINT_STYLE));
        Consumer<WorldSelectionList.WorldListEntry> joinWorld = WorldSelectionList.WorldListEntry::joinWorld;
        this.list = this.layout
            .addToContents(
                new WorldSelectionList.Builder(this.minecraft, this)
                    .width(this.width)
                    .height(this.layout.getContentHeight())
                    .filter(this.searchBox.getValue())
                    .oldList(this.list)
                    .onEntrySelect(this::updateButtonStatus)
                    .onEntryInteract(joinWorld)
                    .build()
            );
        this.createFooterButtons(joinWorld, this.list);
        this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
        this.repositionElements();
        this.updateButtonStatus(null);
    }
 
    private void createFooterButtons(Consumer<WorldSelectionList.WorldListEntry> joinWorld, WorldSelectionList list) {
        GridLayout footer = this.layout.addToFooter(new GridLayout().columnSpacing(8).rowSpacing(4));
        footer.defaultCellSetting().alignHorizontallyCenter();
        GridLayout.RowHelper rowHelper = footer.createRowHelper(4);
        this.playWorldButton = rowHelper.addChild(Button.builder(LevelSummary.PLAY_WORLD, button -> list.getSelectedOpt().ifPresent(joinWorld)).build(), 2);
        rowHelper.addChild(
            Button.builder(Component.translatable("selectWorld.create"), button -> CreateWorldScreen.openFresh(this.minecraft, list::returnToScreen)).build(),
            2
        );
        this.editButton = rowHelper.addChild(
            Button.builder(Component.translatable("selectWorld.edit"), button -> list.getSelectedOpt().ifPresent(WorldSelectionList.WorldListEntry::editWorld))
                .width(71)
                .build()
        );
        this.deleteButton = rowHelper.addChild(
            Button.builder(
                    Component.translatable("selectWorld.delete"), button -> list.getSelectedOpt().ifPresent(WorldSelectionList.WorldListEntry::deleteWorld)
                )
                .width(71)
                .build()
        );
        this.recreateButton = rowHelper.addChild(
            Button.builder(
                    Component.translatable("selectWorld.recreate"), button -> list.getSelectedOpt().ifPresent(WorldSelectionList.WorldListEntry::recreateWorld)
                )
                .width(71)
                .build()
        );
        rowHelper.addChild(Button.builder(CommonComponents.GUI_BACK, button -> this.minecraft.setScreen(this.lastScreen)).width(71).build());
    }
 
    private Button createDebugWorldRecreateButton() {
        return Button.builder(
                Component.literal("DEBUG recreate"),
                button -> {
                    try {
                        String levelName = "DEBUG world";
                        if (this.list != null && !this.list.children().isEmpty()) {
                            WorldSelectionList.Entry entry = this.list.children().getFirst();
                            if (entry instanceof WorldSelectionList.WorldListEntry worldEntry && worldEntry.getLevelName().equals("DEBUG world")) {
                                worldEntry.doDeleteWorld();
                            }
                        }
 
                        LevelSettings levelSettings = new LevelSettings(
                            "DEBUG world", GameType.SPECTATOR, LevelSettings.DifficultySettings.DEFAULT, true, WorldDataConfiguration.DEFAULT
                        );
                        String resultFolder = FileUtil.findAvailableName(this.minecraft.getLevelSource().getBaseDir(), "DEBUG world", "");
                        this.minecraft
                            .createWorldOpenFlows()
                            .createFreshLevel(resultFolder, levelSettings, TEST_OPTIONS, WorldPresets::createNormalWorldDimensions, this);
                    } catch (IOException var5) {
                        LOGGER.error("Failed to recreate the debug world", (Throwable)var5);
                    }
                }
            )
            .width(72)
            .build();
    }
 
    @Override
    protected void repositionElements() {
        if (this.list != null) {
            this.list.updateSize(this.width, this.layout);
        }
 
        this.layout.arrangeElements();
    }
 
    @Override
    protected void setInitialFocus() {
        if (this.searchBox != null) {
            this.setInitialFocus(this.searchBox);
        }
    }
 
    @Override
    public void onClose() {
        this.minecraft.setScreen(this.lastScreen);
    }
 
    public void updateButtonStatus(@Nullable LevelSummary summary) {
        if (this.playWorldButton != null && this.editButton != null && this.recreateButton != null && this.deleteButton != null) {
            if (summary == null) {
                this.playWorldButton.setMessage(LevelSummary.PLAY_WORLD);
                this.playWorldButton.active = false;
                this.editButton.active = false;
                this.recreateButton.active = false;
                this.deleteButton.active = false;
            } else {
                this.playWorldButton.setMessage(summary.primaryActionMessage());
                this.playWorldButton.active = summary.primaryActionActive();
                this.editButton.active = summary.canEdit();
                this.recreateButton.active = summary.canRecreate();
                this.deleteButton.active = summary.canDelete();
                if (summary.requiresFileFixing()) {
                    this.editButton.setTooltip(Tooltip.create(Component.translatable("selectWorld.requiresFileFixingTooltip.edit")));
                    this.playWorldButton.setTooltip(Tooltip.create(Component.translatable("selectWorld.requiresFileFixingTooltip.play")));
                    this.recreateButton.setTooltip(Tooltip.create(Component.translatable("selectWorld.requiresFileFixingTooltip.recreate")));
                } else {
                    this.editButton.setTooltip(null);
                    this.playWorldButton.setTooltip(null);
                    this.recreateButton.setTooltip(null);
                }
            }
        }
    }
 
    @Override
    public void removed() {
        if (this.list != null) {
            this.list.children().forEach(WorldSelectionList.Entry::close);
        }
    }
}

引用的其他类

  • Button

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

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

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

    • 引用位置: 方法调用
    • 关联成员: Tooltip.create()
  • GridLayout

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

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

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

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

    • 引用位置: 方法调用
    • 关联成员: CreateWorldScreen.openFresh()
  • WorldSelectionList

    • 引用位置: 参数/字段/方法调用/构造调用
    • 关联成员: Builder(), WorldSelectionList.Builder()
  • Component

    • 引用位置: 方法调用
    • 关联成员: Component.literal(), Component.translatable()
  • FileUtil

    • 引用位置: 方法调用
    • 关联成员: FileUtil.findAvailableName()
  • LevelSettings

    • 引用位置: 构造调用
    • 关联成员: LevelSettings()
  • WorldOptions

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

    • 引用位置: 参数