RealmsBackupInfoScreen.java

com.mojang.realmsclient.gui.screens.configuration.RealmsBackupInfoScreen

信息

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

    TODO

字段/常量

  • TITLE

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

      TODO

  • UNKNOWN

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

      TODO

  • lastScreen

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

      TODO

  • backup

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

      TODO

  • layout

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

      TODO

  • backupInfoList

    • 类型: RealmsBackupInfoScreen.BackupInfoList
    • 修饰符: private
    • 源码定位: L26
    • 说明:

      TODO

内部类/嵌套类型

  • com.mojang.realmsclient.gui.screens.configuration.RealmsBackupInfoScreen.BackupInfoList

    • 类型: class
    • 修饰符: private
    • 源码定位: L90
    • 说明:

      TODO

  • com.mojang.realmsclient.gui.screens.configuration.RealmsBackupInfoScreen.BackupInfoListEntry

    • 类型: class
    • 修饰符: private
    • 源码定位: L109
    • 说明:

      TODO

构造器

public RealmsBackupInfoScreen(Screen lastScreen, Backup backup) @ L28

  • 构造器名:RealmsBackupInfoScreen
  • 源码定位:L28
  • 修饰符:public

参数:

  • lastScreen: Screen
  • backup: Backup

说明:

TODO

方法

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

public void init() @ L34

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

参数:

说明:

TODO

protected void repositionElements() @ L43

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

参数:

说明:

TODO

public void onClose() @ L49

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

参数:

说明:

TODO

private Component checkForSpecificMetadata(String key, String value) @ L54

  • 方法名:checkForSpecificMetadata
  • 源码定位:L54
  • 返回类型:Component
  • 修饰符:private

参数:

  • key: String
  • value: String

说明:

TODO

private Component gameDifficultyMetadata(String value) @ L65

  • 方法名:gameDifficultyMetadata
  • 源码定位:L65
  • 返回类型:Component
  • 修饰符:private

参数:

  • value: String

说明:

TODO

private Component gameModeMetadata(String value) @ L73

  • 方法名:gameModeMetadata
  • 源码定位:L73
  • 返回类型:Component
  • 修饰符:private

参数:

  • value: String

说明:

TODO

private Component parseWorldType(String value) @ L81

  • 方法名:parseWorldType
  • 源码定位:L81
  • 返回类型:Component
  • 修饰符:private

