ReportReasonSelectionScreen.java

net.minecraft.client.gui.screens.reporting.ReportReasonSelectionScreen

信息

  • 全限定名:net.minecraft.client.gui.screens.reporting.ReportReasonSelectionScreen
  • 类型:public class
  • 包:net.minecraft.client.gui.screens.reporting
  • 源码路径:src/main/java/net/minecraft/client/gui/screens/reporting/ReportReasonSelectionScreen.java
  • 起始行号:L26
  • 继承:Screen
  • 职责:

    TODO

字段/常量

  • REASON_TITLE

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L27
    • 说明:

      TODO

  • REASON_DESCRIPTION

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L28
    • 说明:

      TODO

  • READ_INFO_LABEL

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L29
    • 说明:

      TODO

  • DESCRIPTION_BOX_WIDTH

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L30
    • 说明:

      TODO

  • DESCRIPTION_BOX_HEIGHT

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L31
    • 说明:

      TODO

  • PADDING

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L32
    • 说明:

      TODO

  • lastScreen

    • 类型: Screen
    • 修饰符: private final
    • 源码定位: L33
    • 说明:

      TODO

  • reasonSelectionList

    • 类型: ReportReasonSelectionScreen.ReasonSelectionList
    • 修饰符: private
    • 源码定位: L34
    • 说明:

      TODO

  • currentlySelectedReason

    • 类型: ReportReason
    • 修饰符: private
    • 源码定位: L35
    • 说明:

      TODO

  • onSelectedReason

    • 类型: Consumer<ReportReason>
    • 修饰符: private final
    • 源码定位: L36
    • 说明:

      TODO

  • layout

    • 类型: HeaderAndFooterLayout
    • 修饰符: private final
    • 源码定位: L37
    • 说明:

      TODO

  • reportType

    • 类型: ReportType
    • 修饰符: private final
    • 源码定位: L38
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.screens.reporting.ReportReasonSelectionScreen.ReasonSelectionList

    • 类型: class
    • 修饰符: public
    • 源码定位: L133
    • 说明:

      TODO

  • net.minecraft.client.gui.screens.reporting.ReportReasonSelectionScreen.ReasonSelectionList.Entry

    • 类型: class
    • 修饰符: public
    • 源码定位: L166
    • 说明:

      TODO

构造器

public ReportReasonSelectionScreen(Screen lastScreen, ReportReason selectedReason, ReportType reportType, Consumer<ReportReason> onSelectedReason) @ L40

  • 构造器名:ReportReasonSelectionScreen
  • 源码定位:L40
  • 修饰符:public

参数:

  • lastScreen: Screen
  • selectedReason: ReportReason
  • reportType: ReportType
  • onSelectedReason: Consumer

说明:

TODO

方法

下面的方法块按源码顺序生成。

protected void init() @ L50

  • 方法名:init
  • 源码定位:L50
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

protected void repositionElements() @ L72

  • 方法名:repositionElements
  • 源码定位:L72
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L80

  • 方法名:extractRenderState
  • 源码定位:L80
  • 返回类型:void
  • 修饰符:public

参数:

  • graphics: GuiGraphicsExtractor
  • mouseX: int
  • mouseY: int
  • a: float

说明:

TODO

private int descriptionLeft() @ L99

  • 方法名:descriptionLeft
  • 源码定位:L99
  • 返回类型:int
  • 修饰符:private

参数:

说明:

TODO

private int descriptionRight() @ L103

  • 方法名:descriptionRight
  • 源码定位:L103
  • 返回类型:int
  • 修饰符:private

参数:

说明:

TODO

private int descriptionTop() @ L107

  • 方法名:descriptionTop
  • 源码定位:L107
  • 返回类型:int
  • 修饰符:private

参数:

说明:

TODO

private int descriptionBottom() @ L111

  • 方法名:descriptionBottom
  • 源码定位:L111
  • 返回类型:int
  • 修饰符:private

参数:

说明:

TODO

private int descriptionWidth() @ L115

  • 方法名:descriptionWidth
  • 源码定位:L115
  • 返回类型:int
  • 修饰符:private

参数:

说明:

TODO

private int descriptionHeight() @ L119

  • 方法名:descriptionHeight
  • 源码定位:L119
  • 返回类型:int
  • 修饰符:private

参数:

说明:

TODO

