ObjectSelectionList.java

net.minecraft.client.gui.components.ObjectSelectionList

信息

  • 全限定名:net.minecraft.client.gui.components.ObjectSelectionList
  • 类型:public abstract class
  • 包:net.minecraft.client.gui.components
  • 源码路径:src/main/java/net/minecraft/client/gui/components/ObjectSelectionList.java
  • 起始行号:L16
  • 继承:AbstractSelectionList
  • 职责:

    TODO

字段/常量

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

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.components.ObjectSelectionList.Entry
    • 类型: class
    • 修饰符: public abstract static
    • 源码定位: L68
    • 说明:

      TODO

构造器

public ObjectSelectionList(Minecraft minecraft, int width, int height, int y, int itemHeight) @ L19

  • 构造器名:ObjectSelectionList
  • 源码定位:L19
  • 修饰符:public

参数:

  • minecraft: Minecraft
  • width: int
  • height: int
  • y: int
  • itemHeight: int

说明:

TODO

方法

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

public ComponentPath nextFocusPath(FocusNavigationEvent navigationEvent) @ L23

  • 方法名:nextFocusPath
  • 源码定位:L23
  • 返回类型:ComponentPath
  • 修饰符:public

参数:

  • navigationEvent: FocusNavigationEvent

说明:

TODO

public void updateWidgetNarration(NarrationElementOutput output) @ L48

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

参数:

  • output: NarrationElementOutput

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public abstract class ObjectSelectionList<E extends ObjectSelectionList.Entry<E>> extends AbstractSelectionList<E> {
    private static final Component USAGE_NARRATION = Component.translatable("narration.selection.usage");
 
    public ObjectSelectionList(Minecraft minecraft, int width, int height, int y, int itemHeight) {
        super(minecraft, width, height, y, itemHeight);
    }
 
    @Override
    public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent navigationEvent) {
        if (this.getItemCount() == 0) {
            return null;
        } else if (this.isFocused() && navigationEvent instanceof FocusNavigationEvent.ArrowNavigation arrowNavigation) {
            E entry = this.nextEntry(arrowNavigation.direction());
            if (entry != null) {
                return ComponentPath.path(this, ComponentPath.leaf(entry));
            } else {
                this.setFocused(null);
                this.setSelected(null);
                return null;
            }
        } else if (!this.isFocused()) {
            E entry = this.getSelected();
            if (entry == null) {
                entry = this.nextEntry(navigationEvent.getVerticalDirectionForInitialFocus());
            }
 
            return entry == null ? null : ComponentPath.path(this, ComponentPath.leaf(entry));
        } else {
            return null;
        }
    }
 
    @Override
    public void updateWidgetNarration(NarrationElementOutput output) {
        E hovered = this.getHovered();
        if (hovered != null) {
            this.narrateListElementPosition(output.nest(), hovered);
            hovered.updateNarration(output);
        } else {
            E selected = this.getSelected();
            if (selected != null) {
                this.narrateListElementPosition(output.nest(), selected);
                selected.updateNarration(output);
            }
        }
 
        if (this.isFocused()) {
            output.add(NarratedElementType.USAGE, USAGE_NARRATION);
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    public abstract static class Entry<E extends ObjectSelectionList.Entry<E>> extends AbstractSelectionList.Entry<E> implements NarrationSupplier {
        public abstract Component getNarration();
 
        @Override
        public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
            return true;
        }
 
        @Override
        public void updateNarration(NarrationElementOutput output) {
            output.add(NarratedElementType.TITLE, this.getNarration());
        }
    }
}

引用的其他类