Implemented basic client/server connection and title font
|
Before Width: | Height: | Size: 442 B |
|
Before Width: | Height: | Size: 322 B |
|
Before Width: | Height: | Size: 286 B |
|
Before Width: | Height: | Size: 436 B |
|
Before Width: | Height: | Size: 326 B |
|
Before Width: | Height: | Size: 367 B |
|
Before Width: | Height: | Size: 386 B |
@@ -10,8 +10,13 @@ text.level.select=Level Select
|
||||
text.level.mode=Gamemode:
|
||||
text.savegame=Save Game
|
||||
text.loadgame=Load Game
|
||||
text.joingame=Join Game
|
||||
text.quit=Quit
|
||||
text.hostserver=Host Server
|
||||
text.joingame.title=Join Game
|
||||
text.joingame.ip=IP:
|
||||
text.connecting=[accent]Connecting...
|
||||
text.connectfail=[crimson]Failed to connect to server: [orange]{0}
|
||||
text.server.port=Port:
|
||||
text.server.invalidport=Invalid port number!
|
||||
text.server.error=[crimson]Error hosting server: [orange]{0}
|
||||
|
||||
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 79 KiB |
|
Before Width: | Height: | Size: 1.0 KiB |
57
core/assets/ui/title.fnt
Normal file
@@ -0,0 +1,57 @@
|
||||
info face="Title" size=16 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=0,0
|
||||
common lineHeight=14 base=0 scaleW=512 scaleH=512 pages=1 packed=0
|
||||
page id=0 file="title.png"
|
||||
chars count=53
|
||||
char id=32 x=0 y=0 width=0 height=0 xoffset=0 yoffset=0 xadvance=3 page=0 chnl=0
|
||||
char id=97 x=1 y=0 width=9 height=12 xoffset=0 yoffset=-12 xadvance=8 page=0 chnl=0
|
||||
char id=65 x=1 y=0 width=9 height=12 xoffset=0 yoffset=-12 xadvance=8 page=0 chnl=0
|
||||
char id=98 x=14 y=0 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=66 x=14 y=0 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=99 x=26 y=0 width=7 height=12 xoffset=0 yoffset=-12 xadvance=6 page=0 chnl=0
|
||||
char id=67 x=26 y=0 width=7 height=12 xoffset=0 yoffset=-12 xadvance=6 page=0 chnl=0
|
||||
char id=100 x=39 y=0 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=68 x=39 y=0 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=101 x=50 y=0 width=7 height=12 xoffset=0 yoffset=-12 xadvance=6 page=0 chnl=0
|
||||
char id=69 x=50 y=0 width=7 height=12 xoffset=0 yoffset=-12 xadvance=6 page=0 chnl=0
|
||||
char id=102 x=63 y=0 width=7 height=12 xoffset=0 yoffset=-12 xadvance=6 page=0 chnl=0
|
||||
char id=70 x=63 y=0 width=7 height=12 xoffset=0 yoffset=-12 xadvance=6 page=0 chnl=0
|
||||
char id=103 x=74 y=0 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=71 x=74 y=0 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=104 x=86 y=0 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=72 x=86 y=0 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=105 x=100 y=0 width=4 height=12 xoffset=0 yoffset=-12 xadvance=3 page=0 chnl=0
|
||||
char id=73 x=100 y=0 width=4 height=12 xoffset=0 yoffset=-12 xadvance=3 page=0 chnl=0
|
||||
char id=106 x=2 y=12 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=74 x=2 y=12 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=107 x=14 y=12 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=75 x=14 y=12 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=108 x=28 y=12 width=7 height=12 xoffset=0 yoffset=-12 xadvance=6 page=0 chnl=0
|
||||
char id=76 x=28 y=12 width=7 height=12 xoffset=0 yoffset=-12 xadvance=6 page=0 chnl=0
|
||||
char id=109 x=38 y=12 width=10 height=12 xoffset=0 yoffset=-12 xadvance=9 page=0 chnl=0
|
||||
char id=77 x=38 y=12 width=10 height=12 xoffset=0 yoffset=-12 xadvance=9 page=0 chnl=0
|
||||
char id=110 x=50 y=12 width=9 height=12 xoffset=0 yoffset=-12 xadvance=8 page=0 chnl=0
|
||||
char id=78 x=50 y=12 width=9 height=12 xoffset=0 yoffset=-12 xadvance=8 page=0 chnl=0
|
||||
char id=111 x=63 y=12 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=79 x=63 y=12 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=112 x=75 y=12 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=80 x=75 y=12 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=113 x=87 y=12 width=9 height=12 xoffset=0 yoffset=-12 xadvance=8 page=0 chnl=0
|
||||
char id=81 x=87 y=12 width=9 height=12 xoffset=0 yoffset=-12 xadvance=8 page=0 chnl=0
|
||||
char id=114 x=99 y=12 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=82 x=99 y=12 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=115 x=2 y=24 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=83 x=2 y=24 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=116 x=14 y=24 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=84 x=14 y=24 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=117 x=26 y=24 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=85 x=26 y=24 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=118 x=37 y=24 width=9 height=12 xoffset=0 yoffset=-12 xadvance=8 page=0 chnl=0
|
||||
char id=86 x=37 y=24 width=9 height=12 xoffset=0 yoffset=-12 xadvance=8 page=0 chnl=0
|
||||
char id=119 x=50 y=24 width=10 height=12 xoffset=0 yoffset=-12 xadvance=9 page=0 chnl=0
|
||||
char id=87 x=50 y=24 width=10 height=12 xoffset=0 yoffset=-12 xadvance=9 page=0 chnl=0
|
||||
char id=120 x=62 y=24 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=88 x=62 y=24 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=121 x=75 y=24 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=89 x=75 y=24 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=122 x=86 y=24 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
char id=90 x=86 y=24 width=8 height=12 xoffset=0 yoffset=-12 xadvance=7 page=0 chnl=0
|
||||
BIN
core/assets/ui/title.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
@@ -4,6 +4,11 @@ com.badlogic.gdx.graphics.g2d.BitmapFont: {
|
||||
file: square.fnt,
|
||||
markupEnabled: true,
|
||||
scale: 0.5
|
||||
},
|
||||
title: {
|
||||
file: title.fnt,
|
||||
markupEnabled: true,
|
||||
scale: 2
|
||||
}
|
||||
},
|
||||
com.badlogic.gdx.graphics.Color: {
|
||||
@@ -75,6 +80,7 @@ io.anuke.ucore.scene.ui.Slider$SliderStyle: {
|
||||
},
|
||||
io.anuke.ucore.scene.ui.Label$LabelStyle: {
|
||||
default: {font: default-font, fontColor: white },
|
||||
title: {font: title, fontColor: white },
|
||||
link-label: {fontColor: link-label, font: default-font },
|
||||
small: {font: default-font, fontColor: white },
|
||||
menuitem-shortcut: {font: default-font, fontColor: menuitem }
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -12,10 +12,7 @@ import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import com.esotericsoftware.kryonet.Client;
|
||||
import com.esotericsoftware.kryonet.Connection;
|
||||
import com.esotericsoftware.kryonet.Listener;
|
||||
import com.esotericsoftware.kryonet.Server;
|
||||
import com.esotericsoftware.kryonet.*;
|
||||
import io.anuke.mindustry.Mindustry;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.Net.ClientProvider;
|
||||
@@ -91,6 +88,7 @@ public class DesktopLauncher {
|
||||
|
||||
@Override
|
||||
public void received (Connection connection, Object object) {
|
||||
if(object instanceof FrameworkMessage) return;
|
||||
Net.handleClientReceived(object);
|
||||
}
|
||||
});
|
||||
@@ -101,6 +99,11 @@ public class DesktopLauncher {
|
||||
client.connect(5000, ip, port, port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
client.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object object, SendMode mode) {
|
||||
if(mode == SendMode.tcp){
|
||||
@@ -155,6 +158,7 @@ public class DesktopLauncher {
|
||||
|
||||
@Override
|
||||
public void received (Connection connection, Object object) {
|
||||
if(object instanceof FrameworkMessage) return;
|
||||
Net.handleServerReceived(object);
|
||||
}
|
||||
});
|
||||
|
||||