ReportReasonSelectionScreen .java

net.minecraft.client.gui.screens.reporting.ReportReasonSelectionScreen (class, 164 lines): members: currentlySelectedReason, DESCRIPTION_BOX_HEIGHT, init.

net.minecraft.client.gui.screens.reportingclass164 linesclientextends Screen6.6 KB

API Surface (6)

void init()
void repositionElements()
void extractRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a)
void onClose()
int getRowWidth()
void setSelected(final Entry/* @Nullable */ selected)

Fields & Constants (12)

REASON_TITLE
REASON_DESCRIPTION
READ_INFO_LABEL
DESCRIPTION_BOX_WIDTH
DESCRIPTION_BOX_HEIGHT
PADDING
lastScreen
reasonSelectionList
currentlySelectedReason
onSelectedReason
layout
reportType

String literals (3)

"gui.abuseReport.reason.title"
"gui.abuseReport.reason.description"
"gui.abuseReport.read_info"

Full Source

ReportReasonSelectionScreen.java164 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.gui.screens.reporting;
2
3
import java.util.function.Consumer;
4
import net.fabricmc.api.EnvType;
5
import net.fabricmc.api.Environment;
6
import net.minecraft.Optionull;
7
import net.minecraft.client.Minecraft;
8
import net.minecraft.client.gui.GuiGraphicsExtractor;
9
import net.minecraft.client.gui.components.Button;
10
import net.minecraft.client.gui.components.ObjectSelectionList;
11
import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
12
import net.minecraft.client.gui.layouts.LinearLayout;
13
import net.minecraft.client.gui.layouts.SpacerElement;
14
import net.minecraft.client.gui.screens.ConfirmLinkScreen;
15
import net.minecraft.client.gui.screens.Screen;
16
import net.minecraft.client.gui.screens.reporting.ReportReasonSelectionScreen.ReasonSelectionList.Entry;
17
import net.minecraft.client.multiplayer.chat.report.ReportReason;
18
import net.minecraft.client.multiplayer.chat.report.ReportType;
19
import net.minecraft.network.chat.CommonComponents;
20
import net.minecraft.network.chat.Component;
21
import net.minecraft.util.CommonLinks;
22
import org.jspecify.annotations.Nullable;
23
24
@Environment(EnvType.CLIENT)
25
public class ReportReasonSelectionScreen extends Screen {
26
	private static final Component REASON_TITLE = Component.translatable("gui.abuseReport.reason.title");
27
	private static final Component REASON_DESCRIPTION = Component.translatable("gui.abuseReport.reason.description");
28
	private static final Component READ_INFO_LABEL = Component.translatable("gui.abuseReport.read_info");
29
	private static final int DESCRIPTION_BOX_WIDTH = 320;
30
	private static final int DESCRIPTION_BOX_HEIGHT = 62;
31
	private static final int PADDING = 4;
32
	private final @Nullable Screen lastScreen;
33
	private ReportReasonSelectionScreen.@Nullable ReasonSelectionList reasonSelectionList;
34
	private @Nullable ReportReason currentlySelectedReason;
35
	private final Consumer<ReportReason> onSelectedReason;
36
	private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
37
	private final ReportType reportType;
38
39
	public ReportReasonSelectionScreen(
40
		final @Nullable Screen lastScreen, final @Nullable ReportReason selectedReason, final ReportType reportType, final Consumer<ReportReason> onSelectedReason
41
	) {
42
		super(REASON_TITLE);
43
		this.lastScreen = lastScreen;
44
		this.currentlySelectedReason = selectedReason;
45
		this.onSelectedReason = onSelectedReason;
46
		this.reportType = reportType;
47
	}
48
49
	@Override
50
	protected void init() {
51
		this.layout.addTitleHeader(REASON_TITLE, this.font);
52
		LinearLayout content = this.layout.addToContents(LinearLayout.vertical().spacing(4));
53
		this.reasonSelectionList = content.addChild(new ReportReasonSelectionScreen.ReasonSelectionList(this.minecraft));
54
		Entry selectedEntry = Optionull.map(this.currentlySelectedReason, this.reasonSelectionList::findEntry);
55
		this.reasonSelectionList.setSelected(selectedEntry);
56
		content.addChild(SpacerElement.height(this.descriptionHeight()));
57
		LinearLayout footer = this.layout.addToFooter(LinearLayout.horizontal().spacing(8));
58
		footer.addChild(Button.builder(READ_INFO_LABEL, ConfirmLinkScreen.confirmLink(this, CommonLinks.REPORTING_HELP)).build());
59
		footer.addChild(Button.builder(CommonComponents.GUI_DONE, button -> {
60
			Entry selected = this.reasonSelectionList.getSelected();
61
			if (selected != null) {
62
				this.onSelectedReason.accept(selected.getReason());
63
			}
64
65
			this.minecraft.gui.setScreen(this.lastScreen);
66
		}).build());
67
		this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
68
		this.repositionElements();
69
	}
70
71
	@Override
72
	protected void repositionElements() {
73
		this.layout.arrangeElements();
74
		if (this.reasonSelectionList != null) {
75
			this.reasonSelectionList.updateSizeAndPosition(this.width, this.listHeight(), this.layout.getHeaderHeight());
76
		}
77
	}
78
79
	@Override
80
	public void extractRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
81
		super.extractRenderState(graphics, mouseX, mouseY, a);
82
		graphics.fill(this.descriptionLeft(), this.descriptionTop(), this.descriptionRight(), this.descriptionBottom(), -16777216);
83
		graphics.outline(this.descriptionLeft(), this.descriptionTop(), this.descriptionWidth(), this.descriptionHeight(), -1);
84
		graphics.text(this.font, REASON_DESCRIPTION, this.descriptionLeft() + 4, this.descriptionTop() + 4, -1);
85
		Entry selectedEntry = this.reasonSelectionList.getSelected();
86
		if (selectedEntry != null) {
87
			int textLeft = this.descriptionLeft() + 4 + 16;
88
			int textRight = this.descriptionRight() - 4;
89
			int textTop = this.descriptionTop() + 4 + 9 + 2;
90
			int textBottom = this.descriptionBottom() - 4;
91
			int textWidth = textRight - textLeft;
92
			int textHeight = textBottom - textTop;
93
			int contentHeight = this.font.wordWrapHeight(selectedEntry.reason.description(), textWidth);
94
			graphics.textWithWordWrap(this.font, selectedEntry.reason.description(), textLeft, textTop + (textHeight - contentHeight) / 2, textWidth, -1);
95
		}
96
	}
97
98
	private int descriptionLeft() {
99
		return (this.width - 320) / 2;
100
	}
101
102
	private int descriptionRight() {
103
		return (this.width + 320) / 2;
104
	}
105
106
	private int descriptionTop() {
107
		return this.descriptionBottom() - this.descriptionHeight();
108
	}
109
110
	private int descriptionBottom() {
111
		return this.height - this.layout.getFooterHeight() - 4;
112
	}
113
114
	private int descriptionWidth() {
115
		return 320;
116
	}
117
118
	private int descriptionHeight() {
119
		return 62;
120
	}
121
122
	private int listHeight() {
123
		return this.layout.getContentHeight() - this.descriptionHeight() - 8;
124
	}
125
126
	@Override
127
	public void onClose() {
128
		this.minecraft.gui.setScreen(this.lastScreen);
129
	}
130
131
	@Environment(EnvType.CLIENT)
132
	public class ReasonSelectionList extends ObjectSelectionList<net.minecraft.client.gui.screens.reporting.ReportReasonSelectionScreen.ReasonSelectionList.Entry> {
133
		public ReasonSelectionList(final Minecraft minecraft) {
134
			super(
135
				minecraft,
136
				ReportReasonSelectionScreen.this.width,
137
				ReportReasonSelectionScreen.this.listHeight(),
138
				ReportReasonSelectionScreen.this.layout.getHeaderHeight(),
139
				18
140
			);
141
142
			for (ReportReason reason : ReportReason.values()) {
143
				if (!ReportReason.getIncompatibleCategories(ReportReasonSelectionScreen.this.reportType).contains(reason)) {
144
					this.addEntry(new net.minecraft.client.gui.screens.reporting.ReportReasonSelectionScreen.ReasonSelectionList.Entry(this, reason));
145
				}
146
			}
147
		}
148
149
		public Entry/* @Nullable */ findEntry(final ReportReason reason) {
150
			return this.children().stream().filter(entry -> entry.reason == reason).findFirst().orElse(null);
151
		}
152
153
		@Override
154
		public int getRowWidth() {
155
			return 320;
156
		}
157
158
		public void setSelected(final Entry/* @Nullable */ selected) {
159
			super.setSelected(selected);
160
			ReportReasonSelectionScreen.this.currentlySelectedReason = selected != null ? selected.getReason() : null;
161
		}
162
	}
163
}
164

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