This commit is contained in:
Anuken
2021-06-10 18:51:49 -04:00
parent 35be671d86
commit 9e8e0709b5
27 changed files with 131 additions and 109 deletions

View File

@@ -494,24 +494,20 @@ public class Blocks implements ContentList{
wall = sporeWall;
}};
metalFloor = new MetalFloor("metal-floor"){{
variants = 0;
attributes.set(Attribute.water, -1f);
}};
metalFloor = new Floor("metal-floor", 0);
metalFloorDamaged = new Floor("metal-floor-damaged", 3);
metalFloorDamaged = new MetalFloor("metal-floor-damaged", 3);
metalFloor2 = new Floor("metal-floor-2", 0);
metalFloor3 = new Floor("metal-floor-3", 0);
metalFloor4 = new Floor("metal-floor-4", 0);
metalFloor5 = new Floor("metal-floor-5", 0);
metalFloor2 = new MetalFloor("metal-floor-2");
metalFloor3 = new MetalFloor("metal-floor-3");
metalFloor4 = new MetalFloor("metal-floor-4");
metalFloor5 = new MetalFloor("metal-floor-5");
darkPanel1 = new MetalFloor("dark-panel-1");
darkPanel2 = new MetalFloor("dark-panel-2");
darkPanel3 = new MetalFloor("dark-panel-3");
darkPanel4 = new MetalFloor("dark-panel-4");
darkPanel5 = new MetalFloor("dark-panel-5");
darkPanel6 = new MetalFloor("dark-panel-6");
darkPanel1 = new Floor("dark-panel-1", 0);
darkPanel2 = new Floor("dark-panel-2", 0);
darkPanel3 = new Floor("dark-panel-3", 0);
darkPanel4 = new Floor("dark-panel-4", 0);
darkPanel5 = new Floor("dark-panel-5", 0);
darkPanel6 = new Floor("dark-panel-6", 0);
darkMetal = new StaticWall("dark-metal");
@@ -757,6 +753,7 @@ public class Blocks implements ContentList{
outputLiquid = new LiquidStack(Liquids.slag, 2f);
craftTime = 10f;
hasLiquids = hasPower = true;
drawer = new DrawLiquid();
consumes.power(1f);
consumes.item(Items.scrap, 1);

View File

@@ -18,6 +18,7 @@ public class MapRenderer implements Disposable{
private IndexedRenderer[][] chunks;
private IntSet updates = new IntSet();
private IntSet delayedUpdates = new IntSet();
private TextureRegion clearEditor;
private int width, height;
public void resize(int width, int height){
@@ -45,6 +46,7 @@ public class MapRenderer implements Disposable{
public void draw(float tx, float ty, float tw, float th){
Draw.flush();
clearEditor = Core.atlas.find("clear-editor");
updates.each(i -> render(i % width, i / width));
updates.clear();
@@ -80,6 +82,7 @@ public class MapRenderer implements Disposable{
}
public void updateAll(){
clearEditor = Core.atlas.find("clear-editor");
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
render(x, y);
@@ -103,7 +106,7 @@ public class MapRenderer implements Disposable{
boolean center = tile.isCenter();
if(wall != Blocks.air && wall.synthetic()){
region = !Core.atlas.isFound(wall.editorIcon()) || !center ? Core.atlas.find("clear-editor") : wall.editorIcon();
region = !wall.editorIcon().found() || !center ? clearEditor : wall.editorIcon();
float width = region.width * Draw.scl, height = region.height * Draw.scl;
@@ -124,13 +127,17 @@ public class MapRenderer implements Disposable{
mesh.setColor(team.color);
region = Core.atlas.find("block-border-editor");
}else if(!wall.synthetic() && wall != Blocks.air && center){
region = !Core.atlas.isFound(wall.editorIcon()) ? Core.atlas.find("clear-editor") : wall.editorIcon();
region = !wall.editorIcon().found() ?
clearEditor : wall.variants > 0 ?
wall.editorVariantRegions()[Mathf.randomSeed(idxWall, 0, wall.editorVariantRegions().length - 1)] :
wall.editorIcon();
offsetX = tilesize / 2f - region.width / 2f * Draw.scl;
offsetY = tilesize / 2f - region.height / 2f * Draw.scl;
}else if(wall == Blocks.air && !tile.overlay().isAir()){
region = tile.overlay().editorVariantRegions()[Mathf.randomSeed(idxWall, 0, tile.overlay().editorVariantRegions().length - 1)];
}else{
region = Core.atlas.find("clear-editor");
region = clearEditor;
}
float width = region.width * Draw.scl, height = region.height * Draw.scl;

View File

@@ -907,7 +907,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
}
public void draw(){
Draw.rect(block.region, x, y, block.rotate ? rotdeg() : 0);
if(block.variants == 0){
Draw.rect(block.region, x, y, block.rotate ? rotdeg() : 0);
}else{
Draw.rect(block.variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, block.variantRegions.length - 1))], x, y, block.rotate ? rotdeg() : 0);
}
drawTeamTop();
}

View File

@@ -149,7 +149,7 @@ public class PlanetRenderer implements Disposable{
public void renderTransparent(Planet planet){
if(!planet.visible()) return;
if(planet.isLandable() && planet == this.planet){
if(planet.hasGrid() && planet == this.planet){
renderSectors(planet);
}

View File

@@ -707,6 +707,11 @@ public class ContentParser{
node.objectives.addAll(parser.readValue(Objective[].class, research.get("objectives")));
}
//all items have a produce requirement unless already specified
if(object instanceof Item i && !node.objectives.contains(o -> o instanceof Produce p && p.content == i)){
node.objectives.add(new Produce(i));
}
//remove old node from parent
if(node.parent != null){
node.parent.children.remove(node);

View File

@@ -127,7 +127,8 @@ public class Planet extends UnlockableContent{
sectors.get(index).preset = preset;
}
public boolean isLandable(){
/** @return whether this planet has a sector grid to select. */
public boolean hasGrid(){
return grid != null && generator != null && sectors.size > 0;
}

View File

@@ -5,7 +5,6 @@ import mindustry.core.GameState.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.type.*;
import mindustry.ui.*;
import static mindustry.Vars.*;
@@ -31,7 +30,7 @@ public class GameOverDialog extends BaseDialog{
}
void rebuild(){
title.setText(state.isCampaign() ? "@sector.curlost" : "@gameover");
title.setText(state.isCampaign() ? Core.bundle.format("sector.lost", state.getSector().name()) : "@gameover");
buttons.clear();
cont.clear();

View File

@@ -593,7 +593,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
}
}
if(planets.planet.isLandable()){
if(planets.planet.hasGrid()){
hovered = planets.planet.getSector(planets.cam.getMouseRay(), PlanetRenderer.outlineRad);
}else{
hovered = selected = null;

View File

@@ -322,7 +322,7 @@ public class HudFragment extends Fragment{
}
return max == 0f ? 0f : val / max;
}).blink(Color.white).outline(new Color(0, 0, 0, 0.6f), 7f)).grow())
.fillX().width(320f).height(60f).name("boss").visible(() -> state.rules.waves && state.boss() != null).padTop(7).row();
.fillX().width(320f).height(60f).name("boss").visible(() -> state.rules.waves && state.boss() != null && !(mobile && Core.graphics.isPortrait())).padTop(7).row();
t.table(Styles.black3, p -> p.margin(4).label(() -> hudText).style(Styles.outlineLabel)).touchable(Touchable.disabled).with(p -> p.visible(() -> {
p.color.a = Mathf.lerpDelta(p.color.a, Mathf.num(showHudText), 0.2f);

View File

@@ -46,6 +46,7 @@ public class Block extends UnlockableContent{
public boolean outputsPayload = false;
public boolean acceptsPayload = false;
public boolean outputFacing = true;
public boolean noSideBlend = false;
public boolean acceptsItems = false;
public int itemCapacity = 10;
@@ -77,6 +78,8 @@ public class Block extends UnlockableContent{
public boolean solidifes;
/** whether this is rotateable */
public boolean rotate;
/** number of different variant regions to use */
public int variants = 0;
/** whether to draw a rotation arrow - this does not apply to lines of blocks */
public boolean drawArrow = true;
/** for static blocks only: if true, tile data() is saved in world data. */
@@ -239,11 +242,11 @@ public class Block extends UnlockableContent{
public ObjectMap<Class<?>, Cons2> configurations = new ObjectMap<>();
protected TextureRegion[] generatedIcons;
protected TextureRegion[] variantRegions, editorVariantRegions;
protected TextureRegion[] editorVariantRegions;
public TextureRegion region, editorIcon;
public @Load("@-team") TextureRegion teamRegion;
public TextureRegion[] teamRegions;
public TextureRegion[] teamRegions, variantRegions;
protected static final Seq<Tile> tempTiles = new Seq<>();
protected static final Seq<Building> tempTileEnts = new Seq<>();
@@ -263,7 +266,11 @@ public class Block extends UnlockableContent{
if(tile.build != null){
tile.build.draw();
}else{
Draw.rect(region, tile.drawx(), tile.drawy());
if(variants == 0){
Draw.rect(region, tile.drawx(), tile.drawy());
}else{
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.drawx(), tile.drawy());
}
}
}
@@ -587,7 +594,8 @@ public class Block extends UnlockableContent{
protected TextureRegion[] icons(){
//use team region in vanilla team blocks
return teamRegion.found() && minfo.mod == null ? new TextureRegion[]{region, teamRegions[Team.sharded.id]} : new TextureRegion[]{region};
TextureRegion r = variants > 0 ? Core.atlas.find(name + "1") : region;
return teamRegion.found() && minfo.mod == null ? new TextureRegion[]{r, teamRegions[Team.sharded.id]} : new TextureRegion[]{r};
}
public TextureRegion[] getGeneratedIcons(){
@@ -830,6 +838,15 @@ public class Block extends UnlockableContent{
for(Team team : Team.all){
teamRegions[team.id] = teamRegion.found() ? Core.atlas.find(name + "-team-" + team.name, teamRegion) : teamRegion;
}
if(variants != 0){
variantRegions = new TextureRegion[variants];
for(int i = 0; i < variants; i++){
variantRegions[i] = Core.atlas.find(name + (i + 1));
}
region = variantRegions[0];
}
}
@Override
@@ -846,6 +863,13 @@ public class Block extends UnlockableContent{
mapColor.set(image.get(image.width/2, image.height/2));
}
if(variants > 0){
for(int i = 0; i < variants; i++){
String rname = name + (i + 1);
packer.add(PageType.editor, "editor-" + rname, Core.atlas.getPixmap(rname));
}
}
Pixmap last = null;
var gen = icons();

View File

@@ -15,8 +15,6 @@ import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class Wall extends Block{
public int variants = 0;
/** Lighting chance. -1 to disable */
public float lightningChance = -1f;
public float lightningDamage = 20f;
@@ -51,20 +49,6 @@ public class Wall extends Block{
}
}
@Override
public void load(){
super.load();
if(variants != 0){
variantRegions = new TextureRegion[variants];
for(int i = 0; i < variants; i++){
variantRegions[i] = Core.atlas.find(name + (i + 1));
}
region = variantRegions[0];
}
}
@Override
public TextureRegion[] icons(){
return new TextureRegion[]{Core.atlas.find(Core.atlas.has(name) ? name : name + "1")};
@@ -75,11 +59,7 @@ public class Wall extends Block{
@Override
public void draw(){
if(variants == 0){
Draw.rect(region, x, y);
}else{
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], x, y);
}
super.draw();
//draw flashing white overlay if enabled
if(flashHit){

View File

@@ -8,6 +8,7 @@ public class ArmoredConveyor extends Conveyor{
public ArmoredConveyor(String name){
super(name);
noSideBlend = true;
}
@Override

View File

@@ -38,6 +38,7 @@ public class Duct extends Block implements Autotiler{
itemCapacity = 1;
noUpdateDisabled = true;
rotate = true;
noSideBlend = true;
envEnabled = Env.space | Env.terrestrial | Env.underwater;
}

View File

@@ -12,7 +12,6 @@ import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.*;
import mindustry.world.blocks.*;
import mindustry.world.blocks.distribution.Conveyor.*;
@@ -63,7 +62,7 @@ public class StackConveyor extends Block implements Autotiler{
return otherblock.outputsItems() && lookingAtEither(tile, rotation, otherx, othery, otherrot, otherblock);
}else if(state == stateUnload){ //router mode
return otherblock.acceptsItems &&
(!(otherblock instanceof ArmoredConveyor) || lookingAtEither(tile, rotation, otherx, othery, otherrot, otherblock)) &&
(!otherblock.noSideBlend || lookingAtEither(tile, rotation, otherx, othery, otherrot, otherblock)) &&
(notLookingAt(tile, rotation, otherx, othery, otherrot, otherblock) ||
(otherblock instanceof StackConveyor && facing(otherx, othery, otherrot, tile.x, tile.y))) &&
!(world.build(otherx, othery) instanceof StackConveyorBuild s && s.state == stateUnload) &&

View File

@@ -20,8 +20,6 @@ import mindustry.world.blocks.*;
import static mindustry.Vars.*;
public class Floor extends Block{
/** number of different variant regions to use */
public int variants = 3;
/** edge fallback, used mainly for ores */
public String edge = "stone";
/** Multiplies unit velocity by this when walked on. */
@@ -76,6 +74,12 @@ public class Floor extends Block{
public Floor(String name){
super(name);
variants = 3;
}
public Floor(String name, int variants){
super(name);
this.variants = variants;
}
@Override
@@ -85,7 +89,6 @@ public class Floor extends Block{
//load variant regions for drawing
if(variants > 0){
variantRegions = new TextureRegion[variants];
for(int i = 0; i < variants; i++){
variantRegions[i] = Core.atlas.find(name + (i + 1));
}
@@ -93,7 +96,6 @@ public class Floor extends Block{
variantRegions = new TextureRegion[1];
variantRegions[0] = Core.atlas.find(name);
}
int size = (int)(tilesize / Draw.scl);
if(Core.atlas.has(name + "-edge")){
edges = Core.atlas.find(name + "-edge").split(size, size);
@@ -130,19 +132,12 @@ public class Floor extends Block{
@Override
public void createIcons(MultiPacker packer){
super.createIcons(packer);
packer.add(PageType.editor, "editor-" + name, Core.atlas.getPixmap(fullIcon).crop());
packer.add(PageType.editor, "editor-" + name, Core.atlas.getPixmap(fullIcon));
if(blendGroup != this){
return;
}
if(variants > 0){
for(int i = 0; i < variants; i++){
String rname = name + (i + 1);
packer.add(PageType.editor, "editor-" + rname, Core.atlas.getPixmap(rname).crop());
}
}
PixmapRegion image = Core.atlas.getPixmap(icons()[0]);
PixmapRegion edge = Core.atlas.getPixmap("edge-stencil");
Pixmap result = new Pixmap(edge.width, edge.height);

View File

@@ -1,19 +0,0 @@
package mindustry.world.blocks.environment;
import mindustry.world.meta.*;
/** Class for quickly defining a floor with no water and no variants. Offers no new functionality. */
public class MetalFloor extends Floor{
public MetalFloor(String name){
super(name);
variants = 0;
attributes.set(Attribute.water, -1);
}
public MetalFloor(String name, int variants){
super(name);
this.variants = variants;
attributes.set(Attribute.water, -1);
}
}

View File

@@ -7,8 +7,6 @@ import mindustry.content.*;
import mindustry.world.*;
public class Prop extends Block{
public int variants;
public Prop(String name){
super(name);
breakable = true;
@@ -28,17 +26,4 @@ public class Prop extends Block{
public TextureRegion[] icons(){
return variants == 0 ? super.icons() : new TextureRegion[]{Core.atlas.find(name + "1")};
}
@Override
public void load(){
super.load();
if(variants > 0){
variantRegions = new TextureRegion[variants];
for(int i = 0; i < variants; i++){
variantRegions[i] = Core.atlas.find(name + (i + 1));
}
}
}
}

View File

@@ -174,6 +174,7 @@ public class LogicBlock extends Block{
public boolean active = true, valid;
public int x, y;
public String name;
Building lastBuild;
public LogicLink(int x, int y, String name, boolean valid){
this.x = x;
@@ -405,20 +406,22 @@ public class LogicBlock extends Block{
if(!l.active) continue;
boolean valid = validLink(world.build(l.x, l.y));
if(valid != l.valid){
var cur = world.build(l.x, l.y);
boolean valid = validLink(cur);
if(valid != l.valid || (l.lastBuild != null && l.lastBuild != cur)){
l.lastBuild = cur;
changed = true;
l.valid = valid;
if(valid){
Building lbuild = world.build(l.x, l.y);
//this prevents conflicts
l.name = "";
//finds a new matching name after toggling
l.name = findLinkName(lbuild.block);
l.name = findLinkName(cur.block);
//remove redundant links
links.removeAll(o -> world.build(o.x, o.y) == lbuild && o != l);
links.removeAll(o -> world.build(o.x, o.y) == cur && o != l);
//break to prevent concurrent modification
updates = true;

View File

@@ -0,0 +1,38 @@
package mindustry.world.draw;
import arc.*;
import arc.graphics.g2d.*;
import mindustry.graphics.*;
import mindustry.world.*;
import mindustry.world.blocks.production.*;
import mindustry.world.blocks.production.GenericCrafter.*;
public class DrawLiquid extends DrawBlock{
public TextureRegion liquid, top;
@Override
public void draw(GenericCrafterBuild build){
Draw.rect(build.block.region, build.x, build.y);
GenericCrafter type = (GenericCrafter)build.block;
if(type.outputLiquid != null && build.liquids.get(type.outputLiquid.liquid) > 0){
Drawf.liquid(liquid, build.x, build.y,
build.liquids.get(type.outputLiquid.liquid) / type.liquidCapacity,
type.outputLiquid.liquid.color
);
}
if(top.found()) Draw.rect(top, build.x, build.y);
}
@Override
public void load(Block block){
top = Core.atlas.find(block.name + "-top");
liquid = Core.atlas.find(block.name + "-liquid");
}
@Override
public TextureRegion[] icons(Block block){
return top.found() ? new TextureRegion[]{block.region, top} : new TextureRegion[]{block.region};
}
}

View File

@@ -6,21 +6,23 @@ import mindustry.world.*;
import mindustry.world.blocks.production.GenericCrafter.*;
public class DrawRotator extends DrawBlock{
public TextureRegion rotator;
public TextureRegion rotator, top;
@Override
public void draw(GenericCrafterBuild build){
Draw.rect(build.block.region, build.x, build.y);
Draw.rect(rotator, build.x, build.y, build.totalProgress * 2f);
if(top.found()) Draw.rect(top, build.x, build.y);
}
@Override
public void load(Block block){
rotator = Core.atlas.find(block.name + "-rotator");
top = Core.atlas.find(block.name + "-top");
}
@Override
public TextureRegion[] icons(Block block){
return new TextureRegion[]{block.region, rotator};
return top.found() ? new TextureRegion[]{block.region, rotator, top} : new TextureRegion[]{block.region, rotator};
}
}