Battery Graphical Updates (#8323)

* Battery Graphical Updates

* Add the vanilla fields back

* Add back topRegion and depricate it
This commit is contained in:
MEEPofFaith 2023-03-25 11:00:08 -07:00 committed by GitHub
parent 0ccbe68a65
commit 9c3ddc398c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 125 additions and 5 deletions

View File

@ -448,6 +448,7 @@ public class ClassMap{
classes.put("DrawParticles", mindustry.world.draw.DrawParticles.class); classes.put("DrawParticles", mindustry.world.draw.DrawParticles.class);
classes.put("DrawPistons", mindustry.world.draw.DrawPistons.class); classes.put("DrawPistons", mindustry.world.draw.DrawPistons.class);
classes.put("DrawPlasma", mindustry.world.draw.DrawPlasma.class); classes.put("DrawPlasma", mindustry.world.draw.DrawPlasma.class);
classes.put("DrawPower", mindustry.world.draw.DrawPower.class);
classes.put("DrawPulseShape", mindustry.world.draw.DrawPulseShape.class); classes.put("DrawPulseShape", mindustry.world.draw.DrawPulseShape.class);
classes.put("DrawPumpLiquid", mindustry.world.draw.DrawPumpLiquid.class); classes.put("DrawPumpLiquid", mindustry.world.draw.DrawPumpLiquid.class);
classes.put("DrawRegion", mindustry.world.draw.DrawRegion.class); classes.put("DrawRegion", mindustry.world.draw.DrawRegion.class);

View File

@ -4,18 +4,24 @@ import arc.graphics.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.*; import arc.math.*;
import arc.struct.*; import arc.struct.*;
import arc.util.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.entities.units.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.world.draw.*;
import mindustry.world.meta.*; import mindustry.world.meta.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class Battery extends PowerDistributor{ public class Battery extends PowerDistributor{
public @Load("@-top") TextureRegion topRegion; public DrawBlock drawer;
public Color emptyLightColor = Color.valueOf("f8c266"); public Color emptyLightColor = Color.valueOf("f8c266");
public Color fullLightColor = Color.valueOf("fb9567"); public Color fullLightColor = Color.valueOf("fb9567");
@Deprecated
public @Load("@-top") TextureRegion topRegion;
public Battery(String name){ public Battery(String name){
super(name); super(name);
outputsPower = true; outputsPower = true;
@ -29,14 +35,54 @@ public class Battery extends PowerDistributor{
update = false; update = false;
} }
@Override
public void init(){
super.init();
if(drawer == null){
drawer = new DrawMulti(new DrawDefault(), new DrawPower(){{
emptyLightColor = Battery.this.emptyLightColor;
fullLightColor = Battery.this.fullLightColor;
}}, new DrawRegion("-top"));
}
}
@Override
public void load(){
super.load();
drawer.load(this);
}
@Override
public void drawPlanRegion(BuildPlan plan, Eachable<BuildPlan> list){
drawer.drawPlan(this, plan, list);
}
@Override
public TextureRegion[] icons(){
return drawer.finalIcons(this);
}
@Override
public void getRegionsToOutline(Seq<TextureRegion> out){
drawer.getRegionsToOutline(this, out);
}
public class BatteryBuild extends Building{ public class BatteryBuild extends Building{
@Override @Override
public void draw(){ public void draw(){
Draw.color(emptyLightColor, fullLightColor, power.status); drawer.draw(this);
Fill.square(x, y, (tilesize * size / 2f - 1) * Draw.xscl); }
Draw.color();
Draw.rect(topRegion, x, y); @Override
public void drawLight(){
super.drawLight();
drawer.drawLight(this);
}
@Override
public float warmup(){
return power.status;
} }
@Override @Override

View File

@ -0,0 +1,73 @@
package mindustry.world.draw;
import arc.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.util.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.world.*;
import static mindustry.Vars.*;
public class DrawPower extends DrawBlock{
public TextureRegion emptyRegion, fullRegion;
public String suffix = "-power";
public boolean drawPlan = true;
/** If false, fades between emptyRegion and fullRegion instead of mixcol between empty and full colors. */
public boolean mixcol = true;
public Color emptyLightColor = Color.valueOf("f8c266");
public Color fullLightColor = Color.valueOf("fb9567");
/** Any number <=0 disables layer changes. */
public float layer = -1;
public DrawPower(){
}
public DrawPower(String suffix){
this.suffix = suffix;
}
@Override
public void draw(Building build){
float z = Draw.z();
if(layer > 0) Draw.z(layer);
if(mixcol){
Draw.color(emptyLightColor, fullLightColor, build.power.status);
if(emptyRegion.found()){
Draw.rect(emptyRegion, build.x, build.y);
}else{
Fill.square(build.x, build.y, (tilesize * build.block.size / 2f - 1) * Draw.xscl);
}
}else{
Draw.rect(emptyRegion, build.x, build.y);
Draw.alpha(build.power.status);
Draw.rect(fullRegion, build.x, build.y);
}
Draw.color();
Draw.z(z);
}
@Override
public void drawPlan(Block block, BuildPlan plan, Eachable<BuildPlan> list){
if(!drawPlan || mixcol || !emptyRegion.found()) return;
Draw.rect(emptyRegion, plan.drawx(), plan.drawy());
}
@Override
public TextureRegion[] icons(Block block){
return !mixcol && emptyRegion.found() ? new TextureRegion[]{emptyRegion} : new TextureRegion[]{};
}
@Override
public void load(Block block){
if(mixcol){
emptyRegion = Core.atlas.find(block.name + suffix);
}else{
emptyRegion = Core.atlas.find(block.name + suffix + "-empty");
fullRegion = Core.atlas.find(block.name + suffix + "-full");
}
}
}