RealmsTermsScreen .java

com.mojang.realmsclient.gui.screens.RealmsTermsScreen (class): members: TERMS_STATIC_TEXT, TERMS_LINK_TEXT, onLink, realmsServer, mouseClicked, lastScreen.

com.mojang.realmsclient.gui.screensclass104 linescommonextends RealmsScreen3.9 KB

API Surface (5)

void init()
boolean keyPressed(final KeyEvent event)
boolean mouseClicked(final MouseButtonEvent event, final boolean doubleClick)
Component getNarrationMessage()
void extractRenderState(final GuiGraphicsExtractor graphics, final int xm, final int ym, final float a)

Fields & Constants (7)

LOGGER
TITLE
TERMS_STATIC_TEXT
TERMS_LINK_TEXT
lastScreen
realmsServer
onLink

String literals (6)

"mco.terms.title"
"mco.terms.sentence.1"
"mco.terms.sentence.2"
"mco.terms.buttons.agree"
"mco.terms.buttons.disagree"
"Couldn't agree to TOS"

Full Source

RealmsTermsScreen.java104 lines · Minecraft 26.3 · verbatim
1
package com.mojang.realmsclient.gui.screens;
2
3
import com.mojang.blaze3d.Blaze3D;
4
import com.mojang.logging.LogUtils;
5
import com.mojang.realmsclient.client.RealmsClient;
6
import com.mojang.realmsclient.dto.RealmsServer;
7
import com.mojang.realmsclient.exception.RealmsServiceException;
8
import com.mojang.realmsclient.util.task.GetServerDetailsTask;
9
import net.fabricmc.api.EnvType;
10
import net.fabricmc.api.Environment;
11
import net.minecraft.client.gui.GuiGraphicsExtractor;
12
import net.minecraft.client.gui.components.Button;
13
import net.minecraft.client.gui.screens.Screen;
14
import net.minecraft.client.input.KeyEvent;
15
import net.minecraft.client.input.MouseButtonEvent;
16
import net.minecraft.network.chat.CommonComponents;
17
import net.minecraft.network.chat.Component;
18
import net.minecraft.network.chat.Style;
19
import net.minecraft.realms.RealmsScreen;
20
import net.minecraft.util.CommonLinks;
21
import org.slf4j.Logger;
22
23
@Environment(EnvType.CLIENT)
24
public class RealmsTermsScreen extends RealmsScreen {
25
	private static final Logger LOGGER = LogUtils.getLogger();
26
	private static final Component TITLE = Component.translatable("mco.terms.title");
27
	private static final Component TERMS_STATIC_TEXT = Component.translatable("mco.terms.sentence.1");
28
	private static final Component TERMS_LINK_TEXT = CommonComponents.space()
29
		.append(Component.translatable("mco.terms.sentence.2").withStyle(Style.EMPTY.withUnderlined(true)));
30
	private final Screen lastScreen;
31
	private final RealmsServer realmsServer;
32
	private boolean onLink;
33
34
	public RealmsTermsScreen(final Screen lastScreen, final RealmsServer realmsServer) {
35
		super(TITLE);
36
		this.lastScreen = lastScreen;
37
		this.realmsServer = realmsServer;
38
	}
39
40
	@Override
41
	public void init() {
42
		int columnWidth = this.width / 4 - 2;
43
		this.addRenderableWidget(
44
			Button.builder(Component.translatable("mco.terms.buttons.agree"), button -> this.agreedToTos()).bounds(this.width / 4, row(12), columnWidth, 20).build()
45
		);
46
		this.addRenderableWidget(
47
			Button.builder(Component.translatable("mco.terms.buttons.disagree"), button -> this.minecraft.gui.setScreen(this.lastScreen))
48
				.bounds(this.width / 2 + 4, row(12), columnWidth, 20)
49
				.build()
50
		);
51
	}
52
53
	@Override
54
	public boolean keyPressed(final KeyEvent event) {
55
		if (event.isEscape()) {
56
			this.minecraft.gui.setScreen(this.lastScreen);
57
			return true;
58
		} else {
59
			return super.keyPressed(event);
60
		}
61
	}
62
63
	private void agreedToTos() {
64
		RealmsClient client = RealmsClient.getOrCreate();
65
66
		try {
67
			client.agreeToTos();
68
			this.minecraft.gui.setScreen(new RealmsLongRunningMcoTaskScreen(this.lastScreen, new GetServerDetailsTask(this.lastScreen, this.realmsServer)));
69
		} catch (RealmsServiceException e) {
70
			LOGGER.error("Couldn't agree to TOS", e);
71
		}
72
	}
73
74
	@Override
75
	public boolean mouseClicked(final MouseButtonEvent event, final boolean doubleClick) {
76
		if (this.onLink) {
77
			this.minecraft.keyboardHandler.setClipboard(CommonLinks.REALMS_TERMS.toString());
78
			Blaze3D.openUri(CommonLinks.REALMS_TERMS);
79
			return true;
80
		} else {
81
			return super.mouseClicked(event, doubleClick);
82
		}
83
	}
84
85
	@Override
86
	public Component getNarrationMessage() {
87
		return CommonComponents.joinForNarration(super.getNarrationMessage(), TERMS_STATIC_TEXT).append(CommonComponents.SPACE).append(TERMS_LINK_TEXT);
88
	}
89
90
	@Override
91
	public void extractRenderState(final GuiGraphicsExtractor graphics, final int xm, final int ym, final float a) {
92
		super.extractRenderState(graphics, xm, ym, a);
93
		graphics.centeredText(this.font, this.title, this.width / 2, 17, -1);
94
		graphics.text(this.font, TERMS_STATIC_TEXT, this.width / 2 - 120, row(5), -1);
95
		int firstPartWidth = this.font.width(TERMS_STATIC_TEXT);
96
		int x1 = this.width / 2 - 121 + firstPartWidth;
97
		int y1 = row(5);
98
		int x2 = x1 + this.font.width(TERMS_LINK_TEXT) + 1;
99
		int y2 = y1 + 1 + 9;
100
		this.onLink = x1 <= xm && xm <= x2 && y1 <= ym && ym <= y2;
101
		graphics.text(this.font, TERMS_LINK_TEXT, this.width / 2 - 120 + firstPartWidth, row(5), this.onLink ? -9670204 : -13408581);
102
	}
103
}
104

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