RealmsNotificationsScreen.java
com.mojang.realmsclient.gui.screens.RealmsNotificationsScreen
信息
- 全限定名:com.mojang.realmsclient.gui.screens.RealmsNotificationsScreen
- 类型:public class
- 包:com.mojang.realmsclient.gui.screens
- 源码路径:src/main/java/com/mojang/realmsclient/gui/screens/RealmsNotificationsScreen.java
- 起始行号:L20
- 继承:RealmsScreen
- 职责:
TODO
字段/常量
-
UNSEEN_NOTIFICATION_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
NEWS_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
INVITE_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
TRIAL_AVAILABLE_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
validClient- 类型:
CompletableFuture<Boolean> - 修饰符:
private final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
realmsDataSubscription- 类型:
DataFetcher.Subscription - 修饰符:
private - 源码定位:
L26 - 说明:
TODO
- 类型:
-
currentConfiguration- 类型:
RealmsNotificationsScreen.DataFetcherConfiguration - 修饰符:
private - 源码定位:
L27 - 说明:
TODO
- 类型:
-
numberOfPendingInvites- 类型:
int - 修饰符:
private volatile - 源码定位:
L28 - 说明:
TODO
- 类型:
-
trialAvailable- 类型:
boolean - 修饰符:
private static - 源码定位:
L29 - 说明:
TODO
- 类型:
-
hasUnreadNews- 类型:
boolean - 修饰符:
private static - 源码定位:
L30 - 说明:
TODO
- 类型:
-
hasUnseenNotifications- 类型:
boolean - 修饰符:
private static - 源码定位:
L31 - 说明:
TODO
- 类型:
-
showAll- 类型:
RealmsNotificationsScreen.DataFetcherConfiguration - 修饰符:
private final public public - 源码定位:
L32 - 说明:
TODO
- 类型:
-
onlyNotifications- 类型:
RealmsNotificationsScreen.DataFetcherConfiguration - 修饰符:
private final public public - 源码定位:
L50 - 说明:
TODO
- 类型:
内部类/嵌套类型
com.mojang.realmsclient.gui.screens.RealmsNotificationsScreen.DataFetcherConfiguration- 类型:
interface - 修饰符:
private - 源码定位:
L183 - 说明:
TODO
- 类型:
构造器
public RealmsNotificationsScreen() @ L68
- 构造器名:RealmsNotificationsScreen
- 源码定位:L68
- 修饰符:public
参数:
- 无
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void init() @ L72
- 方法名:init
- 源码定位:L72
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void added() @ L79
- 方法名:added
- 源码定位:L79
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
private RealmsNotificationsScreen.DataFetcherConfiguration getConfiguration() @ L85
- 方法名:getConfiguration
- 源码定位:L85
- 返回类型:RealmsNotificationsScreen.DataFetcherConfiguration
- 修饰符:private
参数:
- 无
说明:
TODO
public void tick() @ L94
- 方法名:tick
- 源码定位:L94
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
private boolean getRealmsNotificationsEnabled() @ L111
- 方法名:getRealmsNotificationsEnabled
- 源码定位:L111
- 返回类型:boolean
- 修饰符:private
参数:
- 无
说明:
TODO
private boolean inTitleScreen() @ L115
- 方法名:inTitleScreen
- 源码定位:L115
- 返回类型:boolean
- 修饰符:private
参数:
- 无
说明:
TODO
public void extractRenderState(GuiGraphicsExtractor graphics, int xm, int ym, float a) @ L119
- 方法名:extractRenderState
- 源码定位:L119
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- xm: int
- ym: int
- a: float
说明:
TODO
public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) @ L127
- 方法名:extractBackground
- 源码定位:L127
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- mouseX: int
- mouseY: int
- a: float
说明:
TODO
private void extractIcons(GuiGraphicsExtractor graphics) @ L131
- 方法名:extractIcons
- 源码定位:L131
- 返回类型:void
- 修饰符:private
参数:
- graphics: GuiGraphicsExtractor
说明:
TODO
private void addNewsAndInvitesSubscriptions(RealmsDataFetcher dataSource, DataFetcher.Subscription result) @ L160
- 方法名:addNewsAndInvitesSubscriptions
- 源码定位:L160
- 返回类型:void
- 修饰符:private
参数:
- dataSource: RealmsDataFetcher
- result: DataFetcher.Subscription
说明:
TODO
private void addNotificationsSubscriptions(RealmsDataFetcher dataSource, DataFetcher.Subscription result) @ L169
- 方法名:addNotificationsSubscriptions
- 源码定位:L169
- 返回类型:void
- 修饰符:private
参数:
- dataSource: RealmsDataFetcher
- result: DataFetcher.Subscription
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class RealmsNotificationsScreen extends RealmsScreen {
private static final Identifier UNSEEN_NOTIFICATION_SPRITE = Identifier.withDefaultNamespace("icon/unseen_notification");
private static final Identifier NEWS_SPRITE = Identifier.withDefaultNamespace("icon/news");
private static final Identifier INVITE_SPRITE = Identifier.withDefaultNamespace("icon/invite");
private static final Identifier TRIAL_AVAILABLE_SPRITE = Identifier.withDefaultNamespace("icon/trial_available");
private final CompletableFuture<Boolean> validClient = RealmsAvailability.get().thenApply(result -> result.type() == RealmsAvailability.Type.SUCCESS);
private DataFetcher.@Nullable Subscription realmsDataSubscription;
private RealmsNotificationsScreen.@Nullable DataFetcherConfiguration currentConfiguration;
private volatile int numberOfPendingInvites;
private static boolean trialAvailable;
private static boolean hasUnreadNews;
private static boolean hasUnseenNotifications;
private final RealmsNotificationsScreen.DataFetcherConfiguration showAll = new RealmsNotificationsScreen.DataFetcherConfiguration() {
{
Objects.requireNonNull(RealmsNotificationsScreen.this);
}
@Override
public DataFetcher.Subscription initDataFetcher(RealmsDataFetcher dataSource) {
DataFetcher.Subscription result = dataSource.dataFetcher.createSubscription();
RealmsNotificationsScreen.this.addNewsAndInvitesSubscriptions(dataSource, result);
RealmsNotificationsScreen.this.addNotificationsSubscriptions(dataSource, result);
return result;
}
@Override
public boolean showOldNotifications() {
return true;
}
};
private final RealmsNotificationsScreen.DataFetcherConfiguration onlyNotifications = new RealmsNotificationsScreen.DataFetcherConfiguration() {
{
Objects.requireNonNull(RealmsNotificationsScreen.this);
}
@Override
public DataFetcher.Subscription initDataFetcher(RealmsDataFetcher dataSource) {
DataFetcher.Subscription result = dataSource.dataFetcher.createSubscription();
RealmsNotificationsScreen.this.addNotificationsSubscriptions(dataSource, result);
return result;
}
@Override
public boolean showOldNotifications() {
return false;
}
};
public RealmsNotificationsScreen() {
super(GameNarrator.NO_TITLE);
}
@Override
public void init() {
if (this.realmsDataSubscription != null) {
this.realmsDataSubscription.forceUpdate();
}
}
@Override
public void added() {
super.added();
this.minecraft.realmsDataFetcher().notificationsTask.reset();
}
private RealmsNotificationsScreen.@Nullable DataFetcherConfiguration getConfiguration() {
boolean realmsEnabled = this.inTitleScreen() && this.validClient.getNow(false);
if (!realmsEnabled) {
return null;
} else {
return this.getRealmsNotificationsEnabled() ? this.showAll : this.onlyNotifications;
}
}
@Override
public void tick() {
RealmsNotificationsScreen.DataFetcherConfiguration dataFetcherConfiguration = this.getConfiguration();
if (!Objects.equals(this.currentConfiguration, dataFetcherConfiguration)) {
this.currentConfiguration = dataFetcherConfiguration;
if (this.currentConfiguration != null) {
this.realmsDataSubscription = this.currentConfiguration.initDataFetcher(this.minecraft.realmsDataFetcher());
} else {
this.realmsDataSubscription = null;
}
}
if (this.realmsDataSubscription != null) {
this.realmsDataSubscription.tick();
}
}
private boolean getRealmsNotificationsEnabled() {
return this.minecraft.options.realmsNotifications().get();
}
private boolean inTitleScreen() {
return this.minecraft.screen instanceof TitleScreen;
}
@Override
public void extractRenderState(GuiGraphicsExtractor graphics, int xm, int ym, float a) {
super.extractRenderState(graphics, xm, ym, a);
if (this.validClient.getNow(false)) {
this.extractIcons(graphics);
}
}
@Override
public void extractBackground(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float a) {
}
private void extractIcons(GuiGraphicsExtractor graphics) {
int pendingInvitesCount = this.numberOfPendingInvites;
int spacing = 24;
int topPos = this.height / 4 + 48;
int buttonRight = this.width / 2 + 100;
int baseY = topPos + 48 + 2;
int iconRight = buttonRight - 3;
if (hasUnseenNotifications) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, UNSEEN_NOTIFICATION_SPRITE, iconRight - 12, baseY + 3, 10, 10);
iconRight -= 16;
}
if (this.currentConfiguration != null && this.currentConfiguration.showOldNotifications()) {
if (hasUnreadNews) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, NEWS_SPRITE, iconRight - 14, baseY + 1, 14, 14);
iconRight -= 16;
}
if (pendingInvitesCount != 0) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, INVITE_SPRITE, iconRight - 14, baseY + 1, 14, 14);
iconRight -= 16;
}
if (trialAvailable) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, TRIAL_AVAILABLE_SPRITE, iconRight - 10, baseY + 4, 8, 8);
}
}
}
private void addNewsAndInvitesSubscriptions(RealmsDataFetcher dataSource, DataFetcher.Subscription result) {
result.subscribe(dataSource.pendingInvitesTask, value -> this.numberOfPendingInvites = value);
result.subscribe(dataSource.trialAvailabilityTask, value -> trialAvailable = value);
result.subscribe(dataSource.newsTask, value -> {
dataSource.newsManager.updateUnreadNews(value);
hasUnreadNews = dataSource.newsManager.hasUnreadNews();
});
}
private void addNotificationsSubscriptions(RealmsDataFetcher dataSource, DataFetcher.Subscription result) {
result.subscribe(dataSource.notificationsTask, notifications -> {
hasUnseenNotifications = false;
for (RealmsNotification notification : notifications) {
if (!notification.seen()) {
hasUnseenNotifications = true;
break;
}
}
});
}
@OnlyIn(Dist.CLIENT)
private interface DataFetcherConfiguration {
DataFetcher.Subscription initDataFetcher(RealmsDataFetcher realmsDataFetcher);
boolean showOldNotifications();
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
RealmsAvailability.get()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置: