SpectatorGui.java

net.minecraft.client.gui.components.spectator.SpectatorGui

信息

  • 全限定名:net.minecraft.client.gui.components.spectator.SpectatorGui
  • 类型:public class
  • 包:net.minecraft.client.gui.components.spectator
  • 源码路径:src/main/java/net/minecraft/client/gui/components/spectator/SpectatorGui.java
  • 起始行号:L20
  • 实现:SpectatorMenuListener
  • 职责:

    TODO

字段/常量

  • HOTBAR_SPRITE

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

      TODO

  • HOTBAR_SELECTION_SPRITE

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

      TODO

  • FADE_OUT_DELAY

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

      TODO

  • FADE_OUT_TIME

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

      TODO

  • minecraft

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

      TODO

  • lastSelectionTime

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

      TODO

  • menu

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

      TODO

内部类/嵌套类型

构造器

public SpectatorGui(Minecraft minecraft) @ L29

  • 构造器名:SpectatorGui
  • 源码定位:L29
  • 修饰符:public

参数:

  • minecraft: Minecraft

说明:

TODO

方法

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

public void onHotbarSelected(int slot) @ L33

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

参数:

  • slot: int

说明:

TODO

private float getHotbarAlpha() @ L42

  • 方法名:getHotbarAlpha
  • 源码定位:L42
  • 返回类型:float
  • 修饰符:private

参数:

说明:

TODO

public void extractHotbar(GuiGraphicsExtractor graphics) @ L47

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

参数:

  • graphics: GuiGraphicsExtractor

说明:

TODO

protected void extractPage(GuiGraphicsExtractor graphics, float alpha, int screenCenter, int y, SpectatorPage page) @ L61

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

参数:

  • graphics: GuiGraphicsExtractor
  • alpha: float
  • screenCenter: int
  • y: int
  • page: SpectatorPage

说明:

TODO

private void extractSlot(GuiGraphicsExtractor graphics, int slot, int x, float y, float alpha, SpectatorMenuItem item) @ L75

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

参数:

  • graphics: GuiGraphicsExtractor
  • slot: int
  • x: int
  • y: float
  • alpha: float
  • item: SpectatorMenuItem

说明:

TODO

public void extractAction(GuiGraphicsExtractor graphics) @ L89

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

参数:

  • graphics: GuiGraphicsExtractor

说明:

TODO

public void onSpectatorMenuClosed(SpectatorMenu menu) @ L101

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

参数:

  • menu: SpectatorMenu

说明:

TODO

public boolean isMenuActive() @ L107

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

参数:

说明:

TODO

public void onMouseScrolled(int wheel) @ L111

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

参数:

  • wheel: int

说明:

TODO

public void onHotbarActionKeyPressed() @ L124

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

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class SpectatorGui implements SpectatorMenuListener {
    private static final Identifier HOTBAR_SPRITE = Identifier.withDefaultNamespace("hud/hotbar");
    private static final Identifier HOTBAR_SELECTION_SPRITE = Identifier.withDefaultNamespace("hud/hotbar_selection");
    private static final long FADE_OUT_DELAY = 5000L;
    private static final long FADE_OUT_TIME = 2000L;
    private final Minecraft minecraft;
    private long lastSelectionTime;
    private @Nullable SpectatorMenu menu;
 
    public SpectatorGui(Minecraft minecraft) {
        this.minecraft = minecraft;
    }
 
    public void onHotbarSelected(int slot) {
        this.lastSelectionTime = Util.getMillis();
        if (this.menu != null) {
            this.menu.selectSlot(slot);
        } else {
            this.menu = new SpectatorMenu(this);
        }
    }
 
    private float getHotbarAlpha() {
        long delta = this.lastSelectionTime - Util.getMillis() + 5000L;
        return Mth.clamp((float)delta / 2000.0F, 0.0F, 1.0F);
    }
 
    public void extractHotbar(GuiGraphicsExtractor graphics) {
        if (this.menu != null) {
            float alpha = this.getHotbarAlpha();
            if (alpha <= 0.0F) {
                this.menu.exit();
            } else {
                int screenCenter = graphics.guiWidth() / 2;
                int y = Mth.floor(graphics.guiHeight() - 22.0F * alpha);
                SpectatorPage page = this.menu.getCurrentPage();
                this.extractPage(graphics, alpha, screenCenter, y, page);
            }
        }
    }
 
    protected void extractPage(GuiGraphicsExtractor graphics, float alpha, int screenCenter, int y, SpectatorPage page) {
        int color = ARGB.white(alpha);
        graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_SPRITE, screenCenter - 91, y, 182, 22, color);
        if (page.getSelectedSlot() >= 0) {
            graphics.blitSprite(
                RenderPipelines.GUI_TEXTURED, HOTBAR_SELECTION_SPRITE, screenCenter - 91 - 1 + page.getSelectedSlot() * 20, y - 1, 24, 23, color
            );
        }
 
        for (int slot = 0; slot < 9; slot++) {
            this.extractSlot(graphics, slot, graphics.guiWidth() / 2 - 90 + slot * 20 + 2, y + 3, alpha, page.getItem(slot));
        }
    }
 
    private void extractSlot(GuiGraphicsExtractor graphics, int slot, int x, float y, float alpha, SpectatorMenuItem item) {
        if (item != SpectatorMenu.EMPTY_SLOT) {
            graphics.pose().pushMatrix();
            graphics.pose().translate(x, y);
            float brightness = item.isEnabled() ? 1.0F : 0.25F;
            item.extractIcon(graphics, brightness, alpha);
            graphics.pose().popMatrix();
            if (alpha > 0.0F && item.isEnabled()) {
                Component key = this.minecraft.options.keyHotbarSlots[slot].getTranslatedKeyMessage();
                graphics.text(this.minecraft.font, key, x + 19 - 2 - this.minecraft.font.width(key), (int)y + 6 + 3, ARGB.white(alpha));
            }
        }
    }
 
    public void extractAction(GuiGraphicsExtractor graphics) {
        float alpha = this.getHotbarAlpha();
        if (alpha > 0.0F && this.menu != null) {
            SpectatorMenuItem item = this.menu.getSelectedItem();
            Component action = item == SpectatorMenu.EMPTY_SLOT ? this.menu.getSelectedCategory().getPrompt() : item.getName();
            int strWidth = this.minecraft.font.width(action);
            int x = (graphics.guiWidth() - strWidth) / 2;
            int y = graphics.guiHeight() - 35;
            graphics.textWithBackdrop(this.minecraft.font, action, x, y, strWidth, ARGB.white(alpha));
        }
    }
 
    @Override
    public void onSpectatorMenuClosed(SpectatorMenu menu) {
        this.menu = null;
        this.lastSelectionTime = 0L;
    }
 
    public boolean isMenuActive() {
        return this.menu != null;
    }
 
    public void onMouseScrolled(int wheel) {
        int newSlot = this.menu.getSelectedSlot() + wheel;
 
        while (newSlot >= 0 && newSlot <= 8 && (this.menu.getItem(newSlot) == SpectatorMenu.EMPTY_SLOT || !this.menu.getItem(newSlot).isEnabled())) {
            newSlot += wheel;
        }
 
        if (newSlot >= 0 && newSlot <= 8) {
            this.menu.selectSlot(newSlot);
            this.lastSelectionTime = Util.getMillis();
        }
    }
 
    public void onHotbarActionKeyPressed() {
        this.lastSelectionTime = Util.getMillis();
        if (this.isMenuActive()) {
            int selectedSlot = this.menu.getSelectedSlot();
            if (selectedSlot != -1) {
                this.menu.selectSlot(selectedSlot);
            }
        } else {
            this.menu = new SpectatorMenu(this);
        }
    }
}

引用的其他类