mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-10 23:28:52 +07:00
Beginning work on grouped servers
This commit is contained in:
parent
acb14a0986
commit
548dc79fb0
Binary file not shown.
@ -67,7 +67,7 @@ public class Vars implements Loadable{
|
||||
/** 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";
|
||||
/** 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 */
|
||||
public static final float mineTransferRange = 220f;
|
||||
/** max chat message length */
|
||||
|
@ -1,6 +1,14 @@
|
||||
package mindustry.net;
|
||||
|
||||
public class ServerGroup{
|
||||
public String[] addresses;
|
||||
public String name;
|
||||
public String[] addresses;
|
||||
|
||||
public ServerGroup(String name, String[] addresses){
|
||||
this.name = name;
|
||||
this.addresses = addresses;
|
||||
}
|
||||
|
||||
public ServerGroup(){
|
||||
}
|
||||
}
|
||||
|
@ -334,17 +334,36 @@ public class JoinDialog extends BaseDialog{
|
||||
|
||||
global.clear();
|
||||
global.background(null);
|
||||
for(String host : defaultServers){
|
||||
String resaddress = host.contains(":") ? host.split(":")[0] : host;
|
||||
int resport = host.contains(":") ? Strings.parseInt(host.split(":")[1]) : port;
|
||||
net.pingHost(resaddress, resport, res -> {
|
||||
if(refreshes != cur) return;
|
||||
res.port = resport;
|
||||
addGlobalHost(res);
|
||||
}, e -> {});
|
||||
for(ServerGroup group : defaultServers){
|
||||
//table containing all groups
|
||||
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 -> {
|
||||
if(refreshes != cur) return;
|
||||
res.port = resport;
|
||||
addGlobalHost(res, g);
|
||||
|
||||
g.margin(5f);
|
||||
g.pack();
|
||||
}, 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(){
|
||||
if(totalHosts == 0){
|
||||
local.clear();
|
||||
@ -367,26 +386,10 @@ public class JoinDialog extends BaseDialog{
|
||||
|
||||
local.row();
|
||||
|
||||
TextButton button = local.button("", Styles.cleart, () -> {
|
||||
local.button(b -> buildServer(host, b), Styles.cleart, () -> {
|
||||
Events.fire(new ClientPreConnectEvent(host));
|
||||
safeConnect(host.address, host.port, host.version);
|
||||
}).width(w).pad(5f).get();
|
||||
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);
|
||||
}).width(w);
|
||||
}
|
||||
|
||||
public void connect(String ip, int port){
|
||||
@ -443,7 +446,16 @@ public class JoinDialog extends BaseDialog{
|
||||
Core.app.post(() -> {
|
||||
try{
|
||||
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);
|
||||
}catch(Throwable ignored){
|
||||
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()){
|
||||
TextureFilter filter = b ? TextureFilter.linear : TextureFilter.nearest;
|
||||
tex.setFilter(filter, filter);
|
||||
|
@ -108,7 +108,6 @@ public class MenuFragment extends Fragment{
|
||||
editor = new MobileButton(Icon.terrain, "@editor", () -> checkPlay(ui.maps::show)),
|
||||
tools = new MobileButton(Icon.settings, "@settings", ui.settings::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());
|
||||
|
||||
if(!Core.graphics.isPortrait()){
|
||||
@ -195,6 +194,7 @@ public class MenuFragment extends Fragment{
|
||||
}
|
||||
|
||||
private void checkPlay(Runnable run){
|
||||
|
||||
if(!mods.hasContentErrors()){
|
||||
run.run();
|
||||
}else{
|
||||
|
Loading…
Reference in New Issue
Block a user