Multi-line server list

This commit is contained in:
Anuken
2023-03-26 22:46:30 -04:00
parent deb814ce58
commit 83a059b2da
3 changed files with 40 additions and 16 deletions

View File

@ -37,7 +37,7 @@ public class JoinDialog extends BaseDialog{
TextButtonStyle style; TextButtonStyle style;
String lastIp; String lastIp;
int lastPort; int lastPort, lastColumns = -1;
Task ping; Task ping;
String serverSearch = ""; String serverSearch = "";
@ -107,12 +107,17 @@ public class JoinDialog extends BaseDialog{
}); });
onResize(() -> { onResize(() -> {
//only refresh on resize when the minimum dimension is smaller than the maximum preferred width //only refresh on resize when the minimum dimension is smaller than the maximum preferred width
//this means that refreshes on resize will only happen for small phones that need the list to fit in portrait mode //this means that refreshes on resize will only happen for small phones that need the list to fit in portrait mode
if(Math.min(Core.graphics.getWidth(), Core.graphics.getHeight()) / Scl.scl() * 0.9f < 500f){ //also resize if number of cols changes
if(Math.min(Core.graphics.getWidth(), Core.graphics.getHeight()) / Scl.scl() * 0.9f < 500f || lastColumns != columns()){
setup(); setup();
refreshAll(); refreshAll();
} }
lastColumns = columns();
}); });
} }
@ -140,7 +145,11 @@ public class JoinDialog extends BaseDialog{
connect(server.ip, server.port); connect(server.ip, server.port);
} }
} }
}).width(targetWidth()).pad(4f).get(); }).width(targetWidth()).growY().top().left().pad(4f).get();
if(remote.getChildren().size % columns() == 0){
remote.row();
}
Table inner = new Table(Tex.whiteui); Table inner = new Table(Tex.whiteui);
inner.setColor(Pal.gray); inner.setColor(Pal.gray);
@ -181,8 +190,6 @@ public class JoinDialog extends BaseDialog{
button.row(); button.row();
server.content = button.table(t -> {}).grow().get(); server.content = button.table(t -> {}).grow().get();
remote.row();
} }
} }
@ -234,6 +241,7 @@ public class JoinDialog extends BaseDialog{
} }
void buildServer(Host host, Table content){ void buildServer(Host host, Table content){
content.top().left();
String versionString; String versionString;
if(host.version == -1){ if(host.version == -1){
@ -267,6 +275,7 @@ public class JoinDialog extends BaseDialog{
}).growX().height(36f).row(); }).growX().height(36f).row();
content.table(Tex.whitePane, t -> { content.table(Tex.whitePane, t -> {
t.top().left();
t.setColor(color); t.setColor(color);
t.left(); t.left();
@ -295,7 +304,7 @@ public class JoinDialog extends BaseDialog{
if(host.ping > 0){ if(host.ping > 0){
t.add(Iconc.chartBar + " " + host.ping + "ms").style(Styles.outlineLabel).color(Pal.gray).left(); t.add(Iconc.chartBar + " " + host.ping + "ms").style(Styles.outlineLabel).color(Pal.gray).left();
} }
}).growX().left().bottom(); }).growY().growX().left().bottom();
} }
void setup(){ void setup(){
@ -333,7 +342,7 @@ public class JoinDialog extends BaseDialog{
button.update(() -> button.getStyle().imageUpColor = player.color()); button.update(() -> button.getStyle().imageUpColor = player.color());
}).width(w).height(70f).pad(4); }).width(w).height(70f).pad(4);
cont.row(); cont.row();
cont.add(pane).width(w + 38).pad(0); cont.add(pane).width((w + 5) * columns() + 33).pad(0);
cont.row(); cont.row();
cont.buttonCenter("@server.add", Icon.add, () -> { cont.buttonCenter("@server.add", Icon.add, () -> {
renaming = null; renaming = null;
@ -379,7 +388,7 @@ public class JoinDialog extends BaseDialog{
hosts.row(); hosts.row();
hosts.image().growX().pad(5).padLeft(10).padRight(10).height(3).color(Pal.accent); hosts.image().growX().pad(5).padLeft(10).padRight(10).height(3).color(Pal.accent);
hosts.row(); hosts.row();
hosts.add(coll).width(targetWidth()); hosts.add(coll).width((targetWidth() + 5f) * columns());
hosts.row(); hosts.row();
} }
@ -404,7 +413,7 @@ public class JoinDialog extends BaseDialog{
serverSearch = text.trim().replaceAll(" +", " ").toLowerCase() serverSearch = text.trim().replaceAll(" +", " ").toLowerCase()
).grow().pad(8).get().keyDown(KeyCode.enter, this::refreshCommunity); ).grow().pad(8).get().keyDown(KeyCode.enter, this::refreshCommunity);
t.button(Icon.zoom, Styles.emptyi, this::refreshCommunity).size(54f); t.button(Icon.zoom, Styles.emptyi, this::refreshCommunity).size(54f);
}).width(targetWidth()).height(70f).pad(4).row(); }).width((targetWidth() + 5f) * columns()).height(70f).pad(4).row();
for(int i = 0; i < defaultServers.size; i ++){ for(int i = 0; i < defaultServers.size; i ++){
ServerGroup group = defaultServers.get((i + defaultServers.size/2) % defaultServers.size); ServerGroup group = defaultServers.get((i + defaultServers.size/2) % defaultServers.size);
@ -413,7 +422,7 @@ public class JoinDialog extends BaseDialog{
continue; continue;
} }
Table[] groupTable = {null}; Table[] groupTable = {null, null};
//table containing all groups //table containing all groups
for(String address : group.addresses){ for(String address : group.addresses){
@ -430,7 +439,7 @@ public class JoinDialog extends BaseDialog{
//add header //add header
if(groupTable[0] == null){ if(groupTable[0] == null){
global.table(t -> groupTable[0] = t).row(); global.table(t -> groupTable[0] = t).fillX().left().row();
groupTable[0].table(head -> { groupTable[0].table(head -> {
if(!group.name.isEmpty()){ if(!group.name.isEmpty()){
@ -448,10 +457,12 @@ public class JoinDialog extends BaseDialog{
} }
}).size(40f).get(); }).size(40f).get();
image[0].addListener(new Tooltip(t -> t.background(Styles.black6).margin(4).label(() -> !group.hidden() ? "@server.shown" : "@server.hidden"))); image[0].addListener(new Tooltip(t -> t.background(Styles.black6).margin(4).label(() -> !group.hidden() ? "@server.shown" : "@server.hidden")));
}).width(targetWidth()).padBottom(-2).row(); }).width(targetWidth() * columns()).padBottom(-2).row();
groupTable[1] = groupTable[0].row().table().top().left().grow().get();
} }
addCommunityHost(res, groupTable[0]); addCommunityHost(res, groupTable[1]);
groupTable[0].margin(5f); groupTable[0].margin(5f);
groupTable[0].pack(); groupTable[0].pack();
@ -460,11 +471,16 @@ public class JoinDialog extends BaseDialog{
} }
} }
int columns(){
return Mathf.clamp((int)((Core.graphics.getWidth() * 0.85f) / targetWidth()), 1, 3);
}
void addCommunityHost(Host host, Table container){ void addCommunityHost(Host host, Table container){
global.background(null); global.background(null);
float w = targetWidth(); float w = targetWidth();
//TODO looks bad container.left().top();
container.button(b -> buildServer(host, b), style, () -> { container.button(b -> buildServer(host, b), style, () -> {
Events.fire(new ClientPreConnectEvent(host)); Events.fire(new ClientPreConnectEvent(host));
if(!Core.settings.getBool("server-disclaimer", false)){ if(!Core.settings.getBool("server-disclaimer", false)){
@ -477,7 +493,11 @@ public class JoinDialog extends BaseDialog{
}else{ }else{
safeConnect(host.address, host.port, host.version); safeConnect(host.address, host.port, host.version);
} }
}).width(w).padBottom(7).row(); }).width(w).padBottom(7).padRight(4f).top().left().growY().uniformY();
if((container.getChildren().size) % columns() == 0){
container.row();
}
} }
void finishLocalHosts(){ void finishLocalHosts(){

View File

@ -25,4 +25,4 @@ org.gradle.caching=true
#used for slow jitpack builds; TODO see if this actually works #used for slow jitpack builds; TODO see if this actually works
org.gradle.internal.http.socketTimeout=100000 org.gradle.internal.http.socketTimeout=100000
org.gradle.internal.http.connectionTimeout=100000 org.gradle.internal.http.connectionTimeout=100000
archash=cc9c60d49b archash=d62ba7f6c3

View File

@ -42,6 +42,9 @@ public class ServerControl implements ApplicationListener{
protected static DateTimeFormatter dateTime = DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm:ss"), protected static DateTimeFormatter dateTime = DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm:ss"),
autosaveDate = DateTimeFormatter.ofPattern("MM-dd-yyyy_HH-mm-ss"); autosaveDate = DateTimeFormatter.ofPattern("MM-dd-yyyy_HH-mm-ss");
/** Global instance of ServerControl, initialized when the server is created. Should never be null on a dedicated server. */
public static ServerControl instance;
public final CommandHandler handler = new CommandHandler(""); public final CommandHandler handler = new CommandHandler("");
public final Fi logFolder = Core.settings.getDataDirectory().child("logs/"); public final Fi logFolder = Core.settings.getDataDirectory().child("logs/");
@ -68,6 +71,7 @@ public class ServerControl implements ApplicationListener{
public ServerControl(String[] args){ public ServerControl(String[] args){
setup(args); setup(args);
instance = this;
} }
protected void setup(String[] args){ protected void setup(String[] args){