SpriteIconButton.java
net.minecraft.client.gui.components.SpriteIconButton
信息
- 全限定名:net.minecraft.client.gui.components.SpriteIconButton
- 类型:public abstract class
- 包:net.minecraft.client.gui.components
- 源码路径:src/main/java/net/minecraft/client/gui/components/SpriteIconButton.java
- 起始行号:L13
- 继承:Button
- 职责:
TODO
字段/常量
-
sprite- 类型:
WidgetSprites - 修饰符:
protected final - 源码定位:
L14 - 说明:
TODO
- 类型:
-
spriteWidth- 类型:
int - 修饰符:
protected final - 源码定位:
L15 - 说明:
TODO
- 类型:
-
spriteHeight- 类型:
int - 修饰符:
protected final - 源码定位:
L16 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.client.gui.components.SpriteIconButton.Builder- 类型:
class - 修饰符:
public static - 源码定位:
L50 - 说明:
TODO
- 类型:
-
net.minecraft.client.gui.components.SpriteIconButton.CenteredIcon- 类型:
class - 修饰符:
public static - 源码定位:
L119 - 说明:
TODO
- 类型:
-
net.minecraft.client.gui.components.SpriteIconButton.TextAndIcon- 类型:
class - 修饰符:
public static - 源码定位:
L144 - 说明:
TODO
- 类型:
构造器
private SpriteIconButton(int width, int height, Component message, int spriteWidth, int spriteHeight, WidgetSprites sprite, Button.OnPress onPress, Component tooltip, Button.CreateNarration narration) @ L18
- 构造器名:SpriteIconButton
- 源码定位:L18
- 修饰符:private
参数:
- width: int
- height: int
- message: Component
- spriteWidth: int
- spriteHeight: int
- sprite: WidgetSprites
- onPress: Button.OnPress
- tooltip: Component
- narration: Button.CreateNarration
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected void extractSprite(GuiGraphicsExtractor graphics, int x, int y) @ L39
- 方法名:extractSprite
- 源码定位:L39
- 返回类型:void
- 修饰符:protected
参数:
- graphics: GuiGraphicsExtractor
- x: int
- y: int
说明:
TODO
public static SpriteIconButton.Builder builder(Component message, Button.OnPress onPress, boolean iconOnly) @ L45
- 方法名:builder
- 源码定位:L45
- 返回类型:SpriteIconButton.Builder
- 修饰符:public static
参数:
- message: Component
- onPress: Button.OnPress
- iconOnly: boolean
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public abstract class SpriteIconButton extends Button {
protected final WidgetSprites sprite;
protected final int spriteWidth;
protected final int spriteHeight;
private SpriteIconButton(
int width,
int height,
Component message,
int spriteWidth,
int spriteHeight,
WidgetSprites sprite,
Button.OnPress onPress,
@Nullable Component tooltip,
Button.@Nullable CreateNarration narration
) {
super(0, 0, width, height, message, onPress, narration == null ? DEFAULT_NARRATION : narration);
if (tooltip != null) {
this.setTooltip(Tooltip.create(tooltip));
}
this.spriteWidth = spriteWidth;
this.spriteHeight = spriteHeight;
this.sprite = sprite;
}
protected void extractSprite(GuiGraphicsExtractor graphics, int x, int y) {
graphics.blitSprite(
RenderPipelines.GUI_TEXTURED, this.sprite.get(this.isActive(), this.isHoveredOrFocused()), x, y, this.spriteWidth, this.spriteHeight, this.alpha
);
}
public static SpriteIconButton.Builder builder(Component message, Button.OnPress onPress, boolean iconOnly) {
return new SpriteIconButton.Builder(message, onPress, iconOnly);
}
@OnlyIn(Dist.CLIENT)
public static class Builder {
private final Component message;
private final Button.OnPress onPress;
private final boolean iconOnly;
private int width = 150;
private int height = 20;
private @Nullable WidgetSprites sprite;
private int spriteWidth;
private int spriteHeight;
private @Nullable Component tooltip;
private Button.@Nullable CreateNarration narration;
public Builder(Component message, Button.OnPress onPress, boolean iconOnly) {
this.message = message;
this.onPress = onPress;
this.iconOnly = iconOnly;
}
public SpriteIconButton.Builder width(int width) {
this.width = width;
return this;
}
public SpriteIconButton.Builder size(int width, int height) {
this.width = width;
this.height = height;
return this;
}
public SpriteIconButton.Builder sprite(Identifier sprite, int spriteWidth, int spriteHeight) {
this.sprite = new WidgetSprites(sprite);
this.spriteWidth = spriteWidth;
this.spriteHeight = spriteHeight;
return this;
}
public SpriteIconButton.Builder sprite(WidgetSprites sprite, int spriteWidth, int spriteHeight) {
this.sprite = sprite;
this.spriteWidth = spriteWidth;
this.spriteHeight = spriteHeight;
return this;
}
public SpriteIconButton.Builder withTootip() {
this.tooltip = this.message;
return this;
}
public SpriteIconButton.Builder narration(Button.CreateNarration narration) {
this.narration = narration;
return this;
}
public SpriteIconButton build() {
if (this.sprite == null) {
throw new IllegalStateException("Sprite not set");
} else {
return (SpriteIconButton)(this.iconOnly
? new SpriteIconButton.CenteredIcon(
this.width, this.height, this.message, this.spriteWidth, this.spriteHeight, this.sprite, this.onPress, this.tooltip, this.narration
)
: new SpriteIconButton.TextAndIcon(
this.width, this.height, this.message, this.spriteWidth, this.spriteHeight, this.sprite, this.onPress, this.tooltip, this.narration
));
}
}
}
@OnlyIn(Dist.CLIENT)
public static class CenteredIcon extends SpriteIconButton {
protected CenteredIcon(
int width,
int height,
Component message,
int spriteWidth,
int spriteHeight,
WidgetSprites sprite,
Button.OnPress onPress,
@Nullable Component tooltip,
Button.@Nullable CreateNarration narration
) {
super(width, height, message, spriteWidth, spriteHeight, sprite, onPress, tooltip, narration);
}
@Override
public void extractContents(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
this.extractDefaultSprite(graphics);
int x = this.getX() + this.getWidth() / 2 - this.spriteWidth / 2;
int y = this.getY() + this.getHeight() / 2 - this.spriteHeight / 2;
this.extractSprite(graphics, x, y);
}
}
@OnlyIn(Dist.CLIENT)
public static class TextAndIcon extends SpriteIconButton {
protected TextAndIcon(
int width,
int height,
Component message,
int spriteWidth,
int spriteHeight,
WidgetSprites sprite,
Button.OnPress onPress,
@Nullable Component tooltip,
Button.@Nullable CreateNarration narration
) {
super(width, height, message, spriteWidth, spriteHeight, sprite, onPress, tooltip, narration);
}
@Override
public void extractContents(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
this.extractDefaultSprite(graphics);
int left = this.getX() + 2;
int right = this.getX() + this.getWidth() - this.spriteWidth - 4;
int centerX = this.getX() + this.getWidth() / 2;
ActiveTextCollector output = graphics.textRendererForWidget(this, GuiGraphicsExtractor.HoveredTextEffects.NONE);
output.acceptScrolling(this.getMessage(), centerX, left, right, this.getY(), this.getY() + this.getHeight());
int x = this.getX() + this.getWidth() - this.spriteWidth - 2;
int y = this.getY() + this.getHeight() / 2 - this.spriteHeight / 2;
this.extractSprite(graphics, x, y);
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/继承
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Tooltip.create()
- 引用位置:
-
- 引用位置:
参数/字段/构造调用 - 关联成员:
WidgetSprites()
- 引用位置:
-
- 引用位置:
参数
- 引用位置: