Added basic sector classes / Changed play menu dialog

This commit is contained in:
Anuken 2018-07-15 17:19:33 -04:00
parent 9e3af13efc
commit 6a7ff13859
9 changed files with 101 additions and 33 deletions

View File

@ -47,7 +47,8 @@ text.savegame=Save Game
text.loadgame=Load Game
text.joingame=Join Game
text.addplayers=Add/Remove Players
text.newgame=New Game
text.customgame=Custom Game
text.campaign=Campaign
text.quit=Quit
text.maps=Maps
text.maps.none=[LIGHT_GRAY]No maps found!

View File

@ -18,5 +18,5 @@
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.net.Streamable"/>
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.world.meta.BlockBar"/>
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.world.mapgen.WorldGenerator"/>
<extend-configuration-property name="gdx.reflect.include" value="com.badlogic.gdx.utils.Predicate"/>
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.entities.StatusController"/>
</module>

View File

@ -1,7 +1,6 @@
package io.anuke.mindustry.core;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.ai.BlockIndexer;
@ -11,8 +10,8 @@ import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.game.EventType.TileChangeEvent;
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.maps.Map;
import io.anuke.mindustry.io.MapIO;
import io.anuke.mindustry.maps.Map;
import io.anuke.mindustry.maps.MapMeta;
import io.anuke.mindustry.maps.Maps;
import io.anuke.mindustry.maps.Sectors;
@ -31,14 +30,13 @@ import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.*;
public class World extends Module{
private int seed;
private Map currentMap;
private Tile[][] tiles;
private Pathfinder pathfinder = new Pathfinder();
private BlockIndexer indexer = new BlockIndexer();
private Maps maps = new Maps();
private Sectors sectors = new Sectors();
private WorldGenerator generator = new WorldGenerator();
private Array<Tile> tempTiles = new ThreadArray<>();
private boolean generating, invalidMap;
@ -204,9 +202,7 @@ public class World extends Module{
Events.fire(WorldLoadEvent.class);
}
/**
* Loads up a procedural map. This does not call play(), but calls reset().
*/
/**Loads up a procedural map. This does not call play(), but calls reset().*/
public void loadProceduralMap(){
Timers.mark();
Timers.mark();
@ -225,7 +221,7 @@ public class World extends Module{
EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize);
Timers.mark();
WorldGenerator.generateMap(tiles, Mathf.random(9999999));
generator.generateMap(tiles, Mathf.random(9999999));
Log.info("Time to generate base map: {0}", Timers.elapsed());
Log.info("Time to generate fully without additional events: {0}", Timers.elapsed());
@ -236,13 +232,8 @@ public class World extends Module{
}
public void loadMap(Map map){
loadMap(map, MathUtils.random(0, 999999));
}
public void loadMap(Map map, int seed){
beginMapLoad();
this.currentMap = map;
this.seed = seed;
int width = map.meta.width, height = map.meta.height;
@ -250,7 +241,7 @@ public class World extends Module{
EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize);
WorldGenerator.loadTileData(tiles, MapIO.readTileData(map, true), map.meta.hasOreGen(), seed);
generator.loadTileData(tiles, MapIO.readTileData(map, true), map.meta.hasOreGen(), 0);
if(!headless && state.teams.get(players[0].getTeam()).cores.size == 0){
ui.showError("$text.map.nospawn");
@ -263,10 +254,6 @@ public class World extends Module{
endMapLoad();
}
public int getSeed(){
return seed;
}
public void notifyChanged(Tile tile){
if(!generating){
threads.runDelay(() -> Events.fire(TileChangeEvent.class, tile));

View File

@ -1,4 +1,12 @@
package io.anuke.mindustry.maps;
import com.badlogic.gdx.graphics.Texture;
public class Sector{
/**Position on the map, can be positive or negative.*/
public short x, y;
/**Whether this sector has already been captured. TODO statistics?*/
public boolean unlocked;
/**Display texture. Needs to be disposed.*/
public transient Texture texture;
}

View File

@ -1,20 +1,86 @@
package io.anuke.mindustry.maps;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.utils.Array;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.GridMap;
import static io.anuke.mindustry.Vars.headless;
public class Sectors{
private static final int sectorSize = 256;
private static final int sectorImageSize = 8;
private GridMap<Sector> grid = new GridMap<>();
public Sectors(){
}
public void load(){
/**If a sector is not yet unlocked, returns null.*/
public Sector get(int x, int y){
return grid.get(x, y);
}
/**Unlocks a sector. This shows nearby sectors.*/
public void unlockSector(int x, int y){
createSector(x, y);
Sector sector = get(x, y);
sector.unlocked = true;
if(sector.texture == null) createTexture(sector);
for(GridPoint2 point : Geometry.d4){
createSector(sector.x + point.x, sector.y + point.y);
}
}
/**Creates a sector at a location if it is not present, but does not unlock it.*/
public void createSector(int x, int y){
if(grid.containsKey(x, y)) return;
Sector sector = new Sector();
sector.x = (short)x;
sector.y = (short)y;
sector.unlocked = false;
}
public void load(){
Array<Sector> out = Settings.getJson("sectors", Array.class);
for(Sector sector : out){
createTexture(sector);
grid.put(sector.x, sector.y, sector);
}
}
public void save(){
Array<Sector> out = new Array<>();
for(Sector sector : grid.values()){
out.add(sector);
}
Settings.putJson("sectors", out);
Settings.save();
}
private void createTexture(Sector sector){
if(headless) return; //obviously not created or needed on server
Pixmap pixmap = new Pixmap(sectorImageSize, sectorImageSize, Format.RGBA8888);
int worldX = sector.x * sectorSize;
int worldY = sector.y * sectorSize;
for(int x = worldX; x < (worldX + sectorSize); x++){
for(int y = worldY; y < (worldY + sectorSize); y++){
}
}
sector.texture = new Texture(pixmap);
pixmap.dispose();
}
}

View File

@ -0,0 +1,4 @@
package io.anuke.mindustry.ui.dialogs;
public class SectorsDialog{
}

View File

@ -139,14 +139,14 @@ public class MenuFragment extends Fragment{
}
private void showPlaySelect(){
float w = 200f;
float w = 220f;
float bw = w * 2f + 10f;
FloatingDialog dialog = new FloatingDialog("$text.play");
dialog.addCloseButton();
dialog.content().defaults().height(66f).width(w).padRight(5f);
dialog.content().add(new MenuButton("icon-play-2", "$text.newgame", () -> {
dialog.content().add(new MenuButton("icon-play-2", "$text.campaign", () -> {
dialog.hide();
ui.levels.show();
})).width(bw).colspan(2);
@ -161,7 +161,10 @@ public class MenuFragment extends Fragment{
}
}));
dialog.content().add(new MenuButton("icon-tutorial", "$text.tutorial", () -> ui.showInfo("The tutorial is currently not yet implemented.")));
dialog.content().add(new MenuButton("icon-editor", "$text.customgame", () -> {
dialog.hide();
ui.levels.show();
}));
dialog.content().row();

View File

@ -47,7 +47,7 @@ public class ItemBridge extends Block{
hasPower = true;
layer = Layer.power;
expanded = true;
itemCapacity = 30;
itemCapacity = 10;
configurable = true;
hasItems = true;
}

View File

@ -28,12 +28,11 @@ import static io.anuke.mindustry.Vars.world;
public class WorldGenerator{
static int oreIndex = 0;
private int seed;
int oreIndex = 0;
/**
* Should fill spawns with the correct spawnpoints.
*/
public static void loadTileData(Tile[][] tiles, MapTileData data, boolean genOres, int seed){
/**Loads raw map tile data into a Tile[][] array, setting up multiblocks, cliffs and ores. */
public void loadTileData(Tile[][] tiles, MapTileData data, boolean genOres, int seed){
data.position(0, 0);
TileDataMarker marker = data.newDataMarker();
@ -48,7 +47,7 @@ public class WorldGenerator{
prepareTiles(tiles, seed, genOres);
}
public static void prepareTiles(Tile[][] tiles, int seed, boolean genOres){
public void prepareTiles(Tile[][] tiles, int seed, boolean genOres){
//find multiblocks
IntArray multiblocks = new IntArray();
@ -146,7 +145,7 @@ public class WorldGenerator{
}
}
public static void generateMap(Tile[][] tiles, int seed){
public void generateMap(Tile[][] tiles, int seed){
MathUtils.random.setSeed((long) (Math.random() * 99999999));
Simplex sim = new Simplex(Mathf.random(99999));
Simplex sim2 = new Simplex(Mathf.random(99999));
@ -244,7 +243,7 @@ public class WorldGenerator{
prepareTiles(tiles, seed, true);
}
public static class OreEntry{
public class OreEntry{
final float frequency;
final Item item;
final Simplex noise;