Merge branch 'master' of https://github.com/Anuken/Mindustry into new-sectors

This commit is contained in:
Anuken
2018-10-30 22:18:07 -04:00
155 changed files with 1581 additions and 2452 deletions

View File

@@ -13,6 +13,7 @@ public class BorderImage extends Image{
private float thickness = 3f;
public BorderImage(){
}
public BorderImage(Texture texture){

View File

@@ -3,6 +3,7 @@ package io.anuke.mindustry.ui;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.function.Supplier;
import io.anuke.ucore.scene.ui.Image;
import io.anuke.ucore.scene.ui.layout.Stack;
@@ -14,7 +15,7 @@ public class ItemImage extends Stack{
public ItemImage(TextureRegion region, Supplier<CharSequence> text){
Table t = new Table().left().bottom();
t.label(text).color(Color.DARK_GRAY).padBottom(-20).get().setFontScale(Unit.dp.scl(0.5f));
t.label(text).color(Color.DARK_GRAY).padBottom(-Core.skin.font().getData().capHeight * 2).get().setFontScale(Unit.dp.scl(0.5f));
t.row();
t.label(text).get().setFontScale(Unit.dp.scl(0.5f));
@@ -25,7 +26,7 @@ public class ItemImage extends Stack{
public ItemImage(ItemStack stack){
Table t = new Table().left().bottom();
t.add(stack.amount + "").color(Color.DARK_GRAY).padBottom(-20).get().setFontScale(Unit.dp.scl(0.5f));
t.add(stack.amount + "").color(Color.DARK_GRAY).padBottom(-Core.skin.font().getData().capHeight * 2).get().setFontScale(Unit.dp.scl(0.5f));
t.row();
t.add(stack.amount + "").get().setFontScale(Unit.dp.scl(0.5f));

View File

@@ -20,8 +20,6 @@ public class AdminsDialog extends FloatingDialog{
private void setup(){
content().clear();
if(gwt) return;
float w = 400f, h = 80f;
Table table = new Table();

View File

@@ -21,8 +21,6 @@ public class BansDialog extends FloatingDialog{
private void setup(){
content().clear();
if(gwt) return;
float w = 400f, h = 80f;
Table table = new Table();

View File

@@ -3,6 +3,7 @@ package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Scaling;
import io.anuke.mindustry.game.Difficulty;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.maps.Map;
@@ -48,7 +49,7 @@ public class CustomGameDialog extends FloatingDialog{
modes.marginBottom(5);
for(GameMode mode : GameMode.values()){
if(mode.hidden || (mode.isPvp && gwt)) continue;
if(mode.hidden) continue;
modes.addButton("$mode." + mode.name() + ".name", "toggle", () -> state.mode = mode)
.update(b -> b.setChecked(state.mode == mode)).group(group).size(140f, 54f).padBottom(-5);
@@ -106,6 +107,7 @@ public class CustomGameDialog extends FloatingDialog{
image.label((() -> Bundles.format("text.level.highscore", Settings.getInt("hiscore" + map.name, 0)))).pad(3f);
BorderImage border = new BorderImage(map.texture, 3f);
border.setScaling(Scaling.fit);
image.replaceImage(border);
image.clicked(() -> {

View File

@@ -21,15 +21,13 @@ import io.anuke.ucore.util.Pooling;
import java.util.Arrays;
import static io.anuke.mindustry.Vars.gwt;
public class FileChooser extends FloatingDialog{
public static Predicate<FileHandle> pngFilter = file -> file.extension().equalsIgnoreCase("png");
public static Predicate<FileHandle> mapFilter = file -> file.extension().equalsIgnoreCase(Vars.mapExtension);
public static Predicate<FileHandle> jpegFilter = file -> file.extension().equalsIgnoreCase("png") || file.extension().equalsIgnoreCase("jpg") || file.extension().equalsIgnoreCase("jpeg");
public static Predicate<FileHandle> defaultFilter = file -> true;
private Table files;
private FileHandle homeDirectory = gwt ? Gdx.files.internal("") : Gdx.files.absolute(OS.isMac ? OS.getProperty("user.home") + "/Downloads/" :
private FileHandle homeDirectory = Gdx.files.absolute(OS.isMac ? OS.getProperty("user.home") + "/Downloads/" :
Gdx.files.getExternalStoragePath());
private FileHandle directory = homeDirectory;
private ScrollPane pane;
@@ -175,7 +173,7 @@ public class FileChooser extends FloatingDialog{
Arrays.sort(handles, (a, b) -> {
if(a.isDirectory() && !b.isDirectory()) return -1;
if(!a.isDirectory() && b.isDirectory()) return 1;
return a.name().toUpperCase().compareTo(b.name().toUpperCase());
return String.CASE_INSENSITIVE_ORDER.compare(a.name(), b.name());
});
return handles;
}

View File

@@ -18,7 +18,6 @@ import io.anuke.ucore.scene.ui.layout.Cell;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.scene.utils.UIUtils;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Strings;
import static io.anuke.mindustry.Vars.*;
@@ -248,16 +247,14 @@ public class JoinDialog extends FloatingDialog{
}
void refreshLocal(){
if(!Vars.gwt){
totalHosts = 0;
totalHosts = 0;
local.clear();
local.background((Drawable)null);
local.table("button", t -> {
t.label(() -> "[accent]" + Bundles.get("text.hosts.discovering") + Strings.animated(4, 10f, ".")).pad(10f);
}).growX();
Net.discoverServers(this::addLocalHost, this::finishLocalHosts);
}
local.clear();
local.background((Drawable)null);
local.table("button", t -> {
t.label(() -> "[accent]" + Bundles.get("text.hosts.discovering") + Strings.animated(4, 10f, ".")).pad(10f);
}).growX();
Net.discoverServers(this::addLocalHost, this::finishLocalHosts);
}
void finishLocalHosts(){
@@ -300,34 +297,11 @@ public class JoinDialog extends FloatingDialog{
});
Timers.runTask(2f, () -> {
try{
Vars.netClient.beginConnecting();
Net.connect(ip, port);
Vars.netClient.beginConnecting();
Net.connect(ip, port, () -> {
hide();
add.hide();
}catch(Exception e){
Throwable t = e;
while(t.getCause() != null){
t = t.getCause();
}
//TODO localize
String error = t.getMessage() == null ? "" : t.getMessage().toLowerCase();
if(error.contains("connection refused")){
error = "connection refused";
}else if(error.contains("port out of range")){
error = "invalid port!";
}else if(error.contains("invalid argument")){
error = "invalid IP or port!";
}else if(t.getClass().toString().toLowerCase().contains("sockettimeout")){
error = "timed out!\nmake sure the host has port forwarding set up,\nand that the address is correct!";
}else{
error = Strings.parseException(e, false);
}
ui.showError(Bundles.format("text.connectfail", error));
ui.loadfrag.hide();
Log.err(e);
}
});
});
}

View File

@@ -1,6 +1,5 @@
package io.anuke.mindustry.ui.dialogs;
import io.anuke.mindustry.core.Platform;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.scene.ui.ButtonGroup;
import io.anuke.ucore.scene.ui.ScrollPane;
@@ -31,7 +30,7 @@ public class LanguageDialog extends FloatingDialog{
ButtonGroup<TextButton> group = new ButtonGroup<>();
for(Locale loc : locales){
TextButton button = new TextButton(Platform.instance.getLocaleName(loc), "toggle");
TextButton button = new TextButton(loc.getDisplayName(loc), "toggle");
button.clicked(() -> {
if(getLocale().equals(loc)) return;
Settings.putString("locale", loc.toString());

View File

@@ -86,28 +86,27 @@ public class LoadDialog extends FloatingDialog{
});
}).size(14 * 3).right();
if(!gwt){
t.addImageButton("icon-save", "empty", 14 * 3, () -> {
if(!ios){
Platform.instance.showFileChooser(Bundles.get("text.save.export"), "Mindustry Save", file -> {
try{
slot.exportFile(file);
setup();
}catch(IOException e){
ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
}
}, false, saveExtension);
}else{
t.addImageButton("icon-save", "empty", 14 * 3, () -> {
if(!ios){
Platform.instance.showFileChooser(Bundles.get("text.save.export"), "Mindustry Save", file -> {
try{
FileHandle file = Gdx.files.local("save-" + slot.getName() + "." + Vars.saveExtension);
slot.exportFile(file);
Platform.instance.shareFile(file);
}catch(Exception e){
setup();
}catch(IOException e){
ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
}
}, false, saveExtension);
}else{
try{
FileHandle file = Gdx.files.local("save-" + slot.getName() + "." + Vars.saveExtension);
slot.exportFile(file);
Platform.instance.shareFile(file);
}catch(Exception e){
ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
}
}).size(14 * 3).right();
}
}
}).size(14 * 3).right();
}).padRight(-10).growX();
@@ -153,7 +152,7 @@ public class LoadDialog extends FloatingDialog{
slots.row();
if(gwt || ios) return;
if(ios) return;
slots.addImageTextButton("$text.save.import", "icon-add", "clear", 14 * 3, () -> {
Platform.instance.showFileChooser(Bundles.get("text.save.import"), "Mindustry Save", file -> {

View File

@@ -93,7 +93,7 @@ public class MapsDialog extends FloatingDialog{
button.row();
button.addImage("white").growX().pad(4).color(Color.GRAY);
button.row();
((Image) button.stack(new Image(map.texture), new BorderImage(map.texture)).size(mapsize - 20f).get().getChildren().first()).setScaling(Scaling.fit);
button.stack(new Image(map.texture).setScaling(Scaling.fit), new BorderImage(map.texture).setScaling(Scaling.fit)).size(mapsize - 20f);
button.row();
button.add(map.custom ? "$text.custom" : "$text.builtin").color(Color.GRAY).padTop(3);
@@ -114,7 +114,7 @@ public class MapsDialog extends FloatingDialog{
float mapsize = UIUtils.portrait() ? 160f : 300f;
Table table = dialog.content();
((Image) table.stack(new Image(map.texture), new BorderImage(map.texture)).size(mapsize).get().getChildren().first()).setScaling(Scaling.fit);
table.stack(new Image(map.texture).setScaling(Scaling.fit), new BorderImage(map.texture).setScaling(Scaling.fit)).size(mapsize);
table.table("clear", desc -> {
desc.top();

View File

@@ -61,25 +61,14 @@ public class PausedDialog extends FloatingDialog{
content().addButton("$text.settings", ui.settings::show);
content().row();
content().addButton("$text.savegame", () -> {
save.show();
}).disabled(s -> world.getSector() != null);
content().addButton("$text.savegame", save::show).disabled(s -> world.getSector() != null);
content().row();
content().addButton("$text.loadgame", () -> {
load.show();
}).disabled(b -> Net.active());
content().addButton("$text.loadgame", load::show).disabled(b -> Net.active());
content().row();
content().addButton("$text.hostserver", () -> {
if(!gwt){
ui.host.show();
}else{
ui.showInfo("$text.web.unsupported");
}
}).disabled(b -> Net.active());
content().addButton("$text.hostserver", ui.host::show).disabled(b -> Net.active());
content().row();

View File

@@ -175,11 +175,8 @@ public class SettingsMenuDialog extends SettingsDialog{
Settings.prefs().put(map);
Settings.save();
if(!gwt){
Settings.prefs().clear();
for(FileHandle file : dataDirectory.list()){
file.deleteDirectory();
}
for(FileHandle file : dataDirectory.list()){
file.deleteDirectory();
}
Gdx.app.exit();
@@ -193,19 +190,15 @@ public class SettingsMenuDialog extends SettingsDialog{
}
});
if(!gwt){
graphics.sliderPref("fpscap", 125, 5, 125, 5, s -> (s > 120 ? Bundles.get("setting.fpscap.none") : Bundles.format("setting.fpscap.text", s)));
graphics.sliderPref("fpscap", 125, 5, 125, 5, s -> (s > 120 ? Bundles.get("setting.fpscap.none") : Bundles.format("setting.fpscap.text", s)));
graphics.checkPref("multithread", mobile, threads::setEnabled);
if(Settings.getBool("multithread")){
threads.setEnabled(true);
}
if(!gwt){
graphics.checkPref("multithread", mobile, threads::setEnabled);
if(Settings.getBool("multithread")){
threads.setEnabled(true);
}
}
if(!mobile && !gwt){
if(!mobile){
graphics.checkPref("vsync", true, b -> Gdx.graphics.setVSync(b));
graphics.checkPref("fullscreen", false, b -> {
if(b){

View File

@@ -1,10 +1,5 @@
package io.anuke.mindustry.ui.dialogs;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.net.TraceInfo;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
public class TraceDialog extends FloatingDialog{
public TraceDialog(){
@@ -12,14 +7,15 @@ public class TraceDialog extends FloatingDialog{
addCloseButton();
}
public void show(Player player, TraceInfo info){
/*
public void show(Player player, SessionInfo info){
content().clear();
Table table = new Table("clear");
table.margin(14);
table.defaults().pad(1);
/*
table.defaults().left();
table.add(Bundles.format("text.trace.playername", player.name));
table.row();
@@ -50,10 +46,10 @@ public class TraceDialog extends FloatingDialog{
table.add(Bundles.format("text.trace.totalblocksplaced", info.totalBlocksPlaced));
table.row();
table.add(Bundles.format("text.trace.lastblockplaced", info.lastBlockPlaced.formalName));
table.row();*/
table.row();
content().add(table);
show();
}
}*/
}

View File

@@ -127,7 +127,7 @@ public class HudFragment extends Fragment{
t.label(() -> tps.get(threads.getTPS())).visible(() -> threads.isEnabled());
t.row();
if(Net.hasClient()){
t.label(() -> ping.get(Net.getPing())).visible(() -> Net.client() && !gwt).colspan(2);
t.label(() -> ping.get(Net.getPing())).visible(Net::client).colspan(2);
}
}).size(-1).visible(() -> Settings.getBool("fps")).update(t -> t.setTranslation(0, (!waves.isVisible() ? wavetable.getHeight() : Math.min(wavetable.getTranslation().y, wavetable.getHeight())) )).get();

View File

@@ -132,9 +132,7 @@ public class MenuFragment extends Fragment{
out.row();
if(!gwt){
out.add(new MenuButton("icon-exit", "$text.quit", Gdx.app::exit)).width(bw).colspan(2);
}
out.add(new MenuButton("icon-exit", "$text.quit", Gdx.app::exit)).width(bw).colspan(2);
});
}
@@ -153,12 +151,8 @@ public class MenuFragment extends Fragment{
dialog.content().row();
dialog.content().add(new MenuButton("icon-add", "$text.joingame", () -> {
if(!gwt){
ui.join.show();
dialog.hide();
}else{
ui.showInfo("$text.web.unsupported");
}
ui.join.show();
dialog.hide();
}));
dialog.content().add(new MenuButton("icon-editor", "$text.customgame", () -> {

View File

@@ -3,14 +3,12 @@ package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Batch;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetConnection;
import io.anuke.mindustry.net.Packets.AdminAction;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.scene.Group;
@@ -73,7 +71,7 @@ public class PlayerListFragment extends Fragment{
float h = 74f;
playerGroup.forEach(player -> {
NetConnection connection = gwt ? null : player.con;
NetConnection connection = player.con;
if(connection == null && Net.server() && !player.isLocal) return;
@@ -119,7 +117,7 @@ public class PlayerListFragment extends Fragment{
t.addImageButton("icon-admin", "toggle", 14 * 2, () -> {
if(Net.client()) return;
String id = netServer.admins.getTraceByID(player.uuid).uuid;
String id = player.uuid;
if(netServer.admins.isAdmin(id, connection.address)){
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> netServer.admins.unAdminPlayer(id));