Support for built-in servers

This commit is contained in:
Anuken
2019-09-05 19:23:17 -04:00
parent 3cbb02f9fb
commit 5651d1b023
5 changed files with 19 additions and 11 deletions
@@ -176,6 +176,11 @@ public class JoinDialog extends FloatingDialog{
void setupServer(Server server, Host host){
server.lastHost = host;
server.content.clear();
buildServer(host, server.content);
}
void buildServer(Host host, Table content){
String versionString;
if(host.version == -1){
@@ -192,9 +197,8 @@ public class JoinDialog extends FloatingDialog{
versionString = Core.bundle.format("server.version", host.version, host.versionType);
}
server.content.clear();
server.content.table(t -> {
content.table(t -> {
t.add("[lightgray]" + host.name + " " + versionString).width(targetWidth() - 10f).left().get().setEllipsis(true);
t.row();
t.add("[lightgray]" + (Core.bundle.format("players" + (host.players == 1 ? ".single" : ""), (host.players == 0 ? "[lightgray]" : "[accent]") + host.players + (host.playerLimit > 0 ? "[lightgray]/[accent]" + host.playerLimit : "")+ "[lightgray]"))).left();
@@ -268,6 +272,9 @@ public class JoinDialog extends FloatingDialog{
local.background((Drawable)null);
local.table("button", t -> t.label(() -> "[accent]" + Core.bundle.get("hosts.discovering") + Strings.animated(Time.time(), 4, 10f, ".")).pad(10f)).growX();
Net.discoverServers(this::addLocalHost, this::finishLocalHosts);
for(String host : defaultServers){
Net.pingHost(host, port, this::addLocalHost, e -> {});
}
}
void finishLocalHosts(){
@@ -292,12 +299,10 @@ public class JoinDialog extends FloatingDialog{
local.row();
TextButton button = local.addButton("[accent]" + host.name, "clear", () -> connect(host.address, port))
.width(w).height(80f).pad(4f).get();
button.left();
button.row();
button.add("[lightgray]" + (host.players != 1 ? Core.bundle.format("players", host.players) :
Core.bundle.format("players.single", host.players))).padBottom(5);
TextButton button = local.addButton("", "clear", () -> connect(host.address, port))
.width(w).pad(5f).get();
button.clearChildren();
buildServer(host, button);
}
void connect(String ip, int port){