Editor map fix / Crafter renderer system
This commit is contained in:
@@ -173,7 +173,6 @@ public class Block extends UnlockableContent{
|
||||
public boolean instantTransfer = false;
|
||||
|
||||
protected Prov<Tilec> entityType = null; //initialized later
|
||||
//TODO move
|
||||
public ObjectMap<Class<?>, Cons2> configurations = new ObjectMap<>();
|
||||
|
||||
//TODO move
|
||||
@@ -181,10 +180,6 @@ public class Block extends UnlockableContent{
|
||||
protected TextureRegion[] variantRegions, editorVariantRegions;
|
||||
public TextureRegion region, editorIcon;
|
||||
|
||||
//TODO remove completely
|
||||
protected TextureRegion[] cacheRegions = {};
|
||||
protected Seq<String> cacheRegionStrings = new Seq<>();
|
||||
|
||||
//TODO move
|
||||
public static TextureRegion[][] cracks;
|
||||
protected static final Seq<Tile> tempTiles = new Seq<>();
|
||||
@@ -200,7 +195,6 @@ public class Block extends UnlockableContent{
|
||||
initEntity();
|
||||
}
|
||||
|
||||
//TODO rename to draw() once class refactoring is done.
|
||||
public void drawBase(Tile tile){
|
||||
//delegates to entity unless it is null
|
||||
if(tile.entity != null){
|
||||
@@ -574,19 +568,6 @@ public class Block extends UnlockableContent{
|
||||
}
|
||||
}
|
||||
|
||||
/** Adds a region by name to be loaded, with the final name "{name}-suffix". Returns an ID to looks this region up by in {@link #re(int)}.
|
||||
* DO NOT USE. This will eventually be removed. */
|
||||
protected int re(String suffix){
|
||||
cacheRegionStrings.add(name + suffix);
|
||||
return cacheRegionStrings.size - 1;
|
||||
}
|
||||
|
||||
/** Returns an internally cached region by ID.
|
||||
* DO NOT USE. This will eventually be removed*/
|
||||
protected TextureRegion re(int id){
|
||||
return cacheRegions[id];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayInfo(Table table){
|
||||
ContentDisplay.displayBlock(table, this);
|
||||
@@ -631,11 +612,6 @@ public class Block extends UnlockableContent{
|
||||
public void load(){
|
||||
region = Core.atlas.find(name);
|
||||
|
||||
cacheRegions = new TextureRegion[cacheRegionStrings.size];
|
||||
for(int i = 0; i < cacheRegions.length; i++){
|
||||
cacheRegions[i] = Core.atlas.find(cacheRegionStrings.get(i));
|
||||
}
|
||||
|
||||
if(cracks == null || (cracks[0][0].getTexture() != null && cracks[0][0].getTexture().isDisposed())){
|
||||
cracks = new TextureRegion[maxCrackSize][crackRegions];
|
||||
for(int size = 1; size <= maxCrackSize; size++){
|
||||
|
||||
@@ -160,6 +160,11 @@ public class Floor extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] icons(){
|
||||
return new TextureRegion[]{Core.atlas.find(Core.atlas.has(name) ? name : name + "1")};
|
||||
}
|
||||
|
||||
public boolean isDeep(){
|
||||
return drownTime > 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package mindustry.world.blocks.production;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.io.*;
|
||||
@@ -10,6 +9,7 @@ import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.draw.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
public class GenericCrafter extends Block{
|
||||
@@ -21,8 +21,10 @@ public class GenericCrafter extends Block{
|
||||
public Effect updateEffect = Fx.none;
|
||||
public float updateEffectChance = 0.04f;
|
||||
|
||||
public Cons<GenericCrafterEntity> drawer = null;
|
||||
public Prov<TextureRegion[]> drawIcons = null;
|
||||
public DrawBlock drawer = new DrawBlock();
|
||||
|
||||
//public Cons<GenericCrafterEntity> drawer = null;
|
||||
//public Prov<TextureRegion[]> drawIcons = null;
|
||||
|
||||
public GenericCrafter(String name){
|
||||
super(name);
|
||||
@@ -54,6 +56,13 @@ public class GenericCrafter extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
|
||||
drawer.load(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
outputsLiquid = outputLiquid != null;
|
||||
@@ -62,7 +71,7 @@ public class GenericCrafter extends Block{
|
||||
|
||||
@Override
|
||||
public TextureRegion[] icons(){
|
||||
return drawIcons == null ? super.icons() : drawIcons.get();
|
||||
return drawer.icons(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,11 +86,7 @@ public class GenericCrafter extends Block{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
if(drawer == null){
|
||||
super.draw();
|
||||
}else{
|
||||
drawer.get(this);
|
||||
}
|
||||
drawer.draw(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
46
core/src/mindustry/world/draw/DrawAnimation.java
Normal file
46
core/src/mindustry/world/draw/DrawAnimation.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package mindustry.world.draw;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.production.GenericCrafter.*;
|
||||
|
||||
public class DrawAnimation extends DrawBlock{
|
||||
public int frameCount = 3;
|
||||
public float frameSpeed = 5f;
|
||||
public boolean sine = true;
|
||||
public TextureRegion[] frames;
|
||||
public TextureRegion liquid, top;
|
||||
|
||||
@Override
|
||||
public void draw(GenericCrafterEntity entity){
|
||||
Draw.rect(entity.block.region, entity.x, entity.y);
|
||||
Draw.rect(
|
||||
sine ?
|
||||
frames[(int)Mathf.absin(entity.totalProgress, frameSpeed, frameCount - 0.001f)] :
|
||||
frames[(int)((entity.totalProgress / frameSpeed) % frameCount)],
|
||||
entity.x, entity.y);
|
||||
Draw.color(Color.clear, entity.liquids.current().color, entity.liquids.total() / entity.block.liquidCapacity);
|
||||
Draw.rect(liquid, entity.x, entity.y);
|
||||
Draw.color();
|
||||
Draw.rect(top, entity.x, entity.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Block block){
|
||||
frames = new TextureRegion[frameCount];
|
||||
for(int i = 0; i < frameCount; i++){
|
||||
frames[i] = Core.atlas.find(block.name + "-frame" + i);
|
||||
}
|
||||
|
||||
liquid = Core.atlas.find(block.name + "-liquid");
|
||||
top = Core.atlas.find(block.name + "-top");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] icons(Block block){
|
||||
return new TextureRegion[]{block.region, top};
|
||||
}
|
||||
}
|
||||
25
core/src/mindustry/world/draw/DrawBlock.java
Normal file
25
core/src/mindustry/world/draw/DrawBlock.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package mindustry.world.draw;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.production.GenericCrafter.*;
|
||||
|
||||
/** An implementation of custom rendering behavior for a block.
|
||||
* This is used mostly for mods. */
|
||||
public class DrawBlock{
|
||||
|
||||
/** Draws the block. */
|
||||
public void draw(GenericCrafterEntity entity){
|
||||
Draw.rect(entity.block.region, entity.x, entity.y, entity.block.rotate ? entity.rotdeg() : 0);
|
||||
}
|
||||
|
||||
/** Load any relevant texture regions. */
|
||||
public void load(Block block){
|
||||
|
||||
}
|
||||
|
||||
/** @return the generated icons to be used for this block. */
|
||||
public TextureRegion[] icons(Block block){
|
||||
return new TextureRegion[]{block.region};
|
||||
}
|
||||
}
|
||||
25
core/src/mindustry/world/draw/DrawGlow.java
Normal file
25
core/src/mindustry/world/draw/DrawGlow.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package mindustry.world.draw;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.production.GenericCrafter.*;
|
||||
|
||||
public class DrawGlow extends DrawBlock{
|
||||
public float glowAmount = 0.9f, glowScale = 3f;
|
||||
public TextureRegion top;
|
||||
|
||||
@Override
|
||||
public void draw(GenericCrafterEntity entity){
|
||||
Draw.rect(entity.block.region, entity.x, entity.y);
|
||||
Draw.alpha(Mathf.absin(entity.totalProgress, glowScale, glowAmount) * entity.warmup);
|
||||
Draw.rect(top, entity.x, entity.y);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Block block){
|
||||
top = Core.atlas.find(block.name + "-top");
|
||||
}
|
||||
}
|
||||
39
core/src/mindustry/world/draw/DrawMixer.java
Normal file
39
core/src/mindustry/world/draw/DrawMixer.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package mindustry.world.draw;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.production.*;
|
||||
import mindustry.world.blocks.production.GenericCrafter.*;
|
||||
|
||||
public class DrawMixer extends DrawBlock{
|
||||
public TextureRegion liquid, top, bottom;
|
||||
|
||||
@Override
|
||||
public void draw(GenericCrafterEntity entity){
|
||||
float rotation = entity.block.rotate ? entity.rotdeg() : 0;
|
||||
|
||||
Draw.rect(bottom, entity.x, entity.y, rotation);
|
||||
|
||||
if(entity.liquids.total() > 0.001f){
|
||||
Draw.color(((GenericCrafter)entity.block).outputLiquid.liquid.color);
|
||||
Draw.alpha(entity.liquids.get(((GenericCrafter)entity.block).outputLiquid.liquid) / entity.block.liquidCapacity);
|
||||
Draw.rect(liquid, entity.x, entity.y, rotation);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
Draw.rect(top, entity.x, entity.y, rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Block block){
|
||||
liquid = Core.atlas.find(block.name + "-liquid");
|
||||
top = Core.atlas.find(block.name + "-top");
|
||||
bottom = Core.atlas.find(block.name + "-bottom");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] icons(Block block){
|
||||
return new TextureRegion[]{bottom, top};
|
||||
}
|
||||
}
|
||||
26
core/src/mindustry/world/draw/DrawRotator.java
Normal file
26
core/src/mindustry/world/draw/DrawRotator.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package mindustry.world.draw;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.production.GenericCrafter.*;
|
||||
|
||||
public class DrawRotator extends DrawBlock{
|
||||
public TextureRegion rotator;
|
||||
|
||||
@Override
|
||||
public void draw(GenericCrafterEntity entity){
|
||||
Draw.rect(entity.block.region, entity.x, entity.y);
|
||||
Draw.rect(rotator, entity.x, entity.y, entity.totalProgress * 2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Block block){
|
||||
rotator = Core.atlas.find(block.name + "-rotator");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] icons(Block block){
|
||||
return new TextureRegion[]{block.region, rotator};
|
||||
}
|
||||
}
|
||||
43
core/src/mindustry/world/draw/DrawWeave.java
Normal file
43
core/src/mindustry/world/draw/DrawWeave.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package mindustry.world.draw;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import mindustry.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.production.GenericCrafter.*;
|
||||
|
||||
public class DrawWeave extends DrawBlock{
|
||||
public TextureRegion weave, bottom;
|
||||
|
||||
@Override
|
||||
public void draw(GenericCrafterEntity entity){
|
||||
Draw.rect(bottom, entity.x(), entity.y());
|
||||
Draw.rect(weave, entity.x(), entity.y(), entity.totalProgress);
|
||||
|
||||
Draw.color(Pal.accent);
|
||||
Draw.alpha(entity.warmup);
|
||||
|
||||
Lines.lineAngleCenter(
|
||||
entity.x() + Mathf.sin(entity.totalProgress, 6f, Vars.tilesize / 3f * entity.block.size),
|
||||
entity.y(),
|
||||
90,
|
||||
entity.block.size * Vars.tilesize / 2f);
|
||||
|
||||
Draw.reset();
|
||||
|
||||
Draw.rect(entity.block.region, entity.x, entity.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Block block){
|
||||
weave = Core.atlas.find(block.name + "-weave");
|
||||
bottom = Core.atlas.find(block.name + "-bottom");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] icons(Block block){
|
||||
return new TextureRegion[]{bottom, block.region, weave};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user