private int listHeight() @ L123

  • 方法名:listHeight
  • 源码定位:L123
  • 返回类型:int
  • 修饰符:private

参数:

说明:

TODO

public void onClose() @ L127

  • 方法名:onClose
  • 源码定位:L127
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class ReportReasonSelectionScreen extends Screen {
    private static final Component REASON_TITLE = Component.translatable("gui.abuseReport.reason.title");
    private static final Component REASON_DESCRIPTION = Component.translatable("gui.abuseReport.reason.description");
    private static final Component READ_INFO_LABEL = Component.translatable("gui.abuseReport.read_info");
    private static final int DESCRIPTION_BOX_WIDTH = 320;
    private static final int DESCRIPTION_BOX_HEIGHT = 62;
    private static final int PADDING = 4;
    private final @Nullable Screen lastScreen;
    private ReportReasonSelectionScreen.@Nullable ReasonSelectionList reasonSelectionList;
    private @Nullable ReportReason currentlySelectedReason;
    private final Consumer<ReportReason> onSelectedReason;
    private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
    private final ReportType reportType;
 
    public ReportReasonSelectionScreen(
        @Nullable Screen lastScreen, @Nullable ReportReason selectedReason, ReportType reportType, Consumer<ReportReason> onSelectedReason
    ) {
        super(REASON_TITLE);
        this.lastScreen = lastScreen;
        this.currentlySelectedReason = selectedReason;
        this.onSelectedReason = onSelectedReason;
        this.reportType = reportType;
    }
 
    @Override
    protected void init() {
        this.layout.addTitleHeader(REASON_TITLE, this.font);
        LinearLayout content = this.layout.addToContents(LinearLayout.vertical().spacing(4));
        this.reasonSelectionList = content.addChild(new ReportReasonSelectionScreen.ReasonSelectionList(this.minecraft));
        ReportReasonSelectionScreen.ReasonSelectionList.Entry selectedEntry = Optionull.map(this.currentlySelectedReason, this.reasonSelectionList::findEntry);
        this.reasonSelectionList.setSelected(selectedEntry);
        content.addChild(SpacerElement.height(this.descriptionHeight()));
        LinearLayout footer = this.layout.addToFooter(LinearLayout.horizontal().spacing(8));
        footer.addChild(Button.builder(READ_INFO_LABEL, ConfirmLinkScreen.confirmLink(this, CommonLinks.REPORTING_HELP)).build());
        footer.addChild(Button.builder(CommonComponents.GUI_DONE, button -> {
            ReportReasonSelectionScreen.ReasonSelectionList.Entry selected = this.reasonSelectionList.getSelected();
            if (selected != null) {
                this.onSelectedReason.accept(selected.getReason());
            }
 
            this.minecraft.setScreen(this.lastScreen);
        }).build());
        this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
        this.repositionElements();
    }
 
    @Override
    protected void repositionElements() {
        this.layout.arrangeElements();
        if (this.reasonSelectionList != null) {
            this.reasonSelectionList.updateSizeAndPosition(this.width, this.listHeight(), this.layout.getHeaderHeight());
        }
    }
 
    @Override
    public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
        super.extractRenderState(graphics, mouseX, mouseY, a);
        graphics.fill(this.descriptionLeft(), this.descriptionTop(), this.descriptionRight(), this.descriptionBottom(), -16777216);
        graphics.outline(this.descriptionLeft(), this.descriptionTop(), this.descriptionWidth(), this.descriptionHeight(), -1);
        graphics.text(this.font, REASON_DESCRIPTION, this.descriptionLeft() + 4, this.descriptionTop() + 4, -1);
        ReportReasonSelectionScreen.ReasonSelectionList.Entry selectedEntry = this.reasonSelectionList.getSelected();
        if (selectedEntry != null) {
            int textLeft = this.descriptionLeft() + 4 + 16;
            int textRight = this.descriptionRight() - 4;
            int textTop = this.descriptionTop() + 4 + 9 + 2;
            int textBottom = this.descriptionBottom() - 4;
            int textWidth = textRight - textLeft;
            int textHeight = textBottom - textTop;
            int contentHeight = this.font.wordWrapHeight(selectedEntry.reason.description(), textWidth);
            graphics.textWithWordWrap(this.font, selectedEntry.reason.description(), textLeft, textTop + (textHeight - contentHeight) / 2, textWidth, -1);
        }
    }
 
    private int descriptionLeft() {
        return (this.width - 320) / 2;
    }
 
    private int descriptionRight() {
        return (this.width + 320) / 2;
    }
 
    private int descriptionTop() {
        return this.descriptionBottom() - this.descriptionHeight();
    }
 
    private int descriptionBottom() {
        return this.height - this.layout.getFooterHeight() - 4;
    }
 
    private int descriptionWidth() {
        return 320;
    }
 
    private int descriptionHeight() {
        return 62;
    }
 
    private int listHeight() {
        return this.layout.getContentHeight() - this.descriptionHeight() - 8;
    }
 
    @Override
    public void onClose() {
        this.minecraft.setScreen(this.lastScreen);
    }
 
    @OnlyIn(Dist.CLIENT)
    public class ReasonSelectionList extends ObjectSelectionList<ReportReasonSelectionScreen.ReasonSelectionList.Entry> {
        public ReasonSelectionList(Minecraft minecraft) {
            Objects.requireNonNull(ReportReasonSelectionScreen.this);
            super(
                minecraft,
                ReportReasonSelectionScreen.this.width,
                ReportReasonSelectionScreen.this.listHeight(),
                ReportReasonSelectionScreen.this.layout.getHeaderHeight(),
                18
            );
 
            for (ReportReason reason : ReportReason.values()) {
                if (!ReportReason.getIncompatibleCategories(ReportReasonSelectionScreen.this.reportType).contains(reason)) {
                    this.addEntry(new ReportReasonSelectionScreen.ReasonSelectionList.Entry(reason));
                }
            }
        }
 
        public ReportReasonSelectionScreen.ReasonSelectionList.@Nullable Entry findEntry(ReportReason reason) {
            return this.children().stream().filter(entry -> entry.reason == reason).findFirst().orElse(null);
        }
 
        @Override
        public int getRowWidth() {
            return 320;
        }
 
        public void setSelected(ReportReasonSelectionScreen.ReasonSelectionList.@Nullable Entry selected) {
            super.setSelected(selected);
            ReportReasonSelectionScreen.this.currentlySelectedReason = selected != null ? selected.getReason() : null;
        }
 
        @OnlyIn(Dist.CLIENT)
        public class Entry extends ObjectSelectionList.Entry<ReportReasonSelectionScreen.ReasonSelectionList.Entry> {
            private final ReportReason reason;
 
            public Entry(ReportReason reason) {
                Objects.requireNonNull(ReasonSelectionList.this);
                super();
                this.reason = reason;
            }
 
            @Override
            public void extractContent(GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean hovered, float a) {
                int textX = this.getContentX() + 1;
                int textY = this.getContentY() + (this.getContentHeight() - 9) / 2 + 1;
                graphics.text(ReportReasonSelectionScreen.this.font, this.reason.title(), textX, textY, -1);
            }
 
            @Override
            public Component getNarration() {
                return Component.translatable("gui.abuseReport.reason.narration", this.reason.title(), this.reason.description());
            }
 
            @Override
            public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
                ReasonSelectionList.this.setSelected(this);
                return super.mouseClicked(event, doubleClick);
            }
 
            public ReportReason getReason() {
                return this.reason;
            }
        }
    }
}

引用的其他类

  • Optionull

    • 引用位置: 方法调用
    • 关联成员: Optionull.map()
  • GuiGraphicsExtractor

    • 引用位置: 参数
  • Button

    • 引用位置: 方法调用
    • 关联成员: Button.builder()
  • HeaderAndFooterLayout

    • 引用位置: 字段/构造调用
    • 关联成员: HeaderAndFooterLayout()
  • LinearLayout

    • 引用位置: 方法调用
    • 关联成员: LinearLayout.horizontal(), LinearLayout.vertical()
  • SpacerElement

    • 引用位置: 方法调用
    • 关联成员: SpacerElement.height()
  • ConfirmLinkScreen

    • 引用位置: 方法调用
    • 关联成员: ConfirmLinkScreen.confirmLink()
  • Screen

    • 引用位置: 参数/字段/继承
  • ReportReason

    • 引用位置: 参数/字段/方法调用
    • 关联成员: ReportReason.getIncompatibleCategories(), ReportReason.values()
  • ReportType

    • 引用位置: 参数/字段
  • Component

    • 引用位置: 字段/方法调用
    • 关联成员: Component.translatable()