TransferableSelectionList.java
net.minecraft.client.gui.screens.packs.TransferableSelectionList
信息
- 全限定名:net.minecraft.client.gui.screens.packs.TransferableSelectionList
- 类型:public class
- 包:net.minecraft.client.gui.screens.packs
- 源码路径:src/main/java/net/minecraft/client/gui/screens/packs/TransferableSelectionList.java
- 起始行号:L27
- 继承:ObjectSelectionList<TransferableSelectionList.Entry>
- 职责:
TODO
字段/常量
-
SELECT_HIGHLIGHTED_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
SELECT_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
UNSELECT_HIGHLIGHTED_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
UNSELECT_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
MOVE_UP_HIGHLIGHTED_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
MOVE_UP_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L33 - 说明:
TODO
- 类型:
-
MOVE_DOWN_HIGHLIGHTED_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L34 - 说明:
TODO
- 类型:
-
MOVE_DOWN_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L35 - 说明:
TODO
- 类型:
-
INCOMPATIBLE_TITLE- 类型:
Component - 修饰符:
private static final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
INCOMPATIBLE_CONFIRM_TITLE- 类型:
Component - 修饰符:
private static final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
ENTRY_PADDING- 类型:
int - 修饰符:
private static final - 源码定位:
L38 - 说明:
TODO
- 类型:
-
title- 类型:
Component - 修饰符:
private final - 源码定位:
L39 - 说明:
TODO
- 类型:
-
screen- 类型:
PackSelectionScreen - 修饰符:
private final - 源码定位:
L40 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.client.gui.screens.packs.TransferableSelectionList.Entry- 类型:
class - 修饰符:
public abstract - 源码定位:
L81 - 说明:
TODO
- 类型:
-
net.minecraft.client.gui.screens.packs.TransferableSelectionList.HeaderEntry- 类型:
class - 修饰符:
public - 源码定位:
L96 - 说明:
TODO
- 类型:
-
net.minecraft.client.gui.screens.packs.TransferableSelectionList.PackEntry- 类型:
class - 修饰符:
public - 源码定位:
L124 - 说明:
TODO
- 类型:
构造器
public TransferableSelectionList(Minecraft minecraft, PackSelectionScreen screen, int width, int height, Component title) @ L42
- 构造器名:TransferableSelectionList
- 源码定位:L42
- 修饰符:public
参数:
- minecraft: Minecraft
- screen: PackSelectionScreen
- width: int
- height: int
- title: Component
说明:
TODO
方法
下面的方法块按源码顺序生成。
public int getRowWidth() @ L49
- 方法名:getRowWidth
- 源码定位:L49
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
protected int scrollBarX() @ L54
- 方法名:scrollBarX
- 源码定位:L54
- 返回类型:int
- 修饰符:protected
参数:
- 无
说明:
TODO
public boolean keyPressed(KeyEvent event) @ L59
- 方法名:keyPressed
- 源码定位:L59
- 返回类型:boolean
- 修饰符:public
参数:
- event: KeyEvent
说明:
TODO
public void updateList(Stream<PackSelectionModel.Entry> entries, PackSelectionModel.EntryBase transferredEntry) @ L64
- 方法名:updateList
- 源码定位:L64
- 返回类型:void
- 修饰符:public
参数:
- entries: Stream<PackSelectionModel.Entry>
- transferredEntry: PackSelectionModel.EntryBase
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class TransferableSelectionList extends ObjectSelectionList<TransferableSelectionList.Entry> {
private static final Identifier SELECT_HIGHLIGHTED_SPRITE = Identifier.withDefaultNamespace("transferable_list/select_highlighted");
private static final Identifier SELECT_SPRITE = Identifier.withDefaultNamespace("transferable_list/select");
private static final Identifier UNSELECT_HIGHLIGHTED_SPRITE = Identifier.withDefaultNamespace("transferable_list/unselect_highlighted");
private static final Identifier UNSELECT_SPRITE = Identifier.withDefaultNamespace("transferable_list/unselect");
private static final Identifier MOVE_UP_HIGHLIGHTED_SPRITE = Identifier.withDefaultNamespace("transferable_list/move_up_highlighted");
private static final Identifier MOVE_UP_SPRITE = Identifier.withDefaultNamespace("transferable_list/move_up");
private static final Identifier MOVE_DOWN_HIGHLIGHTED_SPRITE = Identifier.withDefaultNamespace("transferable_list/move_down_highlighted");
private static final Identifier MOVE_DOWN_SPRITE = Identifier.withDefaultNamespace("transferable_list/move_down");
private static final Component INCOMPATIBLE_TITLE = Component.translatable("pack.incompatible");
private static final Component INCOMPATIBLE_CONFIRM_TITLE = Component.translatable("pack.incompatible.confirm.title");
private static final int ENTRY_PADDING = 2;
private final Component title;
private final PackSelectionScreen screen;
public TransferableSelectionList(Minecraft minecraft, PackSelectionScreen screen, int width, int height, Component title) {
super(minecraft, width, height, 33, 36);
this.screen = screen;
this.title = title;
this.centerListVertically = false;
}
@Override
public int getRowWidth() {
return this.width - 4;
}
@Override
protected int scrollBarX() {
return this.getRight() - this.scrollbarWidth();
}
@Override
public boolean keyPressed(KeyEvent event) {
return this.getSelected() != null ? this.getSelected().keyPressed(event) : super.keyPressed(event);
}
public void updateList(Stream<PackSelectionModel.Entry> entries, PackSelectionModel.@Nullable EntryBase transferredEntry) {
this.clearEntries();
Component header = Component.empty().append(this.title).withStyle(ChatFormatting.UNDERLINE, ChatFormatting.BOLD);
this.addEntry(new TransferableSelectionList.HeaderEntry(this.minecraft.font, header), (int)(9.0F * 1.5F));
this.setSelected(null);
entries.forEach(e -> {
TransferableSelectionList.PackEntry entry = new TransferableSelectionList.PackEntry(this.minecraft, this, e);
this.addEntry(entry);
if (transferredEntry != null && transferredEntry.getId().equals(e.getId())) {
this.screen.setFocused(this);
this.setFocused(entry);
}
});
this.refreshScrollAmount();
}
@OnlyIn(Dist.CLIENT)
public abstract class Entry extends ObjectSelectionList.Entry<TransferableSelectionList.Entry> {
public Entry() {
Objects.requireNonNull(TransferableSelectionList.this);
super();
}
@Override
public int getWidth() {
return super.getWidth() - (TransferableSelectionList.this.scrollable() ? TransferableSelectionList.this.scrollbarWidth() : 0);
}
public abstract String getPackId();
}
@OnlyIn(Dist.CLIENT)
public class HeaderEntry extends TransferableSelectionList.Entry {
private final Font font;
private final Component text;
public HeaderEntry(Font font, Component text) {
Objects.requireNonNull(TransferableSelectionList.this);
super();
this.font = font;
this.text = text;
}
@Override
public void extractContent(GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean hovered, float a) {
graphics.centeredText(this.font, this.text, this.getX() + this.getWidth() / 2, this.getContentYMiddle() - 9 / 2, -1);
}
@Override
public Component getNarration() {
return this.text;
}
@Override
public String getPackId() {
return "";
}
}
@OnlyIn(Dist.CLIENT)
public class PackEntry extends TransferableSelectionList.Entry implements SelectableEntry {
private static final int MAX_DESCRIPTION_WIDTH_PIXELS = 157;
public static final int ICON_SIZE = 32;
private final TransferableSelectionList parent;
protected final Minecraft minecraft;
private final PackSelectionModel.Entry pack;
private final StringWidget nameWidget;
private final MultiLineTextWidget descriptionWidget;
public PackEntry(Minecraft minecraft, TransferableSelectionList parent, PackSelectionModel.Entry pack) {
Objects.requireNonNull(TransferableSelectionList.this);
super();
this.minecraft = minecraft;
this.pack = pack;
this.parent = parent;
this.nameWidget = new StringWidget(pack.getTitle(), minecraft.font);
this.descriptionWidget = new MultiLineTextWidget(
ComponentUtils.mergeStyles(pack.getExtendedDescription(), Style.EMPTY.withColor(-8355712)), minecraft.font
);
this.descriptionWidget.setMaxRows(2);
}
@Override
public Component getNarration() {
return Component.translatable("narrator.select", this.pack.getTitle());
}
@Override
public void extractContent(GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean hovered, float a) {
PackCompatibility compatibility = this.pack.getCompatibility();
if (!compatibility.isCompatible()) {
int x0 = this.getContentX() - 1;
int y0 = this.getContentY() - 1;
int x1 = this.getContentRight() + 1;
int y1 = this.getContentBottom() + 1;
graphics.fill(x0, y0, x1, y1, -8978432);
}
graphics.blit(RenderPipelines.GUI_TEXTURED, this.pack.getIconTexture(), this.getContentX(), this.getContentY(), 0.0F, 0.0F, 32, 32, 32, 32);
if (!this.nameWidget.getMessage().equals(this.pack.getTitle())) {
this.nameWidget.setMessage(this.pack.getTitle());
}
if (!this.descriptionWidget.getMessage().getContents().equals(this.pack.getExtendedDescription().getContents())) {
this.descriptionWidget.setMessage(ComponentUtils.mergeStyles(this.pack.getExtendedDescription(), Style.EMPTY.withColor(-8355712)));
}
if (this.showHoverOverlay()
&& (this.minecraft.options.touchscreen().get() || hovered || this.parent.getSelected() == this && this.parent.isFocused())) {
graphics.fill(this.getContentX(), this.getContentY(), this.getContentX() + 32, this.getContentY() + 32, -1601138544);
int relX = mouseX - this.getContentX();
int relY = mouseY - this.getContentY();
if (!this.pack.getCompatibility().isCompatible()) {
this.nameWidget.setMessage(TransferableSelectionList.INCOMPATIBLE_TITLE);
this.descriptionWidget.setMessage(this.pack.getCompatibility().getDescription());
}
if (this.pack.canSelect()) {
if (this.mouseOverIcon(relX, relY, 32)) {
graphics.blitSprite(
RenderPipelines.GUI_TEXTURED, TransferableSelectionList.SELECT_HIGHLIGHTED_SPRITE, this.getContentX(), this.getContentY(), 32, 32
);
TransferableSelectionList.this.handleCursor(graphics);
} else {
graphics.blitSprite(
RenderPipelines.GUI_TEXTURED, TransferableSelectionList.SELECT_SPRITE, this.getContentX(), this.getContentY(), 32, 32
);
}
} else {
if (this.pack.canUnselect()) {
if (this.mouseOverLeftHalf(relX, relY, 32)) {
graphics.blitSprite(
RenderPipelines.GUI_TEXTURED,
TransferableSelectionList.UNSELECT_HIGHLIGHTED_SPRITE,
this.getContentX(),
this.getContentY(),
32,
32
);
TransferableSelectionList.this.handleCursor(graphics);
} else {
graphics.blitSprite(
RenderPipelines.GUI_TEXTURED, TransferableSelectionList.UNSELECT_SPRITE, this.getContentX(), this.getContentY(), 32, 32
);
}
}
if (this.pack.canMoveUp()) {
if (this.mouseOverTopRightQuarter(relX, relY, 32)) {
graphics.blitSprite(
RenderPipelines.GUI_TEXTURED,
TransferableSelectionList.MOVE_UP_HIGHLIGHTED_SPRITE,
this.getContentX(),
this.getContentY(),
32,
32
);
TransferableSelectionList.this.handleCursor(graphics);
} else {
graphics.blitSprite(
RenderPipelines.GUI_TEXTURED, TransferableSelectionList.MOVE_UP_SPRITE, this.getContentX(), this.getContentY(), 32, 32
);
}
}
if (this.pack.canMoveDown()) {
if (this.mouseOverBottomRightQuarter(relX, relY, 32)) {
graphics.blitSprite(
RenderPipelines.GUI_TEXTURED,
TransferableSelectionList.MOVE_DOWN_HIGHLIGHTED_SPRITE,
this.getContentX(),
this.getContentY(),
32,
32
);
TransferableSelectionList.this.handleCursor(graphics);
} else {
graphics.blitSprite(
RenderPipelines.GUI_TEXTURED, TransferableSelectionList.MOVE_DOWN_SPRITE, this.getContentX(), this.getContentY(), 32, 32
);
}
}
}
}
this.nameWidget.setMaxWidth(157 - (TransferableSelectionList.this.scrollable() ? 6 : 0));
this.nameWidget.setPosition(this.getContentX() + 32 + 2, this.getContentY() + 1);
this.nameWidget.extractRenderState(graphics, mouseX, mouseY, a);
this.descriptionWidget.setMaxWidth(157 - (TransferableSelectionList.this.scrollable() ? 6 : 0));
this.descriptionWidget.setPosition(this.getContentX() + 32 + 2, this.getContentY() + 12);
this.descriptionWidget.extractRenderState(graphics, mouseX, mouseY, a);
}
@Override
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
if (this.showHoverOverlay()) {
int relX = (int)event.x() - this.getContentX();
int relY = (int)event.y() - this.getContentY();
if (this.pack.canSelect() && this.mouseOverIcon(relX, relY, 32)) {
this.handlePackSelection();
return true;
}
if (this.pack.canUnselect() && this.mouseOverLeftHalf(relX, relY, 32)) {
this.pack.unselect();
return true;
}
if (this.pack.canMoveUp() && this.mouseOverTopRightQuarter(relX, relY, 32)) {
this.pack.moveUp();
return true;
}
if (this.pack.canMoveDown() && this.mouseOverBottomRightQuarter(relX, relY, 32)) {
this.pack.moveDown();
return true;
}
}
return super.mouseClicked(event, doubleClick);
}
@Override
public boolean keyPressed(KeyEvent event) {
if (event.isConfirmation()) {
this.keyboardSelection();
return true;
} else {
if (event.hasShiftDown()) {
if (event.isUp()) {
this.keyboardMoveUp();
return true;
}
if (event.isDown()) {
this.keyboardMoveDown();
return true;
}
}
return super.keyPressed(event);
}
}
private boolean showHoverOverlay() {
return !this.pack.isFixedPosition() || !this.pack.isRequired();
}
public void keyboardSelection() {
if (this.pack.canSelect()) {
this.handlePackSelection();
} else if (this.pack.canUnselect()) {
this.pack.unselect();
}
}
private void keyboardMoveUp() {
if (this.pack.canMoveUp()) {
this.pack.moveUp();
}
}
private void keyboardMoveDown() {
if (this.pack.canMoveDown()) {
this.pack.moveDown();
}
}
private void handlePackSelection() {
if (this.pack.getCompatibility().isCompatible()) {
this.pack.select();
} else {
Component reason = this.pack.getCompatibility().getConfirmation();
this.minecraft.setScreen(new ConfirmScreen(result -> {
this.minecraft.setScreen(this.parent.screen);
if (result) {
this.pack.select();
}
}, TransferableSelectionList.INCOMPATIBLE_CONFIRM_TITLE, reason));
}
}
@Override
public String getPackId() {
return this.pack.getId();
}
@Override
public boolean shouldTakeFocusAfterInteraction() {
return TransferableSelectionList.this.children().stream().anyMatch(entry -> entry.getPackId().equals(this.getPackId()));
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
MultiLineTextWidget()
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
StringWidget()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
ConfirmScreen()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/方法调用 - 关联成员:
Component.empty(), Component.translatable()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ComponentUtils.mergeStyles()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置: