Re-added host dialog, fixed join dialog UI error

This commit is contained in:
Anuken
2018-01-05 12:46:08 -05:00
parent 7fdd50d85c
commit 32e1c6e3b8
4 changed files with 40 additions and 2 deletions

View File

@ -14,6 +14,7 @@ text.joingame=Join Game
text.quit=Quit
text.about.button=About
text.name=Name:
text.public=Public
text.players={0} players online
text.players.single={0} player online
text.server.kicked.kick=You have been kicked from the server!
@ -23,6 +24,7 @@ text.server.disconnected={0} has disconnected.
text.nohost=Can't host server on a custom map!
text.hostserver=Host Server
text.host=Host
text.hosting=[accent]Opening server...
text.hosts.refresh=Refresh
text.hosts.discovering=Discovering LAN games
text.hosts.none=[lightgray]No games found!

View File

@ -217,7 +217,7 @@ public class Renderer extends RendererModule{
Draw.tscl(0.25f/2);
for(Player player : Vars.control.playerGroup.all()){
if(!player.isLocal){
Draw.text(player.name, player.x, player.y + 6);
Draw.text(player.name, player.x, player.y + 7);
}
}
Draw.tscl(Vars.fontscale);

View File

@ -1,12 +1,46 @@
package io.anuke.mindustry.ui.dialogs;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.ui.Dialog;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Strings;
import java.io.IOException;
//TODO
public class HostDialog extends Dialog{
float w = 300;
public HostDialog(){
super("$text.hostserver", "dialog");
content().table(t -> {
t.add("$text.name").padRight(10);
t.addField(Settings.getString("name"), text -> {
if(text.isEmpty()) return;
Vars.player.name = text;
Settings.put("name", text);
Settings.save();
}).grow().pad(8);
}).width(w).height(70f).pad(4);
content().row();
content().addButton("Host", () -> {
Vars.ui.loadfrag.show("$text.hosting");
Timers.runTask(5f, () -> {
try{
Net.host(Vars.port);
}catch (IOException e){
Vars.ui.showError(Bundles.format("text.server.error", Strings.parseException(e, false)));
}
Vars.ui.loadfrag.hide();
hide();
});
}).width(w).height(70f);
}
/*

View File

@ -45,7 +45,7 @@ public class JoinDialog extends FloatingDialog {
join.buttons().addButton("$text.cancel", join::hide);
join.buttons().addButton("$text.ok", () ->
connect(Settings.getString("ip"), Strings.parseInt(Settings.getString("port")))
).disabled(b -> Settings.getString("ip").isEmpty() || Strings.parseInt(Settings.getString("port")) == Integer.MIN_VALUE);
).disabled(b -> Settings.getString("ip").isEmpty() || Strings.parseInt(Settings.getString("port")) == Integer.MIN_VALUE || Net.active());
setup();
@ -110,6 +110,8 @@ public class JoinDialog extends FloatingDialog {
Timers.runTask(2f, () -> {
try{
Net.connect(ip, port);
hide();
join.hide();
}catch (Exception e) {
Throwable t = e;
while(t.getCause() != null){