Unfinished sector selection

This commit is contained in:
Anuken
2020-02-24 23:03:33 -05:00
parent 3211b5da01
commit 8b7f439ef5
7 changed files with 89 additions and 29 deletions

Binary file not shown.

View File

@@ -197,7 +197,7 @@ public class World{
public void loadSector(Sector sector){ public void loadSector(Sector sector){
state.rules.sector = sector; state.rules.sector = sector;
int size = (int)(sector.rect.radius * 3200); int size = sector.getSize();
loadGenerator(size, size, tiles -> sector.planet.generator.generate(tiles, sector)); loadGenerator(size, size, tiles -> sector.planet.generator.generate(tiles, sector));
} }

View File

@@ -8,7 +8,6 @@ import arc.util.*;
import arc.util.noise.*; import arc.util.noise.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.maps.generators.*; import mindustry.maps.generators.*;
import mindustry.type.*;
import mindustry.world.*; import mindustry.world.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
@@ -17,8 +16,6 @@ public class TestPlanetGenerator extends PlanetGenerator{
Simplex noise = new Simplex(); Simplex noise = new Simplex();
RidgedPerlin rid = new RidgedPerlin(1, 2); RidgedPerlin rid = new RidgedPerlin(1, 2);
float scl = 5f; float scl = 5f;
Sector sector;
Tiles tiles;
//TODO generate array from planet image later //TODO generate array from planet image later
Block[][] arr = { Block[][] arr = {

View File

@@ -3,9 +3,11 @@ package mindustry.type;
import arc.math.geom.*; import arc.math.geom.*;
import arc.math3d.*; import arc.math3d.*;
import arc.util.*; import arc.util.*;
import arc.util.ArcAnnotate.*;
import arc.util.io.*; import arc.util.io.*;
import mindustry.*; import mindustry.*;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.game.Saves.*;
import mindustry.graphics.PlanetGrid.*; import mindustry.graphics.PlanetGrid.*;
import mindustry.world.*; import mindustry.world.*;
@@ -30,6 +32,14 @@ public class Sector{
this.data = data; this.data = data;
} }
public int getSize(){
return (int)(rect.radius * 3200);
}
public @Nullable SaveSlot getSave(){
return Vars.headless ? null : Vars.control.saves.getSectorSave(this);
}
//TODO implement //TODO implement
public boolean isLaunchWave(int wave){ public boolean isLaunchWave(int wave){
return metCondition() && wave % launchPeriod == 0; return metCondition() && wave % launchPeriod == 0;
@@ -94,7 +104,7 @@ public class Sector{
/** Cached data about a sector. */ /** Cached data about a sector. */
public static class SectorData{ public static class SectorData{
public Content[] resources = {}; public UnlockableContent[] resources = {};
public int spawnX, spawnY; public int spawnX, spawnY;
public Block[] floors = {}; public Block[] floors = {};
@@ -116,7 +126,7 @@ public class Sector{
} }
public void read(Reads read){ public void read(Reads read){
resources = new Content[read.s()]; resources = new UnlockableContent[read.s()];
for(int i = 0; i < resources.length; i++){ for(int i = 0; i < resources.length; i++){
resources[i] = Vars.content.getByID(ContentType.all[read.b()], read.s()); resources[i] = Vars.content.getByID(ContentType.all[read.b()], read.s());
} }

View File

@@ -10,7 +10,9 @@ import arc.math.geom.*;
import arc.scene.event.*; import arc.scene.event.*;
import arc.scene.ui.layout.*; import arc.scene.ui.layout.*;
import arc.util.*; import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.ctype.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.graphics.PlanetGrid.*; import mindustry.graphics.PlanetGrid.*;
@@ -31,8 +33,8 @@ public class PlanetDialog extends FloatingDialog{
private Planet planet = Planets.starter; private Planet planet = Planets.starter;
private float lastX, lastY; private float lastX, lastY;
private Sector selected, hovered; private @Nullable Sector selected, hovered;
private Table selectTable; private Table stable, infoTable;
public PlanetDialog(){ public PlanetDialog(){
super("", Styles.fullDialog); super("", Styles.fullDialog);
@@ -75,18 +77,23 @@ public class PlanetDialog extends FloatingDialog{
@Override @Override
public void tap(InputEvent event, float x, float y, int count, KeyCode button){ public void tap(InputEvent event, float x, float y, int count, KeyCode button){
selected = hovered; selected = hovered;
if(selected != null){
updateSelected();
}
} }
}); });
selectTable = new Table(t -> { infoTable = new Table();
t.background(Tex.button);
stable = new Table(t -> {
t.background(Styles.black3);
t.margin(12f); t.margin(12f);
t.add("this is some arbitrary text."); t.add("this is some arbitrary text.");
}); });
selectTable.act(1f); stable.act(1f);
selectTable.pack(); stable.pack();
selectTable.setPosition(0, 0, Align.center); stable.setPosition(0, 0, Align.center);
shown(this::setup); shown(this::setup);
} }
@@ -112,6 +119,7 @@ public class PlanetDialog extends FloatingDialog{
cam.lookAt(0, 0, 0); cam.lookAt(0, 0, 0);
cam.update(); cam.update();
projector.proj(cam.combined());
batch.proj(cam.combined()); batch.proj(cam.combined());
PlanetMesh outline = outline(planet.size); PlanetMesh outline = outline(planet.size);
@@ -130,25 +138,70 @@ public class PlanetDialog extends FloatingDialog{
if(selected != null){ if(selected != null){
drawSelection(selected); drawSelection(selected);
projector.proj(cam.combined());
projector.setPlane(
//origin on sector position
Tmp.v33.set(selected.tile.v).setLength(outlineRad + 0.05f),
//face up
selected.plane.project(Tmp.v32.set(selected.tile.v).add(Vec3.Y)).sub(selected.tile.v).nor(),
//right vector
Tmp.v31.set(Tmp.v32).add(selected.tile.v).rotate(selected.tile.v, 90).sub(selected.tile.v).nor()
);
Draw.batch(projector, () -> {
selectTable.draw();
});
} }
Draw.batch(projector, () -> {
if(hovered != null){
setPlane(hovered);
Fonts.outline.draw("" + hovered.id, 0, 0, Align.center);
}
if(selected != null){
setPlane(selected);
stable.draw();
}
});
/*
Vec3 pos = cam.project(Tmp.v31.set(selected.tile.v).setLength(outlineRad));
selectTable.setPosition(pos.x, pos.y, Align.center);
selectTable.draw();
*/
Gl.disable(Gl.depthTest); Gl.disable(Gl.depthTest);
} }
private void updateSelected(){
stable.clear();
stable.background(Styles.black6);
//TODO add strings to bundle after prototyping is done
stable.add("[accent]" + selected.id).row();
stable.addImage().color(Pal.accent).fillX().height(3f).pad(3f).row();
stable.add(selected.getSave() != null ? selected.getSave().getPlayTime() : "[lightgray]Unexplored").row();
stable.add("Resources:").row();
stable.table(t -> {
t.left();
int idx = 0;
int max = 5;
for(UnlockableContent c : selected.data.resources){
t.addImage(c.icon(Cicon.small)).padRight(3);
if(++idx % max == 0) t.row();
}
for(int i = 0; i < Math.min(selected.data.floorCounts.length, 3); i++){
t.addImage(selected.data.floors[i].icon(Cicon.small)).padRight(3);
if(++idx % max == 0) t.row();
}
}).fillX().row();
stable.pack();
stable.setPosition(0, 0, Align.center);
}
private void setPlane(Sector sector){
projector.setPlane(
//origin on sector position
Tmp.v33.set(sector.tile.v).setLength(outlineRad + 0.001f),
//face up
sector.plane.project(Tmp.v32.set(sector.tile.v).add(Vec3.Y)).sub(sector.tile.v).nor(),
//right vector
Tmp.v31.set(Tmp.v32).add(sector.tile.v).rotate(sector.tile.v, 90).sub(sector.tile.v).nor()
);
}
private void drawHover(Sector sector){ private void drawHover(Sector sector){
for(Corner c : sector.tile.corners){ for(Corner c : sector.tile.corners){
batch.color(outlineColor); batch.color(outlineColor);

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=5b1a532e4d5630a39cf83a4f3263dc265f609a20 archash=c6cf22b91f58e7f050574885e18d2b1d9640563f

View File

@@ -77,7 +77,7 @@ public class SectorDataGenerator{
data.floors[i] = entries.get(i).key; data.floors[i] = entries.get(i).key;
} }
data.resources = content.asArray().sort(Structs.comps(Structs.comparing(Content::getContentType), Structs.comparingInt(c -> c.id))).toArray(Content.class); data.resources = content.asArray().sort(Structs.comps(Structs.comparing(Content::getContentType), Structs.comparingInt(c -> c.id))).toArray(UnlockableContent.class);
if(count[0]++ % 10 == 0){ if(count[0]++ % 10 == 0){
Log.info("&lyDone with sector &lm{0}/{1}", count[0], planet.sectors.size); Log.info("&lyDone with sector &lm{0}/{1}", count[0], planet.sectors.size);