ExperimentsScreen.java
net.minecraft.client.gui.screens.worldselection.ExperimentsScreen
信息
- 全限定名:net.minecraft.client.gui.screens.worldselection.ExperimentsScreen
- 类型:public class
- 包:net.minecraft.client.gui.screens.worldselection
- 源码路径:src/main/java/net/minecraft/client/gui/screens/worldselection/ExperimentsScreen.java
- 起始行号:L28
- 继承:Screen
- 职责:
TODO
字段/常量
-
TITLE- 类型:
Component - 修饰符:
private static final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
INFO- 类型:
Component - 修饰符:
private static final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
MAIN_CONTENT_WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
SCROLL_AREA_MIN_HEIGHT- 类型:
int - 修饰符:
private static final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
layout- 类型:
HeaderAndFooterLayout - 修饰符:
private final - 源码定位:
L33 - 说明:
TODO
- 类型:
-
parent- 类型:
Screen - 修饰符:
private final - 源码定位:
L34 - 说明:
TODO
- 类型:
-
packRepository- 类型:
PackRepository - 修饰符:
private final - 源码定位:
L35 - 说明:
TODO
- 类型:
-
output- 类型:
Consumer<PackRepository> - 修饰符:
private final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
packs- 类型:
Object2BooleanMap<Pack> - 修饰符:
private final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
scrollArea- 类型:
ScrollableLayout - 修饰符:
private - 源码定位:
L38 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public ExperimentsScreen(Screen parent, PackRepository packRepository, Consumer<PackRepository> output) @ L40
- 构造器名:ExperimentsScreen
- 源码定位:L40
- 修饰符:public
参数:
- parent: Screen
- packRepository: PackRepository
- output: Consumer
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected void init() @ L53
- 方法名:init
- 源码定位:L53
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
private static Component getHumanReadableTitle(Pack pack) @ L77
- 方法名:getHumanReadableTitle
- 源码定位:L77
- 返回类型:Component
- 修饰符:private static
参数:
- pack: Pack
说明:
TODO
protected void repositionElements() @ L82
- 方法名:repositionElements
- 源码定位:L82
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
public Component getNarrationMessage() @ L90
- 方法名:getNarrationMessage
- 源码定位:L90
- 返回类型:Component
- 修饰符:public
参数:
- 无
说明:
TODO
public void onClose() @ L95
- 方法名:onClose
- 源码定位:L95
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
private void onDone() @ L100
- 方法名:onDone
- 源码定位:L100
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class ExperimentsScreen extends Screen {
private static final Component TITLE = Component.translatable("selectWorld.experiments");
private static final Component INFO = Component.translatable("selectWorld.experiments.info").withStyle(ChatFormatting.RED);
private static final int MAIN_CONTENT_WIDTH = 310;
private static final int SCROLL_AREA_MIN_HEIGHT = 130;
private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
private final Screen parent;
private final PackRepository packRepository;
private final Consumer<PackRepository> output;
private final Object2BooleanMap<Pack> packs = new Object2BooleanLinkedOpenHashMap<>();
private @Nullable ScrollableLayout scrollArea;
public ExperimentsScreen(Screen parent, PackRepository packRepository, Consumer<PackRepository> output) {
super(TITLE);
this.parent = parent;
this.packRepository = packRepository;
this.output = output;
for (Pack pack : packRepository.getAvailablePacks()) {
if (pack.getPackSource() == PackSource.FEATURE) {
this.packs.put(pack, packRepository.getSelectedPacks().contains(pack));
}
}
}
@Override
protected void init() {
this.layout.addTitleHeader(TITLE, this.font);
LinearLayout content = this.layout.addToContents(LinearLayout.vertical());
content.addChild(new MultiLineTextWidget(INFO, this.font).setMaxWidth(310), s -> s.paddingBottom(15));
SwitchGrid.Builder switchGridBuilder = SwitchGrid.builder(299).withInfoUnderneath(2, true).withRowSpacing(4);
this.packs
.forEach(
(pack, selected) -> switchGridBuilder.addSwitch(
getHumanReadableTitle(pack), () -> this.packs.getBoolean(pack), newSelected -> this.packs.put(pack, newSelected.booleanValue())
)
.withInfo(pack.getDescription())
);
Layout switchGridLayout = switchGridBuilder.build().layout();
this.scrollArea = new ScrollableLayout(this.minecraft, switchGridLayout, 130);
this.scrollArea.setMinWidth(310);
content.addChild(this.scrollArea);
LinearLayout footer = this.layout.addToFooter(LinearLayout.horizontal().spacing(8));
footer.addChild(Button.builder(CommonComponents.GUI_DONE, button -> this.onDone()).build());
footer.addChild(Button.builder(CommonComponents.GUI_CANCEL, button -> this.onClose()).build());
this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
this.repositionElements();
}
private static Component getHumanReadableTitle(Pack pack) {
String translationKey = "dataPack." + pack.getId() + ".name";
return (Component)(I18n.exists(translationKey) ? Component.translatable(translationKey) : pack.getTitle());
}
@Override
protected void repositionElements() {
this.scrollArea.setMaxHeight(130);
this.layout.arrangeElements();
int availableExtraHeight = this.height - this.layout.getFooterHeight() - this.scrollArea.getRectangle().bottom();
this.scrollArea.setMaxHeight(this.scrollArea.getHeight() + availableExtraHeight);
}
@Override
public Component getNarrationMessage() {
return CommonComponents.joinForNarration(super.getNarrationMessage(), INFO);
}
@Override
public void onClose() {
this.minecraft.setScreen(this.parent);
}
private void onDone() {
List<Pack> selectedPacks = new ArrayList<>(this.packRepository.getSelectedPacks());
List<Pack> selectedFeatures = new ArrayList<>();
this.packs.forEach((pack, selected) -> {
selectedPacks.remove(pack);
if (selected) {
selectedFeatures.add(pack);
}
});
selectedPacks.addAll(Lists.reverse(selectedFeatures));
this.packRepository.setSelected(selectedPacks.stream().map(Pack::getId).toList());
this.output.accept(this.packRepository);
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
Button.builder()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
MultiLineTextWidget()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
ScrollableLayout()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
HeaderAndFooterLayout()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
LinearLayout.horizontal(), LinearLayout.vertical()
- 引用位置:
-
- 引用位置:
参数/字段/继承
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SwitchGrid.builder()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
I18n.exists()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
CommonComponents.joinForNarration()
- 引用位置:
-
- 引用位置:
字段/方法调用/返回值 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置: