Better bridge linking
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package mindustry.entities.comp;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
@@ -120,10 +121,9 @@ abstract class BuilderComp implements Posc, Teamc, Rotc{
|
||||
/** Draw all current build plans. Does not draw the beam effect, only the positions. */
|
||||
void drawBuildPlans(){
|
||||
|
||||
for(BuildPlan request : plans){
|
||||
if(request.progress > 0.01f || (buildPlan() == request && request.initialized && (within(request.x * tilesize, request.y * tilesize, buildingRange) || state.isEditor()))) continue;
|
||||
|
||||
drawPlan(request, 1f);
|
||||
for(BuildPlan plan : plans){
|
||||
if(plan.progress > 0.01f || (buildPlan() == plan && plan.initialized && (within(plan.x * tilesize, plan.y * tilesize, buildingRange) || state.isEditor()))) continue;
|
||||
drawPlan(plan, 1f);
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
@@ -137,6 +137,11 @@ abstract class BuilderComp implements Posc, Teamc, Rotc{
|
||||
request.block.drawPlan(request, control.input.allRequests(),
|
||||
Build.validPlace(request.block, team, request.x, request.y, request.rotation) || control.input.requestMatches(request),
|
||||
alpha);
|
||||
|
||||
Draw.reset();
|
||||
Draw.mixcol(Color.white, 0.24f + Mathf.absin(Time.globalTime, 6f, 0.28f));
|
||||
Draw.alpha(alpha);
|
||||
request.block.drawRequestConfigTop(request, plans);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -165,14 +165,15 @@ public class BuildPlan implements Position{
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "BuildRequest{" +
|
||||
return "BuildPlan{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
", rotation=" + rotation +
|
||||
", recipe=" + block +
|
||||
", block=" + block +
|
||||
", breaking=" + breaking +
|
||||
", progress=" + progress +
|
||||
", initialized=" + initialized +
|
||||
", config=" + config +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,6 @@ public class DesktopInput extends InputHandler{
|
||||
block.drawRequestConfig(brequest, allRequests());
|
||||
brequest.config = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -743,6 +743,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
for(BuildPlan req : requests){
|
||||
if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){
|
||||
BuildPlan copy = req.copy();
|
||||
req.block.onNewPlan(copy);
|
||||
player.unit().addBuild(copy);
|
||||
}
|
||||
}
|
||||
@@ -1080,12 +1081,6 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
}
|
||||
}
|
||||
|
||||
public void tryPlaceBlock(int x, int y){
|
||||
if(block != null && validPlace(x, y, block, rotation)){
|
||||
placeBlock(x, y, block, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
public void tryBreakBlock(int x, int y){
|
||||
if(validBreak(x, y)){
|
||||
breakBlock(x, y);
|
||||
@@ -1112,14 +1107,6 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
return Build.validBreak(player.team(), x, y);
|
||||
}
|
||||
|
||||
public void placeBlock(int x, int y, Block block, int rotation){
|
||||
BuildPlan req = getRequest(x, y);
|
||||
if(req != null){
|
||||
player.unit().plans().remove(req);
|
||||
}
|
||||
player.unit().addBuild(new BuildPlan(x, y, rotation, block, block.nextConfig()));
|
||||
}
|
||||
|
||||
public void breakBlock(int x, int y){
|
||||
Tile tile = world.tile(x, y);
|
||||
if(tile != null && tile.build != null) tile = tile.build.tile;
|
||||
|
||||
@@ -354,6 +354,9 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
|
||||
Draw.reset();
|
||||
drawRequest(request);
|
||||
if(!request.breaking){
|
||||
drawOverRequest(request);
|
||||
}
|
||||
|
||||
//draw last placed request
|
||||
if(!request.breaking && request == lastPlaced && request.block != null){
|
||||
@@ -596,6 +599,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}else if(mode == placing && isPlacing() && validPlace(cursor.x, cursor.y, block, rotation) && !checkOverlapPlacement(cursor.x, cursor.y, block)){
|
||||
//add to selection queue if it's a valid place position
|
||||
selectRequests.add(lastPlaced = new BuildPlan(cursor.x, cursor.y, rotation, block, block.nextConfig()));
|
||||
block.onNewPlan(lastPlaced);
|
||||
}else if(mode == breaking && validBreak(linked.x,linked.y) && !hasRequest(linked)){
|
||||
//add to selection queue if it's a valid BREAK position
|
||||
selectRequests.add(new BuildPlan(linked.x, linked.y));
|
||||
|
||||
@@ -393,6 +393,11 @@ public class Block extends UnlockableContent{
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Called when a new build plan is created in the player's queue. Blocks can maintain a reference to this plan and add configs to it later. */
|
||||
public void onNewPlan(BuildPlan plan){
|
||||
|
||||
}
|
||||
|
||||
public void drawPlan(BuildPlan req, Eachable<BuildPlan> list, boolean valid){
|
||||
drawPlan(req, list, valid, 1f);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,12 @@ public class ItemBridge extends Block{
|
||||
public @Load("@-end") TextureRegion endRegion;
|
||||
public @Load("@-bridge") TextureRegion bridgeRegion;
|
||||
public @Load("@-arrow") TextureRegion arrowRegion;
|
||||
public int lastPlaced = -1;
|
||||
|
||||
//for autolink
|
||||
@Nullable
|
||||
public ItemBridgeBuild lastBuild;
|
||||
@Nullable
|
||||
public BuildPlan lastPlan;
|
||||
|
||||
public ItemBridge(String name){
|
||||
super(name);
|
||||
@@ -53,27 +58,31 @@ public class ItemBridge extends Block{
|
||||
public void drawRequestConfigTop(BuildPlan req, Eachable<BuildPlan> list){
|
||||
otherReq = null;
|
||||
list.each(other -> {
|
||||
if(other.block == this && req != other && req.config instanceof Point2 && ((Point2)req.config).equals(other.x - req.x, other.y - req.y)){
|
||||
if(other.block == this && req != other && req.config instanceof Point2 p && p.equals(other.x - req.x, other.y - req.y)){
|
||||
otherReq = other;
|
||||
}
|
||||
});
|
||||
|
||||
if(otherReq == null) return;
|
||||
if(otherReq != null){
|
||||
drawBridge(req, otherReq.drawx(), otherReq.drawy(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawBridge(BuildPlan req, float ox, float oy, float flip){
|
||||
Lines.stroke(8f);
|
||||
|
||||
Tmp.v1.set(otherReq.drawx(), otherReq.drawy()).sub(req.drawx(), req.drawy()).setLength(tilesize/2f);
|
||||
Tmp.v1.set(ox, oy).sub(req.drawx(), req.drawy()).setLength(tilesize/2f);
|
||||
|
||||
Lines.line(
|
||||
bridgeRegion,
|
||||
req.drawx() + Tmp.v1.x,
|
||||
req.drawy() + Tmp.v1.y,
|
||||
otherReq.drawx() - Tmp.v1.x,
|
||||
otherReq.drawy() - Tmp.v1.y, false
|
||||
ox - Tmp.v1.x,
|
||||
oy - Tmp.v1.y, false
|
||||
);
|
||||
|
||||
Draw.rect(arrowRegion, (req.drawx() + otherReq.drawx()) / 2f, (req.drawy() + otherReq.drawy()) / 2f,
|
||||
Angles.angle(req.drawx(), req.drawy(), otherReq.drawx(), otherReq.drawy()));
|
||||
Draw.rect(arrowRegion, (req.drawx() + ox) / 2f, (req.drawy() + oy) / 2f,
|
||||
Angles.angle(req.drawx(), req.drawy(), ox, oy) + flip);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,27 +118,40 @@ public class ItemBridge extends Block{
|
||||
}
|
||||
|
||||
public boolean linkValid(Tile tile, Tile other, boolean checkDouble){
|
||||
if(other == null || tile == null) return false;
|
||||
if(tile.x == other.x){
|
||||
if(Math.abs(tile.y - other.y) > range) return false;
|
||||
}else if(tile.y == other.y){
|
||||
if(Math.abs(tile.x - other.x) > range) return false;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
if(other == null || tile == null || !positionsValid(tile.x, tile.y, other.x, other.y)) return false;
|
||||
|
||||
return ((other.block() == tile.block() && tile.block() == this) || (!(tile.block() instanceof ItemBridge) && other.block() == this))
|
||||
&& (other.team() == tile.team() || tile.block() != this)
|
||||
&& (!checkDouble || ((ItemBridgeBuild)other.build).link != tile.pos());
|
||||
}
|
||||
|
||||
public boolean positionsValid(int x1, int y1, int x2, int y2){
|
||||
if(x1 == x2){
|
||||
return Math.abs(y1 - y2) <= range;
|
||||
}else if(y1 == y2){
|
||||
return Math.abs(x1 - x2) <= range;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Tile findLink(int x, int y){
|
||||
if(world.tiles.in(x, y) && linkValid(world.tile(x, y), world.tile(lastPlaced)) && lastPlaced != Point2.pack(x, y)){
|
||||
return world.tile(lastPlaced);
|
||||
Tile tile = world.tile(x, y);
|
||||
if(tile != null && lastBuild != null && linkValid(tile, lastBuild.tile) && lastBuild.tile != tile){
|
||||
return lastBuild.tile;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewPlan(BuildPlan plan){
|
||||
if(lastPlan != null && lastPlan.config == null && positionsValid(lastPlan.x, lastPlan.y, plan.x, plan.y)){
|
||||
lastPlan.config = new Point2(plan.x - lastPlan.x, plan.y - lastPlan.y);
|
||||
}
|
||||
|
||||
lastPlan = plan;
|
||||
}
|
||||
|
||||
public class ItemBridgeBuild extends Building{
|
||||
public int link = -1;
|
||||
public IntSet incoming = new IntSet();
|
||||
@@ -149,7 +171,7 @@ public class ItemBridge extends Block{
|
||||
link.build.configure(tile.pos());
|
||||
}
|
||||
|
||||
lastPlaced = tile.pos();
|
||||
lastBuild = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user