RealmsSubscriptionTab.java
com.mojang.realmsclient.gui.screens.configuration.RealmsSubscriptionTab
信息
- 全限定名:com.mojang.realmsclient.gui.screens.configuration.RealmsSubscriptionTab
- 类型:package-private class
- 包:com.mojang.realmsclient.gui.screens.configuration
- 源码路径:src/main/java/com/mojang/realmsclient/gui/screens/configuration/RealmsSubscriptionTab.java
- 起始行号:L36
- 继承:GridLayoutTab
- 实现:RealmsConfigurationTab
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
DEFAULT_COMPONENT_WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L38 - 说明:
TODO
- 类型:
-
EXTRA_SPACING- 类型:
int - 修饰符:
private static final - 源码定位:
L39 - 说明:
TODO
- 类型:
-
DEFAULT_SPACING- 类型:
int - 修饰符:
private static final - 源码定位:
L40 - 说明:
TODO
- 类型:
-
TITLE- 类型:
Component - 修饰符:
static final - 源码定位:
L41 - 说明:
TODO
- 类型:
-
SUBSCRIPTION_START_LABEL- 类型:
Component - 修饰符:
private static final - 源码定位:
L42 - 说明:
TODO
- 类型:
-
TIME_LEFT_LABEL- 类型:
Component - 修饰符:
private static final - 源码定位:
L43 - 说明:
TODO
- 类型:
-
DAYS_LEFT_LABEL- 类型:
Component - 修饰符:
private static final - 源码定位:
L44 - 说明:
TODO
- 类型:
-
SUBSCRIPTION_EXPIRED_TEXT- 类型:
Component - 修饰符:
private static final - 源码定位:
L45 - 说明:
TODO
- 类型:
-
SUBSCRIPTION_LESS_THAN_A_DAY_TEXT- 类型:
Component - 修饰符:
private static final - 源码定位:
L47 - 说明:
TODO
- 类型:
-
UNKNOWN- 类型:
Component - 修饰符:
private static final - 源码定位:
L49 - 说明:
TODO
- 类型:
-
RECURRING_INFO- 类型:
Component - 修饰符:
private static final - 源码定位:
L50 - 说明:
TODO
- 类型:
-
configurationScreen- 类型:
RealmsConfigureWorldScreen - 修饰符:
private final - 源码定位:
L51 - 说明:
TODO
- 类型:
-
minecraft- 类型:
Minecraft - 修饰符:
private final - 源码定位:
L52 - 说明:
TODO
- 类型:
-
deleteButton- 类型:
Button - 修饰符:
private final - 源码定位:
L53 - 说明:
TODO
- 类型:
-
subscriptionInfo- 类型:
FocusableTextWidget - 修饰符:
private final - 源码定位:
L54 - 说明:
TODO
- 类型:
-
startDateWidget- 类型:
StringWidget - 修饰符:
private final - 源码定位:
L55 - 说明:
TODO
- 类型:
-
daysLeftLabelWidget- 类型:
StringWidget - 修饰符:
private final - 源码定位:
L56 - 说明:
TODO
- 类型:
-
daysLeftWidget- 类型:
StringWidget - 修饰符:
private final - 源码定位:
L57 - 说明:
TODO
- 类型:
-
serverData- 类型:
RealmsServer - 修饰符:
private - 源码定位:
L58 - 说明:
TODO
- 类型:
-
daysLeft- 类型:
Component - 修饰符:
private - 源码定位:
L59 - 说明:
TODO
- 类型:
-
startDate- 类型:
Component - 修饰符:
private - 源码定位:
L60 - 说明:
TODO
- 类型:
-
type- 类型:
Subscription.SubscriptionType - 修饰符:
private - 源码定位:
L61 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
RealmsSubscriptionTab(RealmsConfigureWorldScreen configurationScreen, Minecraft minecraft, RealmsServer serverData) @ L63
- 构造器名:RealmsSubscriptionTab
- 源码定位:L63
- 修饰符:package-private
参数:
- configurationScreen: RealmsConfigureWorldScreen
- minecraft: Minecraft
- serverData: RealmsServer
说明:
TODO
方法
下面的方法块按源码顺序生成。
private void deleteRealm() @ L107
- 方法名:deleteRealm
- 源码定位:L107
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private void getSubscription(long realmId) @ L116
- 方法名:getSubscription
- 源码定位:L116
- 返回类型:void
- 修饰符:private
参数:
- realmId: long
说明:
TODO
private static Component localPresentation(Instant time) @ L130
- 方法名:localPresentation
- 源码定位:L130
- 返回类型:Component
- 修饰符:private static
参数:
- time: Instant
说明:
TODO
private Component daysLeftPresentation(int daysLeft) @ L135
- 方法名:daysLeftPresentation
- 源码定位:L135
- 返回类型:Component
- 修饰符:private
参数:
- daysLeft: int
说明:
TODO
public void updateData(RealmsServer serverData) @ L157
- 方法名:updateData
- 源码定位:L157
- 返回类型:void
- 修饰符:public
参数:
- serverData: RealmsServer
说明:
TODO
public Component getTabExtraNarration() @ L180
- 方法名:getTabExtraNarration
- 源码定位:L180
- 返回类型:Component
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
class RealmsSubscriptionTab extends GridLayoutTab implements RealmsConfigurationTab {
private static final Logger LOGGER = LogUtils.getLogger();
private static final int DEFAULT_COMPONENT_WIDTH = 200;
private static final int EXTRA_SPACING = 2;
private static final int DEFAULT_SPACING = 6;
static final Component TITLE = Component.translatable("mco.configure.world.subscription.tab");
private static final Component SUBSCRIPTION_START_LABEL = Component.translatable("mco.configure.world.subscription.start");
private static final Component TIME_LEFT_LABEL = Component.translatable("mco.configure.world.subscription.timeleft");
private static final Component DAYS_LEFT_LABEL = Component.translatable("mco.configure.world.subscription.recurring.daysleft");
private static final Component SUBSCRIPTION_EXPIRED_TEXT = Component.translatable("mco.configure.world.subscription.expired")
.withStyle(ChatFormatting.GRAY);
private static final Component SUBSCRIPTION_LESS_THAN_A_DAY_TEXT = Component.translatable("mco.configure.world.subscription.less_than_a_day")
.withStyle(ChatFormatting.GRAY);
private static final Component UNKNOWN = Component.translatable("mco.configure.world.subscription.unknown");
private static final Component RECURRING_INFO = Component.translatable("mco.configure.world.subscription.recurring.info");
private final RealmsConfigureWorldScreen configurationScreen;
private final Minecraft minecraft;
private final Button deleteButton;
private final FocusableTextWidget subscriptionInfo;
private final StringWidget startDateWidget;
private final StringWidget daysLeftLabelWidget;
private final StringWidget daysLeftWidget;
private RealmsServer serverData;
private Component daysLeft = UNKNOWN;
private Component startDate = UNKNOWN;
private Subscription.@Nullable SubscriptionType type;
RealmsSubscriptionTab(RealmsConfigureWorldScreen configurationScreen, Minecraft minecraft, RealmsServer serverData) {
super(TITLE);
this.configurationScreen = configurationScreen;
this.minecraft = minecraft;
this.serverData = serverData;
GridLayout.RowHelper helper = this.layout.rowSpacing(6).createRowHelper(1);
Font font = configurationScreen.getFont();
helper.addChild(new StringWidget(200, 9, SUBSCRIPTION_START_LABEL, font));
this.startDateWidget = helper.addChild(new StringWidget(200, 9, this.startDate, font));
helper.addChild(SpacerElement.height(2));
this.daysLeftLabelWidget = helper.addChild(new StringWidget(200, 9, TIME_LEFT_LABEL, font));
this.daysLeftWidget = helper.addChild(new StringWidget(200, 9, this.daysLeft, font));
helper.addChild(SpacerElement.height(2));
helper.addChild(
Button.builder(
Component.translatable("mco.configure.world.subscription.extend"),
button -> ConfirmLinkScreen.confirmLinkNow(
configurationScreen, CommonLinks.extendRealms(serverData.remoteSubscriptionId, minecraft.getUser().getProfileId())
)
)
.bounds(0, 0, 200, 20)
.build()
);
helper.addChild(SpacerElement.height(2));
this.deleteButton = helper.addChild(
Button.builder(
Component.translatable("mco.configure.world.delete.button"),
button -> minecraft.setScreen(
RealmsPopups.warningPopupScreen(
configurationScreen, Component.translatable("mco.configure.world.delete.question.line1"), popup -> this.deleteRealm()
)
)
)
.bounds(0, 0, 200, 20)
.build()
);
helper.addChild(SpacerElement.height(2));
this.subscriptionInfo = helper.addChild(
FocusableTextWidget.builder(Component.empty(), font).maxWidth(200).build(), LayoutSettings.defaults().alignHorizontallyCenter()
);
this.subscriptionInfo.setCentered(false);
this.updateData(serverData);
}
private void deleteRealm() {
RealmsUtil.runAsync(
client -> client.deleteRealm(this.serverData.id),
RealmsUtil.openScreenAndLogOnFailure(this.configurationScreen::createErrorScreen, "Couldn't delete world")
)
.thenRunAsync(() -> this.minecraft.setScreen(this.configurationScreen.getLastScreen()), this.minecraft);
this.minecraft.setScreen(this.configurationScreen);
}
private void getSubscription(long realmId) {
RealmsClient client = RealmsClient.getOrCreate();
try {
Subscription subscription = client.subscriptionFor(realmId);
this.daysLeft = this.daysLeftPresentation(subscription.daysLeft());
this.startDate = localPresentation(subscription.startDate());
this.type = subscription.type();
} catch (RealmsServiceException var5) {
LOGGER.error("Couldn't get subscription", (Throwable)var5);
this.minecraft.setScreen(this.configurationScreen.createErrorScreen(var5));
}
}
private static Component localPresentation(Instant time) {
String formattedDate = ZonedDateTime.ofInstant(time, ZoneId.systemDefault()).format(Util.localizedDateFormatter(FormatStyle.MEDIUM));
return Component.literal(formattedDate).withStyle(ChatFormatting.GRAY);
}
private Component daysLeftPresentation(int daysLeft) {
if (daysLeft < 0 && this.serverData.expired) {
return SUBSCRIPTION_EXPIRED_TEXT;
} else if (daysLeft <= 1) {
return SUBSCRIPTION_LESS_THAN_A_DAY_TEXT;
} else {
int months = daysLeft / 30;
int days = daysLeft % 30;
boolean showMonths = months > 0;
boolean showDays = days > 0;
if (showMonths && showDays) {
return Component.translatable("mco.configure.world.subscription.remaining.months.days", months, days).withStyle(ChatFormatting.GRAY);
} else if (showMonths) {
return Component.translatable("mco.configure.world.subscription.remaining.months", months).withStyle(ChatFormatting.GRAY);
} else {
return showDays
? Component.translatable("mco.configure.world.subscription.remaining.days", days).withStyle(ChatFormatting.GRAY)
: Component.empty();
}
}
}
@Override
public void updateData(RealmsServer serverData) {
this.serverData = serverData;
this.getSubscription(serverData.id);
this.startDateWidget.setMessage(this.startDate);
if (this.type == Subscription.SubscriptionType.NORMAL) {
this.daysLeftLabelWidget.setMessage(TIME_LEFT_LABEL);
} else if (this.type == Subscription.SubscriptionType.RECURRING) {
this.daysLeftLabelWidget.setMessage(DAYS_LEFT_LABEL);
}
this.daysLeftWidget.setMessage(this.daysLeft);
boolean snapshotWorld = RealmsMainScreen.isSnapshot() && serverData.parentWorldName != null;
this.deleteButton.active = serverData.expired;
if (snapshotWorld) {
this.subscriptionInfo.setMessage(Component.translatable("mco.snapshot.subscription.info", serverData.parentWorldName));
} else {
this.subscriptionInfo.setMessage(RECURRING_INFO);
}
this.layout.arrangeElements();
}
@Override
public Component getTabExtraNarration() {
return CommonComponents.joinLines(TITLE, SUBSCRIPTION_START_LABEL, this.startDate, TIME_LEFT_LABEL, this.daysLeft);
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
RealmsMainScreen.isSnapshot()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RealmsClient.getOrCreate()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RealmsPopups.warningPopupScreen()
- 引用位置:
-
- 引用位置:
实现
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RealmsUtil.openScreenAndLogOnFailure(), RealmsUtil.runAsync()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Button.builder()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
FocusableTextWidget.builder()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
StringWidget()
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
LayoutSettings.defaults()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SpacerElement.height()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ConfirmLinkScreen.confirmLinkNow()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
CommonComponents.joinLines()
- 引用位置:
-
- 引用位置:
字段/方法调用/返回值 - 关联成员:
Component.empty(), Component.literal(), Component.translatable()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
CommonLinks.extendRealms()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.localizedDateFormatter()
- 引用位置: