WidgetTooltipHolder.java

net.minecraft.client.gui.components.WidgetTooltipHolder

信息

  • 全限定名:net.minecraft.client.gui.components.WidgetTooltipHolder
  • 类型:public class
  • 包:net.minecraft.client.gui.components
  • 源码路径:src/main/java/net/minecraft/client/gui/components/WidgetTooltipHolder.java
  • 起始行号:L17
  • 职责:

    TODO

字段/常量

  • tooltip

    • 类型: Tooltip
    • 修饰符: private
    • 源码定位: L18
    • 说明:

      TODO

  • delay

    • 类型: Duration
    • 修饰符: private
    • 源码定位: L19
    • 说明:

      TODO

  • displayStartTime

    • 类型: long
    • 修饰符: private
    • 源码定位: L20
    • 说明:

      TODO

  • wasDisplayed

    • 类型: boolean
    • 修饰符: private
    • 源码定位: L21
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

public void setDelay(Duration delay) @ L23

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

参数:

  • delay: Duration

说明:

TODO

public void set(Tooltip tooltip) @ L27

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

参数:

  • tooltip: Tooltip

说明:

TODO

public Tooltip get() @ L31

  • 方法名:get
  • 源码定位:L31
  • 返回类型:Tooltip
  • 修饰符:public

参数:

说明:

TODO

public void refreshTooltipForNextRenderPass(GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean isHovered, boolean isFocused, ScreenRectangle screenRectangle) @ L35

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

参数:

  • graphics: GuiGraphicsExtractor
  • mouseX: int
  • mouseY: int
  • isHovered: boolean
  • isFocused: boolean
  • screenRectangle: ScreenRectangle

说明:

TODO

private ClientTooltipPositioner createTooltipPositioner(ScreenRectangle screenRectangle, boolean isHovered, boolean isFocused) @ L66

  • 方法名:createTooltipPositioner
  • 源码定位:L66
  • 返回类型:ClientTooltipPositioner
  • 修饰符:private

参数:

  • screenRectangle: ScreenRectangle
  • isHovered: boolean
  • isFocused: boolean

说明:

TODO

public void updateNarration(NarrationElementOutput output) @ L72

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

参数:

  • output: NarrationElementOutput

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class WidgetTooltipHolder {
    private @Nullable Tooltip tooltip;
    private Duration delay = Duration.ZERO;
    private long displayStartTime;
    private boolean wasDisplayed;
 
    public void setDelay(Duration delay) {
        this.delay = delay;
    }
 
    public void set(@Nullable Tooltip tooltip) {
        this.tooltip = tooltip;
    }
 
    public @Nullable Tooltip get() {
        return this.tooltip;
    }
 
    public void refreshTooltipForNextRenderPass(
        GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean isHovered, boolean isFocused, ScreenRectangle screenRectangle
    ) {
        if (this.tooltip == null) {
            this.wasDisplayed = false;
        } else {
            Minecraft minecraft = Minecraft.getInstance();
            boolean shouldDisplay = isHovered || isFocused && minecraft.getLastInputType().isKeyboard();
            if (shouldDisplay != this.wasDisplayed) {
                if (shouldDisplay) {
                    this.displayStartTime = Util.getMillis();
                }
 
                this.wasDisplayed = shouldDisplay;
            }
 
            if (shouldDisplay && Util.getMillis() - this.displayStartTime > this.delay.toMillis()) {
                graphics.setTooltipForNextFrame(
                    minecraft.font,
                    this.tooltip.toCharSequence(minecraft),
                    this.tooltip.component(),
                    this.createTooltipPositioner(screenRectangle, isHovered, isFocused),
                    mouseX,
                    mouseY,
                    isFocused,
                    this.tooltip.style()
                );
            }
        }
    }
 
    private ClientTooltipPositioner createTooltipPositioner(ScreenRectangle screenRectangle, boolean isHovered, boolean isFocused) {
        return (ClientTooltipPositioner)(!isHovered && isFocused && Minecraft.getInstance().getLastInputType().isKeyboard()
            ? new BelowOrAboveWidgetTooltipPositioner(screenRectangle)
            : new MenuTooltipPositioner(screenRectangle));
    }
 
    public void updateNarration(NarrationElementOutput output) {
        if (this.tooltip != null) {
            this.tooltip.updateNarration(output);
        }
    }
}

引用的其他类