JoinMultiplayerScreen.java
net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen
信息
- 全限定名:net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen
- 类型:public class
- 包:net.minecraft.client.gui.screens.multiplayer
- 源码路径:src/main/java/net/minecraft/client/gui/screens/multiplayer/JoinMultiplayerScreen.java
- 起始行号:L29
- 继承:Screen
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
TOP_ROW_BUTTON_WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
LOWER_ROW_BUTTON_WIDTH- 类型:
int - 修饰符:
private static final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
layout- 类型:
HeaderAndFooterLayout - 修饰符:
private final - 源码定位:
L33 - 说明:
TODO
- 类型:
-
pinger- 类型:
ServerStatusPinger - 修饰符:
private final - 源码定位:
L34 - 说明:
TODO
- 类型:
-
lastScreen- 类型:
Screen - 修饰符:
private final - 源码定位:
L35 - 说明:
TODO
- 类型:
-
serverSelectionList- 类型:
ServerSelectionList - 修饰符:
protected - 源码定位:
L36 - 说明:
TODO
- 类型:
-
servers- 类型:
ServerList - 修饰符:
private - 源码定位:
L37 - 说明:
TODO
- 类型:
-
editButton- 类型:
Button - 修饰符:
private - 源码定位:
L38 - 说明:
TODO
- 类型:
-
selectButton- 类型:
Button - 修饰符:
private - 源码定位:
L39 - 说明:
TODO
- 类型:
-
deleteButton- 类型:
Button - 修饰符:
private - 源码定位:
L40 - 说明:
TODO
- 类型:
-
editingServer- 类型:
ServerData - 修饰符:
private - 源码定位:
L41 - 说明:
TODO
- 类型:
-
lanServerList- 类型:
LanServerDetection.LanServerList - 修饰符:
private - 源码定位:
L42 - 说明:
TODO
- 类型:
-
lanServerDetector- 类型:
LanServerDetection.LanServerDetector - 修饰符:
private - 源码定位:
L43 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public JoinMultiplayerScreen(Screen lastScreen) @ L45
- 构造器名:JoinMultiplayerScreen
- 源码定位:L45
- 修饰符:public
参数:
- lastScreen: Screen
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected void init() @ L50
- 方法名:init
- 源码定位:L50
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
protected void repositionElements() @ L136
- 方法名:repositionElements
- 源码定位:L136
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
public void onClose() @ L144
- 方法名:onClose
- 源码定位:L144
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void tick() @ L149
- 方法名:tick
- 源码定位:L149
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void removed() @ L160
- 方法名:removed
- 源码定位:L160
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
private void refreshServerList() @ L171
- 方法名:refreshServerList
- 源码定位:L171
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private void deleteCallback(boolean result) @ L175
- 方法名:deleteCallback
- 源码定位:L175
- 返回类型:void
- 修饰符:private
参数:
- result: boolean
说明:
TODO
private void editServerCallback(boolean result) @ L187
- 方法名:editServerCallback
- 源码定位:L187
- 返回类型:void
- 修饰符:private
参数:
- result: boolean
说明:
TODO
private void addServerCallback(boolean result) @ L201
- 方法名:addServerCallback
- 源码定位:L201
- 返回类型:void
- 修饰符:private
参数:
- result: boolean
说明:
TODO
private void directJoinCallback(boolean result) @ L219
- 方法名:directJoinCallback
- 源码定位:L219
- 返回类型:void
- 修饰符:private
参数:
- result: boolean
说明:
TODO
public boolean keyPressed(KeyEvent event) @ L234
- 方法名:keyPressed
- 源码定位:L234
- 返回类型:boolean
- 修饰符:public
参数:
- event: KeyEvent
说明:
TODO
public void join(ServerData data) @ L246
- 方法名:join
- 源码定位:L246
- 返回类型:void
- 修饰符:public
参数:
- data: ServerData
说明:
TODO
protected void onSelectedChange() @ L250
- 方法名:onSelectedChange
- 源码定位:L250
- 返回类型:void
- 修饰符:protected
参数:
- 无
说明:
TODO
public ServerStatusPinger getPinger() @ L264
- 方法名:getPinger
- 源码定位:L264
- 返回类型:ServerStatusPinger
- 修饰符:public
参数:
- 无
说明:
TODO
public ServerList getServers() @ L268
- 方法名:getServers
- 源码定位:L268
- 返回类型:ServerList
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class JoinMultiplayerScreen extends Screen {
private static final Logger LOGGER = LogUtils.getLogger();
private static final int TOP_ROW_BUTTON_WIDTH = 100;
private static final int LOWER_ROW_BUTTON_WIDTH = 74;
private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this, 33, 60);
private final ServerStatusPinger pinger = new ServerStatusPinger();
private final Screen lastScreen;
protected ServerSelectionList serverSelectionList;
private ServerList servers;
private Button editButton;
private Button selectButton;
private Button deleteButton;
private ServerData editingServer;
private LanServerDetection.LanServerList lanServerList;
private LanServerDetection.@Nullable LanServerDetector lanServerDetector;
public JoinMultiplayerScreen(Screen lastScreen) {
super(Component.translatable("multiplayer.title"));
this.lastScreen = lastScreen;
}
@Override
protected void init() {
this.layout.addTitleHeader(this.title, this.font);
this.servers = new ServerList(this.minecraft);
this.servers.load();
this.lanServerList = new LanServerDetection.LanServerList();
try {
this.lanServerDetector = new LanServerDetection.LanServerDetector(this.lanServerList);
this.lanServerDetector.start();
} catch (Exception var5) {
LOGGER.warn("Unable to start LAN server detection: {}", var5.getMessage());
}
this.serverSelectionList = this.layout
.addToContents(new ServerSelectionList(this, this.minecraft, this.width, this.layout.getContentHeight(), this.layout.getHeaderHeight(), 36));
this.serverSelectionList.updateOnlineServers(this.servers);
LinearLayout footer = this.layout.addToFooter(LinearLayout.vertical().spacing(4));
footer.defaultCellSetting().alignHorizontallyCenter();
LinearLayout topFooterButtons = footer.addChild(LinearLayout.horizontal().spacing(4));
LinearLayout bottomFooterButtons = footer.addChild(LinearLayout.horizontal().spacing(4));
this.selectButton = topFooterButtons.addChild(Button.builder(Component.translatable("selectServer.select"), button -> {
ServerSelectionList.Entry entry = this.serverSelectionList.getSelected();
if (entry != null) {
entry.join();
}
}).width(100).build());
topFooterButtons.addChild(Button.builder(Component.translatable("selectServer.direct"), button -> {
this.editingServer = new ServerData(I18n.get("selectServer.defaultName"), "", ServerData.Type.OTHER);
this.minecraft.setScreen(new DirectJoinServerScreen(this, this::directJoinCallback, this.editingServer));
}).width(100).build());
topFooterButtons.addChild(
Button.builder(
Component.translatable("selectServer.add"),
button -> {
this.editingServer = new ServerData("", "", ServerData.Type.OTHER);
this.minecraft
.setScreen(
new ManageServerScreen(this, Component.translatable("manageServer.add.title"), this::addServerCallback, this.editingServer)
);
}
)
.width(100)
.build()
);
this.editButton = bottomFooterButtons.addChild(
Button.builder(
Component.translatable("selectServer.edit"),
button -> {
ServerSelectionList.Entry entry = this.serverSelectionList.getSelected();
if (entry instanceof ServerSelectionList.OnlineServerEntry) {
ServerData current = ((ServerSelectionList.OnlineServerEntry)entry).getServerData();
this.editingServer = new ServerData(current.name, current.ip, ServerData.Type.OTHER);
this.editingServer.copyFrom(current);
this.minecraft
.setScreen(
new ManageServerScreen(
this, Component.translatable("manageServer.edit.title"), this::editServerCallback, this.editingServer
)
);
}
}
)
.width(74)
.build()
);
this.deleteButton = bottomFooterButtons.addChild(Button.builder(Component.translatable("selectServer.delete"), button -> {
ServerSelectionList.Entry entry = this.serverSelectionList.getSelected();
if (entry instanceof ServerSelectionList.OnlineServerEntry) {
String serverName = ((ServerSelectionList.OnlineServerEntry)entry).getServerData().name;
if (serverName != null) {
Component title = Component.translatable("selectServer.deleteQuestion");
Component warning = Component.translatable("selectServer.deleteWarning", serverName);
Component yes = Component.translatable("selectServer.deleteButton");
Component no = CommonComponents.GUI_CANCEL;
this.minecraft.setScreen(new ConfirmScreen(this::deleteCallback, title, warning, yes, no));
}
}
}).width(74).build());
bottomFooterButtons.addChild(Button.builder(Component.translatable("selectServer.refresh"), button -> this.refreshServerList()).width(74).build());
bottomFooterButtons.addChild(Button.builder(CommonComponents.GUI_BACK, button -> this.onClose()).width(74).build());
this.layout.visitWidgets(x$0 -> this.addRenderableWidget(x$0));
this.repositionElements();
this.onSelectedChange();
}
@Override
protected void repositionElements() {
this.layout.arrangeElements();
if (this.serverSelectionList != null) {
this.serverSelectionList.updateSize(this.width, this.layout);
}
}
@Override
public void onClose() {
this.minecraft.setScreen(this.lastScreen);
}
@Override
public void tick() {
super.tick();
List<LanServer> lanServers = this.lanServerList.takeDirtyServers();
if (lanServers != null) {
this.serverSelectionList.updateNetworkServers(lanServers);
}
this.pinger.tick();
}
@Override
public void removed() {
if (this.lanServerDetector != null) {
this.lanServerDetector.interrupt();
this.lanServerDetector = null;
}
this.pinger.removeAll();
this.serverSelectionList.removed();
}
private void refreshServerList() {
this.minecraft.setScreen(new JoinMultiplayerScreen(this.lastScreen));
}
private void deleteCallback(boolean result) {
ServerSelectionList.Entry entry = this.serverSelectionList.getSelected();
if (result && entry instanceof ServerSelectionList.OnlineServerEntry) {
this.servers.remove(((ServerSelectionList.OnlineServerEntry)entry).getServerData());
this.servers.save();
this.serverSelectionList.setSelected(null);
this.serverSelectionList.updateOnlineServers(this.servers);
}
this.minecraft.setScreen(this);
}
private void editServerCallback(boolean result) {
ServerSelectionList.Entry entry = this.serverSelectionList.getSelected();
if (result && entry instanceof ServerSelectionList.OnlineServerEntry) {
ServerData current = ((ServerSelectionList.OnlineServerEntry)entry).getServerData();
current.name = this.editingServer.name;
current.ip = this.editingServer.ip;
current.copyFrom(this.editingServer);
this.servers.save();
this.serverSelectionList.updateOnlineServers(this.servers);
}
this.minecraft.setScreen(this);
}
private void addServerCallback(boolean result) {
if (result) {
ServerData serverData = this.servers.unhide(this.editingServer.ip);
if (serverData != null) {
serverData.copyNameIconFrom(this.editingServer);
this.servers.save();
} else {
this.servers.add(this.editingServer, false);
this.servers.save();
}
this.serverSelectionList.setSelected(null);
this.serverSelectionList.updateOnlineServers(this.servers);
}
this.minecraft.setScreen(this);
}
private void directJoinCallback(boolean result) {
if (result) {
ServerData serverData = this.servers.get(this.editingServer.ip);
if (serverData == null) {
this.servers.add(this.editingServer, true);
this.servers.save();
this.join(this.editingServer);
} else {
this.join(serverData);
}
} else {
this.minecraft.setScreen(this);
}
}
@Override
public boolean keyPressed(KeyEvent event) {
if (super.keyPressed(event)) {
return true;
} else if (event.key() == 294) {
this.refreshServerList();
return true;
} else {
return false;
}
}
public void join(ServerData data) {
ConnectScreen.startConnecting(this, this.minecraft, ServerAddress.parseString(data.ip), data, false, null);
}
protected void onSelectedChange() {
this.selectButton.active = false;
this.editButton.active = false;
this.deleteButton.active = false;
ServerSelectionList.Entry entry = this.serverSelectionList.getSelected();
if (entry != null && !(entry instanceof ServerSelectionList.LANHeader)) {
this.selectButton.active = true;
if (entry instanceof ServerSelectionList.OnlineServerEntry) {
this.editButton.active = true;
this.deleteButton.active = true;
}
}
}
public ServerStatusPinger getPinger() {
return this.pinger;
}
public ServerList getServers() {
return this.servers;
}
}引用的其他类
-
- 引用位置:
字段/方法调用 - 关联成员:
Button.builder()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
HeaderAndFooterLayout()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
LinearLayout.horizontal(), LinearLayout.vertical()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
ConfirmScreen()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ConnectScreen.startConnecting()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
DirectJoinServerScreen()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
ManageServerScreen()
- 引用位置:
-
- 引用位置:
参数/字段/继承
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
ServerSelectionList()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/构造调用 - 关联成员:
ServerData()
- 引用位置:
-
- 引用位置:
字段/构造调用/返回值 - 关联成员:
ServerList()
- 引用位置:
-
- 引用位置:
字段/构造调用/返回值 - 关联成员:
ServerStatusPinger()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ServerAddress.parseString()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
I18n.get()
- 引用位置:
-
- 引用位置:
字段/方法调用/构造调用 - 关联成员:
LanServerDetection.LanServerDetector(), LanServerDetection.LanServerList(), LanServerDetector(), LanServerList()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable()
- 引用位置: