MultiLineTextWidget.java
net.minecraft.client.gui.components.MultiLineTextWidget
信息
- 全限定名:net.minecraft.client.gui.components.MultiLineTextWidget
- 类型:public class
- 包:net.minecraft.client.gui.components
- 源码路径:src/main/java/net/minecraft/client/gui/components/MultiLineTextWidget.java
- 起始行号:L14
- 继承:AbstractStringWidget
- 职责:
TODO
字段/常量
-
maxWidth- 类型:
OptionalInt - 修饰符:
private - 源码定位:
L15 - 说明:
TODO
- 类型:
-
maxRows- 类型:
OptionalInt - 修饰符:
private - 源码定位:
L16 - 说明:
TODO
- 类型:
-
cache- 类型:
SingleKeyCache<MultiLineTextWidget.CacheKey,MultiLineLabel> - 修饰符:
private final - 源码定位:
L17 - 说明:
TODO
- 类型:
-
centered- 类型:
boolean - 修饰符:
private - 源码定位:
L18 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.client.gui.components.MultiLineTextWidget.CacheKey- 类型:
record - 修饰符:
private - 源码定位:
L86 - 说明:
TODO
- 类型:
构造器
public MultiLineTextWidget(Component message, Font font) @ L20
- 构造器名:MultiLineTextWidget
- 源码定位:L20
- 修饰符:public
参数:
- message: Component
- font: Font
说明:
TODO
public MultiLineTextWidget(int x, int y, Component message, Font font) @ L24
- 构造器名:MultiLineTextWidget
- 源码定位:L24
- 修饰符:public
参数:
- x: int
- y: int
- message: Component
- font: Font
说明:
TODO
方法
下面的方法块按源码顺序生成。
public MultiLineTextWidget setMaxWidth(int maxWidth) @ L34
- 方法名:setMaxWidth
- 源码定位:L34
- 返回类型:MultiLineTextWidget
- 修饰符:public
参数:
- maxWidth: int
说明:
TODO
public MultiLineTextWidget setMaxRows(int maxRows) @ L39
- 方法名:setMaxRows
- 源码定位:L39
- 返回类型:MultiLineTextWidget
- 修饰符:public
参数:
- maxRows: int
说明:
TODO
public MultiLineTextWidget setCentered(boolean centered) @ L44
- 方法名:setCentered
- 源码定位:L44
- 返回类型:MultiLineTextWidget
- 修饰符:public
参数:
- centered: boolean
说明:
TODO
public int getWidth() @ L49
- 方法名:getWidth
- 源码定位:L49
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int getHeight() @ L54
- 方法名:getHeight
- 源码定位:L54
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public void visitLines(ActiveTextCollector output) @ L59
- 方法名:visitLines
- 源码定位:L59
- 返回类型:void
- 修饰符:public
参数:
- output: ActiveTextCollector
说明:
TODO
protected int getTextX() @ L73
- 方法名:getTextX
- 源码定位:L73
- 返回类型:int
- 修饰符:protected
参数:
- 无
说明:
TODO
protected int getTextY() @ L77
- 方法名:getTextY
- 源码定位:L77
- 返回类型:int
- 修饰符:protected
参数:
- 无
说明:
TODO
private MultiLineTextWidget.CacheKey getFreshCacheKey() @ L81
- 方法名:getFreshCacheKey
- 源码定位:L81
- 返回类型:MultiLineTextWidget.CacheKey
- 修饰符:private
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class MultiLineTextWidget extends AbstractStringWidget {
private OptionalInt maxWidth = OptionalInt.empty();
private OptionalInt maxRows = OptionalInt.empty();
private final SingleKeyCache<MultiLineTextWidget.CacheKey, MultiLineLabel> cache;
private boolean centered = false;
public MultiLineTextWidget(Component message, Font font) {
this(0, 0, message, font);
}
public MultiLineTextWidget(int x, int y, Component message, Font font) {
super(x, y, 0, 0, message, font);
this.cache = Util.singleKeyCache(
key -> key.maxRows.isPresent()
? MultiLineLabel.create(font, key.maxWidth, key.maxRows.getAsInt(), key.message)
: MultiLineLabel.create(font, key.message, key.maxWidth)
);
this.active = false;
}
public MultiLineTextWidget setMaxWidth(int maxWidth) {
this.maxWidth = OptionalInt.of(maxWidth);
return this;
}
public MultiLineTextWidget setMaxRows(int maxRows) {
this.maxRows = OptionalInt.of(maxRows);
return this;
}
public MultiLineTextWidget setCentered(boolean centered) {
this.centered = centered;
return this;
}
@Override
public int getWidth() {
return this.cache.getValue(this.getFreshCacheKey()).getWidth();
}
@Override
public int getHeight() {
return this.cache.getValue(this.getFreshCacheKey()).getLineCount() * 9;
}
@Override
public void visitLines(ActiveTextCollector output) {
MultiLineLabel multilineLabel = this.cache.getValue(this.getFreshCacheKey());
int x = this.getTextX();
int y = this.getTextY();
int lineHeight = 9;
if (this.centered) {
int midX = this.getX() + this.getWidth() / 2;
multilineLabel.visitLines(TextAlignment.CENTER, midX, y, lineHeight, output);
} else {
multilineLabel.visitLines(TextAlignment.LEFT, x, y, lineHeight, output);
}
}
protected int getTextX() {
return this.getX();
}
protected int getTextY() {
return this.getY();
}
private MultiLineTextWidget.CacheKey getFreshCacheKey() {
return new MultiLineTextWidget.CacheKey(this.getMessage(), this.maxWidth.orElse(Integer.MAX_VALUE), this.maxRows);
}
@OnlyIn(Dist.CLIENT)
private record CacheKey(Component message, int maxWidth, OptionalInt maxRows) {
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
MultiLineLabel.create()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.singleKeyCache()
- 引用位置: