From c02c00cdfb82fdb08cad799bd5c9a1b0d9a5f0e9 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 4 Mar 2020 19:21:40 -0500 Subject: [PATCH] Schematic tweaks and improvements --- core/src/mindustry/game/Schematics.java | 10 +++++----- core/src/mindustry/input/DesktopInput.java | 4 ++++ core/src/mindustry/input/InputHandler.java | 17 +++++++++++++---- core/src/mindustry/input/MobileInput.java | 3 --- .../world/blocks/distribution/ItemBridge.java | 8 +++++--- .../world/blocks/distribution/MassDriver.java | 5 +++-- .../mindustry/world/blocks/power/PowerNode.java | 9 +++++---- 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/core/src/mindustry/game/Schematics.java b/core/src/mindustry/game/Schematics.java index f2efb8bbb6..d833a50b38 100644 --- a/core/src/mindustry/game/Schematics.java +++ b/core/src/mindustry/game/Schematics.java @@ -266,7 +266,7 @@ public class Schematics implements Loadable{ tile.set(st.block, state.rules.defaultTeam); tile.rotation(st.rotation); - Object config = BuildRequest.pointConfig(st.config, point -> point.add(tile.x - st.x, tile.y - st.y)); + Object config = st.config; tile.configureAny(config); if(st.block instanceof Drill){ @@ -350,7 +350,7 @@ public class Schematics implements Loadable{ if(tile != null && tile.entity != null && !counted.contains(tile.pos()) && !(tile.block() instanceof BuildBlock) && (tile.entity.block().isVisible() || (tile.entity.block() instanceof CoreBlock && Core.settings.getBool("coreselect")))){ - Object config = BuildRequest.pointConfig(tile.entity.config(), point -> point.add(offsetX, offsetY)); + Object config = tile.entity.config(); tiles.add(new Stile(tile.block(), tile.x + offsetX, tile.y + offsetY, config, tile.rotation())); counted.add(tile.pos()); @@ -422,7 +422,7 @@ public class Schematics implements Loadable{ for(int i = 0; i < total; i++){ Block block = blocks.get(stream.readByte()); int position = stream.readInt(); - Object config = ver == 0 ? mapConfig(block, stream.readInt()) : TypeIO.readObject(Reads.get(stream)); + Object config = ver == 0 ? mapConfig(block, stream.readInt(), position) : TypeIO.readObject(Reads.get(stream)); byte rotation = stream.readByte(); if(block != Blocks.air){ tiles.add(new Stile(block, Point2.x(position), Point2.y(position), config, rotation)); @@ -473,10 +473,10 @@ public class Schematics implements Loadable{ } /** Maps legacy int configs to new config objects. */ - private static Object mapConfig(Block block, int value){ + private static Object mapConfig(Block block, int value, int position){ if(block instanceof Sorter || block instanceof Unloader || block instanceof ItemSource) return content.item(value); - if(block instanceof MassDriver || block instanceof ItemBridge) return Point2.unpack(value); if(block instanceof LiquidSource) return content.liquid(value); + if(block instanceof MassDriver || block instanceof ItemBridge) return Point2.unpack(value).sub(Point2.x(position), Point2.y(position)); if(block instanceof LightBlock || block instanceof CommandCenter) return value; return null; diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index 50516c0dc3..dab4efd267 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -115,6 +115,10 @@ public class DesktopInput extends InputHandler{ drawRequest(request); } + for(BuildRequest request : selectRequests){ + drawOverRequest(request); + } + if(sreq != null){ boolean valid = validPlace(sreq.x, sreq.y, sreq.block, sreq.rotation, sreq); if(sreq.block.rotate){ diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index 3f4d887021..77af23a5ec 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -265,7 +265,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ requests.each(req -> { req.pointConfig(p -> { - int cx = p.x - req.originalX, cy = p.y - req.originalY; + int cx = p.x, cy = p.y; int lx = cx; if(direction >= 0){ @@ -275,7 +275,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ cx = cy; cy = -lx; } - p.set(cx + req.originalX, cy + req.originalY); + p.set(cx, cy); }); //rotate actual request, centered on its multiblock position @@ -308,7 +308,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ req.pointConfig(p -> { int corigin = x ? req.originalWidth/2 : req.originalHeight/2; - int nvalue = -((x ? p.x : p.y) - corigin) + corigin; + int nvalue = -(x ? p.x : p.y); if(x){ req.originalX = -(req.originalX - corigin) + corigin; p.x = nvalue; @@ -449,12 +449,21 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ for(BuildRequest req : requests){ if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){ BuildRequest copy = req.copy(); - copy.pointConfig(p -> p.add(copy.x - copy.originalX, copy.y - copy.originalY)); player.builder().addBuild(copy); } } } + protected void drawOverRequest(BuildRequest request){ + boolean valid = validPlace(request.x, request.y, request.block, request.rotation); + + Draw.reset(); + Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime(), 6f, 0.28f)); + Draw.alpha(1f); + request.block.drawRequestConfigTop(request, selectRequests); + Draw.reset(); + } + protected void drawRequest(BuildRequest request){ request.block.drawRequest(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation)); } diff --git a/core/src/mindustry/input/MobileInput.java b/core/src/mindustry/input/MobileInput.java index a61af1767b..8532154b4e 100644 --- a/core/src/mindustry/input/MobileInput.java +++ b/core/src/mindustry/input/MobileInput.java @@ -222,8 +222,6 @@ public class MobileInput extends InputHandler implements GestureListener{ BuildRequest other = getRequest(request.x, request.y, request.block.size, null); BuildRequest copy = request.copy(); - copy.pointConfig(p -> p.add(copy.x - copy.originalX, copy.y - copy.originalY)); - if(other == null){ player.builder().addBuild(copy); }else if(!other.breaking && other.x == request.x && other.y == request.y && other.block.size == request.block.size){ @@ -340,7 +338,6 @@ public class MobileInput extends InputHandler implements GestureListener{ if(request.block.rotate) drawArrow(request.block, tile.x, tile.y, request.rotation); } - //Draw.mixcol(Tmp.c1, 1f); Draw.reset(); drawRequest(request); diff --git a/core/src/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/mindustry/world/blocks/distribution/ItemBridge.java index 6f79e310f9..f244fee5de 100644 --- a/core/src/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/mindustry/world/blocks/distribution/ItemBridge.java @@ -41,7 +41,9 @@ public class ItemBridge extends Block{ group = BlockGroup.transportation; entityType = ItemBridgeEntity::new; - config(Point2.class, (tile, i) -> tile.ent().link = i.pack()); + //point2 config is relative + config(Point2.class, (tile, i) -> tile.ent().link = Point2.pack(i.x + tile.x, i.y + tile.y)); + //integer is not config(Integer.class, (tile, i) -> tile.ent().link = i); } @@ -58,7 +60,7 @@ public class ItemBridge extends Block{ public void drawRequestConfigTop(BuildRequest req, Eachable list){ otherReq = null; list.each(other -> { - if(other.block == this && req.config instanceof Point2 && ((Point2)req.config).equals(other.x, other.y)){ + if(other.block == this && req != other && req.config instanceof Point2 && ((Point2)req.config).equals(other.x - req.x, other.y - req.y)){ otherReq = other; } }); @@ -367,7 +369,7 @@ public class ItemBridge extends Block{ @Override public Point2 config(){ - return Point2.unpack(link); + return Point2.unpack(link).sub(tile.x, tile.y); } @Override diff --git a/core/src/mindustry/world/blocks/distribution/MassDriver.java b/core/src/mindustry/world/blocks/distribution/MassDriver.java index 655f463daa..595accecf9 100644 --- a/core/src/mindustry/world/blocks/distribution/MassDriver.java +++ b/core/src/mindustry/world/blocks/distribution/MassDriver.java @@ -42,7 +42,8 @@ public class MassDriver extends Block{ outlineIcon = true; entityType = MassDriverEntity::new; - config(Point2.class, (tile, point) -> tile.ent().link = point.pack()); + //point2 is relative + config(Point2.class, (tile, point) -> tile.ent().link = Point2.pack(point.x + tile.x, point.y + tile.y)); config(Integer.class, (tile, point) -> tile.ent().link = point); } @@ -325,7 +326,7 @@ public class MassDriver extends Block{ @Override public Point2 config(){ - return Point2.unpack(link); + return Point2.unpack(link).sub(tile.x, tile.y); } @Override diff --git a/core/src/mindustry/world/blocks/power/PowerNode.java b/core/src/mindustry/world/blocks/power/PowerNode.java index 7ee1d39944..5869854b9d 100644 --- a/core/src/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/mindustry/world/blocks/power/PowerNode.java @@ -80,7 +80,9 @@ public class PowerNode extends PowerBlock{ config(Point2[].class, (tile, value) -> { tile.entity.power().links.clear(); for(Point2 p : value){ - tile.entity.power().links.add(p.pack()); + if(tile.entity.power().links.size < maxNodes){ + tile.entity.power().links.add(Point2.pack(p.x + tile.x, p.y + tile.y)); + } } }); } @@ -295,8 +297,7 @@ public class PowerNode extends PowerBlock{ for(Point2 point : (Point2[])req.config){ otherReq = null; list.each(other -> { - if(other.x == point.x && other.y == point.y){ - Log.info("found match " + other); + if((other.x == req.x + point.x && other.y == req.y + point.y) && other != req){ otherReq = other; } }); @@ -396,7 +397,7 @@ public class PowerNode extends PowerBlock{ public Point2[] config(){ Point2[] out = new Point2[power.links.size]; for(int i = 0; i < out.length; i++){ - out[i] = Point2.unpack(power.links.get(i)); + out[i] = Point2.unpack(power.links.get(i)).sub(tile.x, tile.y); } return out; }