Merge branch 'master' of https://github.com/Anuken/Mindustry into 4.0

This commit is contained in:
Anuken
2018-04-28 16:28:58 -04:00
114 changed files with 509 additions and 129 deletions

View File

@@ -27,9 +27,12 @@ import java.util.Locale;
public class Vars{
public static final boolean testAndroid = false;
public static final boolean testMobile = false;
//shorthand for whether or not this is running on android
public static final boolean android = (Gdx.app.getType() == ApplicationType.Android) || testAndroid;
public static final boolean mobile = (Gdx.app.getType() == ApplicationType.Android) ||
Gdx.app.getType() == ApplicationType.iOS || testMobile;
public static final boolean ios = Gdx.app.getType() == ApplicationType.iOS;
public static final boolean android = Gdx.app.getType() == ApplicationType.Android;
//shorthand for whether or not this is running on GWT
public static final boolean gwt = (Gdx.app.getType() == ApplicationType.WebGL);
//whether to send block state change events to players
@@ -39,7 +42,7 @@ public class Vars{
//respawn time in frames
public static final float respawnduration = 60*4;
//time between waves in frames (on normal mode)
public static final float wavespace = 60*60*(android ? 1 : 1);
public static final float wavespace = 60*60*(mobile ? 1 : 1);
//waves can last no longer than 3 minutes, otherwise the next one spawns
public static final float maxwavespace = 60*60*4f;
//advance time the pathfinding starts at

View File

@@ -60,7 +60,7 @@ public class Control extends Module{
Gdx.input.setCatchBackKey(true);
if(android){
if(mobile){
input = new AndroidInput();
}else{
input = new DesktopInput();
@@ -98,19 +98,21 @@ public class Control extends Module{
item.init();
}
Sounds.load("shoot.ogg", "place.ogg", "explosion.ogg", "enemyshoot.ogg",
"corexplode.ogg", "break.ogg", "spawn.ogg", "flame.ogg", "die.ogg",
"respawn.ogg", "purchase.ogg", "flame2.ogg", "bigshot.ogg", "laser.ogg", "lasershot.ogg",
"ping.ogg", "tesla.ogg", "waveend.ogg", "railgun.ogg", "blast.ogg", "bang2.ogg");
Sounds.load("shoot.mp3", "place.mp3", "explosion.mp3", "enemyshoot.mp3",
"corexplode.mp3", "break.mp3", "spawn.mp3", "flame.mp3", "die.mp3",
"respawn.mp3", "purchase.mp3", "flame2.mp3", "bigshot.mp3", "laser.mp3", "lasershot.mp3",
"ping.mp3", "tesla.mp3", "waveend.mp3", "railgun.mp3", "blast.mp3", "bang2.mp3");
Sounds.setFalloff(9000f);
Musics.load("1.mp3", "2.mp3", "3.mp3", "4.mp3", "5.mp3", "6.mp3");
DefaultKeybinds.load();
Settings.defaultList(
"ip", "localhost",
"port", port+"",
"name", android || gwt ? "player" : UCore.getProperty("user.name"),
"name", mobile || gwt ? "player" : UCore.getProperty("user.name"),
"servers", "",
"color", Color.rgba8888(playerColors[8]),
"lastVersion", "3.2",
@@ -121,7 +123,7 @@ public class Control extends Module{
player = new Player();
player.name = Settings.getString("name");
player.mech = android ? Mechs.standardShip : Mechs.standard;
player.mech = mobile ? Mechs.standardShip : Mechs.standard;
player.color.set(Settings.getInt("color"));
player.isLocal = true;

View File

@@ -68,7 +68,7 @@ public class NetClient extends Module {
ConnectPacket c = new ConnectPacket();
c.name = player.name;
c.android = android;
c.android = mobile;
c.color = Color.rgba8888(player.color);
c.uuid = Platform.instance.getUUID();

View File

@@ -170,7 +170,7 @@ public class NetServer extends Module{
if(!Timers.get("fastshoot-" + id + "-" + weapon.id, wtrc)){
info.fastShots.getAndIncrement(weapon.id, 0, 1);
if(info.fastShots.get(weapon.id, 0) > (int)(wtrc / (weapon.getReload() / 2f)) + 6){
if(info.fastShots.get(weapon.id, 0) > (int)(wtrc / (weapon.getReload() / 2f)) + 8){
kick(id, KickReason.kick);
}
}else{

View File

@@ -173,7 +173,7 @@ public class Renderer extends RendererModule{
float deltax = camera.position.x - prex, deltay = camera.position.y - prey;
if(android){
if(mobile){
player.x += camera.position.x - prevx;
player.y += camera.position.y - prevy;
}
@@ -405,7 +405,7 @@ public class Renderer extends RendererModule{
int tilex = control.input().getBlockX();
int tiley = control.input().getBlockY();
if(android){
if(mobile){
Vector2 vec = Graphics.world(Gdx.input.getX(0), Gdx.input.getY(0));
tilex = Mathf.scl2(vec.x, tilesize);
tiley = Mathf.scl2(vec.y, tilesize);
@@ -414,7 +414,7 @@ public class Renderer extends RendererModule{
InputHandler input = control.input();
//draw placement box
if((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) && (!ui.hasMouse() || android)
if((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) && (!ui.hasMouse() || mobile)
&& control.input().drawPlace())){
input.placeMode.draw(control.input().getBlockX(), control.input().getBlockY(),
@@ -425,7 +425,7 @@ public class Renderer extends RendererModule{
}else if(input.breakMode.delete && control.input().drawPlace()
&& (input.recipe == null || !state.inventory.hasItems(input.recipe.requirements))
&& (input.placeMode.delete || input.breakMode.both || !android)){
&& (input.placeMode.delete || input.breakMode.both || !mobile)){
if(input.breakMode == PlaceMode.holdDelete)
input.breakMode.draw(tilex, tiley, 0, 0);

View File

@@ -166,7 +166,7 @@ public class MapEditorDialog extends Dialog{
openImage.show();
menu.hide();
});
/*
loadDialog = new MapLoadDialog(map -> {
@@ -365,13 +365,13 @@ public class MapEditorDialog extends Dialog{
}}.left().growY().end();
new table("button"){{
margin(5);
marginBottom(10);
add(view).grow();
}}.grow().end();
new table(){{
row();
@@ -413,7 +413,7 @@ public class MapEditorDialog extends Dialog{
}
}
}
private void addBlockSelection(Table table){
Table content = new Table();
pane = new ScrollPane(content, "volume");

View File

@@ -28,7 +28,7 @@ public class BlockRenderer{
private int iterateidx = 0;
private float storeX, storeY;
public BlockRenderer(){
floorRenderer = new FloorRenderer();
@@ -59,7 +59,7 @@ public class BlockRenderer{
int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2)+2;
int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2)+2;
int expandr = 4;
Graphics.surface(renderer.shadowSurface);

View File

@@ -25,8 +25,8 @@ public abstract class InputHandler extends InputAdapter{
public float breaktime = 0;
public Recipe recipe;
public int rotation;
public PlaceMode placeMode = android ? PlaceMode.cursor : PlaceMode.hold;
public PlaceMode breakMode = android ? PlaceMode.none : PlaceMode.holdDelete;
public PlaceMode placeMode = mobile ? PlaceMode.cursor : PlaceMode.hold;
public PlaceMode breakMode = mobile ? PlaceMode.none : PlaceMode.holdDelete;
public PlaceMode lastPlaceMode = placeMode;
public PlaceMode lastBreakMode = breakMode;
public boolean droppingItem, transferring;

View File

@@ -28,8 +28,8 @@ public enum PlaceMode{
float x = tilex * tilesize;
float y = tiley * tilesize;
boolean valid = control.input().validPlace(tilex, tiley, control.input().recipe.result) && (android || control.input().cursorNear());
boolean valid = control.input().validPlace(tilex, tiley, control.input().recipe.result) && (mobile || control.input().cursorNear());
Vector2 offset = control.input().recipe.result.getPlaceOffset();
float si = MathUtils.sin(Timers.time() / 6f) + 1.5f;
@@ -89,7 +89,7 @@ public enum PlaceMode{
tile = tile.getLinked();
float fin = control.input().breaktime / tile.getBreakTime();
if(android && control.input().breaktime > 0){
if(mobile && control.input().breaktime > 0){
Draw.color(Colors.get("breakStart"), Colors.get("break"), fin);
Lines.poly(tile.drawx(), tile.drawy(), 25, 4 + (1f - fin) * 26);
}
@@ -169,8 +169,8 @@ public enum PlaceMode{
process(tilex, tiley, endx, endy);
tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy;
if(android){
if(mobile){
ToolFragment t = ui.toolfrag;
if(!t.confirming || t.px != tilex || t.py != tiley || t.px2 != endx || t.py2 != endy) {
t.confirming = true;
@@ -236,7 +236,7 @@ public enum PlaceMode{
}
public void draw(int tilex, int tiley, int endx, int endy){
if(android && !Gdx.input.isTouched(0) && !control.showCursor()){
if(mobile && !Gdx.input.isTouched(0) && !control.showCursor()){
return;
}
@@ -300,8 +300,8 @@ public enum PlaceMode{
Lines.stroke(2f);
Draw.color("placeInvalid");
Lines.crect(
px * t + (isX ? 0 : offset.x) + (ex < tx && isX ? t : 0) - (block.size == 3 && ex > tx && isX ? t : 0),
py * t + (isX ? offset.y : 0) + (ey < ty && !isX ? t : 0) - (block.size == 3 && ey > ty && !isX ? t : 0),
px * t + (isX ? 0 : offset.x) + (ex < tx && isX && block.size > 1 ? t : 0) - (block.size == 3 && ex > tx && isX ? t : 0),
py * t + (isX ? offset.y : 0) + (ey < ty && !isX && block.size > 1 ? t : 0) - (block.size == 3 && ey > ty && !isX ? t : 0),
t*(isX ? 1 : block.size),
t*(isX ? block.size : 1));
Draw.color("place");

View File

@@ -1,12 +1,15 @@
package io.anuke.mindustry.io;
import com.badlogic.gdx.utils.Base64Coder;
import io.anuke.mindustry.core.ThreadHandler.ThreadProvider;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.scene.ui.TextField;
import java.util.Date;
import java.util.Locale;
import java.util.Random;
public abstract class Platform {
public static Platform instance = new Platform() {};
@@ -31,7 +34,18 @@ public abstract class Platform {
}
public boolean isDebug(){return false;}
/**Must be 8 bytes in length.*/
public byte[] getUUID(){return null;}
public byte[] getUUID(){
String uuid = Settings.getString("uuid", "");
if(uuid.isEmpty()){
byte[] result = new byte[8];
new Random().nextBytes(result);
uuid = new String(Base64Coder.encode(result));
Settings.putString("uuid", uuid);
Settings.save();
return result;
}
return Base64Coder.decode(uuid);
}
public ThreadProvider getThreadProvider(){
return new ThreadProvider() {
@Override public boolean isOnThread() {return true;}

View File

@@ -44,6 +44,11 @@ public class ChangelogDialog extends FloatingDialog{
table.row();
table.add("$text.changelog.error.android").padTop(8);
}
if(Vars.ios){
table.row();
table.add("$text.changelog.error.ios").padTop(8);
}
}else{
for(VersionInfo info : versions){
Table in = new Table("clear");

View File

@@ -35,7 +35,7 @@ public class PausedDialog extends FloatingDialog{
if(!Net.active()) state.set(State.paused);
});
if(!android){
if(!mobile){
content().defaults().width(220).height(50);
content().addButton("$text.back", () -> {

View File

@@ -84,7 +84,7 @@ public class SettingsMenuDialog extends SettingsDialog{
menu.addButton("$text.settings.graphics", () -> visible(1));
menu.row();
menu.addButton("$text.settings.sound", () -> visible(2));
if(!Vars.android) {
if(!Vars.mobile) {
menu.row();
menu.addButton("$text.settings.controls", ui.controls::show);
}
@@ -142,7 +142,7 @@ public class SettingsMenuDialog extends SettingsDialog{
}
}
if(!android && !gwt) {
if(!mobile && !gwt) {
graphics.checkPref("vsync", true, b -> Gdx.graphics.setVSync(b));
graphics.checkPref("fullscreen", false, b -> {
if (b) {

View File

@@ -39,7 +39,7 @@ public class BlocksFragment implements Fragment{
private boolean shown = true;
private Recipe hoveredDescriptionRecipe;
private IntSet itemset = new IntSet();
public void build(){
InputHandler input = control.input();

View File

@@ -107,12 +107,12 @@ public class ChatFragment extends Table implements Fragment{
add(chatfield).padBottom(offsety).padLeft(offsetx).growX().padRight(offsetx).height(28);
if(Vars.android) {
if(Vars.mobile) {
marginBottom(105f);
marginRight(240f);
}
if(Vars.android) {
if(Vars.mobile) {
addImageButton("icon-arrow-right", 14 * 2, this::toggle).size(46f, 51f).visible(() -> chatOpen).pad(2f);
}
}

View File

@@ -71,14 +71,14 @@ public class HudFragment implements Fragment{
}).get();
new imagebutton("icon-pause", isize, () -> {
if(android) DebugFragment.printDebugInfo();
if (Net.active() && android) {
if(mobile) DebugFragment.printDebugInfo();
if (Net.active() && mobile) {
ui.listfrag.visible = !ui.listfrag.visible;
} else {
state.set(state.is(State.paused) ? State.playing : State.paused);
}
}).update(i -> {
if (Net.active() && android) {
if (Net.active() && mobile) {
i.getStyle().imageUp = Core.skin.getDrawable("icon-players");
} else {
i.setDisabled(Net.active());
@@ -87,7 +87,7 @@ public class HudFragment implements Fragment{
}).get();
new imagebutton("icon-settings", isize, () -> {
if (Net.active() && android) {
if (Net.active() && mobile) {
if (ui.chatfrag.chatOpen()) {
ui.chatfrag.hide();
} else {
@@ -97,7 +97,7 @@ public class HudFragment implements Fragment{
ui.settings.show();
}
}).update(i -> {
if (Net.active() && android) {
if (Net.active() && mobile) {
i.getStyle().imageUp = Core.skin.getDrawable("icon-chat");
} else {
i.getStyle().imageUp = Core.skin.getDrawable("icon-settings");

View File

@@ -18,7 +18,7 @@ public class MenuFragment implements Fragment{
new table(){{
visible(() -> state.is(State.menu));
if(!android){
if(!mobile){
new table(){{
float w = 200f;

View File

@@ -29,7 +29,7 @@ public class PlacementFragment implements Fragment{
Label modelabel;
public void build(){
if(!android) return;
if(!mobile) return;
InputHandler input = control.input();

View File

@@ -63,7 +63,7 @@ public class PlayerListFragment implements Fragment{
}}.end();
update(t -> {
if(!android){
if(!mobile){
visible = Inputs.keyDown("player_list");
}
if(!(Net.active() && !state.is(State.menu))){

View File

@@ -11,8 +11,6 @@ import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.scene.ui.layout.Table;
import static io.anuke.mindustry.Vars.*;
public class ToolFragment implements Fragment{
private Table tools;
public int px, py, px2, py2;
@@ -50,7 +48,7 @@ public class ToolFragment implements Fragment{
Core.scene.add(tools);
tools.setVisible(() ->
!state.is(State.menu) && android && ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) &&
!state.is(State.menu) && mobile && ((input.recipe != null && state.inventory.hasItems(input.recipe.requirements) &&
input.placeMode == PlaceMode.cursor) || confirming)
);

View File

@@ -48,7 +48,7 @@ public class WeaponFactory extends Block{
@Override
public boolean isConfigurable(Tile tile){
return !Vars.android;
return !Vars.mobile;
}
@Override