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

View File

@@ -197,7 +197,7 @@ public class World{
public void loadSector(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));
}

View File

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

View File

@@ -3,9 +3,11 @@ package mindustry.type;
import arc.math.geom.*;
import arc.math3d.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import arc.util.io.*;
import mindustry.*;
import mindustry.ctype.*;
import mindustry.game.Saves.*;
import mindustry.graphics.PlanetGrid.*;
import mindustry.world.*;
@@ -30,6 +32,14 @@ public class Sector{
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
public boolean isLaunchWave(int wave){
return metCondition() && wave % launchPeriod == 0;
@@ -94,7 +104,7 @@ public class Sector{
/** Cached data about a sector. */
public static class SectorData{
public Content[] resources = {};
public UnlockableContent[] resources = {};
public int spawnX, spawnY;
public Block[] floors = {};
@@ -116,7 +126,7 @@ public class Sector{
}
public void read(Reads read){
resources = new Content[read.s()];
resources = new UnlockableContent[read.s()];
for(int i = 0; i < resources.length; i++){
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.ui.layout.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.content.*;
import mindustry.ctype.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.graphics.PlanetGrid.*;
@@ -31,8 +33,8 @@ public class PlanetDialog extends FloatingDialog{
private Planet planet = Planets.starter;
private float lastX, lastY;
private Sector selected, hovered;
private Table selectTable;
private @Nullable Sector selected, hovered;
private Table stable, infoTable;
public PlanetDialog(){
super("", Styles.fullDialog);
@@ -75,18 +77,23 @@ public class PlanetDialog extends FloatingDialog{
@Override
public void tap(InputEvent event, float x, float y, int count, KeyCode button){
selected = hovered;
if(selected != null){
updateSelected();
}
}
});
selectTable = new Table(t -> {
t.background(Tex.button);
infoTable = new Table();
stable = new Table(t -> {
t.background(Styles.black3);
t.margin(12f);
t.add("this is some arbitrary text.");
});
selectTable.act(1f);
selectTable.pack();
selectTable.setPosition(0, 0, Align.center);
stable.act(1f);
stable.pack();
stable.setPosition(0, 0, Align.center);
shown(this::setup);
}
@@ -112,6 +119,7 @@ public class PlanetDialog extends FloatingDialog{
cam.lookAt(0, 0, 0);
cam.update();
projector.proj(cam.combined());
batch.proj(cam.combined());
PlanetMesh outline = outline(planet.size);
@@ -130,25 +138,70 @@ public class PlanetDialog extends FloatingDialog{
if(selected != null){
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);
}
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){
for(Corner c : sector.tile.corners){
batch.color(outlineColor);