Better bridge linking
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package mindustry.entities.comp;
|
package mindustry.entities.comp;
|
||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
|
import arc.graphics.*;
|
||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.math.geom.*;
|
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. */
|
/** Draw all current build plans. Does not draw the beam effect, only the positions. */
|
||||||
void drawBuildPlans(){
|
void drawBuildPlans(){
|
||||||
|
|
||||||
for(BuildPlan request : plans){
|
for(BuildPlan plan : plans){
|
||||||
if(request.progress > 0.01f || (buildPlan() == request && request.initialized && (within(request.x * tilesize, request.y * tilesize, buildingRange) || state.isEditor()))) continue;
|
if(plan.progress > 0.01f || (buildPlan() == plan && plan.initialized && (within(plan.x * tilesize, plan.y * tilesize, buildingRange) || state.isEditor()))) continue;
|
||||||
|
drawPlan(plan, 1f);
|
||||||
drawPlan(request, 1f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
@@ -137,6 +137,11 @@ abstract class BuilderComp implements Posc, Teamc, Rotc{
|
|||||||
request.block.drawPlan(request, control.input.allRequests(),
|
request.block.drawPlan(request, control.input.allRequests(),
|
||||||
Build.validPlace(request.block, team, request.x, request.y, request.rotation) || control.input.requestMatches(request),
|
Build.validPlace(request.block, team, request.x, request.y, request.rotation) || control.input.requestMatches(request),
|
||||||
alpha);
|
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
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return "BuildRequest{" +
|
return "BuildPlan{" +
|
||||||
"x=" + x +
|
"x=" + x +
|
||||||
", y=" + y +
|
", y=" + y +
|
||||||
", rotation=" + rotation +
|
", rotation=" + rotation +
|
||||||
", recipe=" + block +
|
", block=" + block +
|
||||||
", breaking=" + breaking +
|
", breaking=" + breaking +
|
||||||
", progress=" + progress +
|
", progress=" + progress +
|
||||||
", initialized=" + initialized +
|
", initialized=" + initialized +
|
||||||
|
", config=" + config +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,7 +168,6 @@ public class DesktopInput extends InputHandler{
|
|||||||
block.drawRequestConfig(brequest, allRequests());
|
block.drawRequestConfig(brequest, allRequests());
|
||||||
brequest.config = null;
|
brequest.config = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -743,6 +743,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
for(BuildPlan req : requests){
|
for(BuildPlan req : requests){
|
||||||
if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){
|
if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){
|
||||||
BuildPlan copy = req.copy();
|
BuildPlan copy = req.copy();
|
||||||
|
req.block.onNewPlan(copy);
|
||||||
player.unit().addBuild(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){
|
public void tryBreakBlock(int x, int y){
|
||||||
if(validBreak(x, y)){
|
if(validBreak(x, y)){
|
||||||
breakBlock(x, y);
|
breakBlock(x, y);
|
||||||
@@ -1112,14 +1107,6 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
return Build.validBreak(player.team(), x, y);
|
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){
|
public void breakBlock(int x, int y){
|
||||||
Tile tile = world.tile(x, y);
|
Tile tile = world.tile(x, y);
|
||||||
if(tile != null && tile.build != null) tile = tile.build.tile;
|
if(tile != null && tile.build != null) tile = tile.build.tile;
|
||||||
|
|||||||
@@ -354,6 +354,9 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||||||
|
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
drawRequest(request);
|
drawRequest(request);
|
||||||
|
if(!request.breaking){
|
||||||
|
drawOverRequest(request);
|
||||||
|
}
|
||||||
|
|
||||||
//draw last placed request
|
//draw last placed request
|
||||||
if(!request.breaking && request == lastPlaced && request.block != null){
|
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)){
|
}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
|
//add to selection queue if it's a valid place position
|
||||||
selectRequests.add(lastPlaced = new BuildPlan(cursor.x, cursor.y, rotation, block, block.nextConfig()));
|
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)){
|
}else if(mode == breaking && validBreak(linked.x,linked.y) && !hasRequest(linked)){
|
||||||
//add to selection queue if it's a valid BREAK position
|
//add to selection queue if it's a valid BREAK position
|
||||||
selectRequests.add(new BuildPlan(linked.x, linked.y));
|
selectRequests.add(new BuildPlan(linked.x, linked.y));
|
||||||
|
|||||||
@@ -393,6 +393,11 @@ public class Block extends UnlockableContent{
|
|||||||
return null;
|
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){
|
public void drawPlan(BuildPlan req, Eachable<BuildPlan> list, boolean valid){
|
||||||
drawPlan(req, list, valid, 1f);
|
drawPlan(req, list, valid, 1f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,12 @@ public class ItemBridge extends Block{
|
|||||||
public @Load("@-end") TextureRegion endRegion;
|
public @Load("@-end") TextureRegion endRegion;
|
||||||
public @Load("@-bridge") TextureRegion bridgeRegion;
|
public @Load("@-bridge") TextureRegion bridgeRegion;
|
||||||
public @Load("@-arrow") TextureRegion arrowRegion;
|
public @Load("@-arrow") TextureRegion arrowRegion;
|
||||||
public int lastPlaced = -1;
|
|
||||||
|
//for autolink
|
||||||
|
@Nullable
|
||||||
|
public ItemBridgeBuild lastBuild;
|
||||||
|
@Nullable
|
||||||
|
public BuildPlan lastPlan;
|
||||||
|
|
||||||
public ItemBridge(String name){
|
public ItemBridge(String name){
|
||||||
super(name);
|
super(name);
|
||||||
@@ -53,27 +58,31 @@ public class ItemBridge extends Block{
|
|||||||
public void drawRequestConfigTop(BuildPlan req, Eachable<BuildPlan> list){
|
public void drawRequestConfigTop(BuildPlan req, Eachable<BuildPlan> list){
|
||||||
otherReq = null;
|
otherReq = null;
|
||||||
list.each(other -> {
|
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;
|
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);
|
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(
|
Lines.line(
|
||||||
bridgeRegion,
|
bridgeRegion,
|
||||||
req.drawx() + Tmp.v1.x,
|
req.drawx() + Tmp.v1.x,
|
||||||
req.drawy() + Tmp.v1.y,
|
req.drawy() + Tmp.v1.y,
|
||||||
otherReq.drawx() - Tmp.v1.x,
|
ox - Tmp.v1.x,
|
||||||
otherReq.drawy() - Tmp.v1.y, false
|
oy - Tmp.v1.y, false
|
||||||
);
|
);
|
||||||
|
|
||||||
Draw.rect(arrowRegion, (req.drawx() + otherReq.drawx()) / 2f, (req.drawy() + otherReq.drawy()) / 2f,
|
Draw.rect(arrowRegion, (req.drawx() + ox) / 2f, (req.drawy() + oy) / 2f,
|
||||||
Angles.angle(req.drawx(), req.drawy(), otherReq.drawx(), otherReq.drawy()));
|
Angles.angle(req.drawx(), req.drawy(), ox, oy) + flip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -109,27 +118,40 @@ public class ItemBridge extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean linkValid(Tile tile, Tile other, boolean checkDouble){
|
public boolean linkValid(Tile tile, Tile other, boolean checkDouble){
|
||||||
if(other == null || tile == null) return false;
|
if(other == null || tile == null || !positionsValid(tile.x, tile.y, other.x, other.y)) 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ((other.block() == tile.block() && tile.block() == this) || (!(tile.block() instanceof ItemBridge) && other.block() == this))
|
return ((other.block() == tile.block() && tile.block() == this) || (!(tile.block() instanceof ItemBridge) && other.block() == this))
|
||||||
&& (other.team() == tile.team() || tile.block() != this)
|
&& (other.team() == tile.team() || tile.block() != this)
|
||||||
&& (!checkDouble || ((ItemBridgeBuild)other.build).link != tile.pos());
|
&& (!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){
|
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)){
|
Tile tile = world.tile(x, y);
|
||||||
return world.tile(lastPlaced);
|
if(tile != null && lastBuild != null && linkValid(tile, lastBuild.tile) && lastBuild.tile != tile){
|
||||||
|
return lastBuild.tile;
|
||||||
}
|
}
|
||||||
return null;
|
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 class ItemBridgeBuild extends Building{
|
||||||
public int link = -1;
|
public int link = -1;
|
||||||
public IntSet incoming = new IntSet();
|
public IntSet incoming = new IntSet();
|
||||||
@@ -149,7 +171,7 @@ public class ItemBridge extends Block{
|
|||||||
link.build.configure(tile.pos());
|
link.build.configure(tile.pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPlaced = tile.pos();
|
lastBuild = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
org.gradle.daemon=true
|
org.gradle.daemon=true
|
||||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||||
archash=0e5096b145f78d010ee30ea9730d98e42257d705
|
archash=2eb670fd55b9210b804ae729293b358d5368f9f3
|
||||||
|
|||||||
Reference in New Issue
Block a user