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

View File

@@ -8,6 +8,8 @@ import io.anuke.mindustry.type.Mech;
import io.anuke.mindustry.type.Upgrade;
import io.anuke.mindustry.world.Block;
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 {
@@ -21,20 +23,56 @@ public class Generators {
continue;
}
if(regions[0] == null){
context.err("Error in block \"{0}\": null region!", block.name);
}
if(block instanceof Turret){
Color color = Color.ROYAL;
Image image = context.get(regions[0]);
for(TextureRegion region : regions){
if(region == null){
context.err("Error in block \"{0}\": null region!", block.name);
Image image = context.get(block.name);
if(image.width() != block.size*8 + 2){
Image resized = context.create(block.size*8 + 2, block.size*8 + 2);
resized.draw(image, (resized.width() - image.width())/2, (resized.height() - image.height())/2);
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);
}
}
});

View File

@@ -2,6 +2,7 @@ package io.anuke.mindustry;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.ucore.util.Mathf;
import javax.imageio.ImageIO;
import java.awt.*;
@@ -20,12 +21,16 @@ public class Image {
private Color color = new Color();
public Image(BufferedImage atlas, TextureRegion region){
this.atlas = atlas;
this.image = new BufferedImage(region.getRegionWidth(), region.getRegionHeight(), BufferedImage.TYPE_INT_ARGB);
this.graphics = image.createGraphics();
this(atlas, region.getRegionWidth(), region.getRegionHeight());
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);
}
@@ -38,6 +43,14 @@ public class Image {
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){
int i = image.getRGB(x, y);
Color.argb8888ToColor(color, i);
@@ -56,7 +69,12 @@ public class Image {
/**Draws an image at the top left corner.*/
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){

View File

@@ -93,6 +93,10 @@ public class ImageContext {
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){
return get(Core.atlas.getRegion(name));
}