Implemented basic client/server connection and title font
This commit is contained in:
@@ -15,6 +15,14 @@ public class Network extends Module{
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(GameState.is(State.playing) && Net.active()){
|
||||
if(Net.server()){
|
||||
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(isHosting && GameState.is(State.menu)){
|
||||
Net.closeServer();
|
||||
isHosting = false;
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.mapeditor.MapEditor;
|
||||
import io.anuke.mindustry.mapeditor.MapEditorDialog;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.ui.*;
|
||||
import io.anuke.mindustry.ui.fragments.*;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@@ -43,24 +44,28 @@ import io.anuke.ucore.scene.builders.table;
|
||||
import io.anuke.ucore.scene.event.Touchable;
|
||||
import io.anuke.ucore.scene.ui.*;
|
||||
import io.anuke.ucore.scene.ui.TextField.TextFieldFilter;
|
||||
import io.anuke.ucore.scene.ui.TextField.TextFieldFilter.DigitsOnlyFilter;
|
||||
import io.anuke.ucore.scene.ui.Window.WindowStyle;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
import javax.tools.Tool;
|
||||
import java.io.IOException;
|
||||
|
||||
public class UI extends SceneModule{
|
||||
Table loadingtable, desctable, configtable;
|
||||
Table loadingtable, configtable;
|
||||
MindustrySettingsDialog prefs;
|
||||
MindustryKeybindDialog keys;
|
||||
MapEditorDialog editorDialog;
|
||||
Dialog about, restart, levels, upgrades, load, settingserror, gameerror, discord;
|
||||
Dialog about, restart, levels, upgrades, load, settingserror, gameerror, discord, join;
|
||||
MenuDialog menu;
|
||||
Tooltip tooltip;
|
||||
Tile configTile;
|
||||
Array<String> statlist = new Array<>();
|
||||
MapEditor editor;
|
||||
String lastip = "localhost";
|
||||
int lastport = Vars.port;
|
||||
boolean wasPaused = false;
|
||||
|
||||
private Fragment menufrag = new MenuFragment(),
|
||||
@@ -68,9 +73,6 @@ public class UI extends SceneModule{
|
||||
hudfrag = new HudFragment(),
|
||||
placefrag = new PlacementFragment(),
|
||||
weaponfrag = new WeaponFragment();
|
||||
|
||||
VisibilityProvider play = () -> !GameState.is(State.menu);
|
||||
VisibilityProvider nplay = () -> GameState.is(State.menu);
|
||||
|
||||
public UI() {
|
||||
Dialog.setShowAction(()-> sequence(
|
||||
@@ -156,7 +158,7 @@ public class UI extends SceneModule{
|
||||
public void update(){
|
||||
if(Vars.debug && !Vars.showUI) return;
|
||||
|
||||
if(nplay.visible()){
|
||||
if(GameState.is(State.menu)){
|
||||
scene.getBatch().getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
scene.getBatch().begin();
|
||||
|
||||
@@ -187,13 +189,32 @@ public class UI extends SceneModule{
|
||||
editor = new MapEditor();
|
||||
editorDialog = new MapEditorDialog(editor);
|
||||
}
|
||||
|
||||
join = new FloatingDialog("$text.joingame.title");
|
||||
join.content().add("$text.joingame.ip").left();
|
||||
join.content().addField("localhost", text -> lastip = text).size(180f, 54f);
|
||||
join.content().row();
|
||||
join.content().add("$text.server.port").left();
|
||||
join.content().addField(Vars.port + "", new DigitsOnlyFilter(), text -> lastport = Strings.parseInt(text)).size(180f, 54f);
|
||||
join.buttons().defaults().size(140f, 60f).pad(4f);
|
||||
join.buttons().addButton("$text.cancel", join::hide);
|
||||
join.buttons().addButton("$text.ok", () -> {
|
||||
showLoading("$text.connecting");
|
||||
|
||||
Timers.runTask(2f, () -> {
|
||||
try{
|
||||
Net.connect(lastip, lastport);
|
||||
}catch (IOException e) {
|
||||
showError(Bundles.format("text.connectfail", Strings.parseException(e, false)));
|
||||
hideLoading();
|
||||
}
|
||||
});
|
||||
}).disabled(b -> lastip.isEmpty() || lastport == Integer.MIN_VALUE);
|
||||
|
||||
settingserror = new Dialog("Warning", "dialog");
|
||||
settingserror.content().add("[crimson]Failed to access local storage.\nSettings will not be saved.");
|
||||
settingserror.content().margin(10f);
|
||||
settingserror.getButtonTable().addButton("OK", ()->{
|
||||
settingserror.hide();
|
||||
}).size(80f, 55f).pad(4);
|
||||
settingserror.getButtonTable().addButton("OK", settingserror::hide).size(80f, 55f).pad(4);
|
||||
|
||||
gameerror = new Dialog("$text.error.crashtitle", "dialog");
|
||||
gameerror.content().labelWrap("$text.error.crashmessage").width(600f).pad(10f);
|
||||
@@ -326,14 +347,6 @@ public class UI extends SceneModule{
|
||||
|
||||
}
|
||||
|
||||
void invalidateAll(){
|
||||
for(Element e : scene.getElements()){
|
||||
if(e instanceof Table){
|
||||
((Table)e).invalidateHierarchy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void showGameError(){
|
||||
gameerror.show();
|
||||
}
|
||||
@@ -437,6 +450,10 @@ public class UI extends SceneModule{
|
||||
public void showLoadGame(){
|
||||
load.show();
|
||||
}
|
||||
|
||||
public void showJoinGame(){
|
||||
join.show();
|
||||
}
|
||||
|
||||
public void showMenu(){
|
||||
menu.show();
|
||||
|
||||
@@ -19,13 +19,15 @@ public class Net{
|
||||
/**Connect to an address.*/
|
||||
public static void connect(String ip, int port) throws IOException{
|
||||
clientProvider.connect(ip, port);
|
||||
active = true;
|
||||
server = false;
|
||||
}
|
||||
|
||||
/**Host a server at an address*/
|
||||
public static void host(int port) throws IOException{
|
||||
serverProvider.host(port);
|
||||
active = true;
|
||||
server = true;
|
||||
serverProvider.host(port);
|
||||
}
|
||||
|
||||
/**Closes the server.*/
|
||||
@@ -34,6 +36,12 @@ public class Net{
|
||||
server = false;
|
||||
active = false;
|
||||
}
|
||||
|
||||
public static void disconnect(){
|
||||
clientProvider.disconnect();
|
||||
server = false;
|
||||
active = false;
|
||||
}
|
||||
|
||||
/**Send an object to all connected clients, or to the server if this is a client.*/
|
||||
public static void send(Object object, SendMode mode){
|
||||
@@ -108,6 +116,8 @@ public class Net{
|
||||
public void updatePing();
|
||||
/**Get ping in milliseconds. Will only be valid after a call to updatePing.*/
|
||||
public int getPing();
|
||||
/**Disconnect from the server.*/
|
||||
public void disconnect();
|
||||
/**Register classes to be sent.*/
|
||||
public void register(Class<?>... types);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Colors;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Scaling;
|
||||
|
||||
@@ -9,13 +11,9 @@ import io.anuke.ucore.scene.ui.Image;
|
||||
|
||||
public class MenuButton extends Button{
|
||||
|
||||
public MenuButton(String icon, PressGroup group, Listenable clicked){
|
||||
public MenuButton(String text, PressGroup group, Listenable clicked){
|
||||
super("menu");
|
||||
Image image = new Image(icon);
|
||||
image.setScaling(Scaling.fit);
|
||||
image.setScale(4f);
|
||||
image.setOrigin(Align.center);
|
||||
add(image);
|
||||
add(text, "title", 4);
|
||||
clicked(clicked);
|
||||
group.add(this);
|
||||
}
|
||||
|
||||
@@ -79,15 +79,10 @@ public class MenuDialog extends FloatingDialog{
|
||||
content().row();
|
||||
|
||||
content().addButton("$text.quit", () -> {
|
||||
new ConfirmDialog("$text.confirm", "$text.quit.confirm", () -> {
|
||||
Vars.ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
|
||||
hide();
|
||||
GameState.set(State.menu);
|
||||
}){
|
||||
{
|
||||
for(Cell<?> cell : getButtonTable().getCells())
|
||||
cell.pad(3).size(180, 44);
|
||||
}
|
||||
}.show();
|
||||
});
|
||||
});
|
||||
|
||||
}else{
|
||||
@@ -111,13 +106,10 @@ public class MenuDialog extends FloatingDialog{
|
||||
new imagebutton("icon-load", isize, () -> load.show()).text("$text.load").padTop(4f);
|
||||
|
||||
new imagebutton("icon-quit", isize, () -> {
|
||||
new ConfirmDialog("$text.confirm", "$text.quit.confirm", () -> {
|
||||
Vars.ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
|
||||
hide();
|
||||
GameState.set(State.menu);
|
||||
}){{
|
||||
for(Cell<?> cell : getButtonTable().getCells())
|
||||
cell.pad(3).size(180, 44);
|
||||
}}.show();
|
||||
});
|
||||
}).text("Quit").padTop(4f);
|
||||
|
||||
for(Element e : content().getChildren()){
|
||||
|
||||
@@ -25,25 +25,30 @@ public class MenuFragment implements Fragment{
|
||||
float scale = 4f;
|
||||
defaults().size(100*scale, 21*scale).pad(-10f);
|
||||
|
||||
add(new MenuButton("text-play", group, ui::showLevels));
|
||||
add(new MenuButton("$text.play", group, ui::showLevels));
|
||||
row();
|
||||
|
||||
add(new MenuButton("text-tutorial", group, ()-> control.playMap(world.maps().getMap("tutorial"))));
|
||||
row();
|
||||
|
||||
|
||||
if(!gwt){
|
||||
add(new MenuButton("text-load", group, ui::showLoadGame));
|
||||
row();
|
||||
|
||||
add(new MenuButton("text-editor", group, ui::showEditor));
|
||||
add(new MenuButton("$text.joingame", group, ui::showJoinGame));
|
||||
row();
|
||||
}
|
||||
|
||||
add(new MenuButton("text-settings", group, ui::showPrefs));
|
||||
add(new MenuButton("$text.tutorial", group, ()-> control.playMap(world.maps().getMap("tutorial"))));
|
||||
row();
|
||||
|
||||
if(!gwt){
|
||||
add(new MenuButton("text-exit", group, Gdx.app::exit));
|
||||
add(new MenuButton("$text.loadgame", group, ui::showLoadGame));
|
||||
row();
|
||||
|
||||
add(new MenuButton("$text.editor", group, ui::showEditor));
|
||||
row();
|
||||
}
|
||||
|
||||
add(new MenuButton("$text.settings", group, ui::showPrefs));
|
||||
row();
|
||||
|
||||
if(!gwt){
|
||||
add(new MenuButton("$text.quit", group, Gdx.app::exit));
|
||||
}
|
||||
get().margin(16);
|
||||
}}.end();
|
||||
|
||||
Reference in New Issue
Block a user