RealmsResetWorldScreen.java

com.mojang.realmsclient.gui.screens.RealmsResetWorldScreen

信息

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

    TODO

字段/常量

  • LOGGER

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

      TODO

  • CREATE_REALM_TITLE

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

      TODO

  • CREATE_REALM_SUBTITLE

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

      TODO

  • CREATE_WORLD_TITLE

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

      TODO

  • CREATE_WORLD_SUBTITLE

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

      TODO

  • GENERATE_NEW_WORLD

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

      TODO

  • RESET_WORLD_TITLE

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

      TODO

  • RESET_WORLD_SUBTITLE

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

      TODO

  • CREATE_WORLD_RESET_TASK_TITLE

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

      TODO

  • RESET_WORLD_RESET_TASK_TITLE

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

      TODO

  • WORLD_TEMPLATES_TITLE

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

      TODO

  • ADVENTURES_TITLE

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

      TODO

  • EXPERIENCES_TITLE

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

      TODO

  • INSPIRATION_TITLE

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

      TODO

  • lastScreen

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

      TODO

  • serverData

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

      TODO

  • subtitle

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

      TODO

  • resetTaskTitle

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

      TODO

  • UPLOAD_LOCATION

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

      TODO

  • ADVENTURE_MAP_LOCATION

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

      TODO

  • SURVIVAL_SPAWN_LOCATION

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

      TODO

  • NEW_WORLD_LOCATION

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

      TODO

  • EXPERIENCE_LOCATION

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

      TODO

  • INSPIRATION_LOCATION

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

      TODO

  • templates

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

      TODO

  • adventuremaps

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

      TODO

  • experiences

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

      TODO

  • inspirations

    • 类型: WorldTemplatePaginatedList
    • 修饰符: private
    • 源码定位: L68
    • 说明:

      TODO

  • slot

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

      TODO

  • realmCreationTask

    • 类型: RealmCreationTask
    • 修饰符: private final
    • 源码定位: L70
    • 说明:

      TODO

  • resetWorldRunnable

    • 类型: Runnable
    • 修饰符: private final
    • 源码定位: L71
    • 说明:

      TODO

  • layout

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

      TODO

内部类/嵌套类型

  • com.mojang.realmsclient.gui.screens.RealmsResetWorldScreen.FrameButton
    • 类型: class
    • 修饰符: private
    • 源码定位: L274
    • 说明:

      TODO

构造器

private RealmsResetWorldScreen(Screen lastScreen, RealmsServer serverData, int slot, Component title, Component subtitle, Component resetTaskTitle, Runnable resetWorldRunnable) @ L74

  • 构造器名:RealmsResetWorldScreen
  • 源码定位:L74
  • 修饰符:private

参数:

  • lastScreen: Screen
  • serverData: RealmsServer
  • slot: int
  • title: Component
  • subtitle: Component
  • resetTaskTitle: Component
  • resetWorldRunnable: Runnable

说明:

TODO

public RealmsResetWorldScreen(Screen lastScreen, RealmsServer serverData, int slot, Component title, Component subtitle, Component resetTaskTitle, RealmCreationTask realmCreationTask, Runnable resetWorldRunnable) @ L80

  • 构造器名:RealmsResetWorldScreen
  • 源码定位:L80
  • 修饰符:public

参数:

  • lastScreen: Screen
  • serverData: RealmsServer
  • slot: int
  • title: Component
  • subtitle: Component
  • resetTaskTitle: Component
  • realmCreationTask: RealmCreationTask
  • resetWorldRunnable: Runnable

说明:

TODO

方法

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

public static RealmsResetWorldScreen forNewRealm(Screen lastScreen, RealmsServer serverData, RealmCreationTask realmCreationTask, Runnable resetWorldRunnable) @ L100

  • 方法名:forNewRealm
  • 源码定位:L100
  • 返回类型:RealmsResetWorldScreen
  • 修饰符:public static

参数:

  • lastScreen: Screen
  • serverData: RealmsServer
  • realmCreationTask: RealmCreationTask
  • resetWorldRunnable: Runnable

说明:

TODO

public static RealmsResetWorldScreen forEmptySlot(Screen lastScreen, int slot, RealmsServer serverData, Runnable resetWorldRunnable) @ L115

  • 方法名:forEmptySlot
  • 源码定位:L115
  • 返回类型:RealmsResetWorldScreen
  • 修饰符:public static

参数:

  • lastScreen: Screen
  • slot: int
  • serverData: RealmsServer
  • resetWorldRunnable: Runnable

说明:

TODO

public static RealmsResetWorldScreen forResetSlot(Screen lastScreen, RealmsServer serverData, Runnable resetWorldRunnable) @ L121

  • 方法名:forResetSlot
  • 源码定位:L121
  • 返回类型:RealmsResetWorldScreen
  • 修饰符:public static

参数:

  • lastScreen: Screen
  • serverData: RealmsServer
  • resetWorldRunnable: Runnable

说明:

TODO

public void init() @ L127

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

参数:

说明:

TODO

protected void repositionElements() @ L235

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

参数:

说明:

TODO

public Component getNarrationMessage() @ L240

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

参数:

说明:

TODO

public void onClose() @ L245

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

参数:

说明:

TODO

private void templateSelectionCallback(WorldTemplate template) @ L250

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

参数:

  • template: WorldTemplate

说明:

TODO

private void runResetTasks(LongRunningTask resetTask) @ L259

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

参数:

  • resetTask: LongRunningTask

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class RealmsResetWorldScreen extends RealmsScreen {
    private static final Logger LOGGER = LogUtils.getLogger();
    private static final Component CREATE_REALM_TITLE = Component.translatable("mco.selectServer.create");
    private static final Component CREATE_REALM_SUBTITLE = Component.translatable("mco.selectServer.create.subtitle").withColor(-6250336);
    private static final Component CREATE_WORLD_TITLE = Component.translatable("mco.configure.world.switch.slot");
    private static final Component CREATE_WORLD_SUBTITLE = Component.translatable("mco.configure.world.switch.slot.subtitle").withColor(-6250336);
    private static final Component GENERATE_NEW_WORLD = Component.translatable("mco.reset.world.generate");
    private static final Component RESET_WORLD_TITLE = Component.translatable("mco.reset.world.title");
    private static final Component RESET_WORLD_SUBTITLE = Component.translatable("mco.reset.world.warning").withColor(-65536);
    public static final Component CREATE_WORLD_RESET_TASK_TITLE = Component.translatable("mco.create.world.reset.title");
    private static final Component RESET_WORLD_RESET_TASK_TITLE = Component.translatable("mco.reset.world.resetting.screen.title");
    private static final Component WORLD_TEMPLATES_TITLE = Component.translatable("mco.reset.world.template");
    private static final Component ADVENTURES_TITLE = Component.translatable("mco.reset.world.adventure");
    private static final Component EXPERIENCES_TITLE = Component.translatable("mco.reset.world.experience");
    private static final Component INSPIRATION_TITLE = Component.translatable("mco.reset.world.inspiration");
    private final Screen lastScreen;
    private final RealmsServer serverData;
    private final Component subtitle;
    private final Component resetTaskTitle;
    private static final Identifier UPLOAD_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/upload.png");
    private static final Identifier ADVENTURE_MAP_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/adventure.png");
    private static final Identifier SURVIVAL_SPAWN_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/survival_spawn.png");
    private static final Identifier NEW_WORLD_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/new_world.png");
    private static final Identifier EXPERIENCE_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/experience.png");
    private static final Identifier INSPIRATION_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/inspiration.png");
    private WorldTemplatePaginatedList templates;
    private WorldTemplatePaginatedList adventuremaps;
    private WorldTemplatePaginatedList experiences;
    private WorldTemplatePaginatedList inspirations;
    public final int slot;
    private final @Nullable RealmCreationTask realmCreationTask;
    private final Runnable resetWorldRunnable;
    private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
 
    private RealmsResetWorldScreen(
        Screen lastScreen, RealmsServer serverData, int slot, Component title, Component subtitle, Component resetTaskTitle, Runnable resetWorldRunnable
    ) {
        this(lastScreen, serverData, slot, title, subtitle, resetTaskTitle, null, resetWorldRunnable);
    }
 
    public RealmsResetWorldScreen(
        Screen lastScreen,
        RealmsServer serverData,
        int slot,
        Component title,
        Component subtitle,
        Component resetTaskTitle,
        @Nullable RealmCreationTask realmCreationTask,
        Runnable resetWorldRunnable
    ) {
        super(title);
        this.lastScreen = lastScreen;
        this.serverData = serverData;
        this.slot = slot;
        this.subtitle = subtitle;
        this.resetTaskTitle = resetTaskTitle;
        this.realmCreationTask = realmCreationTask;
        this.resetWorldRunnable = resetWorldRunnable;
    }
 
    public static RealmsResetWorldScreen forNewRealm(
        Screen lastScreen, RealmsServer serverData, RealmCreationTask realmCreationTask, Runnable resetWorldRunnable
    ) {
        return new RealmsResetWorldScreen(
            lastScreen,
            serverData,
            serverData.activeSlot,
            CREATE_REALM_TITLE,
            CREATE_REALM_SUBTITLE,
            CREATE_WORLD_RESET_TASK_TITLE,
            realmCreationTask,
            resetWorldRunnable
        );
    }
 
    public static RealmsResetWorldScreen forEmptySlot(Screen lastScreen, int slot, RealmsServer serverData, Runnable resetWorldRunnable) {
        return new RealmsResetWorldScreen(
            lastScreen, serverData, slot, CREATE_WORLD_TITLE, CREATE_WORLD_SUBTITLE, CREATE_WORLD_RESET_TASK_TITLE, resetWorldRunnable
        );
    }
 
    public static RealmsResetWorldScreen forResetSlot(Screen lastScreen, RealmsServer serverData, Runnable resetWorldRunnable) {
        return new RealmsResetWorldScreen(
            lastScreen, serverData, serverData.activeSlot, RESET_WORLD_TITLE, RESET_WORLD_SUBTITLE, RESET_WORLD_RESET_TASK_TITLE, resetWorldRunnable
        );
    }
 
    @Override
    public void init() {
        LinearLayout header = this.layout.addToHeader(LinearLayout.vertical());
        header.defaultCellSetting().padding(9 / 3);
        header.addChild(new StringWidget(this.title, this.font), LayoutSettings::alignHorizontallyCenter);
        header.addChild(new StringWidget(this.subtitle, this.font), LayoutSettings::alignHorizontallyCenter);
        (new Thread("Realms-reset-world-fetcher") {
            {
                Objects.requireNonNull(RealmsResetWorldScreen.this);
            }
 
            @Override
            public void run() {
                RealmsClient client = RealmsClient.getOrCreate();
 
                try {
                    WorldTemplatePaginatedList templates = client.fetchWorldTemplates(1, 10, RealmsServer.WorldType.NORMAL);
                    WorldTemplatePaginatedList adventuremaps = client.fetchWorldTemplates(1, 10, RealmsServer.WorldType.ADVENTUREMAP);
                    WorldTemplatePaginatedList experiences = client.fetchWorldTemplates(1, 10, RealmsServer.WorldType.EXPERIENCE);
                    WorldTemplatePaginatedList inspirations = client.fetchWorldTemplates(1, 10, RealmsServer.WorldType.INSPIRATION);
                    RealmsResetWorldScreen.this.minecraft.execute(() -> {
                        RealmsResetWorldScreen.this.templates = templates;
                        RealmsResetWorldScreen.this.adventuremaps = adventuremaps;
                        RealmsResetWorldScreen.this.experiences = experiences;
                        RealmsResetWorldScreen.this.inspirations = inspirations;
                    });
                } catch (RealmsServiceException var6) {
                    RealmsResetWorldScreen.LOGGER.error("Couldn't fetch templates in reset world", (Throwable)var6);
                }
            }
        }).start();
        GridLayout grid = this.layout.addToContents(new GridLayout());
        GridLayout.RowHelper helper = grid.createRowHelper(3);
        helper.defaultCellSetting().paddingHorizontal(16);
        helper.addChild(
            new RealmsResetWorldScreen.FrameButton(
                this.minecraft.font,
                GENERATE_NEW_WORLD,
                NEW_WORLD_LOCATION,
                button -> RealmsCreateWorldFlow.createWorld(this.minecraft, this.lastScreen, this, this.slot, this.serverData, this.realmCreationTask)
            )
        );
        helper.addChild(
            new RealmsResetWorldScreen.FrameButton(
                this.minecraft.font,
                RealmsSelectFileToUploadScreen.TITLE,
                UPLOAD_LOCATION,
                button -> this.minecraft.setScreen(new RealmsSelectFileToUploadScreen(this.realmCreationTask, this.serverData.id, this.slot, this))
            )
        );
        helper.addChild(
            new RealmsResetWorldScreen.FrameButton(
                this.minecraft.font,
                WORLD_TEMPLATES_TITLE,
                SURVIVAL_SPAWN_LOCATION,
                button -> this.minecraft
                    .setScreen(
                        new RealmsSelectWorldTemplateScreen(
                            WORLD_TEMPLATES_TITLE, this::templateSelectionCallback, RealmsServer.WorldType.NORMAL, this.templates
                        )
                    )
            )
        );
        helper.addChild(SpacerElement.height(16), 3);
        helper.addChild(
            new RealmsResetWorldScreen.FrameButton(
                this.minecraft.font,
                ADVENTURES_TITLE,
                ADVENTURE_MAP_LOCATION,
                button -> this.minecraft
                    .setScreen(
                        new RealmsSelectWorldTemplateScreen(
                            ADVENTURES_TITLE, this::templateSelectionCallback, RealmsServer.WorldType.ADVENTUREMAP, this.adventuremaps
                        )
                    )
            )
        );
        helper.addChild(
            new RealmsResetWorldScreen.FrameButton(
                this.minecraft.font,
                EXPERIENCES_TITLE,
                EXPERIENCE_LOCATION,
                button -> this.minecraft
                    .setScreen(
                        new RealmsSelectWorldTemplateScreen(
                            EXPERIENCES_TITLE, this::templateSelectionCallback, RealmsServer.WorldType.EXPERIENCE, this.experiences
                        )
                    )
            )
        );
        helper.addChild(
            new RealmsResetWorldScreen.FrameButton(
                this.minecraft.font,
                INSPIRATION_TITLE,
                INSPIRATION_LOCATION,
                button -> this.minecraft
                    .setScreen(
                        new RealmsSelectWorldTemplateScreen(
                            INSPIRATION_TITLE, this::templateSelectionCallback, RealmsServer.WorldType.INSPIRATION, this.inspirations
                        )
                    )
            )
        );
        this.layout.addToFooter(Button.builder(CommonComponents.GUI_BACK, button -> this.onClose()).build());
        this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
        this.repositionElements();
    }
 
    @Override
    protected void repositionElements() {
        this.layout.arrangeElements();
    }
 
    @Override
    public Component getNarrationMessage() {
        return CommonComponents.joinForNarration(this.getTitle(), this.subtitle);
    }
 
    @Override
    public void onClose() {
        this.minecraft.setScreen(this.lastScreen);
    }
 
    private void templateSelectionCallback(@Nullable WorldTemplate template) {
        this.minecraft.setScreen(this);
        if (template != null) {
            this.runResetTasks(new ResettingTemplateWorldTask(template, this.serverData.id, this.resetTaskTitle, this.resetWorldRunnable));
        }
 
        RealmsMainScreen.refreshServerList();
    }
 
    private void runResetTasks(LongRunningTask resetTask) {
        List<LongRunningTask> tasks = new ArrayList<>();
        if (this.realmCreationTask != null) {
            tasks.add(this.realmCreationTask);
        }
 
        if (this.slot != this.serverData.activeSlot) {
            tasks.add(new SwitchSlotTask(this.serverData.id, this.slot, () -> {}));
        }
 
        tasks.add(resetTask);
        this.minecraft.setScreen(new RealmsLongRunningMcoTaskScreen(this.lastScreen, tasks.toArray(new LongRunningTask[0])));
    }
 
    @OnlyIn(Dist.CLIENT)
    private class FrameButton extends Button {
        private static final Identifier SLOT_FRAME_SPRITE = Identifier.withDefaultNamespace("widget/slot_frame");
        private static final int FRAME_SIZE = 60;
        private static final int FRAME_WIDTH = 2;
        private static final int IMAGE_SIZE = 56;
        private final Identifier image;
 
        private FrameButton(Font font, Component text, Identifier image, Button.OnPress onPress) {
            Objects.requireNonNull(RealmsResetWorldScreen.this);
            super(0, 0, 60, 60 + 9, text, onPress, DEFAULT_NARRATION);
            this.image = image;
        }
 
        @Override
        public void extractContents(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
            boolean hoveredOrFocused = this.isHoveredOrFocused();
            int color = -1;
            if (hoveredOrFocused) {
                color = ARGB.colorFromFloat(1.0F, 0.56F, 0.56F, 0.56F);
            }
 
            int x = this.getX();
            int y = this.getY();
            graphics.blit(RenderPipelines.GUI_TEXTURED, this.image, x + 2, y + 2, 0.0F, 0.0F, 56, 56, 56, 56, 56, 56, color);
            graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_FRAME_SPRITE, x, y, 60, 60, color);
            int textColor = hoveredOrFocused ? -6250336 : -1;
            graphics.centeredText(RealmsResetWorldScreen.this.font, this.getMessage(), x + 28, y - 14, textColor);
        }
    }
}

引用的其他类