From dec6a1296bd0ed3a4ff94730acd973729e3782da Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 17 Oct 2019 22:57:37 -0400 Subject: [PATCH] Better schematic previews, keep on game export --- .../io/anuke/mindustry/game/GlobalData.java | 3 ++ .../io/anuke/mindustry/game/Schematics.java | 46 +++++++++++-------- .../anuke/mindustry/input/DesktopInput.java | 12 +---- .../ui/dialogs/SchematicsDialog.java | 10 ++-- core/src/io/anuke/mindustry/world/Block.java | 4 ++ .../world/blocks/distribution/ItemBridge.java | 24 ++++++++++ 6 files changed, 67 insertions(+), 32 deletions(-) diff --git a/core/src/io/anuke/mindustry/game/GlobalData.java b/core/src/io/anuke/mindustry/game/GlobalData.java index 5ef1ae09fb..f0b7bfecab 100644 --- a/core/src/io/anuke/mindustry/game/GlobalData.java +++ b/core/src/io/anuke/mindustry/game/GlobalData.java @@ -39,6 +39,9 @@ public class GlobalData{ files.add(Core.settings.getSettingsFile()); files.addAll(customMapDirectory.list()); files.addAll(saveDirectory.list()); + files.addAll(screenshotDirectory.list()); + files.addAll(modDirectory.list()); + files.addAll(schematicDirectory.list()); String base = Core.settings.getDataDirectory().path(); try(OutputStream fos = file.write(false, 2048); ZipOutputStream zos = new ZipOutputStream(fos)){ diff --git a/core/src/io/anuke/mindustry/game/Schematics.java b/core/src/io/anuke/mindustry/game/Schematics.java index cc75794bff..11c496988f 100644 --- a/core/src/io/anuke/mindustry/game/Schematics.java +++ b/core/src/io/anuke/mindustry/game/Schematics.java @@ -99,7 +99,7 @@ public class Schematics{ Draw.proj().setOrtho(0, buffer.getHeight(), buffer.getWidth(), -buffer.getHeight()); for(int x = 0; x < schematic.width + padding; x++){ 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.color(); - Array 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 - public float drawy(){ - float offset = (t.block.size + 1) % 2 / 2f; - return (t.y + 0.5f + padding/2f + offset) * resolution; - } - }.configure(t.config)); + Array requests = schematic.tiles.map(t -> new BuildRequest(t.x, t.y, t.rotation, t.block).configure(t.config)); + + Draw.flush(); + Draw.trans().scale(4f, 4f).translate(tilesize*1.5f, tilesize*1.5f); requests.each(req -> { - req.animScale = 4f; + req.animScale = 1f; req.block.drawRequestRegion(req, requests::each); }); + requests.each(req -> req.block.drawRequestConfigTop(req, requests::each)); + + Draw.flush(); + Draw.trans().idt(); + buffer.endDraw(); 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)); } + /** 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. */ public Schematic create(int x, int y, int x2, int y2){ if(x > x2){ @@ -163,14 +170,15 @@ public class Schematics{ boolean found = false; for(int cx = x; cx <= x2; cx++){ for(int cy = y; cy <= y2; cy++){ - Tile tile = world.tile(cx, cy); Tile linked = world.ltile(cx, cy); if(linked != null && linked.entity != null){ - minx = Math.min(tile.x, minx); - miny = Math.min(tile.y, miny); - maxx = Math.max(tile.x, maxx); - maxy = Math.max(tile.y, maxy); + int top = linked.block().size/2; + int bot = linked.block().size % 2 == 1 ? -linked.block().size/2 : -(linked.block().size - 1)/2; + minx = Math.min(linked.x + bot, minx); + miny = Math.min(linked.y + bot, miny); + maxx = Math.max(linked.x + top, maxx); + maxy = Math.max(linked.y + top, maxy); found = true; } } diff --git a/core/src/io/anuke/mindustry/input/DesktopInput.java b/core/src/io/anuke/mindustry/input/DesktopInput.java index 2a1ec3eca9..f251f9f897 100644 --- a/core/src/io/anuke/mindustry/input/DesktopInput.java +++ b/core/src/io/anuke/mindustry/input/DesktopInput.java @@ -8,20 +8,17 @@ import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.math.*; import io.anuke.arc.scene.*; import io.anuke.arc.scene.ui.*; -import io.anuke.arc.util.*; import io.anuke.arc.util.ArcAnnotate.*; import io.anuke.mindustry.core.GameState.*; import io.anuke.mindustry.entities.traits.BuilderTrait.*; -import io.anuke.mindustry.game.*; import io.anuke.mindustry.game.EventType.*; +import io.anuke.mindustry.game.*; import io.anuke.mindustry.game.Schematics.*; import io.anuke.mindustry.gen.*; import io.anuke.mindustry.graphics.*; import io.anuke.mindustry.ui.*; import io.anuke.mindustry.world.*; -import java.io.*; - import static io.anuke.arc.Core.scene; import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.input.PlaceMode.*; @@ -239,12 +236,7 @@ public class DesktopInput extends InputHandler{ if(Core.input.keyRelease(Binding.schematic)){ Schematic schem = schematics.create(schemX, schemY, rawCursorX, rawCursorY); __REMOVE__= schem; - Log.info(schematics.writeBase64(schem)); - try{ - Schematics.write(schem, Core.files.external("schematic.msch")); - }catch(IOException e){ - throw new RuntimeException(e); - } + schematics.add(schem); } if(sreq != null){ diff --git a/core/src/io/anuke/mindustry/ui/dialogs/SchematicsDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/SchematicsDialog.java index 5c8ca135c0..37d49245a6 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/SchematicsDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/SchematicsDialog.java @@ -1,9 +1,10 @@ package io.anuke.mindustry.ui.dialogs; -import io.anuke.arc.graphics.g2d.*; -import io.anuke.arc.scene.style.*; +import io.anuke.arc.graphics.*; +import io.anuke.arc.scene.ui.*; import io.anuke.mindustry.game.*; import io.anuke.mindustry.game.Schematics.*; +import io.anuke.mindustry.ui.*; import static io.anuke.mindustry.Vars.schematics; @@ -21,7 +22,10 @@ public class SchematicsDialog extends FloatingDialog{ cont.pane(t -> { int i = 0; 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); diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index e41c2be6e2..dd056d84ac 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -705,6 +705,10 @@ public class Block extends BlockStorage{ Draw.color(); } + public void drawRequestConfigTop(BuildRequest req, Eachable list){ + + } + @Override public void createIcons(PixmapPacker packer, PixmapPacker editor){ super.createIcons(packer, editor); diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java index d867f5fd26..4988a524bb 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java @@ -3,11 +3,13 @@ package io.anuke.mindustry.world.blocks.distribution; import io.anuke.arc.*; import io.anuke.arc.collection.*; import io.anuke.arc.collection.IntSet.*; +import io.anuke.arc.function.*; import io.anuke.arc.graphics.*; import io.anuke.arc.graphics.g2d.*; import io.anuke.arc.math.*; import io.anuke.arc.math.geom.*; import io.anuke.arc.util.*; +import io.anuke.mindustry.entities.traits.BuilderTrait.*; import io.anuke.mindustry.entities.type.*; import io.anuke.mindustry.graphics.*; import io.anuke.mindustry.type.*; @@ -23,6 +25,7 @@ public class ItemBridge extends Block{ protected int range; protected float transportTime = 2f; protected TextureRegion endRegion, bridgeRegion, arrowRegion; + protected BuildRequest otherReq; private static int lastPlaced = Pos.invalid; @@ -65,6 +68,27 @@ public class ItemBridge extends Block{ arrowRegion = Core.atlas.find(name + "-arrow"); } + @Override + public void drawRequestConfigTop(BuildRequest req, Eachable 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 public void playerPlaced(Tile tile){ Tile link = findLink(tile.x, tile.y);