Updated uCore / Added hidden sector saves

This commit is contained in:
Anuken
2018-07-17 12:47:11 -04:00
parent c2c2551607
commit 71016f0d7c
21 changed files with 166 additions and 77 deletions

View File

@ -27,7 +27,7 @@ allprojects {
gdxVersion = '1.9.8' gdxVersion = '1.9.8'
roboVMVersion = '2.3.0' roboVMVersion = '2.3.0'
aiVersion = '1.8.1' aiVersion = '1.8.1'
uCoreVersion = 'e4eec58b02' uCoreVersion = '3e5e261181'
getVersionString = { getVersionString = {
String buildVersion = getBuildVersion() String buildVersion = getBuildVersion()

View File

@ -50,9 +50,11 @@ text.addplayers=Add/Remove Players
text.customgame=Custom Game text.customgame=Custom Game
text.campaign=Campaign text.campaign=Campaign
text.sectors=Sectors text.sectors=Sectors
text.sector=Selected Sector: {0} text.sector=Selected Sector: [LIGHT_GRAY]{0}
text.sector.deploy=Deploy text.sector.deploy=Deploy
text.sector.resume=Resume
text.sector.locked=[scarlet][[LOCKED] text.sector.locked=[scarlet][[LOCKED]
text.sector.unexplored=[accent][[Unexplored]
text.quit=Quit text.quit=Quit
text.maps=Maps text.maps=Maps
text.maps.none=[LIGHT_GRAY]No maps found! text.maps.none=[LIGHT_GRAY]No maps found!

View File

@ -46,6 +46,7 @@ public class Vars{
public static final float itemSize = 5f; public static final float itemSize = 5f;
public static final int tilesize = 8; public static final int tilesize = 8;
public static final int sectorSize = 256; public static final int sectorSize = 256;
public static final int invalidSector = Integer.MAX_VALUE;
public static final Locale[] locales = {new Locale("en"), new Locale("fr"), new Locale("ru"), new Locale("uk", "UA"), new Locale("pl"), public static final Locale[] locales = {new Locale("en"), new Locale("fr"), new Locale("ru"), new Locale("uk", "UA"), new Locale("pl"),
new Locale("de"), new Locale("pt", "BR"), new Locale("ko"), new Locale("in", "ID"), new Locale("de"), new Locale("pt", "BR"), new Locale("ko"), new Locale("in", "ID"),
new Locale("ita"), new Locale("es"), new Locale("zh","TW")}; new Locale("ita"), new Locale("es"), new Locale("zh","TW")};

View File

@ -11,10 +11,7 @@ import io.anuke.mindustry.game.EventType.TileChangeEvent;
import io.anuke.mindustry.game.EventType.WorldLoadEvent; import io.anuke.mindustry.game.EventType.WorldLoadEvent;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.io.MapIO; import io.anuke.mindustry.io.MapIO;
import io.anuke.mindustry.maps.Map; import io.anuke.mindustry.maps.*;
import io.anuke.mindustry.maps.MapMeta;
import io.anuke.mindustry.maps.Maps;
import io.anuke.mindustry.maps.Sectors;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.maps.generation.WorldGenerator; import io.anuke.mindustry.maps.generation.WorldGenerator;
@ -31,6 +28,7 @@ import static io.anuke.mindustry.Vars.*;
public class World extends Module{ public class World extends Module{
private Map currentMap; private Map currentMap;
private Sector currentSector;
private Tile[][] tiles; private Tile[][] tiles;
private Pathfinder pathfinder = new Pathfinder(); private Pathfinder pathfinder = new Pathfinder();
private BlockIndexer indexer = new BlockIndexer(); private BlockIndexer indexer = new BlockIndexer();
@ -43,6 +41,10 @@ public class World extends Module{
public World(){ public World(){
maps.load(); maps.load();
}
@Override
public void init(){
sectors.load(); sectors.load();
} }
@ -105,6 +107,10 @@ public class World extends Module{
return currentMap; return currentMap;
} }
public Sector getSector(){
return currentSector;
}
public void setMap(Map map){ public void setMap(Map map){
this.currentMap = map; this.currentMap = map;
} }
@ -206,8 +212,9 @@ public class World extends Module{
Events.fire(WorldLoadEvent.class); Events.fire(WorldLoadEvent.class);
} }
/**Loads up a procedural map. This does not call play(), but calls reset().*/ /**Loads up a sector map. This does not call play(), but calls reset().*/
public void loadProceduralMap(int sectorX, int sectorY){ public void loadSector(Sector sector){
currentSector = sector;
Timers.mark(); Timers.mark();
Timers.mark(); Timers.mark();
@ -219,13 +226,13 @@ public class World extends Module{
Tile[][] tiles = createTiles(width, height); Tile[][] tiles = createTiles(width, height);
Map map = new Map("Sector [" + sectorX + ", " + sectorY + "]", new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null); Map map = new Map("Sector [" + sector.x + ", " + sector.y + "]", new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null);
setMap(map); setMap(map);
EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize); EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize);
Timers.mark(); Timers.mark();
generator.generateMap(tiles, sectorX, sectorY); generator.generateMap(tiles, sector.x, sector.y);
Log.info("Time to generate base map: {0}", Timers.elapsed()); Log.info("Time to generate base map: {0}", Timers.elapsed());
Log.info("Time to generate fully without additional events: {0}", Timers.elapsed()); Log.info("Time to generate fully without additional events: {0}", Timers.elapsed());
@ -236,6 +243,7 @@ public class World extends Module{
} }
public void loadMap(Map map){ public void loadMap(Map map){
currentSector = null;
beginMapLoad(); beginMapLoad();
this.currentMap = map; this.currentMap = map;

View File

@ -244,7 +244,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
} }
//on slope //on slope
if(tile.elevation == -1){ if(tile.getElevation() == -1){
velocity.scl(0.7f); velocity.scl(0.7f);
} }
} }

View File

@ -2,6 +2,7 @@ package io.anuke.mindustry.game;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.TimeUtils; import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.game.EventType.StateChangeEvent; import io.anuke.mindustry.game.EventType.StateChangeEvent;
@ -21,6 +22,7 @@ import static io.anuke.mindustry.Vars.*;
public class Saves{ public class Saves{
private int nextSlot; private int nextSlot;
private Array<SaveSlot> saves = new ThreadArray<>(); private Array<SaveSlot> saves = new ThreadArray<>();
private IntMap<SaveSlot> saveMap = new IntMap<>();
private SaveSlot current; private SaveSlot current;
private boolean saving; private boolean saving;
private float time; private float time;
@ -44,6 +46,7 @@ public class Saves{
if(SaveIO.isSaveValid(index)){ if(SaveIO.isSaveValid(index)){
SaveSlot slot = new SaveSlot(index); SaveSlot slot = new SaveSlot(index);
saves.add(slot); saves.add(slot);
saveMap.put(slot.index, slot);
slot.meta = SaveIO.getData(index); slot.meta = SaveIO.getData(index);
nextSlot = Math.max(index + 1, nextSlot); nextSlot = Math.max(index + 1, nextSlot);
} }
@ -99,16 +102,18 @@ public class Saves{
return saving; return saving;
} }
public void addSave(String name){ public SaveSlot addSave(String name){
SaveSlot slot = new SaveSlot(nextSlot); SaveSlot slot = new SaveSlot(nextSlot);
nextSlot++; nextSlot++;
slot.setName(name); slot.setName(name);
saves.add(slot); saves.add(slot);
saveMap.put(slot.index, slot);
SaveIO.saveToSlot(slot.index); SaveIO.saveToSlot(slot.index);
slot.meta = SaveIO.getData(slot.index); slot.meta = SaveIO.getData(slot.index);
current = slot; current = slot;
saveSlots(); saveSlots();
return slot;
} }
public SaveSlot importSave(FileHandle file) throws IOException{ public SaveSlot importSave(FileHandle file) throws IOException{
@ -117,12 +122,17 @@ public class Saves{
nextSlot++; nextSlot++;
slot.setName(file.nameWithoutExtension()); slot.setName(file.nameWithoutExtension());
saves.add(slot); saves.add(slot);
saveMap.put(slot.index, slot);
slot.meta = SaveIO.getData(slot.index); slot.meta = SaveIO.getData(slot.index);
current = slot; current = slot;
saveSlots(); saveSlots();
return slot; return slot;
} }
public SaveSlot getByID(int id){
return saveMap.get(id);
}
public Array<SaveSlot> getSaveSlots(){ public Array<SaveSlot> getSaveSlots(){
return saves; return saves;
} }
@ -157,6 +167,10 @@ public class Saves{
current = this; current = this;
} }
public boolean isHidden(){
return meta.sector != invalidSector;
}
public String getPlayTime(){ public String getPlayTime(){
return Strings.formatMillis(current == this ? totalPlaytime : meta.timePlayed); return Strings.formatMillis(current == this ? totalPlaytime : meta.timePlayed);
} }
@ -223,11 +237,16 @@ public class Saves{
} }
public void delete(){ public void delete(){
if(!gwt){ //can't delete files
SaveIO.fileFor(index).delete(); SaveIO.fileFor(index).delete();
}
saves.removeValue(this, true); saves.removeValue(this, true);
saveMap.remove(index);
if(this == current){ if(this == current){
current = null; current = null;
} }
saveSlots();
} }
} }
} }

View File

@ -139,15 +139,8 @@ public class MinimapRenderer implements Disposable{
} }
private int colorFor(Tile tile){ private int colorFor(Tile tile){
int color = tile.breakable() ? tile.target().getTeam().intColor : ColorMapper.getBlockColor(tile.block()); tile = tile.target();
if(color == 0) color = ColorMapper.getBlockColor(tile.floor()); return ColorMapper.colorFor(tile.floor(), tile.block(), tile.getTeam(), tile.getElevation());
if(tile.elevation > 0){
float mul = 1.1f + tile.elevation / 4f;
tmpColor.set(color);
tmpColor.mul(mul, mul, mul, 1f);
color = Color.rgba8888(tmpColor);
}
return color;
} }
@Override @Override

View File

@ -14,14 +14,15 @@ public abstract class SaveFileVersion{
} }
public SaveMeta getData(DataInputStream stream) throws IOException{ public SaveMeta getData(DataInputStream stream) throws IOException{
long time = stream.readLong(); //read last saved time long time = stream.readLong();
long playtime = stream.readLong(); long playtime = stream.readLong();
int build = stream.readInt(); int build = stream.readInt();
byte mode = stream.readByte(); //read the gamemode int sector = stream.readInt();
String map = stream.readUTF(); //read the map byte mode = stream.readByte();
int wave = stream.readInt(); //read the wave String map = stream.readUTF();
byte difficulty = stream.readByte(); //read the difficulty int wave = stream.readInt();
return new SaveMeta(version, time, playtime, build, mode, map, wave, Difficulty.values()[difficulty]); byte difficulty = stream.readByte();
return new SaveMeta(version, time, playtime, build, sector, mode, map, wave, Difficulty.values()[difficulty]);
} }
public abstract void read(DataInputStream stream) throws IOException; public abstract void read(DataInputStream stream) throws IOException;

View File

@ -14,16 +14,18 @@ public class SaveMeta{
public int build; public int build;
public String date; public String date;
public long timePlayed; public long timePlayed;
public int sector;
public GameMode mode; public GameMode mode;
public Map map; public Map map;
public int wave; public int wave;
public Difficulty difficulty; public Difficulty difficulty;
public SaveMeta(int version, long date, long timePlayed, int build, int mode, String map, int wave, Difficulty difficulty){ public SaveMeta(int version, long date, long timePlayed, int build, int sector, int mode, String map, int wave, Difficulty difficulty){
this.version = version; this.version = version;
this.build = build; this.build = build;
this.date = Platform.instance.format(new Date(date)); this.date = Platform.instance.format(new Date(date));
this.timePlayed = timePlayed; this.timePlayed = timePlayed;
this.sector = sector;
this.mode = GameMode.values()[mode]; this.mode = GameMode.values()[mode];
this.map = world.maps().getByName(map); this.map = world.maps().getByName(map);
this.wave = wave; this.wave = wave;

View File

@ -38,6 +38,7 @@ public class Save16 extends SaveFileVersion{
stream.readLong(); //time stream.readLong(); //time
stream.readLong(); //total playtime stream.readLong(); //total playtime
stream.readInt(); //build stream.readInt(); //build
stream.readInt(); //sector ID
//general state //general state
byte mode = stream.readByte(); byte mode = stream.readByte();
@ -102,7 +103,7 @@ public class Save16 extends SaveFileVersion{
byte elevation = stream.readByte(); byte elevation = stream.readByte();
Tile tile = new Tile(x, y, floorid, wallid); Tile tile = new Tile(x, y, floorid, wallid);
tile.elevation = elevation; tile.setElevation(elevation);
if(wallid == Blocks.blockpart.id){ if(wallid == Blocks.blockpart.id){
tile.link = stream.readByte(); tile.link = stream.readByte();
@ -136,7 +137,7 @@ public class Save16 extends SaveFileVersion{
for(int j = i + 1; j < i + 1 + consecutives; j++){ for(int j = i + 1; j < i + 1 + consecutives; j++){
int newx = j % width, newy = j / width; int newx = j % width, newy = j / width;
Tile newTile = new Tile(newx, newy, floorid, wallid); Tile newTile = new Tile(newx, newy, floorid, wallid);
newTile.elevation = elevation; newTile.setElevation(elevation);
tiles[newx][newy] = newTile; tiles[newx][newy] = newTile;
} }
@ -156,6 +157,7 @@ public class Save16 extends SaveFileVersion{
stream.writeLong(TimeUtils.millis()); //last saved stream.writeLong(TimeUtils.millis()); //last saved
stream.writeLong(headless ? 0 : control.getSaves().getTotalPlaytime()); //playtime stream.writeLong(headless ? 0 : control.getSaves().getTotalPlaytime()); //playtime
stream.writeInt(Version.build); //build stream.writeInt(Version.build); //build
stream.writeInt(world.getSector() == null ? invalidSector : world.getSector().packedPosition()); //sector ID
//--GENERAL STATE-- //--GENERAL STATE--
stream.writeByte(state.mode.ordinal()); //gamemode stream.writeByte(state.mode.ordinal()); //gamemode
@ -212,7 +214,7 @@ public class Save16 extends SaveFileVersion{
stream.writeByte(tile.getFloorID()); stream.writeByte(tile.getFloorID());
stream.writeByte(tile.getWallID()); stream.writeByte(tile.getWallID());
stream.writeByte(tile.elevation); stream.writeByte(tile.getElevation());
if(tile.block() instanceof BlockPart){ if(tile.block() instanceof BlockPart){
stream.writeByte(tile.link); stream.writeByte(tile.link);
@ -232,7 +234,7 @@ public class Save16 extends SaveFileVersion{
for(int j = i + 1; j < world.width() * world.height() && consecutives < 255; j++){ for(int j = i + 1; j < world.width() * world.height() && consecutives < 255; j++){
Tile nextTile = world.tile(j); Tile nextTile = world.tile(j);
if(nextTile.getFloorID() != tile.getFloorID() || nextTile.getWallID() != 0 || nextTile.elevation != tile.elevation){ if(nextTile.getFloorID() != tile.getFloorID() || nextTile.getWallID() != 0 || nextTile.getElevation() != tile.getElevation()){
break; break;
} }

View File

@ -1,12 +1,26 @@
package io.anuke.mindustry.maps; package io.anuke.mindustry.maps;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import io.anuke.mindustry.io.SaveIO;
import io.anuke.ucore.util.Bits;
import static io.anuke.mindustry.Vars.control;
public class Sector{ public class Sector{
/**Position on the map, can be positive or negative.*/ /**Position on the map, can be positive or negative.*/
public short x, y; public short x, y;
/**Whether this sector has already been captured. TODO statistics?*/ /**Whether this sector has already been captured. TODO statistics?*/
public boolean unlocked; public boolean unlocked;
/**Slot ID of this sector's save. -1 means no save has been created.*/
public int saveID = -1;
/**Display texture. Needs to be disposed.*/ /**Display texture. Needs to be disposed.*/
public transient Texture texture; public transient Texture texture;
public boolean hasSave(){
return saveID != -1 && SaveIO.isSaveValid(saveID) && control.getSaves().getByID(saveID) != null;
}
public int packedPosition(){
return Bits.packInt(x, y);
}
} }

View File

@ -1,12 +1,13 @@
package io.anuke.mindustry.maps; package io.anuke.mindustry.maps;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.GridPoint2; import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.maps.generation.WorldGenerator.GenResult; import io.anuke.mindustry.maps.generation.WorldGenerator.GenResult;
import io.anuke.mindustry.world.ColorMapper;
import io.anuke.ucore.core.Settings; import io.anuke.ucore.core.Settings;
import io.anuke.ucore.util.Geometry; import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.GridMap; import io.anuke.ucore.util.GridMap;
@ -19,7 +20,7 @@ public class Sectors{
private GridMap<Sector> grid = new GridMap<>(); private GridMap<Sector> grid = new GridMap<>();
public Sectors(){ public Sectors(){
Settings.json().addClassTag("Sector", Sector.class);
} }
/**If a sector is not yet unlocked, returns null.*/ /**If a sector is not yet unlocked, returns null.*/
@ -34,9 +35,8 @@ public class Sectors{
sector.unlocked = true; sector.unlocked = true;
if(sector.texture == null) createTexture(sector); if(sector.texture == null) createTexture(sector);
//TODO fix
for(GridPoint2 point : Geometry.d4){ for(GridPoint2 point : Geometry.d4){
// createSector(sector.x + point.x, sector.y + point.y); createSector(sector.x + point.x, sector.y + point.y);
} }
} }
@ -58,6 +58,10 @@ public class Sectors{
createTexture(sector); createTexture(sector);
grid.put(sector.x, sector.y, sector); grid.put(sector.x, sector.y, sector);
} }
if(out.size == 0){
unlockSector(0, 0);
}
} }
public void save(){ public void save(){
@ -83,7 +87,7 @@ public class Sectors{
GenResult result = world.generator().generateTile(sector.x, sector.y, toX, toY); GenResult result = world.generator().generateTile(sector.x, sector.y, toX, toY);
int color = Color.rgba8888(result.floor.minimapColor); int color = ColorMapper.colorFor(result.floor, result.wall, Team.none, result.elevation);
pixmap.drawPixel(x, sectorImageSize - 1 - y, color); pixmap.drawPixel(x, sectorImageSize - 1 - y, color);
} }
} }

View File

@ -180,14 +180,14 @@ public class WorldGenerator{
for(int y = 0; y < height; y++){ for(int y = 0; y < height; y++){
Tile tile = tiles[x][y]; Tile tile = tiles[x][y];
byte elevation = tile.elevation; byte elevation = tile.getElevation();
for(GridPoint2 point : Geometry.d4){ for(GridPoint2 point : Geometry.d4){
if(!Mathf.inBounds(x + point.x, y + point.y, width, height)) continue; if(!Mathf.inBounds(x + point.x, y + point.y, width, height)) continue;
if(tiles[x + point.x][y + point.y].elevation < elevation){ if(tiles[x + point.x][y + point.y].getElevation() < elevation){
if(Mathf.chance(0.05)){ if(Mathf.chance(0.05)){
tile.elevation = -1; tile.setElevation(-1);
} }
break; break;
} }

View File

@ -64,7 +64,7 @@ public class NetworkIO{
stream.writeByte(tile.getFloorID()); stream.writeByte(tile.getFloorID());
stream.writeByte(tile.getWallID()); stream.writeByte(tile.getWallID());
stream.writeByte(tile.elevation); stream.writeByte(tile.getElevation());
if(tile.block() instanceof BlockPart){ if(tile.block() instanceof BlockPart){
stream.writeByte(tile.link); stream.writeByte(tile.link);
@ -84,7 +84,7 @@ public class NetworkIO{
for(int j = i + 1; j < world.width() * world.height() && consecutives < 255; j++){ for(int j = i + 1; j < world.width() * world.height() && consecutives < 255; j++){
Tile nextTile = world.tile(j); Tile nextTile = world.tile(j);
if(nextTile.getFloorID() != tile.getFloorID() || nextTile.getWallID() != 0 || nextTile.elevation != tile.elevation){ if(nextTile.getFloorID() != tile.getFloorID() || nextTile.getWallID() != 0 || nextTile.getElevation() != tile.getElevation()){
break; break;
} }
@ -178,7 +178,7 @@ public class NetworkIO{
byte elevation = stream.readByte(); byte elevation = stream.readByte();
Tile tile = new Tile(x, y, floorid, wallid); Tile tile = new Tile(x, y, floorid, wallid);
tile.elevation = elevation; tile.setElevation(elevation);
if(wallid == Blocks.blockpart.id){ if(wallid == Blocks.blockpart.id){
tile.link = stream.readByte(); tile.link = stream.readByte();
@ -205,7 +205,7 @@ public class NetworkIO{
for(int j = i + 1; j < i + 1 + consecutives; j++){ for(int j = i + 1; j < i + 1 + consecutives; j++){
int newx = j % width, newy = j / width; int newx = j % width, newy = j / width;
Tile newTile = new Tile(newx, newy, floorid, wallid); Tile newTile = new Tile(newx, newy, floorid, wallid);
newTile.elevation = elevation; newTile.setElevation(elevation);
tiles[newx][newy] = newTile; tiles[newx][newy] = newTile;
} }

View File

@ -125,7 +125,7 @@ public class LevelDialog extends FloatingDialog{
Timers.run(5f, () -> { Timers.run(5f, () -> {
Cursors.restoreCursor(); Cursors.restoreCursor();
threads.run(() -> { threads.run(() -> {
world.loadProceduralMap(0, 0); world.loadSector(0, 0);
logic.play(); logic.play();
Gdx.app.postRunnable(ui.loadfrag::hide); Gdx.app.postRunnable(ui.loadfrag::hide);
}); });

View File

@ -56,6 +56,7 @@ public class LoadDialog extends FloatingDialog{
Array<SaveSlot> array = control.getSaves().getSaveSlots(); Array<SaveSlot> array = control.getSaves().getSaveSlots();
for(SaveSlot slot : array){ for(SaveSlot slot : array){
if(slot.isHidden()) continue;
TextButton button = new TextButton("[accent]" + slot.getName(), "clear"); TextButton button = new TextButton("[accent]" + slot.getName(), "clear");
button.getLabelCell().growX().left(); button.getLabelCell().growX().left();
@ -140,7 +141,10 @@ public class LoadDialog extends FloatingDialog{
} }
public void addSetup(){ public void addSetup(){
if(control.getSaves().getSaveSlots().size == 0){ boolean valids = false;
for(SaveSlot slot : control.getSaves().getSaveSlots()) if(!slot.isHidden()) valids = true;
if(!valids){
slots.row(); slots.row();
slots.addButton("$text.save.none", "clear", () -> { slots.addButton("$text.save.none", "clear", () -> {

View File

@ -12,6 +12,7 @@ import io.anuke.ucore.scene.Element;
import io.anuke.ucore.scene.event.ClickListener; import io.anuke.ucore.scene.event.ClickListener;
import io.anuke.ucore.scene.event.InputEvent; import io.anuke.ucore.scene.event.InputEvent;
import io.anuke.ucore.scene.event.InputListener; import io.anuke.ucore.scene.event.InputListener;
import io.anuke.ucore.scene.ui.TextButton;
import io.anuke.ucore.scene.utils.Cursors; import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.scene.utils.ScissorStack; import io.anuke.ucore.scene.utils.ScissorStack;
import io.anuke.ucore.util.Bundles; import io.anuke.ucore.util.Bundles;
@ -26,15 +27,18 @@ public class SectorsDialog extends FloatingDialog{
public SectorsDialog(){ public SectorsDialog(){
super("$text.sectors"); super("$text.sectors");
addCloseButton(); shown(this::setup);
setup();
} }
void setup(){ void setup(){
content().clear(); content().clear();
buttons().clear();
addCloseButton();
content().label(() -> Bundles.format("text.sector", selected == null ? "<none>" : content().label(() -> Bundles.format("text.sector", selected == null ? "<none>" :
selected.x + ", " + selected.y + (!selected.unlocked ? Bundles.get("text.sector.locked") : ""))); (selected.x + ", " + selected.y + (!selected.unlocked ? " " + Bundles.get("text.sector.locked") : ""))
+ (selected.saveID == -1 && selected.unlocked ? " " + Bundles.get("text.sector.unexplored") : "")));
content().row(); content().row();
content().add(new SectorView()).grow(); content().add(new SectorView()).grow();
content().row(); content().row();
@ -42,10 +46,22 @@ public class SectorsDialog extends FloatingDialog{
hide(); hide();
ui.loadLogic(() -> { ui.loadLogic(() -> {
world.loadProceduralMap(selected.x, selected.y); if(!selected.hasSave()){
world.loadSector(selected);
logic.play(); logic.play();
selected.saveID = control.getSaves().addSave("sector-" + selected.packedPosition()).index;
world.sectors().save();
}else{
control.getSaves().getByID(selected.saveID).load();
logic.play();
}
}); });
}).size(230f, 64f).disabled(b -> selected == null); }).size(230f, 64f).name("deploy-button").disabled(b -> selected == null || !selected.unlocked);
}
void selectSector(Sector sector){
buttons().<TextButton>find("deploy-button").setText(sector.hasSave() ? "$text.sector.resume" : "$text.sector.deploy");
selected = sector;
} }
class SectorView extends Element{ class SectorView extends Element{
@ -110,22 +126,20 @@ public class SectorsDialog extends FloatingDialog{
float drawX = x + width/2f+ sectorX * sectorSize - offsetX * sectorSize - panX % sectorSize; float drawX = x + width/2f+ sectorX * sectorSize - offsetX * sectorSize - panX % sectorSize;
float drawY = y + height/2f + sectorY * sectorSize - offsetY * sectorSize - panY % sectorSize; float drawY = y + height/2f + sectorY * sectorSize - offsetY * sectorSize - panY % sectorSize;
if(world.sectors().get(sectorX, sectorY) == null){
world.sectors().unlockSector(sectorX, sectorY);
}
Sector sector = world.sectors().get(sectorX, sectorY); Sector sector = world.sectors().get(sectorX, sectorY);
if(sector == null) continue; if(sector != null && sector.texture != null){
Draw.color(Color.WHITE); Draw.color(Color.WHITE);
Draw.rect(sector.texture, drawX, drawY, sectorSize, sectorSize); Draw.rect(sector.texture, drawX, drawY, sectorSize, sectorSize);
}
if(sector == selected){ if(sector == null){
Draw.color(Color.DARK_GRAY);
}else if(sector == selected){
Draw.color(Palette.place); Draw.color(Palette.place);
}else if(Mathf.inRect(mouse.x, mouse.y, drawX - sectorSize/2f, drawY - sectorSize/2f, drawX + sectorSize/2f, drawY + sectorSize/2f)){ }else if(Mathf.inRect(mouse.x, mouse.y, drawX - sectorSize/2f, drawY - sectorSize/2f, drawX + sectorSize/2f, drawY + sectorSize/2f)){
if(clicked){ if(clicked){
selected = sector; selectSector(sector);
} }
Draw.color(Palette.remove); Draw.color(Palette.remove);
}else if (sector.unlocked){ }else if (sector.unlocked){
@ -134,7 +148,7 @@ public class SectorsDialog extends FloatingDialog{
Draw.color(Color.LIGHT_GRAY); Draw.color(Color.LIGHT_GRAY);
} }
Lines.stroke(selected == sector ? 5f : 3f); Lines.stroke(sector != null && selected == sector ? 5f : 3f);
Lines.crect(drawX, drawY, sectorSize, sectorSize); Lines.crect(drawX, drawY, sectorSize, sectorSize);
} }
} }

View File

@ -5,11 +5,13 @@ import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntMap; import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectIntMap; import com.badlogic.gdx.utils.ObjectIntMap;
import io.anuke.mindustry.game.Content; import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.type.ContentList; import io.anuke.mindustry.type.ContentList;
public class ColorMapper implements ContentList{ public class ColorMapper implements ContentList{
private static IntMap<Block> blockMap = new IntMap<>(); private static IntMap<Block> blockMap = new IntMap<>();
private static ObjectIntMap<Block> colorMap = new ObjectIntMap<>(); private static ObjectIntMap<Block> colorMap = new ObjectIntMap<>();
private static Color tmpColor = new Color();
public static Block getByColor(int color){ public static Block getByColor(int color){
return blockMap.get(color); return blockMap.get(color);
@ -19,6 +21,18 @@ public class ColorMapper implements ContentList{
return colorMap.get(block, 0); return colorMap.get(block, 0);
} }
public static int colorFor(Block floor, Block wall, Team team, int elevation){
int color = wall.breakable ? team.intColor : getBlockColor(wall);
if(color == 0) color = ColorMapper.getBlockColor(floor);
if(elevation > 0){
float mul = 1.1f + elevation / 4f;
tmpColor.set(color);
tmpColor.mul(mul, mul, mul, 1f);
color = Color.rgba8888(tmpColor);
}
return color;
}
@Override @Override
public void load(){ public void load(){
for(Block block : Block.all()){ for(Block block : Block.all()){

View File

@ -34,8 +34,6 @@ public class Tile implements PosTrait, TargetTrait{
public short x, y; public short x, y;
/** Tile traversal cost. */ /** Tile traversal cost. */
public byte cost = 1; public byte cost = 1;
/** Elevation of tile. */
public byte elevation;
/** Position of cliffs around the tile, packed into bits 0-8. */ /** Position of cliffs around the tile, packed into bits 0-8. */
public byte cliffs; public byte cliffs;
/** Tile entity, usually null. */ /** Tile entity, usually null. */
@ -47,6 +45,8 @@ public class Tile implements PosTrait, TargetTrait{
private byte rotation; private byte rotation;
/** Team ordinal. */ /** Team ordinal. */
private byte team; private byte team;
/** Tile elevation. -1 means slope.*/
private byte elevation;
public Tile(int x, int y){ public Tile(int x, int y){
this.x = (short) x; this.x = (short) x;
@ -65,7 +65,7 @@ public class Tile implements PosTrait, TargetTrait{
this.floor = (Floor) Block.getByID(floor); this.floor = (Floor) Block.getByID(floor);
this.wall = Block.getByID(wall); this.wall = Block.getByID(wall);
this.rotation = rotation; this.rotation = rotation;
this.elevation = elevation; this.setElevation(elevation);
changed(); changed();
this.team = team; this.team = team;
} }
@ -201,6 +201,14 @@ public class Tile implements PosTrait, TargetTrait{
this.rotation = dump; this.rotation = dump;
} }
public byte getElevation(){
return elevation;
}
public void setElevation(int elevation){
this.elevation = (byte)elevation;
}
public boolean passable(){ public boolean passable(){
Block block = block(); Block block = block();
Block floor = floor(); Block floor = floor();

View File

@ -11,7 +11,7 @@ import io.anuke.mindustry.world.meta.BlockGroup;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
public class Splitter extends Block{ public class Splitter extends Block{
protected float speed = 8f; protected float speed = 7f;
public Splitter(String name){ public Splitter(String name){
super(name); super(name);

View File

@ -104,13 +104,11 @@ public class ServerControl extends Module{
world.loadMap(map); world.loadMap(map);
}else{ }else{
info("Selected a procedural map."); info("Selected a procedural map.");
world.loadProceduralMap(); playSectorMap();
logic.play();
} }
}else{ }else{
info("Selected a procedural map."); info("Selected a procedural map.");
world.loadProceduralMap(); playSectorMap();
logic.play();
} }
}else{ }else{
state.set(State.menu); state.set(State.menu);
@ -181,17 +179,17 @@ public class ServerControl extends Module{
logic.reset(); logic.reset();
world.loadMap(result); world.loadMap(result);
}else{
Log.info("&ly&fiNo map specified, so a procedural one was generated.");
world.loadProceduralMap();
}
}else{
Log.info("&ly&fiNo map specified, so a procedural one was generated.");
world.loadProceduralMap();
}
logic.play(); logic.play();
}else{
Log.info("&ly&fiNo map specified, so a procedural one was generated.");
playSectorMap();
}
}else{
Log.info("&ly&fiNo map specified, so a procedural one was generated.");
playSectorMap();
}
info("Map loaded."); info("Map loaded.");
host(); host();
@ -807,6 +805,11 @@ public class ServerControl extends Module{
} }
} }
private void playSectorMap(){
world.loadSector(world.sectors().get(0, 0));
logic.play();
}
private void host(){ private void host(){
try{ try{
Net.host(port); Net.host(port);