mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-11 03:08:38 +07:00
Battery Graphical Updates (#8323)
* Battery Graphical Updates * Add the vanilla fields back * Add back topRegion and depricate it
This commit is contained in:
parent
0ccbe68a65
commit
9c3ddc398c
@ -448,6 +448,7 @@ public class ClassMap{
|
||||
classes.put("DrawParticles", mindustry.world.draw.DrawParticles.class);
|
||||
classes.put("DrawPistons", mindustry.world.draw.DrawPistons.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("DrawPumpLiquid", mindustry.world.draw.DrawPumpLiquid.class);
|
||||
classes.put("DrawRegion", mindustry.world.draw.DrawRegion.class);
|
||||
|
@ -4,18 +4,24 @@ import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.draw.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class Battery extends PowerDistributor{
|
||||
public @Load("@-top") TextureRegion topRegion;
|
||||
public DrawBlock drawer;
|
||||
|
||||
public Color emptyLightColor = Color.valueOf("f8c266");
|
||||
public Color fullLightColor = Color.valueOf("fb9567");
|
||||
|
||||
@Deprecated
|
||||
public @Load("@-top") TextureRegion topRegion;
|
||||
|
||||
public Battery(String name){
|
||||
super(name);
|
||||
outputsPower = true;
|
||||
@ -29,14 +35,54 @@ public class Battery extends PowerDistributor{
|
||||
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{
|
||||
@Override
|
||||
public void draw(){
|
||||
Draw.color(emptyLightColor, fullLightColor, power.status);
|
||||
Fill.square(x, y, (tilesize * size / 2f - 1) * Draw.xscl);
|
||||
Draw.color();
|
||||
drawer.draw(this);
|
||||
}
|
||||
|
||||
Draw.rect(topRegion, x, y);
|
||||
@Override
|
||||
public void drawLight(){
|
||||
super.drawLight();
|
||||
drawer.drawLight(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float warmup(){
|
||||
return power.status;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
73
core/src/mindustry/world/draw/DrawPower.java
Normal file
73
core/src/mindustry/world/draw/DrawPower.java
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user