RealmsPreferredRegionSelectionScreen.java
com.mojang.realmsclient.gui.screens.configuration.RealmsPreferredRegionSelectionScreen
信息
- 全限定名:com.mojang.realmsclient.gui.screens.configuration.RealmsPreferredRegionSelectionScreen
- 类型:public class
- 包:com.mojang.realmsclient.gui.screens.configuration
- 源码路径:src/main/java/com/mojang/realmsclient/gui/screens/configuration/RealmsPreferredRegionSelectionScreen.java
- 起始行号:L26
- 继承:Screen
- 职责:
TODO
字段/常量
-
REGION_SELECTION_LABEL- 类型:
Component - 修饰符:
private static final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
SPACING- 类型:
int - 修饰符:
private static final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
layout- 类型:
HeaderAndFooterLayout - 修饰符:
private final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
parent- 类型:
Screen - 修饰符:
private final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
applySettings- 类型:
BiConsumer<RegionSelectionPreference,RealmsRegion> - 修饰符:
private final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
regionServiceQuality- 类型:
Map<RealmsRegion,ServiceQuality> - 修饰符:
private final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
list- 类型:
RealmsPreferredRegionSelectionScreen.RegionSelectionList - 修饰符:
private - 源码定位:
L33 - 说明:
TODO
- 类型:
-
selection- 类型:
RealmsSettingsTab.RegionSelection - 修饰符:
private - 源码定位:
L34 - 说明:
TODO
- 类型:
-
doneButton- 类型:
Button - 修饰符:
private - 源码定位:
L35 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
com.mojang.realmsclient.gui.screens.configuration.RealmsPreferredRegionSelectionScreen.RegionSelectionList- 类型:
class - 修饰符:
private - 源码定位:
L92 - 说明:
TODO
- 类型:
-
com.mojang.realmsclient.gui.screens.configuration.RealmsPreferredRegionSelectionScreen.RegionSelectionList.Entry- 类型:
class - 修饰符:
private - 源码定位:
L121 - 说明:
TODO
- 类型:
构造器
public RealmsPreferredRegionSelectionScreen(Screen parent, BiConsumer<RegionSelectionPreference,RealmsRegion> applySettings, Map<RealmsRegion,ServiceQuality> regionServiceQuality, RealmsSettingsTab.RegionSelection currentSelection) @ L37
- 构造器名:RealmsPreferredRegionSelectionScreen
- 源码定位:L37
- 修饰符:public
参数:
- parent: Screen
- applySettings: BiConsumer<RegionSelectionPreference,RealmsRegion>
- regionServiceQuality: Map<RealmsRegion,ServiceQuality>
- currentSelection: RealmsSettingsTab.RegionSelection
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void onClose() @ L50
- 方法名:onClose
- 源码定位:L50
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
protected void init() @ L55
- 方法名:init
- 源码定位:L55
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
protected void repositionElements() @ L69
- 方法名:repositionElements
- 源码定位:L69
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
private void onDone() @ L77
- 方法名:onDone
- 源码定位:L77
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private void updateButtonValidity() @ L85
- 方法名:updateButtonValidity
- 源码定位:L85
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class RealmsPreferredRegionSelectionScreen extends Screen {
private static final Component REGION_SELECTION_LABEL = Component.translatable("mco.configure.world.region_preference.title");
private static final int SPACING = 8;
private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
private final Screen parent;
private final BiConsumer<RegionSelectionPreference, RealmsRegion> applySettings;
private final Map<RealmsRegion, ServiceQuality> regionServiceQuality;
private RealmsPreferredRegionSelectionScreen.@Nullable RegionSelectionList list;
private RealmsSettingsTab.RegionSelection selection;
private @Nullable Button doneButton;
public RealmsPreferredRegionSelectionScreen(
Screen parent,
BiConsumer<RegionSelectionPreference, RealmsRegion> applySettings,
Map<RealmsRegion, ServiceQuality> regionServiceQuality,
RealmsSettingsTab.RegionSelection currentSelection
) {
super(REGION_SELECTION_LABEL);
this.parent = parent;
this.applySettings = applySettings;
this.regionServiceQuality = regionServiceQuality;
this.selection = currentSelection;
}
@Override
public void onClose() {
this.minecraft.setScreen(this.parent);
}
@Override
protected void init() {
LinearLayout header = this.layout.addToHeader(LinearLayout.vertical().spacing(8));
header.defaultCellSetting().alignHorizontallyCenter();
header.addChild(new StringWidget(this.getTitle(), this.font));
this.list = this.layout.addToContents(new RealmsPreferredRegionSelectionScreen.RegionSelectionList());
LinearLayout footer = this.layout.addToFooter(LinearLayout.horizontal().spacing(8));
this.doneButton = footer.addChild(Button.builder(CommonComponents.GUI_DONE, button -> this.onDone()).build());
footer.addChild(Button.builder(CommonComponents.GUI_CANCEL, button -> this.onClose()).build());
this.list.setSelected(this.list.children().stream().filter(e -> Objects.equals(e.regionSelection, this.selection)).findFirst().orElse(null));
this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
this.repositionElements();
}
@Override
protected void repositionElements() {
this.layout.arrangeElements();
if (this.list != null) {
this.list.updateSize(this.width, this.layout);
}
}
private void onDone() {
if (this.selection.region() != null) {
this.applySettings.accept(this.selection.preference(), this.selection.region());
}
this.onClose();
}
private void updateButtonValidity() {
if (this.doneButton != null && this.list != null) {
this.doneButton.active = this.list.getSelected() != null;
}
}
@OnlyIn(Dist.CLIENT)
private class RegionSelectionList extends ObjectSelectionList<RealmsPreferredRegionSelectionScreen.RegionSelectionList.Entry> {
private RegionSelectionList() {
Objects.requireNonNull(RealmsPreferredRegionSelectionScreen.this);
super(
RealmsPreferredRegionSelectionScreen.this.minecraft,
RealmsPreferredRegionSelectionScreen.this.width,
RealmsPreferredRegionSelectionScreen.this.height - 77,
40,
16
);
this.addEntry(new RealmsPreferredRegionSelectionScreen.RegionSelectionList.Entry(RegionSelectionPreference.AUTOMATIC_PLAYER, null));
this.addEntry(new RealmsPreferredRegionSelectionScreen.RegionSelectionList.Entry(RegionSelectionPreference.AUTOMATIC_OWNER, null));
RealmsPreferredRegionSelectionScreen.this.regionServiceQuality
.keySet()
.stream()
.map(region -> new RealmsPreferredRegionSelectionScreen.RegionSelectionList.Entry(RegionSelectionPreference.MANUAL, region))
.forEach(x$0 -> this.addEntry(x$0));
}
public void setSelected(RealmsPreferredRegionSelectionScreen.RegionSelectionList.@Nullable Entry selected) {
super.setSelected(selected);
if (selected != null) {
RealmsPreferredRegionSelectionScreen.this.selection = selected.regionSelection;
}
RealmsPreferredRegionSelectionScreen.this.updateButtonValidity();
}
@OnlyIn(Dist.CLIENT)
private class Entry extends ObjectSelectionList.Entry<RealmsPreferredRegionSelectionScreen.RegionSelectionList.Entry> {
private final RealmsSettingsTab.RegionSelection regionSelection;
private final Component name;
public Entry(RegionSelectionPreference preference, @Nullable RealmsRegion region) {
this(new RealmsSettingsTab.RegionSelection(preference, region));
}
public Entry(RealmsSettingsTab.RegionSelection regionSelection) {
Objects.requireNonNull(RegionSelectionList.this);
super();
this.regionSelection = regionSelection;
if (regionSelection.preference() == RegionSelectionPreference.MANUAL) {
if (regionSelection.region() != null) {
this.name = Component.translatable(regionSelection.region().translationKey);
} else {
this.name = Component.empty();
}
} else {
this.name = Component.translatable(regionSelection.preference().translationKey);
}
}
@Override
public Component getNarration() {
return Component.translatable("narrator.select", this.name);
}
@Override
public void extractContent(GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean hovered, float a) {
graphics.text(RealmsPreferredRegionSelectionScreen.this.font, this.name, this.getContentX() + 5, this.getContentY() + 2, -1);
if (this.regionSelection.region() != null
&& RealmsPreferredRegionSelectionScreen.this.regionServiceQuality.containsKey(this.regionSelection.region())) {
ServiceQuality serviceQuality = RealmsPreferredRegionSelectionScreen.this.regionServiceQuality
.getOrDefault(this.regionSelection.region(), ServiceQuality.UNKNOWN);
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, serviceQuality.getIcon(), this.getContentRight() - 18, this.getContentY() + 2, 10, 8);
}
}
@Override
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
RegionSelectionList.this.setSelected(this);
if (doubleClick) {
RegionSelectionList.this.playDownSound(RegionSelectionList.this.minecraft.getSoundManager());
RealmsPreferredRegionSelectionScreen.this.onDone();
return true;
} else {
return super.mouseClicked(event, doubleClick);
}
}
@Override
public boolean keyPressed(KeyEvent event) {
if (event.isSelection()) {
RegionSelectionList.this.playDownSound(RegionSelectionList.this.minecraft.getSoundManager());
RealmsPreferredRegionSelectionScreen.this.onDone();
return true;
} else {
return super.keyPressed(event);
}
}
}
}
}引用的其他类
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/字段/方法调用/构造调用 - 关联成员:
RealmsSettingsTab.RegionSelection(), RegionSelection()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Button.builder()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
StringWidget()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
HeaderAndFooterLayout()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
LinearLayout.horizontal(), LinearLayout.vertical()
- 引用位置:
-
- 引用位置:
参数/字段/继承
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Component.empty(), Component.translatable()
- 引用位置: