DialogScreen.java
net.minecraft.client.gui.screens.dialog.DialogScreen
信息
- 全限定名:net.minecraft.client.gui.screens.dialog.DialogScreen
- 类型:public abstract class
- 包:net.minecraft.client.gui.screens.dialog
- 源码路径:src/main/java/net/minecraft/client/gui/screens/dialog/DialogScreen.java
- 起始行号:L35
- 继承:Screen
- 职责:
TODO
字段/常量
-
DISCONNECT- 类型:
Component - 修饰符:
public static final - 源码定位:
L36 - 说明:
TODO
- 类型:
-
WARNING_BUTTON_SIZE- 类型:
int - 修饰符:
private static final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
WARNING_BUTTON_SPRITES- 类型:
WidgetSprites - 修饰符:
private static final - 源码定位:
L38 - 说明:
TODO
- 类型:
-
dialog- 类型:
T - 修饰符:
private final - 源码定位:
L43 - 说明:
TODO
- 类型:
-
layout- 类型:
HeaderAndFooterLayout - 修饰符:
private final - 源码定位:
L44 - 说明:
TODO
- 类型:
-
previousScreen- 类型:
Screen - 修饰符:
private final - 源码定位:
L45 - 说明:
TODO
- 类型:
-
bodyScroll- 类型:
ScrollableLayout - 修饰符:
private - 源码定位:
L46 - 说明:
TODO
- 类型:
-
warningButton- 类型:
Button - 修饰符:
private - 源码定位:
L47 - 说明:
TODO
- 类型:
-
connectionAccess- 类型:
DialogConnectionAccess - 修饰符:
private final - 源码定位:
L48 - 说明:
TODO
- 类型:
-
onClose- 类型:
Supplier<Optional<ClickEvent>> - 修饰符:
private - 源码定位:
L49 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.client.gui.screens.dialog.DialogScreen.WarningScreen- 类型:
class - 修饰符:
public static - 源码定位:
L218 - 说明:
TODO
- 类型:
构造器
public DialogScreen(Screen previousScreen, T dialog, DialogConnectionAccess connectionAccess) @ L51
- 构造器名:DialogScreen
- 源码定位:L51
- 修饰符:public
参数:
- previousScreen: Screen
- dialog: T
- connectionAccess: DialogConnectionAccess
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected final void init() @ L58
- 方法名:init
- 源码定位:L58
- 返回类型:void
- 修饰符:protected final
参数:
- 无
说明:
TODO
protected void populateBodyElements(LinearLayout layout, DialogControlSet controlSet, T dialog, DialogConnectionAccess connectionAccess) @ L93
- 方法名:populateBodyElements
- 源码定位:L93
- 返回类型:void
- 修饰符:protected
参数:
- layout: LinearLayout
- controlSet: DialogControlSet
- dialog: T
- connectionAccess: DialogConnectionAccess
说明:
TODO
protected void updateHeaderAndFooter(HeaderAndFooterLayout layout, DialogControlSet controlSet, T dialog, DialogConnectionAccess connectionAccess) @ L96
- 方法名:updateHeaderAndFooter
- 源码定位:L96
- 返回类型:void
- 修饰符:protected
参数:
- layout: HeaderAndFooterLayout
- controlSet: DialogControlSet
- dialog: T
- connectionAccess: DialogConnectionAccess
说明:
TODO
protected void repositionElements() @ L99
- 方法名:repositionElements
- 源码定位:L99
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
protected LayoutElement createTitleWithWarningButton() @ L107
- 方法名:createTitleWithWarningButton
- 源码定位:L107
- 返回类型:LayoutElement
- 修饰符:protected
参数:
- 无
说明:
TODO
protected void makeSureWarningButtonIsInBounds() @ L115
- 方法名:makeSureWarningButtonIsInBounds
- 源码定位:L115
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
private Button createWarningButton() @ L124
- 方法名:createWarningButton
- 源码定位:L124
- 返回类型:Button
- 修饰符:private
参数:
- 无
说明:
TODO
public boolean isPauseScreen() @ L138
- 方法名:isPauseScreen
- 源码定位:L138
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean shouldCloseOnEsc() @ L143
- 方法名:shouldCloseOnEsc
- 源码定位:L143
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public void onClose() @ L148
- 方法名:onClose
- 源码定位:L148
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void runAction(Optional<ClickEvent> closeAction) @ L153
- 方法名:runAction
- 源码定位:L153
- 返回类型:void
- 修饰符:public
参数:
- closeAction: Optional
说明:
TODO
public void runAction(Optional<ClickEvent> closeAction, DialogAction afterAction) @ L157
- 方法名:runAction
- 源码定位:L157
- 返回类型:void
- 修饰符:public
参数:
- closeAction: Optional
- afterAction: DialogAction
说明:
TODO
private void handleDialogClickEvent(ClickEvent event, Screen activeScreen) @ L170
- 方法名:handleDialogClickEvent
- 源码定位:L170
- 返回类型:void
- 修饰符:private
参数:
- event: ClickEvent
- activeScreen: Screen
说明:
TODO
public Screen previousScreen() @ L187
- 方法名:previousScreen
- 源码定位:L187
- 返回类型:Screen
- 修饰符:public
参数:
- 无
说明:
TODO
protected static LayoutElement packControlsIntoColumns(List<?extends LayoutElement> controls, int columns) @ L191
- 方法名:packControlsIntoColumns
- 源码定位:L191
- 返回类型:LayoutElement
- 修饰符:protected static
参数:
- controls: List<?extends LayoutElement>
- columns: int
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public abstract class DialogScreen<T extends Dialog> extends Screen {
public static final Component DISCONNECT = Component.translatable("menu.custom_screen_info.disconnect");
private static final int WARNING_BUTTON_SIZE = 20;
private static final WidgetSprites WARNING_BUTTON_SPRITES = new WidgetSprites(
Identifier.withDefaultNamespace("dialog/warning_button"),
Identifier.withDefaultNamespace("dialog/warning_button_disabled"),
Identifier.withDefaultNamespace("dialog/warning_button_highlighted")
);
private final T dialog;
private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
private final @Nullable Screen previousScreen;
private @Nullable ScrollableLayout bodyScroll;
private Button warningButton;
private final DialogConnectionAccess connectionAccess;
private Supplier<Optional<ClickEvent>> onClose = DialogControlSet.EMPTY_ACTION;
public DialogScreen(@Nullable Screen previousScreen, T dialog, DialogConnectionAccess connectionAccess) {
super(dialog.common().title());
this.dialog = dialog;
this.previousScreen = previousScreen;
this.connectionAccess = connectionAccess;
}
@Override
protected final void init() {
super.init();
this.warningButton = this.createWarningButton();
this.warningButton.setTabOrderGroup(-10);
DialogControlSet controlSet = new DialogControlSet(this);
LinearLayout body = LinearLayout.vertical().spacing(10);
body.defaultCellSetting().alignHorizontallyCenter();
this.layout.addToHeader(this.createTitleWithWarningButton());
for (DialogBody dialogBody : this.dialog.common().body()) {
LayoutElement bodyElement = DialogBodyHandlers.createBodyElement(this, dialogBody);
if (bodyElement != null) {
body.addChild(bodyElement);
}
}
for (Input input : this.dialog.common().inputs()) {
controlSet.addInput(input, body::addChild);
}
this.populateBodyElements(body, controlSet, this.dialog, this.connectionAccess);
this.bodyScroll = new ScrollableLayout(this.minecraft, body, this.layout.getContentHeight());
this.layout.addToContents(this.bodyScroll);
this.updateHeaderAndFooter(this.layout, controlSet, this.dialog, this.connectionAccess);
this.onClose = controlSet.bindAction(this.dialog.onCancel());
this.layout.visitWidgets(widget -> {
if (widget != this.warningButton) {
this.addRenderableWidget(widget);
}
});
this.addRenderableWidget(this.warningButton);
this.repositionElements();
}
protected void populateBodyElements(LinearLayout layout, DialogControlSet controlSet, T dialog, DialogConnectionAccess connectionAccess) {
}
protected void updateHeaderAndFooter(HeaderAndFooterLayout layout, DialogControlSet controlSet, T dialog, DialogConnectionAccess connectionAccess) {
}
@Override
protected void repositionElements() {
this.bodyScroll.arrangeElements();
this.bodyScroll.setMaxHeight(this.layout.getContentHeight());
this.layout.arrangeElements();
this.makeSureWarningButtonIsInBounds();
}
protected LayoutElement createTitleWithWarningButton() {
LinearLayout layout = LinearLayout.horizontal().spacing(10);
layout.defaultCellSetting().alignHorizontallyCenter().alignVerticallyMiddle();
layout.addChild(new StringWidget(this.title, this.font));
layout.addChild(this.warningButton);
return layout;
}
protected void makeSureWarningButtonIsInBounds() {
int x = this.warningButton.getX();
int y = this.warningButton.getY();
if (x < 0 || y < 0 || x > this.width - 20 || y > this.height - 20) {
this.warningButton.setX(Math.max(0, this.width - 40));
this.warningButton.setY(Math.min(5, this.height));
}
}
private Button createWarningButton() {
ImageButton result = new ImageButton(
0,
0,
20,
20,
WARNING_BUTTON_SPRITES,
button -> this.minecraft.setScreen(DialogScreen.WarningScreen.create(this.minecraft, this.connectionAccess, this)),
Component.translatable("menu.custom_screen_info.button_narration")
);
result.setTooltip(Tooltip.create(Component.translatable("menu.custom_screen_info.tooltip")));
return result;
}
@Override
public boolean isPauseScreen() {
return this.dialog.common().pause();
}
@Override
public boolean shouldCloseOnEsc() {
return this.dialog.common().canCloseWithEscape();
}
@Override
public void onClose() {
this.runAction(this.onClose.get(), DialogAction.CLOSE);
}
public void runAction(Optional<ClickEvent> closeAction) {
this.runAction(closeAction, this.dialog.common().afterAction());
}
public void runAction(Optional<ClickEvent> closeAction, DialogAction afterAction) {
Screen screenToActivate = (Screen)(switch (afterAction) {
case NONE -> this;
case CLOSE -> this.previousScreen;
case WAIT_FOR_RESPONSE -> new WaitingForResponseScreen(this.previousScreen);
});
if (closeAction.isPresent()) {
this.handleDialogClickEvent(closeAction.get(), screenToActivate);
} else {
this.minecraft.setScreen(screenToActivate);
}
}
private void handleDialogClickEvent(ClickEvent event, @Nullable Screen activeScreen) {
switch (event) {
case ClickEvent.RunCommand(String var10):
this.connectionAccess.runCommand(Commands.trimOptionalPrefix(var10), activeScreen);
break;
case ClickEvent.ShowDialog dialog:
this.connectionAccess.openDialog(dialog.dialog(), activeScreen);
break;
case ClickEvent.Custom custom:
this.connectionAccess.sendCustomAction(custom.id(), custom.payload());
this.minecraft.setScreen(activeScreen);
break;
default:
defaultHandleClickEvent(event, this.minecraft, activeScreen);
}
}
public @Nullable Screen previousScreen() {
return this.previousScreen;
}
protected static LayoutElement packControlsIntoColumns(List<? extends LayoutElement> controls, int columns) {
GridLayout gridLayout = new GridLayout();
gridLayout.defaultCellSetting().alignHorizontallyCenter();
gridLayout.columnSpacing(2).rowSpacing(2);
int count = controls.size();
int lastFullRow = count / columns;
int countInFullRows = lastFullRow * columns;
for (int i = 0; i < countInFullRows; i++) {
gridLayout.addChild(controls.get(i), i / columns, i % columns);
}
if (count != countInFullRows) {
LinearLayout lastRow = LinearLayout.horizontal().spacing(2);
lastRow.defaultCellSetting().alignHorizontallyCenter();
for (int i = countInFullRows; i < count; i++) {
lastRow.addChild(controls.get(i));
}
gridLayout.addChild(lastRow, lastFullRow, 0, 1, columns);
}
return gridLayout;
}
@OnlyIn(Dist.CLIENT)
public static class WarningScreen extends ConfirmScreen {
private final MutableObject<@Nullable Screen> returnScreen;
public static Screen create(Minecraft minecraft, DialogConnectionAccess connectionAccess, Screen returnScreen) {
return new DialogScreen.WarningScreen(minecraft, connectionAccess, new MutableObject<>(returnScreen));
}
private WarningScreen(Minecraft minecraft, DialogConnectionAccess connectionAccess, MutableObject<Screen> returnScreen) {
super(
disconnect -> {
if (disconnect) {
connectionAccess.disconnect(DialogScreen.DISCONNECT);
} else {
minecraft.setScreen(returnScreen.get());
}
},
Component.translatable("menu.custom_screen_info.title"),
Component.translatable("menu.custom_screen_info.contents"),
CommonComponents.disconnectButtonLabel(minecraft.isLocalServer()),
CommonComponents.GUI_BACK
);
this.returnScreen = returnScreen;
}
public @Nullable Screen returnScreen() {
return this.returnScreen.get();
}
public void updateReturnScreen(@Nullable Screen newReturnScreen) {
this.returnScreen.setValue(newReturnScreen);
}
}
}引用的其他类
-
- 引用位置:
字段/返回值
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
ImageButton()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
ScrollableLayout()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
StringWidget()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Tooltip.create()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
WidgetSprites()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
GridLayout()
- 引用位置:
-
- 引用位置:
参数/字段/构造调用 - 关联成员:
HeaderAndFooterLayout()
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
LinearLayout.horizontal(), LinearLayout.vertical()
- 引用位置:
-
- 引用位置:
参数/字段/继承/返回值
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数/构造调用 - 关联成员:
DialogControlSet()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
WaitingForResponseScreen()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
DialogBodyHandlers.createBodyElement()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.trimOptionalPrefix()
- 引用位置:
-
- 引用位置:
参数/字段/方法调用 - 关联成员:
ClickEvent.RunCommand()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
CommonComponents.disconnectButtonLabel()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
参数
- 引用位置: