FocusableTextWidget.java
net.minecraft.client.gui.components.FocusableTextWidget
信息
- 全限定名:net.minecraft.client.gui.components.FocusableTextWidget
- 类型:public class
- 包:net.minecraft.client.gui.components
- 源码路径:src/main/java/net/minecraft/client/gui/components/FocusableTextWidget.java
- 起始行号:L14
- 继承:MultiLineTextWidget
- 职责:
TODO
字段/常量
-
DEFAULT_PADDING- 类型:
int - 修饰符:
public static final - 源码定位:
L15 - 说明:
TODO
- 类型:
-
padding- 类型:
int - 修饰符:
private final - 源码定位:
L16 - 说明:
TODO
- 类型:
-
maxWidth- 类型:
int - 修饰符:
private final - 源码定位:
L17 - 说明:
TODO
- 类型:
-
alwaysShowBorder- 类型:
boolean - 修饰符:
private final - 源码定位:
L18 - 说明:
TODO
- 类型:
-
backgroundFill- 类型:
FocusableTextWidget.BackgroundFill - 修饰符:
private final - 源码定位:
L19 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.client.gui.components.FocusableTextWidget.BackgroundFill- 类型:
enum - 修饰符:
public static - 源码定位:
L131 - 说明:
TODO
- 类型:
-
net.minecraft.client.gui.components.FocusableTextWidget.Builder- 类型:
class - 修饰符:
public static - 源码定位:
L138 - 说明:
TODO
- 类型:
构造器
private FocusableTextWidget(Component message, Font font, int padding, int maxWidth, FocusableTextWidget.BackgroundFill backgroundFill, boolean alwaysShowBorder) @ L21
- 构造器名:FocusableTextWidget
- 源码定位:L21
- 修饰符:private
参数:
- message: Component
- font: Font
- padding: int
- maxWidth: int
- backgroundFill: FocusableTextWidget.BackgroundFill
- alwaysShowBorder: boolean
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected void updateWidgetNarration(NarrationElementOutput output) @ L35
- 方法名:updateWidgetNarration
- 源码定位:L35
- 返回类型:void
- 修饰符:protected
参数:
- output: NarrationElementOutput
说明:
TODO
public void extractWidgetRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L40
- 方法名:extractWidgetRenderState
- 源码定位:L40
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
protected int getTextX() @ L61
- 方法名:getTextX
- 源码定位:L61
- 返回类型:int
- 修饰符:protected
参数:
- 无
说明:
TODO
protected int getTextY() @ L66
- 方法名:getTextY
- 源码定位:L66
- 返回类型:int
- 修饰符:protected
参数:
- 无
说明:
TODO
public MultiLineTextWidget setMaxWidth(int maxWidth) @ L71
- 方法名:setMaxWidth
- 源码定位:L71
- 返回类型:MultiLineTextWidget
- 修饰符:public
参数:
- maxWidth: int
说明:
TODO
public int getWidth() @ L76
- 方法名:getWidth
- 源码定位:L76
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int getHeight() @ L81
- 方法名:getHeight
- 源码定位:L81
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int getPadding() @ L86
- 方法名:getPadding
- 源码定位:L86
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public void updateWidth() @ L90
- 方法名:updateWidth
- 源码定位:L90
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void updateHeight() @ L99
- 方法名:updateHeight
- 源码定位:L99
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void setMessage(Component message) @ L104
- 方法名:setMessage
- 源码定位:L104
- 返回类型:void
- 修饰符:public
参数:
- message: Component
说明:
TODO
public void playDownSound(SoundManager soundManager) @ L118
- 方法名:playDownSound
- 源码定位:L118
- 返回类型:void
- 修饰符:public
参数:
- soundManager: SoundManager
说明:
TODO
public static FocusableTextWidget.Builder builder(Component message, Font font) @ L122
- 方法名:builder
- 源码定位:L122
- 返回类型:FocusableTextWidget.Builder
- 修饰符:public static
参数:
- message: Component
- font: Font
说明:
TODO
public static FocusableTextWidget.Builder builder(Component message, Font font, int padding) @ L126
- 方法名:builder
- 源码定位:L126
- 返回类型:FocusableTextWidget.Builder
- 修饰符:public static
参数:
- message: Component
- font: Font
- padding: int
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class FocusableTextWidget extends MultiLineTextWidget {
public static final int DEFAULT_PADDING = 4;
private final int padding;
private final int maxWidth;
private final boolean alwaysShowBorder;
private final FocusableTextWidget.BackgroundFill backgroundFill;
private FocusableTextWidget(
Component message, Font font, int padding, int maxWidth, FocusableTextWidget.BackgroundFill backgroundFill, boolean alwaysShowBorder
) {
super(message, font);
this.active = true;
this.padding = padding;
this.maxWidth = maxWidth;
this.alwaysShowBorder = alwaysShowBorder;
this.backgroundFill = backgroundFill;
this.updateWidth();
this.updateHeight();
this.setCentered(true);
}
@Override
protected void updateWidgetNarration(NarrationElementOutput output) {
output.add(NarratedElementType.TITLE, this.getMessage());
}
@Override
public void extractWidgetRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
int borderColor = this.alwaysShowBorder && !this.isFocused() ? ARGB.color(this.alpha, -6250336) : ARGB.white(this.alpha);
switch (this.backgroundFill) {
case ALWAYS:
graphics.fill(this.getX() + 1, this.getY(), this.getRight(), this.getBottom(), ARGB.black(this.alpha));
break;
case ON_FOCUS:
if (this.isFocused()) {
graphics.fill(this.getX() + 1, this.getY(), this.getRight(), this.getBottom(), ARGB.black(this.alpha));
}
case NEVER:
}
if (this.isFocused() || this.alwaysShowBorder) {
graphics.outline(this.getX(), this.getY(), this.getWidth(), this.getHeight(), borderColor);
}
super.extractWidgetRenderState(graphics, mouseX, mouseY, a);
}
@Override
protected int getTextX() {
return this.getX() + this.padding;
}
@Override
protected int getTextY() {
return super.getTextY() + this.padding;
}
@Override
public MultiLineTextWidget setMaxWidth(int maxWidth) {
return super.setMaxWidth(maxWidth - this.padding * 2);
}
@Override
public int getWidth() {
return this.width;
}
@Override
public int getHeight() {
return this.height;
}
public int getPadding() {
return this.padding;
}
public void updateWidth() {
if (this.maxWidth != -1) {
this.setWidth(this.maxWidth);
this.setMaxWidth(this.maxWidth);
} else {
this.setWidth(this.getFont().width(this.getMessage()) + this.padding * 2);
}
}
public void updateHeight() {
int textHeight = 9 * this.getFont().split(this.getMessage(), super.getWidth()).size();
this.setHeight(textHeight + this.padding * 2);
}
@Override
public void setMessage(Component message) {
this.message = message;
int width;
if (this.maxWidth != -1) {
width = this.maxWidth;
} else {
width = this.getFont().width(message) + this.padding * 2;
}
this.setWidth(width);
this.updateHeight();
}
@Override
public void playDownSound(SoundManager soundManager) {
}
public static FocusableTextWidget.Builder builder(Component message, Font font) {
return new FocusableTextWidget.Builder(message, font);
}
public static FocusableTextWidget.Builder builder(Component message, Font font, int padding) {
return new FocusableTextWidget.Builder(message, font, padding);
}
@OnlyIn(Dist.CLIENT)
public static enum BackgroundFill {
ALWAYS,
ON_FOCUS,
NEVER;
}
@OnlyIn(Dist.CLIENT)
public static class Builder {
private final Component message;
private final Font font;
private final int padding;
private int maxWidth = -1;
private boolean alwaysShowBorder = true;
private FocusableTextWidget.BackgroundFill backgroundFill = FocusableTextWidget.BackgroundFill.ALWAYS;
private Builder(Component message, Font font) {
this(message, font, 4);
}
private Builder(Component message, Font font, int padding) {
this.message = message;
this.font = font;
this.padding = padding;
}
public FocusableTextWidget.Builder maxWidth(int maxWidth) {
this.maxWidth = maxWidth;
return this;
}
public FocusableTextWidget.Builder textWidth(int textWidth) {
this.maxWidth = textWidth + this.padding * 2;
return this;
}
public FocusableTextWidget.Builder alwaysShowBorder(boolean alwaysShowBorder) {
this.alwaysShowBorder = alwaysShowBorder;
return this;
}
public FocusableTextWidget.Builder backgroundFill(FocusableTextWidget.BackgroundFill backgroundFill) {
this.backgroundFill = backgroundFill;
return this;
}
public FocusableTextWidget build() {
return new FocusableTextWidget(this.message, this.font, this.padding, this.maxWidth, this.backgroundFill, this.alwaysShowBorder);
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
继承/返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ARGB.black(), ARGB.color(), ARGB.white()
- 引用位置: