BookSignScreen.java

net.minecraft.client.gui.screens.inventory.BookSignScreen

信息

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

    TODO

字段/常量

  • EDIT_TITLE_LABEL

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

      TODO

  • FINALIZE_WARNING_LABEL

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

      TODO

  • TITLE

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

      TODO

  • TITLE_EDIT_BOX

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

      TODO

  • bookEditScreen

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

      TODO

  • owner

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

      TODO

  • pages

    • 类型: List<String>
    • 修饰符: private final
    • 源码定位: L29
    • 说明:

      TODO

  • hand

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

      TODO

  • ownerText

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

      TODO

  • titleBox

    • 类型: EditBox
    • 修饰符: private
    • 源码定位: L32
    • 说明:

      TODO

  • titleValue

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

      TODO

内部类/嵌套类型

构造器

public BookSignScreen(BookEditScreen bookEditScreen, Player owner, InteractionHand hand, List<String> pages) @ L35

  • 构造器名:BookSignScreen
  • 源码定位:L35
  • 修饰符:public

参数:

  • bookEditScreen: BookEditScreen
  • owner: Player
  • hand: InteractionHand
  • pages: List

说明:

TODO

方法

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

protected void init() @ L44

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

参数:

说明:

TODO

protected void setInitialFocus() @ L66

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

参数:

说明:

TODO

private void saveChanges() @ L71

  • 方法名:saveChanges
  • 源码定位:L71
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

public boolean isInGameUi() @ L76

  • 方法名:isInGameUi
  • 源码定位:L76
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public boolean keyPressed(KeyEvent event) @ L81

  • 方法名:keyPressed
  • 源码定位:L81
  • 返回类型:boolean
  • 修饰符:public

参数:

  • event: KeyEvent

说明:

TODO

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

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

参数:

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

说明:

TODO

public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L104

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

参数:

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

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class BookSignScreen extends Screen {
    private static final Component EDIT_TITLE_LABEL = Component.translatable("book.editTitle");
    private static final Component FINALIZE_WARNING_LABEL = Component.translatable("book.finalizeWarning");
    private static final Component TITLE = Component.translatable("book.sign.title");
    private static final Component TITLE_EDIT_BOX = Component.translatable("book.sign.titlebox");
    private final BookEditScreen bookEditScreen;
    private final Player owner;
    private final List<String> pages;
    private final InteractionHand hand;
    private final Component ownerText;
    private EditBox titleBox;
    private String titleValue = "";
 
    public BookSignScreen(BookEditScreen bookEditScreen, Player owner, InteractionHand hand, List<String> pages) {
        super(TITLE);
        this.bookEditScreen = bookEditScreen;
        this.owner = owner;
        this.hand = hand;
        this.pages = pages;
        this.ownerText = Component.translatable("book.byAuthor", owner.getName()).withStyle(ChatFormatting.DARK_GRAY);
    }
 
    @Override
    protected void init() {
        Button finalizeButton = Button.builder(Component.translatable("book.finalizeButton"), button -> {
            this.saveChanges();
            this.minecraft.setScreen(null);
        }).bounds(this.width / 2 - 100, 196, 98, 20).build();
        finalizeButton.active = false;
        this.titleBox = this.addRenderableWidget(new EditBox(this.minecraft.font, (this.width - 114) / 2 - 3, 50, 114, 20, TITLE_EDIT_BOX));
        this.titleBox.setMaxLength(15);
        this.titleBox.setBordered(false);
        this.titleBox.setCentered(true);
        this.titleBox.setTextColor(-16777216);
        this.titleBox.setTextShadow(false);
        this.titleBox.setResponder(value -> finalizeButton.active = !StringUtil.isBlank(value));
        this.titleBox.setValue(this.titleValue);
        this.addRenderableWidget(finalizeButton);
        this.addRenderableWidget(Button.builder(CommonComponents.GUI_CANCEL, button -> {
            this.titleValue = this.titleBox.getValue();
            this.minecraft.setScreen(this.bookEditScreen);
        }).bounds(this.width / 2 + 2, 196, 98, 20).build());
    }
 
    @Override
    protected void setInitialFocus() {
        this.setInitialFocus(this.titleBox);
    }
 
    private void saveChanges() {
        int slot = this.hand == InteractionHand.MAIN_HAND ? this.owner.getInventory().getSelectedSlot() : 40;
        this.minecraft.getConnection().send(new ServerboundEditBookPacket(slot, this.pages, Optional.of(this.titleBox.getValue().trim())));
    }
 
    @Override
    public boolean isInGameUi() {
        return true;
    }
 
    @Override
    public boolean keyPressed(KeyEvent event) {
        if (this.titleBox.isFocused() && !this.titleBox.getValue().isEmpty() && event.isConfirmation()) {
            this.saveChanges();
            this.minecraft.setScreen(null);
            return true;
        } else {
            return super.keyPressed(event);
        }
    }
 
    @Override
    public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
        super.extractRenderState(graphics, mouseX, mouseY, a);
        int xo = (this.width - 192) / 2;
        int yo = 2;
        int titleHeaderWidth = this.font.width(EDIT_TITLE_LABEL);
        graphics.text(this.font, EDIT_TITLE_LABEL, xo + 36 + (114 - titleHeaderWidth) / 2, 34, -16777216, false);
        int nameWidth = this.font.width(this.ownerText);
        graphics.text(this.font, this.ownerText, xo + 36 + (114 - nameWidth) / 2, 60, -16777216, false);
        graphics.textWithWordWrap(this.font, FINALIZE_WARNING_LABEL, xo + 36, 82, 114, -16777216, false);
    }
 
    @Override
    public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
        super.extractBackground(graphics, mouseX, mouseY, a);
        graphics.blit(RenderPipelines.GUI_TEXTURED, BookViewScreen.BOOK_LOCATION, (this.width - 192) / 2, 2, 0.0F, 0.0F, 192, 192, 256, 256);
    }
}

引用的其他类