Building cleanup

This commit is contained in:
Anuken
2020-12-17 11:38:03 -05:00
parent 0d81681af5
commit 9f5183b36f
6 changed files with 47 additions and 25 deletions

View File

@@ -117,24 +117,29 @@ abstract class BuilderComp implements Posc, Teamc, Rotc{
current.progress = entity.progress;
}
/** Draw all current build requests. Does not draw the beam effect, only the positions. */
void drawBuildRequests(){
/** 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 && (dst(request.x * tilesize, request.y * tilesize) <= buildingRange || state.isEditor()))) continue;
if(request.progress > 0.01f || (buildPlan() == request && request.initialized && (within(request.x * tilesize, request.y * tilesize, buildingRange) || state.isEditor()))) continue;
request.animScale = 1f;
if(request.breaking){
control.input.drawBreaking(request);
}else{
request.block.drawRequest(request, control.input.allRequests(),
Build.validPlace(request.block, team, request.x, request.y, request.rotation) || control.input.requestMatches(request));
}
drawPlan(request, 1f);
}
Draw.reset();
}
void drawPlan(BuildPlan request, float alpha){
request.animScale = 1f;
if(request.breaking){
control.input.drawBreaking(request);
}else{
request.block.drawPlan(request, control.input.allRequests(),
Build.validPlace(request.block, team, request.x, request.y, request.rotation) || control.input.requestMatches(request),
alpha);
}
}
/** @return whether this request should be skipped, in favor of the next one. */
boolean shouldSkip(BuildPlan request, @Nullable Building core){
//requests that you have at least *started* are considered
@@ -193,8 +198,10 @@ abstract class BuilderComp implements Posc, Teamc, Rotc{
boolean activelyBuilding(){
//not actively building when not near the build plan
if(isBuilding() && !within(buildPlan(), state.rules.infiniteResources ? Float.MAX_VALUE : buildingRange)){
return false;
if(isBuilding()){
if(!within(buildPlan(), state.rules.infiniteResources ? Float.MAX_VALUE : buildingRange)){
return false;
}
}
return isBuilding() && updateBuilding;
}
@@ -206,19 +213,26 @@ abstract class BuilderComp implements Posc, Teamc, Rotc{
}
public void draw(){
if(!isBuilding() || !updateBuilding || !canBuild()) return;
if(!activelyBuilding()) return;
//TODO check correctness
Draw.z(Layer.flyingUnit);
BuildPlan plan = buildPlan();
Tile tile = world.tile(plan.x, plan.y);
var core = team.core();
if(tile == null || (!within(tile, buildingRange) && !state.isEditor())){
return;
}
//draw remote plans.
if(core != null && !isLocal() && !(tile.block() instanceof ConstructBlock)){
Draw.z(Layer.plans - 1f);
drawPlan(plan, 0.5f);
Draw.z(Layer.flyingUnit);
}
int size = plan.breaking ? tile.block().size : plan.block.size;
float tx = plan.drawx(), ty = plan.drawy();

View File

@@ -28,7 +28,7 @@ public class OverlayRenderer{
if(player.dead()) return;
if(player.isBuilder()){
player.unit().drawBuildRequests();
player.unit().drawBuildPlans();
}
input.drawBottom();

View File

@@ -123,7 +123,7 @@ public class DesktopInput extends InputHandler{
drawArrow(sreq.block, sreq.x, sreq.y, sreq.rotation, valid);
}
sreq.block.drawRequest(sreq, allRequests(), valid);
sreq.block.drawPlan(sreq, allRequests(), valid);
drawSelected(sreq.x, sreq.y, sreq.block, getRequest(sreq.x, sreq.y, sreq.block.size, sreq) != null ? Pal.remove : Pal.accent);
}

View File

@@ -759,14 +759,14 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
protected void drawRequest(BuildPlan request){
request.block.drawRequest(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation));
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation));
}
/** Draws a placement icon for a specific block. */
protected void drawRequest(int x, int y, Block block, int rotation){
brequest.set(x, y, rotation, block);
brequest.animScale = 1f;
block.drawRequest(brequest, allRequests(), validPlace(x, y, block, rotation));
block.drawPlan(brequest, allRequests(), validPlace(x, y, block, rotation));
}
/** Remove everything from the queue in a selection. */
@@ -1048,7 +1048,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public boolean canShoot(){
return block == null && !onConfigurable() && !isDroppingItem() && !player.unit().activelyBuilding() &&
!(player.unit() instanceof Mechc && player.unit().isFlying());
!(player.unit() instanceof Mechc && player.unit().isFlying()) && !player.unit().mining();
}
public boolean onConfigurable(){

View File

@@ -292,7 +292,7 @@ public class MobileInput extends InputHandler implements GestureListener{
if(request.breaking){
drawSelected(request.x, request.y, tile.block(), Pal.remove);
}else{
request.block.drawRequest(request, allRequests(), true);
request.block.drawPlan(request, allRequests(), true);
}
}
@@ -311,7 +311,7 @@ public class MobileInput extends InputHandler implements GestureListener{
if(i == lineRequests.size - 1 && request.block.rotate){
drawArrow(block, request.x, request.y, request.rotation);
}
request.block.drawRequest(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation) && getRequest(request.x, request.y, request.block.size, null) == null);
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation) && getRequest(request.x, request.y, request.block.size, null) == null);
drawSelected(request.x, request.y, request.block, Pal.accent);
}
}else if(mode == breaking){
@@ -391,7 +391,7 @@ public class MobileInput extends InputHandler implements GestureListener{
if(request.breaking){
drawSelected(request.x, request.y, request.tile().block(), Pal.remove);
}else{
request.block.drawRequest(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation));
request.block.drawPlan(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation));
drawSelected(request.x, request.y, request.block, Pal.accent);
}
}
@@ -736,6 +736,10 @@ public class MobileInput extends InputHandler implements GestureListener{
i--;
}
}
if(player.shooting && (player.unit().activelyBuilding() || player.unit().mining())){
player.shooting = false;
}
}
protected void autoPan(){
@@ -913,7 +917,7 @@ public class MobileInput extends InputHandler implements GestureListener{
}
//update shooting if not building + not mining
if(!player.unit().isBuilding() && player.unit().mineTile == null){
if(!player.unit().activelyBuilding() && player.unit().mineTile == null){
//autofire targeting
if(manualShooting){

View File

@@ -393,10 +393,14 @@ public class Block extends UnlockableContent{
return null;
}
public void drawRequest(BuildPlan req, Eachable<BuildPlan> list, boolean valid){
public void drawPlan(BuildPlan req, Eachable<BuildPlan> list, boolean valid){
drawPlan(req, list, valid, 1f);
}
public void drawPlan(BuildPlan req, Eachable<BuildPlan> list, boolean valid, float alpha){
Draw.reset();
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime, 6f, 0.28f));
Draw.alpha(1f);
Draw.alpha(alpha);
float prevScale = Draw.scl;
Draw.scl *= req.animScale;
drawRequestRegion(req, list);