Beginning work on grouped servers

This commit is contained in:
Anuken
2020-11-09 12:34:34 -05:00
parent acb14a0986
commit 548dc79fb0
6 changed files with 51 additions and 31 deletions
Binary file not shown.
+1 -1
View File
@@ -67,7 +67,7 @@ public class Vars implements Loadable{
/** URL of the github issue report template.*/ /** URL of the github issue report template.*/
public static final String reportIssueURL = "https://github.com/Anuken/Mindustry/issues/new?labels=bug&template=bug_report.md"; public static final String reportIssueURL = "https://github.com/Anuken/Mindustry/issues/new?labels=bug&template=bug_report.md";
/** list of built-in servers.*/ /** list of built-in servers.*/
public static final Seq<String> defaultServers = Seq.with(); public static final Seq<ServerGroup> defaultServers = Seq.with();
/** maximum distance between mine and core that supports automatic transferring */ /** maximum distance between mine and core that supports automatic transferring */
public static final float mineTransferRange = 220f; public static final float mineTransferRange = 220f;
/** max chat message length */ /** max chat message length */
+9 -1
View File
@@ -1,6 +1,14 @@
package mindustry.net; package mindustry.net;
public class ServerGroup{ public class ServerGroup{
public String[] addresses;
public String name; public String name;
public String[] addresses;
public ServerGroup(String name, String[] addresses){
this.name = name;
this.addresses = addresses;
}
public ServerGroup(){
}
} }
+35 -23
View File
@@ -334,15 +334,34 @@ public class JoinDialog extends BaseDialog{
global.clear(); global.clear();
global.background(null); global.background(null);
for(String host : defaultServers){ for(ServerGroup group : defaultServers){
String resaddress = host.contains(":") ? host.split(":")[0] : host; //table containing all groups
int resport = host.contains(":") ? Strings.parseInt(host.split(":")[1]) : port; global.table(g -> {
//TODO groups
for(String address : group.addresses){
String resaddress = address.contains(":") ? address.split(":")[0] : address;
int resport = address.contains(":") ? Strings.parseInt(address.split(":")[1]) : port;
net.pingHost(resaddress, resport, res -> { net.pingHost(resaddress, resport, res -> {
if(refreshes != cur) return; if(refreshes != cur) return;
res.port = resport; res.port = resport;
addGlobalHost(res); addGlobalHost(res, g);
g.margin(5f);
g.pack();
}, e -> {}); }, e -> {});
} }
}).row();
}
}
void addGlobalHost(Host host, Table container){
global.background(null);
float w = targetWidth();
container.button(b -> buildServer(host, b), Styles.cleart, () -> {
Events.fire(new ClientPreConnectEvent(host));
safeConnect(host.address, host.port, host.version);
}).width(w).row();
} }
void finishLocalHosts(){ void finishLocalHosts(){
@@ -367,26 +386,10 @@ public class JoinDialog extends BaseDialog{
local.row(); local.row();
TextButton button = local.button("", Styles.cleart, () -> { local.button(b -> buildServer(host, b), Styles.cleart, () -> {
Events.fire(new ClientPreConnectEvent(host)); Events.fire(new ClientPreConnectEvent(host));
safeConnect(host.address, host.port, host.version); safeConnect(host.address, host.port, host.version);
}).width(w).pad(5f).get(); }).width(w);
button.clearChildren();
buildServer(host, button);
}
void addGlobalHost(Host host){
global.background(null);
float w = targetWidth();
global.row();
TextButton button = global.button("", Styles.cleart, () -> {
Events.fire(new ClientPreConnectEvent(host));
safeConnect(host.address, host.port, host.version);
}).width(w).pad(5f).get();
button.clearChildren();
buildServer(host, button);
} }
public void connect(String ip, int port){ public void connect(String ip, int port){
@@ -443,7 +446,16 @@ public class JoinDialog extends BaseDialog{
Core.app.post(() -> { Core.app.post(() -> {
try{ try{
defaultServers.clear(); defaultServers.clear();
val.asArray().each(child -> defaultServers.add(child.getString("address", "<invalid>"))); val.asArray().each(child -> {
String name = child.getString("name", "");
String[] addresses;
if(child.has("addresses")){
addresses = child.get("addresses").asArray().map(Jval::asString).toArray(String.class);
}else{
addresses = new String[]{child.getString("addresses", "<invalid>")};
}
defaultServers.add(new ServerGroup(name, addresses));
});
Log.info("Fetched @ global servers.", defaultServers.size); Log.info("Fetched @ global servers.", defaultServers.size);
}catch(Throwable ignored){ }catch(Throwable ignored){
Log.err("Failed to parse community servers."); Log.err("Failed to parse community servers.");
@@ -429,7 +429,7 @@ public class SettingsMenuDialog extends SettingsDialog{
} }
}); });
graphics.checkPref("linear", true, b -> { graphics.checkPref("linear", !mobile, b -> {
for(Texture tex : Core.atlas.getTextures()){ for(Texture tex : Core.atlas.getTextures()){
TextureFilter filter = b ? TextureFilter.linear : TextureFilter.nearest; TextureFilter filter = b ? TextureFilter.linear : TextureFilter.nearest;
tex.setFilter(filter, filter); tex.setFilter(filter, filter);
@@ -108,7 +108,6 @@ public class MenuFragment extends Fragment{
editor = new MobileButton(Icon.terrain, "@editor", () -> checkPlay(ui.maps::show)), editor = new MobileButton(Icon.terrain, "@editor", () -> checkPlay(ui.maps::show)),
tools = new MobileButton(Icon.settings, "@settings", ui.settings::show), tools = new MobileButton(Icon.settings, "@settings", ui.settings::show),
mods = new MobileButton(Icon.book, "@mods", ui.mods::show), mods = new MobileButton(Icon.book, "@mods", ui.mods::show),
donate = new MobileButton(Icon.link, "@website", () -> Core.app.openURI("https://anuke.itch.io/mindustry")),
exit = new MobileButton(Icon.exit, "@quit", () -> Core.app.exit()); exit = new MobileButton(Icon.exit, "@quit", () -> Core.app.exit());
if(!Core.graphics.isPortrait()){ if(!Core.graphics.isPortrait()){
@@ -195,6 +194,7 @@ public class MenuFragment extends Fragment{
} }
private void checkPlay(Runnable run){ private void checkPlay(Runnable run){
if(!mods.hasContentErrors()){ if(!mods.hasContentErrors()){
run.run(); run.run();
}else{ }else{