参数:

  • value: String

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class RealmsBackupInfoScreen extends RealmsScreen {
    private static final Component TITLE = Component.translatable("mco.backup.info.title");
    private static final Component UNKNOWN = Component.translatable("mco.backup.unknown");
    private final Screen lastScreen;
    private final Backup backup;
    private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
    private RealmsBackupInfoScreen.BackupInfoList backupInfoList;
 
    public RealmsBackupInfoScreen(Screen lastScreen, Backup backup) {
        super(TITLE);
        this.lastScreen = lastScreen;
        this.backup = backup;
    }
 
    @Override
    public void init() {
        this.layout.addTitleHeader(TITLE, this.font);
        this.backupInfoList = this.layout.addToContents(new RealmsBackupInfoScreen.BackupInfoList(this.minecraft));
        this.layout.addToFooter(Button.builder(CommonComponents.GUI_BACK, button -> this.onClose()).build());
        this.repositionElements();
        this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
    }
 
    @Override
    protected void repositionElements() {
        this.backupInfoList.updateSize(this.width, this.layout);
        this.layout.arrangeElements();
    }
 
    @Override
    public void onClose() {
        this.minecraft.setScreen(this.lastScreen);
    }
 
    private Component checkForSpecificMetadata(String key, String value) {
        String k = key.toLowerCase(Locale.ROOT);
        if (k.contains("game") && k.contains("mode")) {
            return this.gameModeMetadata(value);
        } else if (k.contains("game") && k.contains("difficulty")) {
            return this.gameDifficultyMetadata(value);
        } else {
            return (Component)(key.equals("world_type") ? this.parseWorldType(value) : Component.literal(value));
        }
    }
 
    private Component gameDifficultyMetadata(String value) {
        try {
            return RealmsSlotOptionsScreen.DIFFICULTIES.get(Integer.parseInt(value)).getDisplayName();
        } catch (Exception var3) {
            return UNKNOWN;
        }
    }
 
    private Component gameModeMetadata(String value) {
        try {
            return RealmsSlotOptionsScreen.GAME_MODES.get(Integer.parseInt(value)).getShortDisplayName();
        } catch (Exception var3) {
            return UNKNOWN;
        }
    }
 
    private Component parseWorldType(String value) {
        try {
            return RealmsServer.WorldType.valueOf(value.toUpperCase(Locale.ROOT)).getDisplayName();
        } catch (Exception var3) {
            return RealmsServer.WorldType.UNKNOWN.getDisplayName();
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    private class BackupInfoList extends ObjectSelectionList<RealmsBackupInfoScreen.BackupInfoListEntry> {
        public BackupInfoList(Minecraft minecraft) {
            Objects.requireNonNull(RealmsBackupInfoScreen.this);
            super(
                minecraft,
                RealmsBackupInfoScreen.this.width,
                RealmsBackupInfoScreen.this.layout.getContentHeight(),
                RealmsBackupInfoScreen.this.layout.getHeaderHeight(),
                36
            );
            if (RealmsBackupInfoScreen.this.backup.changeList != null) {
                RealmsBackupInfoScreen.this.backup
                    .changeList
                    .forEach((key, value) -> this.addEntry(RealmsBackupInfoScreen.this.new BackupInfoListEntry(key, value)));
            }
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    private class BackupInfoListEntry extends ObjectSelectionList.Entry<RealmsBackupInfoScreen.BackupInfoListEntry> {
        private static final Component TEMPLATE_NAME = Component.translatable("mco.backup.entry.templateName");
        private static final Component GAME_DIFFICULTY = Component.translatable("mco.backup.entry.gameDifficulty");
        private static final Component NAME = Component.translatable("mco.backup.entry.name");
        private static final Component GAME_SERVER_VERSION = Component.translatable("mco.backup.entry.gameServerVersion");
        private static final Component UPLOADED = Component.translatable("mco.backup.entry.uploaded");
        private static final Component ENABLED_PACK = Component.translatable("mco.backup.entry.enabledPack");
        private static final Component DESCRIPTION = Component.translatable("mco.backup.entry.description");
        private static final Component GAME_MODE = Component.translatable("mco.backup.entry.gameMode");
        private static final Component SEED = Component.translatable("mco.backup.entry.seed");
        private static final Component WORLD_TYPE = Component.translatable("mco.backup.entry.worldType");
        private static final Component UNDEFINED = Component.translatable("mco.backup.entry.undefined");
        private final String key;
        private final String value;
        private final Component keyComponent;
        private final Component valueComponent;
 
        public BackupInfoListEntry(String key, String value) {
            Objects.requireNonNull(RealmsBackupInfoScreen.this);
            super();
            this.key = key;
            this.value = value;
            this.keyComponent = this.translateKey(key);
            this.valueComponent = RealmsBackupInfoScreen.this.checkForSpecificMetadata(key, value);
        }
 
        @Override
        public void extractContent(GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean hovered, float a) {
            graphics.text(RealmsBackupInfoScreen.this.font, this.keyComponent, this.getContentX(), this.getContentY(), -6250336);
            graphics.text(RealmsBackupInfoScreen.this.font, this.valueComponent, this.getContentX(), this.getContentY() + 12, -1);
        }
 
        private Component translateKey(String key) {
            return switch (key) {
                case "template_name" -> TEMPLATE_NAME;
                case "game_difficulty" -> GAME_DIFFICULTY;
                case "name" -> NAME;
                case "game_server_version" -> GAME_SERVER_VERSION;
                case "uploaded" -> UPLOADED;
                case "enabled_packs" -> ENABLED_PACK;
                case "description" -> DESCRIPTION;
                case "game_mode" -> GAME_MODE;
                case "seed" -> SEED;
                case "world_type" -> WORLD_TYPE;
                default -> UNDEFINED;
            };
        }
 
        @Override
        public Component getNarration() {
            return Component.translatable("narrator.select", this.key + " " + this.value);
        }
    }
}

引用的其他类

  • Backup

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

    • 引用位置: 方法调用
    • 关联成员: RealmsServer.WorldType.valueOf()
  • Button

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

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

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

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

    • 引用位置: 继承