RealmsBackupInfoScreen .java

com.mojang.realmsclient.gui.screens.configuration.RealmsBackupInfoScreen (class): members: BackupInfoListEntry, BackupInfoList, backupInfoList, backup.

com.mojang.realmsclient.gui.screens.configurationclass157 linescommonextends RealmsScreen6.3 KB

API Surface (5)

void init()
void repositionElements()
void onClose()
void extractContent(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final boolean hovered, final float a)
Component getNarration()

Fields & Constants (6)

TITLE
UNKNOWN
lastScreen
backup
layout
backupInfoList

String literals (26)

"mco.backup.info.title"
"mco.backup.unknown"
"game"
"mode"
"difficulty"
"world_type"
"mco.backup.entry.templateName"
"mco.backup.entry.gameDifficulty"
"mco.backup.entry.name"
"mco.backup.entry.gameServerVersion"
"mco.backup.entry.uploaded"
"mco.backup.entry.enabledPack"
"mco.backup.entry.description"
"mco.backup.entry.gameMode"
"mco.backup.entry.seed"
"mco.backup.entry.worldType"
"mco.backup.entry.undefined"
"template_name"
"game_difficulty"
"game_server_version"
"uploaded"
"enabled_packs"
"description"
"game_mode"

Full Source

RealmsBackupInfoScreen.java157 lines · Minecraft 26.3 · verbatim
1
package com.mojang.realmsclient.gui.screens.configuration;
2
3
import com.mojang.realmsclient.dto.Backup;
4
import com.mojang.realmsclient.dto.RealmsServer;
5
import java.util.Locale;
6
import net.fabricmc.api.EnvType;
7
import net.fabricmc.api.Environment;
8
import net.minecraft.client.Minecraft;
9
import net.minecraft.client.gui.GuiGraphicsExtractor;
10
import net.minecraft.client.gui.components.Button;
11
import net.minecraft.client.gui.components.ObjectSelectionList;
12
import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
13
import net.minecraft.client.gui.screens.Screen;
14
import net.minecraft.network.chat.CommonComponents;
15
import net.minecraft.network.chat.Component;
16
import net.minecraft.realms.RealmsScreen;
17
18
@Environment(EnvType.CLIENT)
19
public class RealmsBackupInfoScreen extends RealmsScreen {
20
	private static final Component TITLE = Component.translatable("mco.backup.info.title");
21
	private static final Component UNKNOWN = Component.translatable("mco.backup.unknown");
22
	private final Screen lastScreen;
23
	private final Backup backup;
24
	private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
25
	private RealmsBackupInfoScreen.BackupInfoList backupInfoList;
26
27
	public RealmsBackupInfoScreen(final Screen lastScreen, final Backup backup) {
28
		super(TITLE);
29
		this.lastScreen = lastScreen;
30
		this.backup = backup;
31
	}
32
33
	@Override
34
	public void init() {
35
		this.layout.addTitleHeader(TITLE, this.font);
36
		this.backupInfoList = this.layout.addToContents(new RealmsBackupInfoScreen.BackupInfoList(this.minecraft));
37
		this.layout.addToFooter(Button.builder(CommonComponents.GUI_BACK, button -> this.onClose()).build());
38
		this.repositionElements();
39
		this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
40
	}
41
42
	@Override
43
	protected void repositionElements() {
44
		this.backupInfoList.updateSize(this.width, this.layout);
45
		this.layout.arrangeElements();
46
	}
47
48
	@Override
49
	public void onClose() {
50
		this.minecraft.gui.setScreen(this.lastScreen);
51
	}
52
53
	private Component checkForSpecificMetadata(final String key, final String value) {
54
		String k = key.toLowerCase(Locale.ROOT);
55
		if (k.contains("game") && k.contains("mode")) {
56
			return this.gameModeMetadata(value);
57
		} else if (k.contains("game") && k.contains("difficulty")) {
58
			return this.gameDifficultyMetadata(value);
59
		} else {
60
			return key.equals("world_type") ? this.parseWorldType(value) : Component.literal(value);
61
		}
62
	}
63
64
	private Component gameDifficultyMetadata(final String value) {
65
		try {
66
			return RealmsSlotOptionsScreen.DIFFICULTIES.get(Integer.parseInt(value)).getDisplayName();
67
		} catch (Exception ignored) {
68
			return UNKNOWN;
69
		}
70
	}
71
72
	private Component gameModeMetadata(final String value) {
73
		try {
74
			return RealmsSlotOptionsScreen.GAME_MODES.get(Integer.parseInt(value)).getShortDisplayName();
75
		} catch (Exception ignored) {
76
			return UNKNOWN;
77
		}
78
	}
79
80
	private Component parseWorldType(final String value) {
81
		try {
82
			return RealmsServer.WorldType.valueOf(value.toUpperCase(Locale.ROOT)).getDisplayName();
83
		} catch (Exception ignored) {
84
			return RealmsServer.WorldType.UNKNOWN.getDisplayName();
85
		}
86
	}
87
88
	@Environment(EnvType.CLIENT)
89
	private class BackupInfoList extends ObjectSelectionList<RealmsBackupInfoScreen.BackupInfoListEntry> {
90
		public BackupInfoList(final Minecraft minecraft) {
91
			super(
92
				minecraft,
93
				RealmsBackupInfoScreen.this.width,
94
				RealmsBackupInfoScreen.this.layout.getContentHeight(),
95
				RealmsBackupInfoScreen.this.layout.getHeaderHeight(),
96
				36
97
			);
98
			if (RealmsBackupInfoScreen.this.backup.changeList != null) {
99
				RealmsBackupInfoScreen.this.backup.changeList.forEach((key, value) -> this.addEntry(RealmsBackupInfoScreen.this.new BackupInfoListEntry(key, value)));
100
			}
101
		}
102
	}
103
104
	@Environment(EnvType.CLIENT)
105
	private class BackupInfoListEntry extends ObjectSelectionList.Entry<RealmsBackupInfoScreen.BackupInfoListEntry> {
106
		private static final Component TEMPLATE_NAME = Component.translatable("mco.backup.entry.templateName");
107
		private static final Component GAME_DIFFICULTY = Component.translatable("mco.backup.entry.gameDifficulty");
108
		private static final Component NAME = Component.translatable("mco.backup.entry.name");
109
		private static final Component GAME_SERVER_VERSION = Component.translatable("mco.backup.entry.gameServerVersion");
110
		private static final Component UPLOADED = Component.translatable("mco.backup.entry.uploaded");
111
		private static final Component ENABLED_PACK = Component.translatable("mco.backup.entry.enabledPack");
112
		private static final Component DESCRIPTION = Component.translatable("mco.backup.entry.description");
113
		private static final Component GAME_MODE = Component.translatable("mco.backup.entry.gameMode");
114
		private static final Component SEED = Component.translatable("mco.backup.entry.seed");
115
		private static final Component WORLD_TYPE = Component.translatable("mco.backup.entry.worldType");
116
		private static final Component UNDEFINED = Component.translatable("mco.backup.entry.undefined");
117
		private final String key;
118
		private final String value;
119
		private final Component keyComponent;
120
		private final Component valueComponent;
121
122
		public BackupInfoListEntry(final String key, final String value) {
123
			this.key = key;
124
			this.value = value;
125
			this.keyComponent = this.translateKey(key);
126
			this.valueComponent = RealmsBackupInfoScreen.this.checkForSpecificMetadata(key, value);
127
		}
128
129
		@Override
130
		public void extractContent(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final boolean hovered, final float a) {
131
			graphics.text(RealmsBackupInfoScreen.this.font, this.keyComponent, this.getContentX(), this.getContentY(), -6250336);
132
			graphics.text(RealmsBackupInfoScreen.this.font, this.valueComponent, this.getContentX(), this.getContentY() + 12, -1);
133
		}
134
135
		private Component translateKey(final String key) {
136
			return switch (key) {
137
				case "template_name" -> TEMPLATE_NAME;
138
				case "game_difficulty" -> GAME_DIFFICULTY;
139
				case "name" -> NAME;
140
				case "game_server_version" -> GAME_SERVER_VERSION;
141
				case "uploaded" -> UPLOADED;
142
				case "enabled_packs" -> ENABLED_PACK;
143
				case "description" -> DESCRIPTION;
144
				case "game_mode" -> GAME_MODE;
145
				case "seed" -> SEED;
146
				case "world_type" -> WORLD_TYPE;
147
				default -> UNDEFINED;
148
			};
149
		}
150
151
		@Override
152
		public Component getNarration() {
153
			return Component.translatable("narrator.select", this.key + " " + this.value);
154
		}
155
	}
156
}
157

Decompiled Minecraft 26.3 source of RealmsBackupInfoScreen (com/mojang/realmsclient/gui/screens/configuration/RealmsBackupInfoScreen.java) with Mojang official mappings, stored verbatim on the site.