BackupConfirmScreen .java

net.minecraft.client.gui.screens.BackupConfirmScreen (class): members: promptForCacheErase, BACKUP_AND_JOIN, SKIP_AND_JOIN, onProceed, confirmation, title.

net.minecraft.client.gui.screensclass104 linesclientextends Screen3.7 KB

API Surface (4)

void init()
void extractRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a)
boolean shouldCloseOnEsc()
boolean keyPressed(final KeyEvent event)

Fields & Constants (11)

SKIP_AND_JOIN
BACKUP_AND_JOIN
onCancel
onProceed
description
promptForCacheErase
message
confirmation
id
eraseCache
title

String literals (3)

"selectWorld.backupJoinSkipButton"
"selectWorld.backupJoinConfirmButton"
"selectWorld.backupEraseCache"

Full Source

BackupConfirmScreen.java104 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.screens;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.gui.ActiveTextCollector;
6
import net.minecraft.client.gui.GuiGraphicsExtractor;
7
import net.minecraft.client.gui.TextAlignment;
8
import net.minecraft.client.gui.components.Button;
9
import net.minecraft.client.gui.components.Checkbox;
10
import net.minecraft.client.gui.components.MultiLineLabel;
11
import net.minecraft.client.input.KeyEvent;
12
import net.minecraft.network.chat.CommonComponents;
13
import net.minecraft.network.chat.Component;
14
15
@Environment(EnvType.CLIENT)
16
public class BackupConfirmScreen extends Screen {
17
	private static final Component SKIP_AND_JOIN = Component.translatable("selectWorld.backupJoinSkipButton");
18
	public static final Component BACKUP_AND_JOIN = Component.translatable("selectWorld.backupJoinConfirmButton");
19
	private final Runnable onCancel;
20
	protected final BackupConfirmScreen.Listener onProceed;
21
	private final Component description;
22
	private final boolean promptForCacheErase;
23
	private MultiLineLabel message = MultiLineLabel.EMPTY;
24
	private final Component confirmation;
25
	protected int id;
26
	private Checkbox eraseCache;
27
28
	public BackupConfirmScreen(
29
		final Runnable onCancel, final BackupConfirmScreen.Listener onProceed, final Component title, final Component description, final boolean promptForCacheErase
30
	) {
31
		this(onCancel, onProceed, title, description, BACKUP_AND_JOIN, promptForCacheErase);
32
	}
33
34
	public BackupConfirmScreen(
35
		final Runnable onCancel,
36
		final BackupConfirmScreen.Listener onProceed,
37
		final Component title,
38
		final Component description,
39
		final Component confirmation,
40
		final boolean promptForCacheErase
41
	) {
42
		super(title);
43
		this.onCancel = onCancel;
44
		this.onProceed = onProceed;
45
		this.description = description;
46
		this.promptForCacheErase = promptForCacheErase;
47
		this.confirmation = confirmation;
48
	}
49
50
	@Override
51
	protected void init() {
52
		super.init();
53
		this.message = MultiLineLabel.create(this.font, this.description, this.width - 50);
54
		int textSize = (this.message.getLineCount() + 1) * 9;
55
		this.eraseCache = Checkbox.builder(Component.translatable("selectWorld.backupEraseCache").withColor(-2039584), this.font)
56
			.pos(this.width / 2 - 155 + 80, 76 + textSize)
57
			.build();
58
		if (this.promptForCacheErase) {
59
			this.addRenderableWidget(this.eraseCache);
60
		}
61
62
		this.addRenderableWidget(
63
			Button.builder(this.confirmation, button -> this.onProceed.proceed(true, this.eraseCache.selected()))
64
				.bounds(this.width / 2 - 155, 100 + textSize, 150, 20)
65
				.build()
66
		);
67
		Button skipAndJoinButton = Button.builder(SKIP_AND_JOIN, button -> this.onProceed.proceed(false, this.eraseCache.selected()))
68
			.bounds(this.width / 2 - 155 + 160, 100 + textSize, 150, 20)
69
			.build();
70
		this.addRenderableWidget(skipAndJoinButton);
71
		this.addRenderableWidget(
72
			Button.builder(CommonComponents.GUI_CANCEL, button -> this.onCancel.run()).bounds(this.width / 2 - 155 + 80, 124 + textSize, 150, 20).build()
73
		);
74
	}
75
76
	@Override
77
	public void extractRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
78
		super.extractRenderState(graphics, mouseX, mouseY, a);
79
		ActiveTextCollector textRenderer = graphics.textRenderer();
80
		graphics.centeredText(this.font, this.title, this.width / 2, 50, -1);
81
		this.message.visitLines(TextAlignment.CENTER, this.width / 2, 70, 9, textRenderer);
82
	}
83
84
	@Override
85
	public boolean shouldCloseOnEsc() {
86
		return false;
87
	}
88
89
	@Override
90
	public boolean keyPressed(final KeyEvent event) {
91
		if (event.isEscape()) {
92
			this.onCancel.run();
93
			return true;
94
		} else {
95
			return super.keyPressed(event);
96
		}
97
	}
98
99
	@Environment(EnvType.CLIENT)
100
	public interface Listener {
101
		void proceed(final boolean backup, final boolean eraseCache);
102
	}
103
}
104

Decompiled Minecraft 26.3 source of BackupConfirmScreen (net/minecraft/client/gui/screens/BackupConfirmScreen.java) with Mojang official mappings, stored verbatim on the site.