LockIconButton.java

net.minecraft.client.gui.components.LockIconButton

信息

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

    TODO

字段/常量

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

      TODO

内部类/嵌套类型

  • net.minecraft.client.gui.components.LockIconButton.Icon
    • 类型: enum
    • 修饰符: private static
    • 源码定位: L53
    • 说明:

      TODO

构造器

public LockIconButton(int x, int y, Button.OnPress onPress) @ L16

  • 构造器名:LockIconButton
  • 源码定位:L16
  • 修饰符:public

参数:

  • x: int
  • y: int
  • onPress: Button.OnPress

说明:

TODO

方法

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

protected MutableComponent createNarrationMessage() @ L20

  • 方法名:createNarrationMessage
  • 源码定位:L20
  • 返回类型:MutableComponent
  • 修饰符:protected

参数:

说明:

TODO

public boolean isLocked() @ L30

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

参数:

说明:

TODO

public void setLocked(boolean locked) @ L34

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

参数:

  • locked: boolean

说明:

TODO

public void extractContents(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L38

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

参数:

  • graphics: GuiGraphicsExtractor
  • mouseX: int
  • mouseY: int
  • a: float

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class LockIconButton extends Button {
    private boolean locked;
 
    public LockIconButton(int x, int y, Button.OnPress onPress) {
        super(x, y, 20, 20, Component.translatable("narrator.button.difficulty_lock"), onPress, DEFAULT_NARRATION);
    }
 
    @Override
    protected MutableComponent createNarrationMessage() {
        return CommonComponents.joinForNarration(
            super.createNarrationMessage(),
            this.isLocked()
                ? Component.translatable("narrator.button.difficulty_lock.locked")
                : Component.translatable("narrator.button.difficulty_lock.unlocked")
        );
    }
 
    public boolean isLocked() {
        return this.locked;
    }
 
    public void setLocked(boolean locked) {
        this.locked = locked;
    }
 
    @Override
    public void extractContents(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
        LockIconButton.Icon icon;
        if (!this.active) {
            icon = this.locked ? LockIconButton.Icon.LOCKED_DISABLED : LockIconButton.Icon.UNLOCKED_DISABLED;
        } else if (this.isHoveredOrFocused()) {
            icon = this.locked ? LockIconButton.Icon.LOCKED_HOVER : LockIconButton.Icon.UNLOCKED_HOVER;
        } else {
            icon = this.locked ? LockIconButton.Icon.LOCKED : LockIconButton.Icon.UNLOCKED;
        }
 
        graphics.blitSprite(RenderPipelines.GUI_TEXTURED, icon.sprite, this.getX(), this.getY(), this.width, this.height);
    }
 
    @OnlyIn(Dist.CLIENT)
    private static enum Icon {
        LOCKED(Identifier.withDefaultNamespace("widget/locked_button")),
        LOCKED_HOVER(Identifier.withDefaultNamespace("widget/locked_button_highlighted")),
        LOCKED_DISABLED(Identifier.withDefaultNamespace("widget/locked_button_disabled")),
        UNLOCKED(Identifier.withDefaultNamespace("widget/unlocked_button")),
        UNLOCKED_HOVER(Identifier.withDefaultNamespace("widget/unlocked_button_highlighted")),
        UNLOCKED_DISABLED(Identifier.withDefaultNamespace("widget/unlocked_button_disabled"));
 
        private final Identifier sprite;
 
        private Icon(Identifier sprite) {
            this.sprite = sprite;
        }
    }
}

引用的其他类