A significant waste of time and effort
This commit is contained in:
@@ -710,6 +710,10 @@ public class Block extends UnlockableContent{
|
||||
return teamRegion.found() && minfo.mod == null ? new TextureRegion[]{r, teamRegions[Team.sharded.id]} : new TextureRegion[]{r};
|
||||
}
|
||||
|
||||
public void getRegionsToOutline(Seq<TextureRegion> out){
|
||||
|
||||
}
|
||||
|
||||
public TextureRegion[] getGeneratedIcons(){
|
||||
return generatedIcons == null ? (generatedIcons = icons()) : generatedIcons;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ContinuousTurret extends Turret{
|
||||
|
||||
@Override
|
||||
public boolean hasAmmo(){
|
||||
return consValid();
|
||||
return cons.canConsume();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -48,6 +48,7 @@ public class Turret extends ReloadTurret{
|
||||
public float ammoEjectBack = 1f;
|
||||
public float inaccuracy = 0f;
|
||||
public float velocityInaccuracy = 0f;
|
||||
public float shootWarmupSpeed = 3f / 60f;
|
||||
public int shots = 1;
|
||||
public float spread = 4f;
|
||||
public float recoilAmount = 1f;
|
||||
@@ -149,6 +150,11 @@ public class Turret extends ReloadTurret{
|
||||
return draw.icons(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getRegionsToOutline(Seq<TextureRegion> out){
|
||||
draw.getRegionsToOutline(out);
|
||||
}
|
||||
|
||||
public static abstract class AmmoEntry{
|
||||
public int amount;
|
||||
|
||||
@@ -165,6 +171,7 @@ public class Turret extends ReloadTurret{
|
||||
public Seq<AmmoEntry> ammo = new Seq<>();
|
||||
public int totalAmmo;
|
||||
public float recoil, heat, logicControlTime = -1;
|
||||
public float shootWarmup;
|
||||
public int shotCounter;
|
||||
public boolean logicShooting = false;
|
||||
public @Nullable Posc target;
|
||||
@@ -172,6 +179,11 @@ public class Turret extends ReloadTurret{
|
||||
public BlockUnitc unit = (BlockUnitc)UnitTypes.block.create(team);
|
||||
public boolean wasShooting, charging;
|
||||
|
||||
@Override
|
||||
public float warmup(){
|
||||
return shootWarmup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float drawrot(){
|
||||
return rotation - 90;
|
||||
@@ -273,6 +285,9 @@ public class Turret extends ReloadTurret{
|
||||
public void updateTile(){
|
||||
if(!validateTarget()) target = null;
|
||||
|
||||
//TODO can be lerp instead, that's smoother
|
||||
shootWarmup = Mathf.approachDelta(shootWarmup, isActive() ? 1f : 0f, shootWarmupSpeed);
|
||||
|
||||
wasShooting = false;
|
||||
|
||||
recoil = Mathf.lerpDelta(recoil, 0f, restitution);
|
||||
|
||||
@@ -138,6 +138,11 @@ public class GenericCrafter extends Block{
|
||||
return outputItems != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getRegionsToOutline(Seq<TextureRegion> out){
|
||||
drawer.getRegionsToOutline(out);
|
||||
}
|
||||
|
||||
public class GenericCrafterBuild extends Building{
|
||||
public float progress;
|
||||
public float totalProgress;
|
||||
|
||||
@@ -2,6 +2,7 @@ package mindustry.world.draw;
|
||||
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
@@ -22,6 +23,10 @@ public class DrawBlock{
|
||||
@Deprecated
|
||||
public void drawLight(GenericCrafterBuild build){}
|
||||
|
||||
public void getRegionsToOutline(Seq<TextureRegion> out){
|
||||
|
||||
}
|
||||
|
||||
/** Draws the block itself. */
|
||||
public void drawBase(Building build){
|
||||
Draw.rect(build.block.region, build.x, build.y, build.drawrot());
|
||||
|
||||
@@ -24,6 +24,13 @@ public class DrawMulti extends DrawBlock{
|
||||
this.drawers = drawers.toArray(DrawBlock.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getRegionsToOutline(Seq<TextureRegion> out){
|
||||
for(var draw : drawers){
|
||||
draw.getRegionsToOutline(out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
for(var draw : drawers){
|
||||
|
||||
@@ -4,6 +4,8 @@ import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
@@ -14,8 +16,9 @@ import mindustry.world.blocks.defense.turrets.Turret.*;
|
||||
public class DrawTurret extends DrawBlock{
|
||||
protected static final Rand rand = new Rand();
|
||||
|
||||
public Seq<TurretPart> parts = new Seq<>();
|
||||
public String basePrefix = "";
|
||||
public TextureRegion base, liquid, top, heat;
|
||||
public TextureRegion base, liquid, top, heat, preview;
|
||||
|
||||
public DrawTurret(String basePrefix){
|
||||
this.basePrefix = basePrefix;
|
||||
@@ -24,6 +27,13 @@ public class DrawTurret extends DrawBlock{
|
||||
public DrawTurret(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getRegionsToOutline(Seq<TextureRegion> out){
|
||||
for(var part : parts){
|
||||
part.getOutlines(out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBase(Building build){
|
||||
Turret turret = (Turret)build.block;
|
||||
@@ -38,6 +48,12 @@ public class DrawTurret extends DrawBlock{
|
||||
|
||||
drawTurret(turret, tb);
|
||||
drawHeat(turret, tb);
|
||||
|
||||
if(parts.size > 0){
|
||||
for(var part : parts){
|
||||
part.draw(tb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawTurret(Turret block, TurretBuild build){
|
||||
@@ -67,11 +83,16 @@ public class DrawTurret extends DrawBlock{
|
||||
public void load(Block block){
|
||||
if(!(block instanceof Turret)) throw new ClassCastException("This drawer can only be used on turrets.");
|
||||
|
||||
preview = Core.atlas.find(block.name + "-preview", block.region);
|
||||
liquid = Core.atlas.find(block.name + "-liquid");
|
||||
top = Core.atlas.find(block.name + "-top");
|
||||
heat = Core.atlas.find(block.name + "-heat");
|
||||
base = Core.atlas.find(block.name + "-base");
|
||||
|
||||
for(var part : parts){
|
||||
part.load(block);
|
||||
}
|
||||
|
||||
//TODO test this for mods, e.g. exotic
|
||||
if(!base.found() && block.minfo.mod != null) base = Core.atlas.find(block.minfo.mod.name + "-block-" + block.size);
|
||||
if(!base.found()) base = Core.atlas.find(basePrefix + "block-" + block.size);
|
||||
@@ -80,6 +101,98 @@ public class DrawTurret extends DrawBlock{
|
||||
/** @return the generated icons to be used for this block. */
|
||||
@Override
|
||||
public TextureRegion[] icons(Block block){
|
||||
return top.found() ? new TextureRegion[]{base, block.region, top} : new TextureRegion[]{base, block.region};
|
||||
TextureRegion showTop = preview.found() ? preview : block.region;
|
||||
return top.found() ? new TextureRegion[]{base, showTop, top} : new TextureRegion[]{base, showTop};
|
||||
}
|
||||
|
||||
public static class RegionPart extends TurretPart{
|
||||
public String suffix = "";
|
||||
public boolean mirror = true;
|
||||
public TextureRegion[] regions;
|
||||
public TextureRegion[] outlines;
|
||||
|
||||
public boolean outline = false;
|
||||
public float layer = -1;
|
||||
public float outlineLayerOffset = -0.01f;
|
||||
public float rotation, rotMove;
|
||||
public float originX, originY;
|
||||
public float offsetX, offsetY, offsetMoveX, offsetMoveY;
|
||||
|
||||
public RegionPart(String region){
|
||||
this.suffix = region;
|
||||
}
|
||||
|
||||
public RegionPart(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(TurretBuild build){
|
||||
float z = Draw.z();
|
||||
if(layer > 0){
|
||||
Draw.z(layer);
|
||||
}
|
||||
float prevZ = layer > 0 ? layer : z;
|
||||
|
||||
float progress = build.warmup();
|
||||
|
||||
for(int i = 0; i < regions.length; i++){
|
||||
var region = regions[i];
|
||||
float sign = i == 1 ? -1 : 1;
|
||||
Tmp.v1.set((offsetX + offsetMoveX * progress) * sign, offsetY + offsetMoveY*progress).rotate(build.rotation - 90);
|
||||
|
||||
float
|
||||
x = build.x + Tmp.v1.x,
|
||||
y = build.y + Tmp.v1.y,
|
||||
rot = (i == 0 ? rotation : 180f - rotation) + rotMove * progress * sign + build.rotation,
|
||||
ox = originX + region.width * Draw.scl/2f, oy = originY + region.height * Draw.scl/2f;
|
||||
|
||||
if(outline){
|
||||
Draw.z(prevZ + outlineLayerOffset);
|
||||
|
||||
Draw.rect(outlines[i],
|
||||
x, y, region.width * Draw.scl, region.height * Draw.scl,
|
||||
ox, oy, rot);
|
||||
|
||||
Draw.z(prevZ);
|
||||
}
|
||||
|
||||
Draw.rect(region,
|
||||
x, y, region.width * Draw.scl, region.height * Draw.scl,
|
||||
ox, oy, rot);
|
||||
}
|
||||
|
||||
Draw.z(z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Block block){
|
||||
if(mirror){
|
||||
regions = new TextureRegion[]{
|
||||
Core.atlas.find(block.name + suffix + "1"),
|
||||
Core.atlas.find(block.name + suffix + "2")
|
||||
};
|
||||
|
||||
outlines = new TextureRegion[]{
|
||||
Core.atlas.find(block.name + suffix + "1-outline"),
|
||||
Core.atlas.find(block.name + suffix + "2-outline")
|
||||
};
|
||||
}else{
|
||||
regions = new TextureRegion[]{Core.atlas.find(block.name + suffix)};
|
||||
outlines = new TextureRegion[]{Core.atlas.find(block.name + suffix + "-outline")};
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getOutlines(Seq<TextureRegion> out){
|
||||
if(outline){
|
||||
out.addAll(regions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class TurretPart{
|
||||
public abstract void draw(TurretBuild build);
|
||||
public abstract void load(Block block);
|
||||
public void getOutlines(Seq<TextureRegion> out){}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user