Better schematic previews, keep on game export
This commit is contained in:
@@ -39,6 +39,9 @@ public class GlobalData{
|
|||||||
files.add(Core.settings.getSettingsFile());
|
files.add(Core.settings.getSettingsFile());
|
||||||
files.addAll(customMapDirectory.list());
|
files.addAll(customMapDirectory.list());
|
||||||
files.addAll(saveDirectory.list());
|
files.addAll(saveDirectory.list());
|
||||||
|
files.addAll(screenshotDirectory.list());
|
||||||
|
files.addAll(modDirectory.list());
|
||||||
|
files.addAll(schematicDirectory.list());
|
||||||
String base = Core.settings.getDataDirectory().path();
|
String base = Core.settings.getDataDirectory().path();
|
||||||
|
|
||||||
try(OutputStream fos = file.write(false, 2048); ZipOutputStream zos = new ZipOutputStream(fos)){
|
try(OutputStream fos = file.write(false, 2048); ZipOutputStream zos = new ZipOutputStream(fos)){
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class Schematics{
|
|||||||
Draw.proj().setOrtho(0, buffer.getHeight(), buffer.getWidth(), -buffer.getHeight());
|
Draw.proj().setOrtho(0, buffer.getHeight(), buffer.getWidth(), -buffer.getHeight());
|
||||||
for(int x = 0; x < schematic.width + padding; x++){
|
for(int x = 0; x < schematic.width + padding; x++){
|
||||||
for(int y = 0; y < schematic.height + padding; y++){
|
for(int y = 0; y < schematic.height + padding; y++){
|
||||||
Draw.rect("dark-panel-4", x * resolution + resolution/2f, y * resolution + resolution/2f, resolution, resolution);
|
Draw.rect("metal-floor", x * resolution + resolution/2f, y * resolution + resolution/2f, resolution, resolution);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,25 +108,22 @@ public class Schematics{
|
|||||||
Draw.rect(Tmp.tr1, buffer.getWidth()/2f, buffer.getHeight()/2f, buffer.getWidth(), -buffer.getHeight());
|
Draw.rect(Tmp.tr1, buffer.getWidth()/2f, buffer.getHeight()/2f, buffer.getWidth(), -buffer.getHeight());
|
||||||
Draw.color();
|
Draw.color();
|
||||||
|
|
||||||
Array<BuildRequest> requests = schematic.tiles.map(t -> new BuildRequest(t.x, t.y, t.rotation, t.block){
|
|
||||||
@Override
|
|
||||||
public float drawx(){
|
|
||||||
float offset = (t.block.size + 1) % 2 / 2f;
|
|
||||||
return (t.x + 0.5f + padding/2f + offset) * resolution;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
Array<BuildRequest> requests = schematic.tiles.map(t -> new BuildRequest(t.x, t.y, t.rotation, t.block).configure(t.config));
|
||||||
public float drawy(){
|
|
||||||
float offset = (t.block.size + 1) % 2 / 2f;
|
Draw.flush();
|
||||||
return (t.y + 0.5f + padding/2f + offset) * resolution;
|
Draw.trans().scale(4f, 4f).translate(tilesize*1.5f, tilesize*1.5f);
|
||||||
}
|
|
||||||
}.configure(t.config));
|
|
||||||
|
|
||||||
requests.each(req -> {
|
requests.each(req -> {
|
||||||
req.animScale = 4f;
|
req.animScale = 1f;
|
||||||
req.block.drawRequestRegion(req, requests::each);
|
req.block.drawRequestRegion(req, requests::each);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
requests.each(req -> req.block.drawRequestConfigTop(req, requests::each));
|
||||||
|
|
||||||
|
Draw.flush();
|
||||||
|
Draw.trans().idt();
|
||||||
|
|
||||||
buffer.endDraw();
|
buffer.endDraw();
|
||||||
|
|
||||||
Draw.proj(Tmp.m3);
|
Draw.proj(Tmp.m3);
|
||||||
@@ -143,6 +140,16 @@ public class Schematics{
|
|||||||
return schem.tiles.map(t -> new BuildRequest(t.x + x - schem.width/2, t.y + y - schem.height/2, t.rotation, t.block).configure(t.config));
|
return schem.tiles.map(t -> new BuildRequest(t.x + x - schem.width/2, t.y + y - schem.height/2, t.rotation, t.block).configure(t.config));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Adds a schematic to the list, also copying it into the files.*/
|
||||||
|
public void add(Schematic schematic){
|
||||||
|
all.add(schematic);
|
||||||
|
try{
|
||||||
|
write(schematic, schematicDirectory.child(Time.millis() + "." + schematicExtension));
|
||||||
|
}catch(IOException e){
|
||||||
|
Log.err(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Creates a schematic from a world selection. */
|
/** Creates a schematic from a world selection. */
|
||||||
public Schematic create(int x, int y, int x2, int y2){
|
public Schematic create(int x, int y, int x2, int y2){
|
||||||
if(x > x2){
|
if(x > x2){
|
||||||
@@ -163,14 +170,15 @@ public class Schematics{
|
|||||||
boolean found = false;
|
boolean found = false;
|
||||||
for(int cx = x; cx <= x2; cx++){
|
for(int cx = x; cx <= x2; cx++){
|
||||||
for(int cy = y; cy <= y2; cy++){
|
for(int cy = y; cy <= y2; cy++){
|
||||||
Tile tile = world.tile(cx, cy);
|
|
||||||
Tile linked = world.ltile(cx, cy);
|
Tile linked = world.ltile(cx, cy);
|
||||||
|
|
||||||
if(linked != null && linked.entity != null){
|
if(linked != null && linked.entity != null){
|
||||||
minx = Math.min(tile.x, minx);
|
int top = linked.block().size/2;
|
||||||
miny = Math.min(tile.y, miny);
|
int bot = linked.block().size % 2 == 1 ? -linked.block().size/2 : -(linked.block().size - 1)/2;
|
||||||
maxx = Math.max(tile.x, maxx);
|
minx = Math.min(linked.x + bot, minx);
|
||||||
maxy = Math.max(tile.y, maxy);
|
miny = Math.min(linked.y + bot, miny);
|
||||||
|
maxx = Math.max(linked.x + top, maxx);
|
||||||
|
maxy = Math.max(linked.y + top, maxy);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,20 +8,17 @@ import io.anuke.arc.graphics.g2d.*;
|
|||||||
import io.anuke.arc.math.*;
|
import io.anuke.arc.math.*;
|
||||||
import io.anuke.arc.scene.*;
|
import io.anuke.arc.scene.*;
|
||||||
import io.anuke.arc.scene.ui.*;
|
import io.anuke.arc.scene.ui.*;
|
||||||
import io.anuke.arc.util.*;
|
|
||||||
import io.anuke.arc.util.ArcAnnotate.*;
|
import io.anuke.arc.util.ArcAnnotate.*;
|
||||||
import io.anuke.mindustry.core.GameState.*;
|
import io.anuke.mindustry.core.GameState.*;
|
||||||
import io.anuke.mindustry.entities.traits.BuilderTrait.*;
|
import io.anuke.mindustry.entities.traits.BuilderTrait.*;
|
||||||
import io.anuke.mindustry.game.*;
|
|
||||||
import io.anuke.mindustry.game.EventType.*;
|
import io.anuke.mindustry.game.EventType.*;
|
||||||
|
import io.anuke.mindustry.game.*;
|
||||||
import io.anuke.mindustry.game.Schematics.*;
|
import io.anuke.mindustry.game.Schematics.*;
|
||||||
import io.anuke.mindustry.gen.*;
|
import io.anuke.mindustry.gen.*;
|
||||||
import io.anuke.mindustry.graphics.*;
|
import io.anuke.mindustry.graphics.*;
|
||||||
import io.anuke.mindustry.ui.*;
|
import io.anuke.mindustry.ui.*;
|
||||||
import io.anuke.mindustry.world.*;
|
import io.anuke.mindustry.world.*;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
import static io.anuke.arc.Core.scene;
|
import static io.anuke.arc.Core.scene;
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
import static io.anuke.mindustry.input.PlaceMode.*;
|
import static io.anuke.mindustry.input.PlaceMode.*;
|
||||||
@@ -239,12 +236,7 @@ public class DesktopInput extends InputHandler{
|
|||||||
if(Core.input.keyRelease(Binding.schematic)){
|
if(Core.input.keyRelease(Binding.schematic)){
|
||||||
Schematic schem = schematics.create(schemX, schemY, rawCursorX, rawCursorY);
|
Schematic schem = schematics.create(schemX, schemY, rawCursorX, rawCursorY);
|
||||||
__REMOVE__= schem;
|
__REMOVE__= schem;
|
||||||
Log.info(schematics.writeBase64(schem));
|
schematics.add(schem);
|
||||||
try{
|
|
||||||
Schematics.write(schem, Core.files.external("schematic.msch"));
|
|
||||||
}catch(IOException e){
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sreq != null){
|
if(sreq != null){
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package io.anuke.mindustry.ui.dialogs;
|
package io.anuke.mindustry.ui.dialogs;
|
||||||
|
|
||||||
import io.anuke.arc.graphics.g2d.*;
|
import io.anuke.arc.graphics.*;
|
||||||
import io.anuke.arc.scene.style.*;
|
import io.anuke.arc.scene.ui.*;
|
||||||
import io.anuke.mindustry.game.*;
|
import io.anuke.mindustry.game.*;
|
||||||
import io.anuke.mindustry.game.Schematics.*;
|
import io.anuke.mindustry.game.Schematics.*;
|
||||||
|
import io.anuke.mindustry.ui.*;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.schematics;
|
import static io.anuke.mindustry.Vars.schematics;
|
||||||
|
|
||||||
@@ -21,7 +22,10 @@ public class SchematicsDialog extends FloatingDialog{
|
|||||||
cont.pane(t -> {
|
cont.pane(t -> {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(Schematic s : schematics.all()){
|
for(Schematic s : schematics.all()){
|
||||||
addImageButton(new TextureRegionDrawable(new TextureRegion(schematics.getPreview(s, PreviewRes.low))), 100f, () -> {
|
addButton(b -> {
|
||||||
|
Texture tex = schematics.getPreview(s, PreviewRes.low);
|
||||||
|
b.stack(new Image(tex), new BorderImage(tex)).size(100f);
|
||||||
|
}, () -> {
|
||||||
|
|
||||||
}).size(110f).pad(4);
|
}).size(110f).pad(4);
|
||||||
|
|
||||||
|
|||||||
@@ -705,6 +705,10 @@ public class Block extends BlockStorage{
|
|||||||
Draw.color();
|
Draw.color();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void drawRequestConfigTop(BuildRequest req, Eachable<BuildRequest> list){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createIcons(PixmapPacker packer, PixmapPacker editor){
|
public void createIcons(PixmapPacker packer, PixmapPacker editor){
|
||||||
super.createIcons(packer, editor);
|
super.createIcons(packer, editor);
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package io.anuke.mindustry.world.blocks.distribution;
|
|||||||
import io.anuke.arc.*;
|
import io.anuke.arc.*;
|
||||||
import io.anuke.arc.collection.*;
|
import io.anuke.arc.collection.*;
|
||||||
import io.anuke.arc.collection.IntSet.*;
|
import io.anuke.arc.collection.IntSet.*;
|
||||||
|
import io.anuke.arc.function.*;
|
||||||
import io.anuke.arc.graphics.*;
|
import io.anuke.arc.graphics.*;
|
||||||
import io.anuke.arc.graphics.g2d.*;
|
import io.anuke.arc.graphics.g2d.*;
|
||||||
import io.anuke.arc.math.*;
|
import io.anuke.arc.math.*;
|
||||||
import io.anuke.arc.math.geom.*;
|
import io.anuke.arc.math.geom.*;
|
||||||
import io.anuke.arc.util.*;
|
import io.anuke.arc.util.*;
|
||||||
|
import io.anuke.mindustry.entities.traits.BuilderTrait.*;
|
||||||
import io.anuke.mindustry.entities.type.*;
|
import io.anuke.mindustry.entities.type.*;
|
||||||
import io.anuke.mindustry.graphics.*;
|
import io.anuke.mindustry.graphics.*;
|
||||||
import io.anuke.mindustry.type.*;
|
import io.anuke.mindustry.type.*;
|
||||||
@@ -23,6 +25,7 @@ public class ItemBridge extends Block{
|
|||||||
protected int range;
|
protected int range;
|
||||||
protected float transportTime = 2f;
|
protected float transportTime = 2f;
|
||||||
protected TextureRegion endRegion, bridgeRegion, arrowRegion;
|
protected TextureRegion endRegion, bridgeRegion, arrowRegion;
|
||||||
|
protected BuildRequest otherReq;
|
||||||
|
|
||||||
private static int lastPlaced = Pos.invalid;
|
private static int lastPlaced = Pos.invalid;
|
||||||
|
|
||||||
@@ -65,6 +68,27 @@ public class ItemBridge extends Block{
|
|||||||
arrowRegion = Core.atlas.find(name + "-arrow");
|
arrowRegion = Core.atlas.find(name + "-arrow");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawRequestConfigTop(BuildRequest req, Eachable<BuildRequest> list){
|
||||||
|
otherReq = null;
|
||||||
|
list.each(other -> {
|
||||||
|
if(other.block == this && req.config == Pos.get(other.x, other.y)){
|
||||||
|
otherReq = other;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(otherReq == null) return;
|
||||||
|
|
||||||
|
Lines.stroke(8f);
|
||||||
|
Lines.line(bridgeRegion,
|
||||||
|
req.drawx(),
|
||||||
|
req.drawy(),
|
||||||
|
otherReq.drawx(),
|
||||||
|
otherReq.drawy(), CapStyle.none, -tilesize / 2f);
|
||||||
|
Draw.rect(arrowRegion, (req.drawx() + otherReq.drawx()) / 2f, (req.drawy() + otherReq.drawy()) / 2f,
|
||||||
|
Angles.angle(req.drawx(), req.drawy(), otherReq.drawx(), otherReq.drawy()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playerPlaced(Tile tile){
|
public void playerPlaced(Tile tile){
|
||||||
Tile link = findLink(tile.x, tile.y);
|
Tile link = findLink(tile.x, tile.y);
|
||||||
|
|||||||
Reference in New Issue
Block a user