Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better range visualisation #5968

Closed
22 changes: 19 additions & 3 deletions core/src/mindustry/graphics/Drawf.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,18 @@ public static void liquid(TextureRegion region, float x, float y, float alpha, C
Draw.color();
}

public static void dashCircle(float x, float y, float rad, Color color){
Lines.stroke(3f, Pal.gray);
public static void dashCircle(float x, float y, float rad, Color color, float alpha){
Lines.stroke(3f, Tmp.c1.set(Pal.gray).mulA(alpha));
Lines.dashCircle(x, y, rad);
Lines.stroke(1f, color);
Lines.stroke(1f, Tmp.c1.set(color).mulA(alpha));
Lines.dashCircle(x, y, rad);
Draw.reset();
}

public static void dashCircle(float x, float y, float rad, Color color){
dashCircle(x, y, rad, color, 1f);
}

public static void circles(float x, float y, float rad){
circles(x, y, rad, Pal.accent);
}
Expand Down Expand Up @@ -373,6 +377,18 @@ public static void square(float x, float y, float radius){
square(x, y, radius, 45);
}

public static void polygon(float x, float y, int sides, float radius, float rotation, Color color, float alpha){
Lines.stroke(3f, Tmp.c1.set(Pal.gray).mulA(alpha));
Lines.poly(x, y, sides, radius, rotation);
Lines.stroke(1f, Tmp.c1.set(color).mulA(alpha));
Lines.poly(x, y, sides, radius, rotation);
Draw.reset();
}

public static void polygon(float x, float y, int sides, float radius, float rotation, Color color){
polygon(x, y, sides, radius, rotation, color, 1f);
}

public static void arrow(float x, float y, float x2, float y2, float length, float radius){
arrow(x, y, x2, y2, length, radius, Pal.accent);
}
Expand Down
24 changes: 17 additions & 7 deletions core/src/mindustry/world/blocks/defense/ForceProjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,11 @@ public void setStats(){
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
super.drawPlace(x, y, rotation, valid);
float wx = x * tilesize + offset, wy = y * tilesize + offset;

Draw.color(Pal.gray);
Lines.stroke(3f);
Lines.poly(x * tilesize + offset, y * tilesize + offset, sides, radius, shieldRotation);
Draw.color(player.team().color);
Lines.stroke(1f);
Lines.poly(x * tilesize + offset, y * tilesize + offset, sides, radius, shieldRotation);
Draw.color();
if(itemConsumer != null) Drawf.polygon(wx, wy, sides, radius + phaseRadiusBoost, shieldRotation, player.team().color, 0.5f);

Drawf.polygon(wx, wy, sides, radius, shieldRotation, player.team().color);
}

public class ForceBuild extends Building implements Ranged{
Expand Down Expand Up @@ -262,6 +259,19 @@ public void drawShield(){
Draw.reset();
}

@Override
public void drawSelect(){
super.drawSelect();
float realRad = realRadius();

float boostRad = radius + phaseRadiusBoost;
if(realRad < boostRad && itemConsumer != null){
Drawf.polygon(x, y, sides, boostRad, shieldRotation, team.color, 0.5f - Mathf.curve(realRad, radius + phaseRadiusBoost * 0.9f, boostRad) / 2f);
}

if(realRad < radius) Drawf.polygon(x, y, sides, radius, shieldRotation, team.color, 1f - Mathf.curve(realRad, radius * 0.9f, radius));
}

@Override
public void write(Writes write){
super.write(write);
Expand Down
31 changes: 25 additions & 6 deletions core/src/mindustry/world/blocks/defense/MendProjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class MendProjector extends Block{
public float healPercent = 12f;
public float phaseBoost = 12f;
public float phaseRangeBoost = 50f;
public boolean hasBoost = true;
public float useTime = 400f;

public MendProjector(String name){
Expand Down Expand Up @@ -53,17 +54,26 @@ public void setStats(){
stats.add(Stat.repairTime, (int)(100f / healPercent * reload / 60f), StatUnit.seconds);
stats.add(Stat.range, range / tilesize, StatUnit.blocks);

stats.add(Stat.boostEffect, phaseRangeBoost / tilesize, StatUnit.blocks);
stats.add(Stat.boostEffect, (phaseBoost + healPercent) / healPercent, StatUnit.timesSpeed);
if(hasBoost){
stats.add(Stat.boostEffect, phaseRangeBoost / tilesize, StatUnit.blocks);
stats.add(Stat.boostEffect, (phaseBoost + healPercent) / healPercent, StatUnit.timesSpeed);
}
}

@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
super.drawPlace(x, y, rotation, valid);

Drawf.dashCircle(x * tilesize + offset, y * tilesize + offset, range, baseColor);
float wx = x * tilesize + offset, wy = y * tilesize + offset;

if(hasBoost){
indexer.eachBlock(player.team(), wx, wy, range + phaseRangeBoost, other -> Mathf.dst(x * tilesize + offset, y * tilesize + offset, other.x, other.y) >= range, other -> Drawf.selected(other, Tmp.c1.set(phaseColor).a(Mathf.absin(4f, 1f) / 2f)));

Drawf.dashCircle(wx, wy, range + phaseRangeBoost, phaseColor, 0.5f);
}

indexer.eachBlock(player.team(), wx, wy, range, other -> true, other -> Drawf.selected(other, Tmp.c1.set(baseColor).a(Mathf.absin(4f, 1f))));

indexer.eachBlock(player.team(), x * tilesize + offset, y * tilesize + offset, range, other -> true, other -> Drawf.selected(other, Tmp.c1.set(baseColor).a(Mathf.absin(4f, 1f))));
Drawf.dashCircle(wx, wy, range, baseColor);
}

public class MendBuild extends Building implements Ranged{
Expand All @@ -82,7 +92,9 @@ public void updateTile(){
heat = Mathf.lerpDelta(heat, efficiency > 0 && canHeal ? 1f : 0f, 0.08f);
charge += heat * delta();

phaseHeat = Mathf.lerpDelta(phaseHeat, optionalEfficiency, 0.1f);
if(hasBoost){
phaseHeat = Mathf.lerpDelta(phaseHeat, optionalEfficiency, 0.1f);
}

if(optionalEfficiency > 0 && timer(timerUse, useTime) && canHeal){
consume();
Expand Down Expand Up @@ -110,6 +122,13 @@ public double sense(LAccess sensor){
public void drawSelect(){
float realRange = range + phaseHeat * phaseRangeBoost;

if(hasBoost && phaseHeat <= 0.999f){
float a = 0.5f - Mathf.curve(phaseHeat, 0.9f, 1f) / 2f;
indexer.eachBlock(this, range + phaseRangeBoost, other -> dst(other) >= range, other -> Drawf.selected(other, Tmp.c1.set(phaseColor).a(Mathf.absin(4f, 1f) * a)));

Drawf.dashCircle(x, y, range + phaseRangeBoost, phaseColor, a);
}

indexer.eachBlock(this, realRange, other -> true, other -> Drawf.selected(other, Tmp.c1.set(baseColor).a(Mathf.absin(4f, 1f))));

Drawf.dashCircle(x, y, realRange, baseColor);
Expand Down
18 changes: 16 additions & 2 deletions core/src/mindustry/world/blocks/defense/OverdriveProjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ public boolean outputsItems(){
@Override
public void drawPlace(int x, int y, int rotation, boolean valid){
super.drawPlace(x, y, rotation, valid);
float wx = x * tilesize + offset, wy = y * tilesize + offset;

Drawf.dashCircle(x * tilesize + offset, y * tilesize + offset, range, baseColor);
if(hasBoost){
indexer.eachBlock(player.team(), wx, wy, range + phaseRangeBoost, other -> other.block.canOverdrive && Mathf.dst(x * tilesize + offset, y * tilesize + offset, other.x, other.y) >= range, other -> Drawf.selected(other, Tmp.c1.set(phaseColor).a(Mathf.absin(4f, 1f) / 2f)));

Drawf.dashCircle(wx, wy, range + phaseRangeBoost, phaseColor, 0.5f);
}

indexer.eachBlock(player.team(), wx, wy, range, other -> other.block.canOverdrive, other -> Drawf.selected(other, Tmp.c1.set(baseColor).a(Mathf.absin(4f, 1f))));

indexer.eachBlock(player.team(), x * tilesize + offset, y * tilesize + offset, range, other -> other.block.canOverdrive, other -> Drawf.selected(other, Tmp.c1.set(baseColor).a(Mathf.absin(4f, 1f))));
Drawf.dashCircle(wx, wy, range, baseColor);
}

@Override
Expand Down Expand Up @@ -122,6 +129,13 @@ public float realBoost(){
public void drawSelect(){
float realRange = range + phaseHeat * phaseRangeBoost;

if(hasBoost && phaseHeat <= 0.999f){
float a = 0.5f - Mathf.curve(phaseHeat, 0.9f, 1f) / 2f;
indexer.eachBlock(this, range + phaseRangeBoost, other -> other.block.canOverdrive && dst(other) >= range, other -> Drawf.selected(other, Tmp.c1.set(phaseColor).a(Mathf.absin(4f, 1f) * a)));

Drawf.dashCircle(x, y, range + phaseRangeBoost, phaseColor, a);
}

indexer.eachBlock(this, realRange, other -> other.block.canOverdrive, other -> Drawf.selected(other, Tmp.c1.set(baseColor).a(Mathf.absin(4f, 1f))));

Drawf.dashCircle(x, y, realRange, baseColor);
Expand Down