BookEditScreen.java
net.minecraft.client.gui.screens.inventory.BookEditScreen
信息
- 全限定名:net.minecraft.client.gui.screens.inventory.BookEditScreen
- 类型:public class
- 包:net.minecraft.client.gui.screens.inventory
- 源码路径:src/main/java/net/minecraft/client/gui/screens/inventory/BookEditScreen.java
- 起始行号:L29
- 继承:Screen
- 职责:
TODO
字段/常量
-
TEXT_WIDTH- 类型:
int - 修饰符:
public static final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
TEXT_HEIGHT- 类型:
int - 修饰符:
public static final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
IMAGE_WIDTH- 类型:
int - 修饰符:
public static final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
IMAGE_HEIGHT- 类型:
int - 修饰符:
public static final - 源码定位:
L33 - 说明:
TODO
- 类型:
-
BACKGROUND_TEXTURE_WIDTH- 类型:
int - 修饰符:
public static final - 源码定位:
L34 - 说明:
TODO
- 类型:
-
BACKGROUND_TEXTURE_HEIGHT- 类型:
int - 修饰符:
public static final - 源码定位:
L35 - 说明:
TODO
- 类型:
-
MENU_BUTTON_MARGIN- 类型:
int - 修饰符:
private static final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
MENU_BUTTON_SIZE- 类型:
int - 修饰符:
private static final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
PAGE_BUTTON_Y- 类型:
int - 修饰符:
private static final - 源码定位:
L38 - 说明:
TODO
- 类型:
-
PAGE_BACK_BUTTON_X- 类型:
int - 修饰符:
private static final - 源码定位:
L39 - 说明:
TODO
- 类型:
-
PAGE_FORWARD_BUTTON_X- 类型:
int - 修饰符:
private static final - 源码定位:
L40 - 说明:
TODO
- 类型:
-
PAGE_INDICATOR_TEXT_Y_OFFSET- 类型:
int - 修饰符:
private static final - 源码定位:
L41 - 说明:
TODO
- 类型:
-
PAGE_INDICATOR_X_OFFSET- 类型:
int - 修饰符:
private static final - 源码定位:
L42 - 说明:
TODO
- 类型:
-
TITLE- 类型:
Component - 修饰符:
private static final - 源码定位:
L43 - 说明:
TODO
- 类型:
-
SIGN_BOOK_LABEL- 类型:
Component - 修饰符:
private static final - 源码定位:
L44 - 说明:
TODO
- 类型:
-
owner- 类型:
Player - 修饰符:
private final - 源码定位:
L45 - 说明:
TODO
- 类型:
-
book- 类型:
ItemStack - 修饰符:
private final - 源码定位:
L46 - 说明:
TODO
- 类型:
-
signScreen- 类型:
BookSignScreen - 修饰符:
private final - 源码定位:
L47 - 说明:
TODO
- 类型:
-
currentPage- 类型:
int - 修饰符:
private - 源码定位:
L48 - 说明:
TODO
- 类型:
-
pages- 类型:
List<String> - 修饰符:
private final - 源码定位:
L49 - 说明:
TODO
- 类型:
-
forwardButton- 类型:
PageButton - 修饰符:
private - 源码定位:
L50 - 说明:
TODO
- 类型:
-
backButton- 类型:
PageButton - 修饰符:
private - 源码定位:
L51 - 说明:
TODO
- 类型:
-
hand- 类型:
InteractionHand - 修饰符:
private final - 源码定位:
L52 - 说明:
TODO
- 类型:
-
numberOfPages- 类型:
Component - 修饰符:
private - 源码定位:
L53 - 说明:
TODO
- 类型:
-
page- 类型:
MultiLineEditBox - 修饰符:
private - 源码定位:
L54 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public BookEditScreen(Player owner, ItemStack book, InteractionHand hand, WritableBookContent content) @ L56
- 构造器名:BookEditScreen
- 源码定位:L56
- 修饰符:public
参数:
- owner: Player
- book: ItemStack
- hand: InteractionHand
- content: WritableBookContent
说明:
TODO
方法
下面的方法块按源码顺序生成。
private int getNumPages() @ L69
- 方法名:getNumPages
- 源码定位:L69
- 返回类型:int
- 修饰符:private
参数:
- 无
说明:
TODO
protected void init() @ L73
- 方法名:init
- 源码定位:L73
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
private int backgroundLeft() @ L108
- 方法名:backgroundLeft
- 源码定位:L108
- 返回类型:int
- 修饰符:private
参数:
- 无
说明:
TODO
private int backgroundTop() @ L112
- 方法名:backgroundTop
- 源码定位:L112
- 返回类型:int
- 修饰符:private
参数:
- 无
说明:
TODO
private int menuControlsTop() @ L116
- 方法名:menuControlsTop
- 源码定位:L116
- 返回类型:int
- 修饰符:private
参数:
- 无
说明:
TODO
protected void setInitialFocus() @ L120
- 方法名:setInitialFocus
- 源码定位:L120
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
public Component getNarrationMessage() @ L125
- 方法名:getNarrationMessage
- 源码定位:L125
- 返回类型:Component
- 修饰符:public
参数:
- 无
说明:
TODO
private Component getPageNumberMessage() @ L130
- 方法名:getPageNumberMessage
- 源码定位:L130
- 返回类型:Component
- 修饰符:private
参数:
- 无
说明:
TODO
private void pageBack() @ L134
- 方法名:pageBack
- 源码定位:L134
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private void pageForward() @ L143
- 方法名:pageForward
- 源码定位:L143
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private void updatePageContent() @ L157
- 方法名:updatePageContent
- 源码定位:L157
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private void updateButtonVisibility() @ L162
- 方法名:updateButtonVisibility
- 源码定位:L162
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private void eraseEmptyTrailingPages() @ L166
- 方法名:eraseEmptyTrailingPages
- 源码定位:L166
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private void saveChanges() @ L174
- 方法名:saveChanges
- 源码定位:L174
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private void updateLocalCopy() @ L181
- 方法名:updateLocalCopy
- 源码定位:L181
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private void appendPageToBook() @ L185
- 方法名:appendPageToBook
- 源码定位:L185
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
public boolean isInGameUi() @ L191
- 方法名:isInGameUi
- 源码定位:L191
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean keyPressed(KeyEvent event) @ L196
- 方法名:keyPressed
- 源码定位:L196
- 返回类型:boolean
- 修饰符:public
参数:
- event: KeyEvent
说明:
TODO
public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L210
- 方法名:extractRenderState
- 源码定位:L210
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
private void visitText(ActiveTextCollector collector) @ L216
- 方法名:visitText
- 源码定位:L216
- 返回类型:void
- 修饰符:private
参数:
- collector: ActiveTextCollector
说明:
TODO
public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L222
- 方法名:extractBackground
- 源码定位:L222
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class BookEditScreen extends Screen {
public static final int TEXT_WIDTH = 114;
public static final int TEXT_HEIGHT = 126;
public static final int IMAGE_WIDTH = 192;
public static final int IMAGE_HEIGHT = 192;
public static final int BACKGROUND_TEXTURE_WIDTH = 256;
public static final int BACKGROUND_TEXTURE_HEIGHT = 256;
private static final int MENU_BUTTON_MARGIN = 4;
private static final int MENU_BUTTON_SIZE = 98;
private static final int PAGE_BUTTON_Y = 157;
private static final int PAGE_BACK_BUTTON_X = 43;
private static final int PAGE_FORWARD_BUTTON_X = 116;
private static final int PAGE_INDICATOR_TEXT_Y_OFFSET = 16;
private static final int PAGE_INDICATOR_X_OFFSET = 148;
private static final Component TITLE = Component.translatable("book.edit.title");
private static final Component SIGN_BOOK_LABEL = Component.translatable("book.signButton");
private final Player owner;
private final ItemStack book;
private final BookSignScreen signScreen;
private int currentPage;
private final List<String> pages = Lists.newArrayList();
private PageButton forwardButton;
private PageButton backButton;
private final InteractionHand hand;
private Component numberOfPages = CommonComponents.EMPTY;
private MultiLineEditBox page;
public BookEditScreen(Player owner, ItemStack book, InteractionHand hand, WritableBookContent content) {
super(TITLE);
this.owner = owner;
this.book = book;
this.hand = hand;
content.getPages(Minecraft.getInstance().isTextFilteringEnabled()).forEach(this.pages::add);
if (this.pages.isEmpty()) {
this.pages.add("");
}
this.signScreen = new BookSignScreen(this, owner, hand, this.pages);
}
private int getNumPages() {
return this.pages.size();
}
@Override
protected void init() {
int left = this.backgroundLeft();
int top = this.backgroundTop();
int padding = 8;
this.page = MultiLineEditBox.builder()
.setShowDecorations(false)
.setTextColor(-16777216)
.setCursorColor(-16777216)
.setShowBackground(false)
.setTextShadow(false)
.setX((this.width - 114) / 2 - 8)
.setY(28)
.build(this.font, 122, 134, CommonComponents.EMPTY);
this.page.setCharacterLimit(1024);
this.page.setLineLimit(126 / 9);
this.page.setValueListener(value -> this.pages.set(this.currentPage, value));
this.addRenderableWidget(this.page);
this.updatePageContent();
this.numberOfPages = this.getPageNumberMessage();
this.backButton = this.addRenderableWidget(new PageButton(left + 43, top + 157, false, button -> this.pageBack(), true));
this.forwardButton = this.addRenderableWidget(new PageButton(left + 116, top + 157, true, button -> this.pageForward(), true));
this.addRenderableWidget(
Button.builder(SIGN_BOOK_LABEL, button -> this.minecraft.setScreen(this.signScreen))
.pos(this.width / 2 - 98 - 2, this.menuControlsTop())
.width(98)
.build()
);
this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, button -> {
this.minecraft.setScreen(null);
this.saveChanges();
}).pos(this.width / 2 + 2, this.menuControlsTop()).width(98).build());
this.updateButtonVisibility();
}
private int backgroundLeft() {
return (this.width - 192) / 2;
}
private int backgroundTop() {
return 2;
}
private int menuControlsTop() {
return this.backgroundTop() + 192 + 2;
}
@Override
protected void setInitialFocus() {
this.setInitialFocus(this.page);
}
@Override
public Component getNarrationMessage() {
return CommonComponents.joinForNarration(super.getNarrationMessage(), this.getPageNumberMessage());
}
private Component getPageNumberMessage() {
return Component.translatable("book.pageIndicator", this.currentPage + 1, this.getNumPages()).withColor(-16777216).withoutShadow();
}
private void pageBack() {
if (this.currentPage > 0) {
this.currentPage--;
this.updatePageContent();
}
this.updateButtonVisibility();
}
private void pageForward() {
if (this.currentPage < this.getNumPages() - 1) {
this.currentPage++;
} else {
this.appendPageToBook();
if (this.currentPage < this.getNumPages() - 1) {
this.currentPage++;
}
}
this.updatePageContent();
this.updateButtonVisibility();
}
private void updatePageContent() {
this.page.setValue(this.pages.get(this.currentPage), true);
this.numberOfPages = this.getPageNumberMessage();
}
private void updateButtonVisibility() {
this.backButton.visible = this.currentPage > 0;
}
private void eraseEmptyTrailingPages() {
ListIterator<String> pagesIt = this.pages.listIterator(this.pages.size());
while (pagesIt.hasPrevious() && pagesIt.previous().isEmpty()) {
pagesIt.remove();
}
}
private void saveChanges() {
this.eraseEmptyTrailingPages();
this.updateLocalCopy();
int slot = this.hand == InteractionHand.MAIN_HAND ? this.owner.getInventory().getSelectedSlot() : 40;
this.minecraft.getConnection().send(new ServerboundEditBookPacket(slot, this.pages, Optional.empty()));
}
private void updateLocalCopy() {
this.book.set(DataComponents.WRITABLE_BOOK_CONTENT, new WritableBookContent(this.pages.stream().map(Filterable::passThrough).toList()));
}
private void appendPageToBook() {
if (this.getNumPages() < 100) {
this.pages.add("");
}
}
@Override
public boolean isInGameUi() {
return true;
}
@Override
public boolean keyPressed(KeyEvent event) {
switch (event.key()) {
case 266:
this.backButton.onPress(event);
return true;
case 267:
this.forwardButton.onPress(event);
return true;
default:
return super.keyPressed(event);
}
}
@Override
public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
super.extractRenderState(graphics, mouseX, mouseY, a);
this.visitText(graphics.textRenderer());
}
private void visitText(ActiveTextCollector collector) {
int left = this.backgroundLeft();
int top = this.backgroundTop();
collector.accept(TextAlignment.RIGHT, left + 148, top + 16, this.numberOfPages);
}
@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.backgroundLeft(), this.backgroundTop(), 0.0F, 0.0F, 192, 192, 256, 256);
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
Minecraft.getInstance()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Button.builder()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
MultiLineEditBox.builder()
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
BookSignScreen()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
PageButton()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
CommonComponents.joinForNarration()
- 引用位置:
-
- 引用位置:
字段/方法调用/返回值 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
ServerboundEditBookPacket()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/构造调用 - 关联成员:
WritableBookContent()
- 引用位置: