TabButton.java
net.minecraft.client.gui.components.TabButton
信息
- 全限定名:net.minecraft.client.gui.components.TabButton
- 类型:public class
- 包:net.minecraft.client.gui.components
- 源码路径:src/main/java/net/minecraft/client/gui/components/TabButton.java
- 起始行号:L20
- 继承:AbstractWidget.WithInactiveMessage
- 职责:
TODO
字段/常量
-
SPRITES- 类型:
WidgetSprites - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
SELECTED_OFFSET- 类型:
int - 修饰符:
private static final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
TEXT_MARGIN- 类型:
int - 修饰符:
private static final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
UNDERLINE_HEIGHT- 类型:
int - 修饰符:
private static final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
UNDERLINE_MARGIN_X- 类型:
int - 修饰符:
private static final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
UNDERLINE_MARGIN_BOTTOM- 类型:
int - 修饰符:
private static final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
tabManager- 类型:
TabManager - 修饰符:
private final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
tab- 类型:
Tab - 修饰符:
private final - 源码定位:
L33 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public TabButton(TabManager tabManager, Tab tab, int width, int height) @ L35
- 构造器名:TabButton
- 源码定位:L35
- 修饰符:public
参数:
- tabManager: TabManager
- tab: Tab
- width: int
- height: int
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void extractWidgetRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L41
- 方法名:extractWidgetRenderState
- 源码定位:L41
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
protected void extractMenuBackground(GuiGraphicsExtractor graphics, int x0, int y0, int x1, int y1) @ L57
- 方法名:extractMenuBackground
- 源码定位:L57
- 返回类型:void
- 修饰符:protected
参数:
- graphics: GuiGraphicsExtractor
- x0: int
- y0: int
- x1: int
- y1: int
说明:
TODO
private void extractLabel(ActiveTextCollector output) @ L61
- 方法名:extractLabel
- 源码定位:L61
- 返回类型:void
- 修饰符:private
参数:
- output: ActiveTextCollector
说明:
TODO
private void extractFocusUnderline(GuiGraphicsExtractor graphics, Font font, int color) @ L69
- 方法名:extractFocusUnderline
- 源码定位:L69
- 返回类型:void
- 修饰符:private
参数:
- graphics: GuiGraphicsExtractor
- font: Font
- color: int
说明:
TODO
protected void updateWidgetNarration(NarrationElementOutput output) @ L76
- 方法名:updateWidgetNarration
- 源码定位:L76
- 返回类型:void
- 修饰符:protected
参数:
- output: NarrationElementOutput
说明:
TODO
public void playDownSound(SoundManager soundManager) @ L82
- 方法名:playDownSound
- 源码定位:L82
- 返回类型:void
- 修饰符:public
参数:
- soundManager: SoundManager
说明:
TODO
public Tab tab() @ L86
- 方法名:tab
- 源码定位:L86
- 返回类型:Tab
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean isSelected() @ L90
- 方法名:isSelected
- 源码定位:L90
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class TabButton extends AbstractWidget.WithInactiveMessage {
private static final WidgetSprites SPRITES = new WidgetSprites(
Identifier.withDefaultNamespace("widget/tab_selected"),
Identifier.withDefaultNamespace("widget/tab"),
Identifier.withDefaultNamespace("widget/tab_selected_highlighted"),
Identifier.withDefaultNamespace("widget/tab_highlighted")
);
private static final int SELECTED_OFFSET = 3;
private static final int TEXT_MARGIN = 1;
private static final int UNDERLINE_HEIGHT = 1;
private static final int UNDERLINE_MARGIN_X = 4;
private static final int UNDERLINE_MARGIN_BOTTOM = 2;
private final TabManager tabManager;
private final Tab tab;
public TabButton(TabManager tabManager, Tab tab, int width, int height) {
super(0, 0, width, height, tab.getTabTitle());
this.tabManager = tabManager;
this.tab = tab;
}
@Override
public void extractWidgetRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
graphics.blitSprite(
RenderPipelines.GUI_TEXTURED, SPRITES.get(this.isSelected(), this.isHoveredOrFocused()), this.getX(), this.getY(), this.width, this.height
);
Font font = Minecraft.getInstance().font;
int underlineColor = this.active ? -1 : -6250336;
if (this.isSelected()) {
this.extractMenuBackground(graphics, this.getX() + 2, this.getY() + 2, this.getRight() - 2, this.getBottom());
this.extractFocusUnderline(graphics, font, underlineColor);
}
this.extractLabel(graphics.textRendererForWidget(this, GuiGraphicsExtractor.HoveredTextEffects.NONE));
this.handleCursor(graphics);
}
protected void extractMenuBackground(GuiGraphicsExtractor graphics, int x0, int y0, int x1, int y1) {
Screen.extractMenuBackgroundTexture(graphics, Screen.MENU_BACKGROUND, x0, y0, 0.0F, 0.0F, x1 - x0, y1 - y0);
}
private void extractLabel(ActiveTextCollector output) {
int left = this.getX() + 1;
int top = this.getY() + (this.isSelected() ? 0 : 3);
int right = this.getX() + this.getWidth() - 1;
int bottom = this.getY() + this.getHeight();
output.acceptScrollingWithDefaultCenter(this.getMessage(), left, right, top, bottom);
}
private void extractFocusUnderline(GuiGraphicsExtractor graphics, Font font, int color) {
int width = Math.min(font.width(this.getMessage()), this.getWidth() - 4);
int left = this.getX() + (this.getWidth() - width) / 2;
int top = this.getY() + this.getHeight() - 2;
graphics.fill(left, top, left + width, top + 1, color);
}
@Override
protected void updateWidgetNarration(NarrationElementOutput output) {
output.add(NarratedElementType.TITLE, Component.translatable("gui.narrate.tab", this.tab.getTabTitle()));
output.add(NarratedElementType.HINT, this.tab.getTabExtraNarration());
}
@Override
public void playDownSound(SoundManager soundManager) {
}
public Tab tab() {
return this.tab;
}
public boolean isSelected() {
return this.tabManager.getCurrentTab() == this.tab;
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
Minecraft.getInstance()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
WidgetSprites()
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Screen.extractMenuBackgroundTexture()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置: