Fixed crude turret icons

This commit is contained in:
Anuken
2018-06-28 11:50:50 -04:00
parent cad44cf379
commit 576af67587
14 changed files with 911 additions and 804 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 682 B

Before

Width:  |  Height:  |  Size: 191 B

After

Width:  |  Height:  |  Size: 191 B

Before

Width:  |  Height:  |  Size: 400 B

After

Width:  |  Height:  |  Size: 400 B

File diff suppressed because it is too large Load Diff
Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 127 KiB

@@ -157,7 +157,7 @@ public class TurretBlocks extends BlockList implements ContentList {
size = 3; size = 3;
}}; }};
spectre = new ItemTurret("eraser") {{ spectre = new ItemTurret("spectre") {{
ammoTypes = new AmmoType[]{AmmoTypes.bulletTungsten, AmmoTypes.bulletLead, AmmoTypes.bulletCarbide, AmmoTypes.bulletThermite, AmmoTypes.bulletThorium, AmmoTypes.bulletSilicon}; ammoTypes = new AmmoType[]{AmmoTypes.bulletTungsten, AmmoTypes.bulletLead, AmmoTypes.bulletCarbide, AmmoTypes.bulletThermite, AmmoTypes.bulletThorium, AmmoTypes.bulletSilicon};
reload = 25f; reload = 25f;
restitution = 0.03f; restitution = 0.03f;
@@ -15,6 +15,7 @@ import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.ui.dialogs.FloatingDialog; import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.defense.turrets.Turret;
import io.anuke.mindustry.world.meta.BlockStat; import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.BlockStats; import io.anuke.mindustry.world.meta.BlockStats;
import io.anuke.mindustry.world.meta.StatCategory; import io.anuke.mindustry.world.meta.StatCategory;
@@ -364,7 +365,13 @@ public class BlocksFragment implements Fragment{
ScrollPane pane = new ScrollPane(table, "clear"); ScrollPane pane = new ScrollPane(table, "clear");
table.table(title -> { table.table(title -> {
title.addImage(Draw.region("block-icon-" + block.name)).size(8 * 6); int size = 8*6;
if(block instanceof Turret){
size = (8 * block.size + 2) * (7 - block.size*2);
}
title.addImage(Draw.region("block-icon-" + block.name)).size(size);
title.add("[accent]" + block.formalName).padLeft(5); title.add("[accent]" + block.formalName).padLeft(5);
}); });
+1 -4
View File
@@ -374,10 +374,7 @@ public class Block extends BaseBlock implements UnlockableContent{
/**Returns a list of icon regions that have been cropped to 8x8*/ /**Returns a list of icon regions that have been cropped to 8x8*/
public TextureRegion[] getCompactIcon(){ public TextureRegion[] getCompactIcon(){
if(compactIcon == null) { if(compactIcon == null) {
compactIcon = new TextureRegion[getIcon().length]; compactIcon = new TextureRegion[]{iconRegion(Draw.region("block-icon-" + name))};
for (int i = 0; i < compactIcon.length; i++) {
compactIcon[i] = iconRegion(getIcon()[i]);
}
} }
return compactIcon; return compactIcon;
} }
@@ -24,7 +24,7 @@ public abstract class LiquidTurret extends Turret {
public void setStats() { public void setStats() {
super.setStats(); super.setStats();
stats.add(BlockStat.inputItems, new LiquidFilterValue(item -> liquidAmmoMap.containsKey(item))); stats.add(BlockStat.inputLiquid, new LiquidFilterValue(item -> liquidAmmoMap.containsKey(item)));
} }
@Override @Override
@@ -56,15 +56,20 @@ public abstract class Turret extends Block{
protected float rotatespeed = 5f; //in degrees per tick protected float rotatespeed = 5f; //in degrees per tick
protected float shootCone = 8f; protected float shootCone = 8f;
protected float shootShake = 0f; protected float shootShake = 0f;
protected Translator tr = new Translator(); protected Translator tr = new Translator();
protected Translator tr2 = new Translator(); protected Translator tr2 = new Translator();
protected String base = null; //name of the region to draw under turret, usually null
protected TextureRegion baseRegion;
protected TextureRegion heatRegion;
protected TextureRegion baseTopRegion;
protected BiConsumer<Tile, TurretEntity> drawer = (tile, entity) -> Draw.rect(name, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90); protected BiConsumer<Tile, TurretEntity> drawer = (tile, entity) -> Draw.rect(name, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
protected BiConsumer<Tile, TurretEntity> heatDrawer = (tile, entity) ->{ protected BiConsumer<Tile, TurretEntity> heatDrawer = (tile, entity) ->{
Graphics.setAdditiveBlending(); Graphics.setAdditiveBlending();
Draw.color(heatColor); Draw.color(heatColor);
Draw.alpha(entity.heat); Draw.alpha(entity.heat);
Draw.rect(name + "-heat", tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90); Draw.rect(heatRegion, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
Graphics.setNormalBlending(); Graphics.setNormalBlending();
}; };
@@ -82,6 +87,15 @@ public abstract class Turret extends Block{
viewRange = range; viewRange = range;
} }
@Override
public void load() {
super.load();
baseRegion = Draw.region("block-" + size);
baseTopRegion = Draw.region("block-" +size + "-top");
heatRegion = Draw.region(name + "-heat");
}
@Override @Override
public void setStats(){ public void setStats(){
super.setStats(); super.setStats();
@@ -98,16 +112,10 @@ public abstract class Turret extends Block{
@Override @Override
public void draw(Tile tile){ public void draw(Tile tile){
if(base == null) { Draw.rect(baseRegion, tile.drawx(), tile.drawy());
Draw.rect("block-" + size, tile.drawx(), tile.drawy()); Draw.color(tile.getTeam().color, Color.WHITE, 0.45f);
if(Draw.hasRegion("block-" + size + "-top")) { Draw.rect(baseTopRegion, tile.drawx(), tile.drawy());
Draw.color(tile.getTeam().color, Color.WHITE, 0.45f); Draw.color();
Draw.rect("block-" + size + "-top", tile.drawx(), tile.drawy());
Draw.color();
}
}else{
Draw.rect(base, tile.drawx(), tile.drawy());
}
} }
@Override @Override
@@ -128,11 +136,11 @@ public abstract class Turret extends Block{
@Override @Override
public TextureRegion[] getBlockIcon(){ public TextureRegion[] getBlockIcon(){
if(blockIcon == null){ if(blockIcon == null){
blockIcon = Draw.hasRegion(name) ? new TextureRegion[]{Draw.region("block-" + size), Draw.region(name)} : new TextureRegion[0]; blockIcon = new TextureRegion[]{Draw.region("block-icon-" + name)};
} }
return blockIcon; return blockIcon;
} }
@Override @Override
public void drawSelect(Tile tile){ public void drawSelect(Tile tile){
Draw.color(tile.getTeam().color); Draw.color(tile.getTeam().color);
+49 -11
View File
@@ -8,6 +8,8 @@ import io.anuke.mindustry.type.Mech;
import io.anuke.mindustry.type.Upgrade; import io.anuke.mindustry.type.Upgrade;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.OreBlock; import io.anuke.mindustry.world.blocks.OreBlock;
import io.anuke.mindustry.world.blocks.defense.turrets.Turret;
import io.anuke.ucore.graphics.Hue;
public class Generators { public class Generators {
@@ -21,20 +23,56 @@ public class Generators {
continue; continue;
} }
if(regions[0] == null){ if(block instanceof Turret){
context.err("Error in block \"{0}\": null region!", block.name); Color color = Color.ROYAL;
}
Image image = context.get(regions[0]); Image image = context.get(block.name);
if(image.width() != block.size*8 + 2){
for(TextureRegion region : regions){ Image resized = context.create(block.size*8 + 2, block.size*8 + 2);
if(region == null){ resized.draw(image, (resized.width() - image.width())/2, (resized.height() - image.height())/2);
context.err("Error in block \"{0}\": null region!", block.name); image = resized;
} }
image.draw(region);
}
image.save("block-icon-" + block.name); Image read = context.create(image.width(), image.height());
read.draw(image);
for (int x = 0; x < image.width(); x++) {
for (int y = 0; y < image.height(); y++) {
if(read.isEmpty(x, y) &&
(!read.isEmpty(x, y + 1) || !read.isEmpty(x, y - 1) || !read.isEmpty(x + 1, y) || !read.isEmpty(x - 1, y))){
image.draw(x, y, color);
}
}
}
Image base = context.get("block-" + block.size);
Image top = context.get("block-" + block.size + "-top");
for (int x = 0; x < base.width(); x++) {
for (int y = 0; y < base.height(); y++) {
Color result = top.getColor(x, y);
if(result.a > 0.01f){
Hue.mix(result, color, 0.45f, result);
base.draw(x, y, result);
}
}
}
Image padded = context.create(base.width() + 2, base.height() + 2);
padded.draw(base, 1, 1);
padded.draw(image, 0, 0);
padded.save("block-icon-" + block.name);
}else {
Image image = context.get(regions[0]);
for (TextureRegion region : regions) {
image.draw(region);
}
image.save("block-icon-" + block.name);
}
} }
}); });
+23 -5
View File
@@ -2,6 +2,7 @@ package io.anuke.mindustry;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.ucore.util.Mathf;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
@@ -20,12 +21,16 @@ public class Image {
private Color color = new Color(); private Color color = new Color();
public Image(BufferedImage atlas, TextureRegion region){ public Image(BufferedImage atlas, TextureRegion region){
this.atlas = atlas; this(atlas, region.getRegionWidth(), region.getRegionHeight());
this.image = new BufferedImage(region.getRegionWidth(), region.getRegionHeight(), BufferedImage.TYPE_INT_ARGB);
this.graphics = image.createGraphics();
draw(region); draw(region);
}
public Image(BufferedImage atlas, int width, int height){
this.atlas = atlas;
this.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
this.graphics = image.createGraphics();
toDispose.add(this); toDispose.add(this);
} }
@@ -38,6 +43,14 @@ public class Image {
return image.getHeight(); return image.getHeight();
} }
public boolean isEmpty(int x, int y){
if(!Mathf.inBounds(x, y, width(), height())){
return true;
}
Color color = getColor(x, y);
return color.a <= 0.001f;
}
public Color getColor(int x, int y){ public Color getColor(int x, int y){
int i = image.getRGB(x, y); int i = image.getRGB(x, y);
Color.argb8888ToColor(color, i); Color.argb8888ToColor(color, i);
@@ -56,7 +69,12 @@ public class Image {
/**Draws an image at the top left corner.*/ /**Draws an image at the top left corner.*/
public void draw(Image image){ public void draw(Image image){
graphics.drawImage(image.image, 0, 0, null); draw(image, 0, 0);
}
/**Draws an image at the coordinates specified.*/
public void draw(Image image, int x, int y){
graphics.drawImage(image.image, x, y, null);
} }
public void draw(TextureRegion region, boolean flipx, boolean flipy){ public void draw(TextureRegion region, boolean flipx, boolean flipy){
@@ -93,6 +93,10 @@ public class ImageContext {
Log.info("&ly[Generator]&lc Time to generate &lm{0}&lc: &lg{1}&lcms", name, Timers.elapsed()); Log.info("&ly[Generator]&lc Time to generate &lm{0}&lc: &lg{1}&lcms", name, Timers.elapsed());
} }
public Image create(int width, int height){
return new Image(image, width, height);
}
public Image get(String name){ public Image get(String name){
return get(Core.atlas.getRegion(name)); return get(Core.atlas.getRegion(name));
} }