Fixed #530 / Better icons / Server list ordering
This commit is contained in:
@@ -2,14 +2,22 @@ package io.anuke.mindustry;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.files.FileHandle;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.Pixmap;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Fill;
|
||||
import io.anuke.arc.graphics.glutils.FrameBuffer;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.ScreenUtils;
|
||||
import io.anuke.arc.util.Tmp;
|
||||
|
||||
public class SquareMarcher{
|
||||
static final int resolution = 128;
|
||||
FrameBuffer buffer = new FrameBuffer(resolution, resolution);
|
||||
final int resolution;
|
||||
FrameBuffer buffer;
|
||||
|
||||
SquareMarcher(int resolution){
|
||||
this.resolution = resolution;
|
||||
this.buffer = new FrameBuffer(resolution, resolution);
|
||||
}
|
||||
|
||||
void render(Pixmap pixmap, FileHandle file){
|
||||
boolean[][] grid = new boolean[pixmap.getWidth()][pixmap.getHeight()];
|
||||
@@ -17,120 +25,135 @@ public class SquareMarcher{
|
||||
for(int x = 0; x < pixmap.getWidth(); x++){
|
||||
for(int y = 0; y < pixmap.getHeight(); y++){
|
||||
Tmp.c1.set(pixmap.getPixel(x, y));
|
||||
grid[x][y] = Tmp.c1.a > 0.01f;
|
||||
grid[x][pixmap.getHeight() - 1 - y] = Tmp.c1.a > 0.01f;
|
||||
}
|
||||
}
|
||||
|
||||
Draw.flush();
|
||||
Draw.proj().setOrtho(0, 0, resolution, resolution);
|
||||
|
||||
buffer.begin();
|
||||
Core.graphics.clear(Color.BLACK);
|
||||
Draw.color(Color.WHITE);
|
||||
float xscl = resolution / (float)pixmap.getWidth(), yscl = resolution / (float)pixmap.getHeight();
|
||||
float scl = xscl;
|
||||
|
||||
for(int x = 0; x < pixmap.getWidth(); x++){
|
||||
for(int y = 0; y < pixmap.getHeight(); y++){
|
||||
Draw.flush();
|
||||
Draw.proj().setOrtho(-xscl / 2f, -yscl / 2f, resolution, resolution);
|
||||
|
||||
buffer.begin();
|
||||
Core.graphics.clear(Color.CLEAR);
|
||||
Draw.color(Color.WHITE);
|
||||
|
||||
for(int x = -1; x < pixmap.getWidth(); x++){
|
||||
for(int y = -1; y < pixmap.getHeight(); y++){
|
||||
int index = index(x, y, pixmap.getWidth(), pixmap.getHeight(), grid);
|
||||
|
||||
float leftx = x * xscl, boty = y*yscl, rightx = x*xscl + xscl, topy = y*xscl + yscl,
|
||||
midx = x*xscl + xscl/2f, midy = y*yscl + yscl/2f;
|
||||
float leftx = x * xscl, boty = y * yscl, rightx = x * xscl + xscl, topy = y * xscl + yscl,
|
||||
midx = x * xscl + xscl / 2f, midy = y * yscl + yscl / 2f;
|
||||
|
||||
switch(index){
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
Fill.tri(
|
||||
leftx, midy,
|
||||
leftx, topy,
|
||||
midx, topy
|
||||
leftx, midy,
|
||||
leftx, topy,
|
||||
midx, topy
|
||||
);
|
||||
break;
|
||||
case 2:
|
||||
Fill.tri(
|
||||
midx, topy,
|
||||
rightx, topy,
|
||||
rightx, midy
|
||||
midx, topy,
|
||||
rightx, topy,
|
||||
rightx, midy
|
||||
);
|
||||
break;
|
||||
case 3:
|
||||
Fill.crect(leftx, midy, scl, scl/2f);
|
||||
Fill.crect(leftx, midy, scl, scl / 2f);
|
||||
break;
|
||||
case 4:
|
||||
Fill.tri(
|
||||
midx, boty,
|
||||
rightx, boty,
|
||||
rightx, midy
|
||||
midx, boty,
|
||||
rightx, boty,
|
||||
rightx, midy
|
||||
);
|
||||
break;
|
||||
case 5:
|
||||
//2 + 8
|
||||
//ambiguous
|
||||
|
||||
//7
|
||||
Fill.tri(
|
||||
midx, topy,
|
||||
rightx, topy,
|
||||
rightx, midy
|
||||
leftx, midy,
|
||||
midx, midy,
|
||||
midx, boty
|
||||
);
|
||||
|
||||
//13
|
||||
Fill.tri(
|
||||
leftx, boty,
|
||||
leftx, midy,
|
||||
midx, boty
|
||||
midx, topy,
|
||||
midx, midy,
|
||||
rightx, midy
|
||||
);
|
||||
|
||||
Fill.crect(leftx, midy, scl / 2f, scl / 2f);
|
||||
Fill.crect(midx, boty, scl / 2f, scl / 2f);
|
||||
|
||||
break;
|
||||
case 6:
|
||||
Fill.crect(midx, boty, scl/2f, scl);
|
||||
Fill.crect(midx, boty, scl / 2f, scl);
|
||||
break;
|
||||
case 7:
|
||||
//invert triangle
|
||||
Fill.tri(
|
||||
leftx, midy,
|
||||
midx, midy,
|
||||
midx, boty
|
||||
leftx, midy,
|
||||
midx, midy,
|
||||
midx, boty
|
||||
);
|
||||
|
||||
//3
|
||||
Fill.crect(leftx, midy, scl, scl/2f);
|
||||
Fill.crect(leftx, midy, scl, scl / 2f);
|
||||
|
||||
Fill.crect(midx, boty, scl/2f, scl/2f);
|
||||
Fill.crect(midx, boty, scl / 2f, scl / 2f);
|
||||
break;
|
||||
case 8:
|
||||
Fill.tri(
|
||||
leftx, boty,
|
||||
leftx, midy,
|
||||
midx, boty
|
||||
leftx, boty,
|
||||
leftx, midy,
|
||||
midx, boty
|
||||
);
|
||||
break;
|
||||
case 9:
|
||||
Fill.crect(leftx, boty, scl/2f, scl);
|
||||
Fill.crect(leftx, boty, scl / 2f, scl);
|
||||
break;
|
||||
case 10:
|
||||
//1 + 4
|
||||
//ambiguous
|
||||
|
||||
//11
|
||||
Fill.tri(
|
||||
leftx, midy,
|
||||
leftx, topy,
|
||||
midx, topy
|
||||
midx, boty,
|
||||
midx, midy,
|
||||
rightx, midy
|
||||
);
|
||||
|
||||
//14
|
||||
Fill.tri(
|
||||
midx, boty,
|
||||
rightx, boty,
|
||||
rightx, midy
|
||||
leftx, midy,
|
||||
midx, midy,
|
||||
midx, topy
|
||||
);
|
||||
|
||||
Fill.crect(midx, midy, scl / 2f, scl / 2f);
|
||||
Fill.crect(leftx, boty, scl / 2f, scl / 2f);
|
||||
|
||||
break;
|
||||
case 11:
|
||||
//invert triangle
|
||||
|
||||
Fill.tri(
|
||||
midx, boty,
|
||||
midx, midy,
|
||||
rightx, midy
|
||||
midx, boty,
|
||||
midx, midy,
|
||||
rightx, midy
|
||||
);
|
||||
|
||||
//3
|
||||
Fill.crect(leftx, midy, scl, scl/2f);
|
||||
Fill.crect(leftx, midy, scl, scl / 2f);
|
||||
|
||||
Fill.crect(leftx, boty, scl/2f, scl/2f);
|
||||
Fill.crect(leftx, boty, scl / 2f, scl / 2f);
|
||||
break;
|
||||
case 12:
|
||||
Fill.crect(leftx, boty, scl, scl / 2f);
|
||||
@@ -139,32 +162,32 @@ public class SquareMarcher{
|
||||
//invert triangle
|
||||
|
||||
Fill.tri(
|
||||
midx, topy,
|
||||
midx, midy,
|
||||
rightx, midy
|
||||
midx, topy,
|
||||
midx, midy,
|
||||
rightx, midy
|
||||
);
|
||||
|
||||
//12
|
||||
Fill.crect(leftx, boty, scl, scl / 2f);
|
||||
|
||||
Fill.crect(leftx, midy, scl/2f, scl/2f);
|
||||
Fill.crect(leftx, midy, scl / 2f, scl / 2f);
|
||||
break;
|
||||
case 14:
|
||||
//invert triangle
|
||||
|
||||
Fill.tri(
|
||||
leftx, midy,
|
||||
midx, midy,
|
||||
midx, topy
|
||||
leftx, midy,
|
||||
midx, midy,
|
||||
midx, topy
|
||||
);
|
||||
|
||||
//12
|
||||
Fill.crect(leftx, boty, scl, scl / 2f);
|
||||
|
||||
Fill.crect(midx, midy, scl/2f, scl/2f);
|
||||
Fill.crect(midx, midy, scl / 2f, scl / 2f);
|
||||
break;
|
||||
case 15:
|
||||
Fill.square(midx, midy, scl * 2f);
|
||||
Fill.square(midx, midy, scl / 2f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -175,11 +198,15 @@ public class SquareMarcher{
|
||||
buffer.end();
|
||||
}
|
||||
|
||||
int index(int x, int y, int w, int h, boolean[][] grid) {
|
||||
int top_left = Pack.byteValue(grid[x][y]);
|
||||
int top_right = x >= w - 1 ? 0 : Pack.byteValue(grid[x+1][y]);
|
||||
int bottom_right = x >= w - 1 || y >= h - 1 ? 0 : Pack.byteValue(grid[x+1][y+1]);
|
||||
int bottom_left = y >= h - 1 ? 0 : Pack.byteValue(grid[x][y+1]);
|
||||
return (bottom_left<<3) | (bottom_right<<2) | (top_right<<1) | top_left;
|
||||
int index(int x, int y, int w, int h, boolean[][] grid){
|
||||
int botleft = sample(grid, x, y);
|
||||
int botright = sample(grid, x + 1, y);
|
||||
int topright = sample(grid, x + 1, y + 1);
|
||||
int topleft = sample(grid, x, y + 1);
|
||||
return (botleft << 3) | (botright << 2) | (topright << 1) | topleft;
|
||||
}
|
||||
|
||||
int sample(boolean[][] grid, int x, int y){
|
||||
return (x < 0 || y < 0 || x >= grid.length || y >= grid.length) ? 0 : grid[x][y] ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,64 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.backends.lwjgl3.*;
|
||||
import io.anuke.arc.ApplicationListener;
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.backends.lwjgl3.Lwjgl3Application;
|
||||
import io.anuke.arc.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||
import io.anuke.arc.files.FileHandle;
|
||||
import io.anuke.arc.graphics.Pixmap;
|
||||
import io.anuke.arc.graphics.Pixmaps;
|
||||
import io.anuke.arc.graphics.g2d.SpriteBatch;
|
||||
import io.anuke.arc.graphics.g2d.TextureAtlas;
|
||||
import io.anuke.arc.util.Log;
|
||||
import io.anuke.mindustry.game.EventType.GameLoadEvent;
|
||||
import io.anuke.arc.util.Time;
|
||||
|
||||
public class Upscaler{
|
||||
static Res[] resolutions = {
|
||||
new Res(Vars.iconsize, ""),
|
||||
new Res(Vars.iconsizesmall, "-small")
|
||||
};
|
||||
|
||||
public static void main(String[] args){
|
||||
Events.on(GameLoadEvent.class, e -> scale());
|
||||
new Lwjgl3Application(new Mindustry(), new Lwjgl3ApplicationConfiguration());
|
||||
new Lwjgl3Application(new ApplicationListener(){
|
||||
@Override
|
||||
public void init(){
|
||||
scale();
|
||||
}
|
||||
}, new Lwjgl3ApplicationConfiguration(){{
|
||||
setInitialVisible(false);
|
||||
}});
|
||||
}
|
||||
|
||||
static void scale(){
|
||||
FileHandle file = Core.files.local("../assets-raw/sprites/ui/icons");
|
||||
Core.batch = new SpriteBatch();
|
||||
Core.atlas = new TextureAtlas();
|
||||
Core.atlas.addRegion("white", Pixmaps.blankTextureRegion());
|
||||
FileHandle file = Core.files.local("");
|
||||
|
||||
SquareMarcher marcher = new SquareMarcher();
|
||||
Log.info("Upscaling icons...");
|
||||
Time.mark();
|
||||
|
||||
for(FileHandle img : file.list()){
|
||||
if(img.extension().equals("png")){
|
||||
marcher.render(new Pixmap(img), Core.files.external("images/").child(img.name()));
|
||||
for(Res res : resolutions){
|
||||
SquareMarcher marcher = new SquareMarcher(res.size);
|
||||
|
||||
for(FileHandle img : file.list()){
|
||||
if(img.extension().equals("png")){
|
||||
marcher.render(new Pixmap(img), img.sibling(img.nameWithoutExtension() + res.suffix + ".png"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log.info("done.");
|
||||
|
||||
Log.info("Done upscaling icons in &lm{0}&lgs.", Time.elapsed()/1000f);
|
||||
Core.app.exit();
|
||||
}
|
||||
|
||||
static class Res{
|
||||
final int size;
|
||||
final String suffix;
|
||||
|
||||
public Res(int size, String suffix){
|
||||
this.size = size;
|
||||
this.suffix = suffix;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user