RealmsWorldSlotButton.java
com.mojang.realmsclient.gui.RealmsWorldSlotButton
信息
- 全限定名:com.mojang.realmsclient.gui.RealmsWorldSlotButton
- 类型:public class
- 包:com.mojang.realmsclient.gui
- 源码路径:src/main/java/com/mojang/realmsclient/gui/RealmsWorldSlotButton.java
- 起始行号:L23
- 继承:Button
- 职责:
TODO
字段/常量
-
SLOT_FRAME_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
EMPTY_SLOT_LOCATION- 类型:
Identifier - 修饰符:
public static final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
DEFAULT_WORLD_SLOT_1- 类型:
Identifier - 修饰符:
public static final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
DEFAULT_WORLD_SLOT_2- 类型:
Identifier - 修饰符:
public static final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
DEFAULT_WORLD_SLOT_3- 类型:
Identifier - 修饰符:
public static final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
SWITCH_TO_MINIGAME_SLOT_TOOLTIP- 类型:
Component - 修饰符:
private static final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
SWITCH_TO_WORLD_SLOT_TOOLTIP- 类型:
Component - 修饰符:
private static final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
MINIGAME- 类型:
Component - 修饰符:
private static final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
slotIndex- 类型:
int - 修饰符:
private final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
slotNameWidget- 类型:
StringWidget - 修饰符:
private final - 源码定位:
L33 - 说明:
TODO
- 类型:
-
state- 类型:
RealmsWorldSlotButton.State - 修饰符:
private - 源码定位:
L34 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
com.mojang.realmsclient.gui.RealmsWorldSlotButton.Action- 类型:
enum - 修饰符:
public static - 源码定位:
L139 - 说明:
TODO
- 类型:
-
com.mojang.realmsclient.gui.RealmsWorldSlotButton.State- 类型:
class - 修饰符:
public static - 源码定位:
L145 - 说明:
TODO
- 类型:
构造器
public RealmsWorldSlotButton(int x, int y, int width, int height, int slotIndex, RealmsServer serverData, Button.OnPress onPress) @ L36
- 构造器名:RealmsWorldSlotButton
- 源码定位:L36
- 修饰符:public
参数:
- x: int
- y: int
- width: int
- height: int
- slotIndex: int
- serverData: RealmsServer
- onPress: Button.OnPress
说明:
TODO
方法
下面的方法块按源码顺序生成。
public RealmsWorldSlotButton.State getState() @ L43
- 方法名:getState
- 源码定位:L43
- 返回类型:RealmsWorldSlotButton.State
- 修饰符:public
参数:
- 无
说明:
TODO
public RealmsWorldSlotButton.State setServerData(RealmsServer serverData) @ L47
- 方法名:setServerData
- 源码定位:L47
- 返回类型:RealmsWorldSlotButton.State
- 修饰符:public
参数:
- serverData: RealmsServer
说明:
TODO
private void setTooltipAndNarration(RealmsWorldSlotButton.State state, String minigameName) @ L53
- 方法名:setTooltipAndNarration
- 源码定位:L53
- 返回类型:void
- 修饰符:private
参数:
- state: RealmsWorldSlotButton.State
- minigameName: String
说明:
TODO
private static RealmsWorldSlotButton.Action getAction(boolean activeSlot, boolean empty, boolean expired) @ L70
- 方法名:getAction
- 源码定位:L70
- 返回类型:RealmsWorldSlotButton.Action
- 修饰符:private static
参数:
- activeSlot: boolean
- empty: boolean
- expired: boolean
说明:
TODO
public boolean isActive() @ L74
- 方法名:isActive
- 源码定位:L74
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public void extractContents(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L79
- 方法名:extractContents
- 源码定位:L79
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
public void updateSlotState(RealmsServer serverData) @ L133
- 方法名:updateSlotState
- 源码定位:L133
- 返回类型:void
- 修饰符:public
参数:
- serverData: RealmsServer
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class RealmsWorldSlotButton extends Button {
private static final Identifier SLOT_FRAME_SPRITE = Identifier.withDefaultNamespace("widget/slot_frame");
public static final Identifier EMPTY_SLOT_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/empty_frame.png");
public static final Identifier DEFAULT_WORLD_SLOT_1 = Identifier.withDefaultNamespace("textures/gui/title/background/panorama_0.png");
public static final Identifier DEFAULT_WORLD_SLOT_2 = Identifier.withDefaultNamespace("textures/gui/title/background/panorama_2.png");
public static final Identifier DEFAULT_WORLD_SLOT_3 = Identifier.withDefaultNamespace("textures/gui/title/background/panorama_3.png");
private static final Component SWITCH_TO_MINIGAME_SLOT_TOOLTIP = Component.translatable("mco.configure.world.slot.tooltip.minigame");
private static final Component SWITCH_TO_WORLD_SLOT_TOOLTIP = Component.translatable("mco.configure.world.slot.tooltip");
private static final Component MINIGAME = Component.translatable("mco.worldSlot.minigame");
private final int slotIndex;
private final StringWidget slotNameWidget;
private RealmsWorldSlotButton.State state;
public RealmsWorldSlotButton(int x, int y, int width, int height, int slotIndex, RealmsServer serverData, Button.OnPress onPress) {
super(x, y, width, height, CommonComponents.EMPTY, onPress, DEFAULT_NARRATION);
this.slotIndex = slotIndex;
this.state = this.setServerData(serverData);
this.slotNameWidget = new StringWidget(Component.literal(this.state.slotName), Minecraft.getInstance().font);
}
public RealmsWorldSlotButton.State getState() {
return this.state;
}
public RealmsWorldSlotButton.State setServerData(RealmsServer serverData) {
this.state = new RealmsWorldSlotButton.State(serverData, this.slotIndex);
this.setTooltipAndNarration(this.state, serverData.minigameName);
return this.state;
}
private void setTooltipAndNarration(RealmsWorldSlotButton.State state, @Nullable String minigameName) {
Component tooltipComponent = switch (state.action) {
case SWITCH_SLOT -> state.minigame ? SWITCH_TO_MINIGAME_SLOT_TOOLTIP : SWITCH_TO_WORLD_SLOT_TOOLTIP;
default -> null;
};
if (tooltipComponent != null) {
this.setTooltip(Tooltip.create(tooltipComponent));
}
MutableComponent slotContents = Component.literal(state.slotName);
if (state.minigame && minigameName != null) {
slotContents = slotContents.append(CommonComponents.SPACE).append(minigameName);
}
this.setMessage(slotContents);
}
private static RealmsWorldSlotButton.Action getAction(boolean activeSlot, boolean empty, boolean expired) {
return activeSlot || empty && expired ? RealmsWorldSlotButton.Action.NOTHING : RealmsWorldSlotButton.Action.SWITCH_SLOT;
}
@Override
public boolean isActive() {
return this.state.action != RealmsWorldSlotButton.Action.NOTHING && super.isActive();
}
@Override
public void extractContents(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
int x = this.getX();
int y = this.getY();
boolean hoveredOrFocused = this.isHoveredOrFocused();
Identifier texture;
if (this.state.minigame) {
texture = RealmsTextureManager.worldTemplate(String.valueOf(this.state.imageId), this.state.image);
} else if (this.state.empty) {
texture = EMPTY_SLOT_LOCATION;
} else if (this.state.image != null && this.state.imageId != -1L) {
texture = RealmsTextureManager.worldTemplate(String.valueOf(this.state.imageId), this.state.image);
} else if (this.slotIndex == 1) {
texture = DEFAULT_WORLD_SLOT_1;
} else if (this.slotIndex == 2) {
texture = DEFAULT_WORLD_SLOT_2;
} else if (this.slotIndex == 3) {
texture = DEFAULT_WORLD_SLOT_3;
} else {
texture = EMPTY_SLOT_LOCATION;
}
int color = -1;
if (!this.state.activeSlot) {
color = ARGB.colorFromFloat(1.0F, 0.56F, 0.56F, 0.56F);
}
graphics.blit(RenderPipelines.GUI_TEXTURED, texture, x + 1, y + 1, 0.0F, 0.0F, this.width - 2, this.height - 2, 74, 74, 74, 74, color);
if (hoveredOrFocused && this.state.action != RealmsWorldSlotButton.Action.NOTHING) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_FRAME_SPRITE, x, y, this.width, this.height);
} else if (this.state.activeSlot) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_FRAME_SPRITE, x, y, this.width, this.height, ARGB.colorFromFloat(1.0F, 0.8F, 0.8F, 0.8F));
} else {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_FRAME_SPRITE, x, y, this.width, this.height, ARGB.colorFromFloat(1.0F, 0.56F, 0.56F, 0.56F));
}
if (this.state.hardcore) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, RealmsMainScreen.HARDCORE_MODE_SPRITE, x + 3, y + 4, 9, 8);
}
this.slotNameWidget.setMaxWidth(this.getWidth() - (this.state.activeSlot ? 2 : 0), StringWidget.TextOverflow.SCROLLING);
this.slotNameWidget.setPosition(this.getX() + this.getWidth() / 2 - this.slotNameWidget.getWidth() / 2, y + this.height - 14);
this.slotNameWidget.extractRenderState(graphics, mouseX, mouseY, a);
if (this.state.activeSlot) {
graphics.centeredText(
Minecraft.getInstance().font,
RealmsMainScreen.getVersionComponent(this.state.slotVersion, this.state.compatibility.isCompatible()),
x + this.width / 2,
y + this.height + 2,
-1
);
}
}
public void updateSlotState(RealmsServer serverData) {
this.state = this.setServerData(serverData);
this.slotNameWidget.setMessage(Component.literal(this.state.slotName));
}
@OnlyIn(Dist.CLIENT)
public static enum Action {
NOTHING,
SWITCH_SLOT;
}
@OnlyIn(Dist.CLIENT)
public static class State {
private final String slotName;
private final String slotVersion;
private final RealmsServer.Compatibility compatibility;
private final long imageId;
private final @Nullable String image;
public final boolean empty;
public final boolean minigame;
public final RealmsWorldSlotButton.Action action;
public final boolean hardcore;
public final boolean activeSlot;
public State(RealmsServer serverData, int slotIndex) {
this.minigame = slotIndex == 4;
if (this.minigame) {
this.slotName = RealmsWorldSlotButton.MINIGAME.getString();
this.imageId = serverData.minigameId;
this.image = serverData.minigameImage;
this.empty = serverData.minigameId == -1;
this.slotVersion = "";
this.compatibility = RealmsServer.Compatibility.UNVERIFIABLE;
this.hardcore = false;
this.activeSlot = serverData.isMinigameActive();
} else {
RealmsSlot slot = serverData.slots.get(slotIndex);
this.slotName = slot.options.getSlotName(slotIndex);
this.imageId = slot.options.templateId;
this.image = slot.options.templateImage;
this.empty = slot.options.empty;
this.slotVersion = slot.options.version;
this.compatibility = slot.options.compatibility;
this.hardcore = slot.isHardcore();
this.activeSlot = serverData.activeSlot == slotIndex && !serverData.isMinigameActive();
}
this.action = RealmsWorldSlotButton.getAction(this.activeSlot, this.empty, serverData.expired);
}
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
RealmsMainScreen.getVersionComponent()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RealmsTextureManager.worldTemplate()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Minecraft.getInstance()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/继承
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
StringWidget()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Tooltip.create()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Component.literal(), Component.translatable()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ARGB.colorFromFloat()
- 引用位置: