| 1 | package net.minecraft.client.gui.screens.reporting;
|
| 2 |
|
| 3 | import it.unimi.dsi.fastutil.ints.IntSet;
|
| 4 | import java.util.UUID;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.client.gui.components.Button;
|
| 8 | import net.minecraft.client.gui.components.MultiLineEditBox;
|
| 9 | import net.minecraft.client.gui.layouts.CommonLayouts;
|
| 10 | import net.minecraft.client.gui.screens.Screen;
|
| 11 | import net.minecraft.client.input.MouseButtonEvent;
|
| 12 | import net.minecraft.client.multiplayer.chat.report.ChatReport;
|
| 13 | import net.minecraft.client.multiplayer.chat.report.ReportReason;
|
| 14 | import net.minecraft.client.multiplayer.chat.report.ReportType;
|
| 15 | import net.minecraft.client.multiplayer.chat.report.ReportingContext;
|
| 16 | import net.minecraft.network.chat.Component;
|
| 17 |
|
| 18 | @Environment(EnvType.CLIENT)
|
| 19 | public class ChatReportScreen extends AbstractReportScreen<ChatReport.Builder> {
|
| 20 | private static final Component TITLE = Component.translatable("gui.chatReport.title");
|
| 21 | private static final Component SELECT_CHAT_MESSAGE = Component.translatable("gui.chatReport.select_chat");
|
| 22 | private MultiLineEditBox commentBox;
|
| 23 | private Button selectMessagesButton;
|
| 24 | private Button selectReasonButton;
|
| 25 |
|
| 26 | private ChatReportScreen(final Screen lastScreen, final ReportingContext reportingContext, final ChatReport.Builder reportBuilder) {
|
| 27 | super(TITLE, lastScreen, reportingContext, reportBuilder);
|
| 28 | }
|
| 29 |
|
| 30 | public ChatReportScreen(final Screen lastScreen, final ReportingContext reportingContext, final UUID playerId) {
|
| 31 | this(lastScreen, reportingContext, new ChatReport.Builder(playerId, reportingContext.sender().reportLimits()));
|
| 32 | }
|
| 33 |
|
| 34 | public ChatReportScreen(final Screen lastScreen, final ReportingContext reportingContext, final ChatReport draft) {
|
| 35 | this(lastScreen, reportingContext, new ChatReport.Builder(draft, reportingContext.sender().reportLimits()));
|
| 36 | }
|
| 37 |
|
| 38 | @Override
|
| 39 | protected void addContent() {
|
| 40 | this.selectMessagesButton = this.layout
|
| 41 | .addChild(
|
| 42 | Button.builder(
|
| 43 | SELECT_CHAT_MESSAGE, b -> this.minecraft.gui.setScreen(new ChatSelectionScreen(this, this.reportingContext, this.reportBuilder, updatedReport -> {
|
| 44 | this.reportBuilder = updatedReport;
|
| 45 | this.onReportChanged();
|
| 46 | }))
|
| 47 | )
|
| 48 | .width(280)
|
| 49 | .build()
|
| 50 | );
|
| 51 | this.selectReasonButton = Button.builder(
|
| 52 | SELECT_REASON, b -> this.minecraft.gui.setScreen(new ReportReasonSelectionScreen(this, this.reportBuilder.reason(), ReportType.CHAT, reason -> {
|
| 53 | this.reportBuilder.setReason(reason);
|
| 54 | this.onReportChanged();
|
| 55 | }))
|
| 56 | )
|
| 57 | .width(280)
|
| 58 | .build();
|
| 59 | this.layout.addChild(CommonLayouts.labeledElement(this.font, this.selectReasonButton, OBSERVED_WHAT_LABEL));
|
| 60 | this.commentBox = this.createCommentBox(280, 9 * 8, comments -> {
|
| 61 | this.reportBuilder.setComments(comments);
|
| 62 | this.onReportChanged();
|
| 63 | });
|
| 64 | this.layout.addChild(CommonLayouts.labeledElement(this.font, this.commentBox, MORE_COMMENTS_LABEL, s -> s.paddingBottom(12)));
|
| 65 | }
|
| 66 |
|
| 67 | @Override
|
| 68 | protected void onReportChanged() {
|
| 69 | IntSet reportedMessages = this.reportBuilder.reportedMessages();
|
| 70 | if (reportedMessages.isEmpty()) {
|
| 71 | this.selectMessagesButton.setMessage(SELECT_CHAT_MESSAGE);
|
| 72 | } else {
|
| 73 | this.selectMessagesButton.setMessage(Component.translatable("gui.chatReport.selected_chat", reportedMessages.size()));
|
| 74 | }
|
| 75 |
|
| 76 | ReportReason reportReason = this.reportBuilder.reason();
|
| 77 | if (reportReason != null) {
|
| 78 | this.selectReasonButton.setMessage(reportReason.title());
|
| 79 | } else {
|
| 80 | this.selectReasonButton.setMessage(SELECT_REASON);
|
| 81 | }
|
| 82 |
|
| 83 | super.onReportChanged();
|
| 84 | }
|
| 85 |
|
| 86 | @Override
|
| 87 | public boolean mouseReleased(final MouseButtonEvent event) {
|
| 88 | return super.mouseReleased(event) ? true : this.commentBox.mouseReleased(event);
|
| 89 | }
|
| 90 | }
|
| 91 |
|