Basic implementation of editor
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#Autogenerated file. Do not modify.
|
#Autogenerated file. Do not modify.
|
||||||
#Sat Mar 17 21:49:13 EDT 2018
|
#Mon Mar 19 23:08:29 EDT 2018
|
||||||
version=release
|
version=release
|
||||||
androidBuildCode=538
|
androidBuildCode=540
|
||||||
name=Mindustry
|
name=Mindustry
|
||||||
code=3.4
|
code=3.4
|
||||||
build=custom build
|
build=custom build
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ public enum EditorTool{
|
|||||||
{
|
{
|
||||||
edit = true;
|
edit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void touched(MapEditor editor, int x, int y){
|
public void touched(MapEditor editor, int x, int y){
|
||||||
editor.draw(x, y);
|
editor.draw(x, y);
|
||||||
}
|
}
|
||||||
@@ -62,9 +63,9 @@ public enum EditorTool{
|
|||||||
|
|
||||||
if((floor ? writer.floor : writer.wall) == dest){
|
if((floor ? writer.floor : writer.wall) == dest){
|
||||||
if(floor)
|
if(floor)
|
||||||
writer.floor = dest;
|
writer.floor = (byte)editor.getDrawBlock().id;
|
||||||
else
|
else
|
||||||
writer.wall = dest;
|
writer.wall = (byte)editor.getDrawBlock().id;
|
||||||
|
|
||||||
editor.getMap().write(px, py, writer);
|
editor.getMap().write(px, py, writer);
|
||||||
editor.renderer().updatePoint(px, py);
|
editor.renderer().updatePoint(px, py);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public class MapEditor{
|
|||||||
drawBlock = Blocks.stone;
|
drawBlock = Blocks.stone;
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.brushSize = 1;
|
this.brushSize = 1;
|
||||||
|
renderer.resize(map.width(), map.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Block getDrawBlock(){
|
public Block getDrawBlock(){
|
||||||
@@ -61,7 +62,10 @@ public class MapEditor{
|
|||||||
|
|
||||||
for(int rx = -brushSize + 1; rx <= brushSize - 1; rx ++){
|
for(int rx = -brushSize + 1; rx <= brushSize - 1; rx ++){
|
||||||
for(int ry = -brushSize + 1; ry <= brushSize - 1; ry ++){
|
for(int ry = -brushSize + 1; ry <= brushSize - 1; ry ++){
|
||||||
if(Mathf.dst(rx, ry) < brushSize){
|
if(Mathf.dst(rx, ry) <= brushSize){
|
||||||
|
if(dx + rx < 0 || dy + ry < 0 || dx + rx >= map.width() || dy + ry >= map.height()){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
map.write(dx + rx, dy + ry, writer);
|
map.write(dx + rx, dy + ry, writer);
|
||||||
renderer.updatePoint(dx + rx, dy + ry);
|
renderer.updatePoint(dx + rx, dy + ry);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.editor;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Input.Keys;
|
import com.badlogic.gdx.Input.Keys;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import io.anuke.mindustry.io.MapTileData;
|
import io.anuke.mindustry.io.MapTileData;
|
||||||
import io.anuke.mindustry.io.Platform;
|
import io.anuke.mindustry.io.Platform;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
@@ -12,13 +13,13 @@ import io.anuke.ucore.core.Core;
|
|||||||
import io.anuke.ucore.core.Graphics;
|
import io.anuke.ucore.core.Graphics;
|
||||||
import io.anuke.ucore.core.Inputs;
|
import io.anuke.ucore.core.Inputs;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
|
||||||
import io.anuke.ucore.scene.Element;
|
import io.anuke.ucore.scene.Element;
|
||||||
|
import io.anuke.ucore.scene.actions.Actions;
|
||||||
import io.anuke.ucore.scene.builders.build;
|
import io.anuke.ucore.scene.builders.build;
|
||||||
import io.anuke.ucore.scene.builders.imagebutton;
|
|
||||||
import io.anuke.ucore.scene.builders.label;
|
import io.anuke.ucore.scene.builders.label;
|
||||||
import io.anuke.ucore.scene.builders.table;
|
import io.anuke.ucore.scene.builders.table;
|
||||||
import io.anuke.ucore.scene.ui.*;
|
import io.anuke.ucore.scene.ui.*;
|
||||||
|
import io.anuke.ucore.scene.ui.layout.Stack;
|
||||||
import io.anuke.ucore.scene.ui.layout.Table;
|
import io.anuke.ucore.scene.ui.layout.Table;
|
||||||
import io.anuke.ucore.util.Bundles;
|
import io.anuke.ucore.util.Bundles;
|
||||||
|
|
||||||
@@ -171,6 +172,12 @@ public class MapEditorDialog extends Dialog{
|
|||||||
hidden(() -> Platform.instance.updateRPC());
|
hidden(() -> Platform.instance.updateRPC());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog show(){
|
||||||
|
return super.show(Core.scene, Actions.sequence(Actions.alpha(0f), Actions.fadeIn(0.3f)));
|
||||||
|
}
|
||||||
|
|
||||||
public MapView getView() {
|
public MapView getView() {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
@@ -200,7 +207,7 @@ public class MapEditorDialog extends Dialog{
|
|||||||
new table(){{
|
new table(){{
|
||||||
float isize = 16*2f;
|
float isize = 16*2f;
|
||||||
aleft();
|
aleft();
|
||||||
|
/*
|
||||||
new table(){{
|
new table(){{
|
||||||
|
|
||||||
defaults().growY().width(130f).padBottom(-6);
|
defaults().growY().width(130f).padBottom(-6);
|
||||||
@@ -237,7 +244,7 @@ public class MapEditorDialog extends Dialog{
|
|||||||
|
|
||||||
new imagebutton("icon-save-image", isize, () ->
|
new imagebutton("icon-save-image", isize, () ->
|
||||||
saveFile.show()
|
saveFile.show()
|
||||||
).text("$text.editor.saveimage");*/
|
).text("$text.editor.saveimage");
|
||||||
|
|
||||||
row();
|
row();
|
||||||
|
|
||||||
@@ -251,6 +258,7 @@ public class MapEditorDialog extends Dialog{
|
|||||||
}).padBottom(0).text("$text.back");
|
}).padBottom(0).text("$text.back");
|
||||||
|
|
||||||
}}.left().growY().end();
|
}}.left().growY().end();
|
||||||
|
*/
|
||||||
|
|
||||||
new table("button"){{
|
new table("button"){{
|
||||||
add(view).grow();
|
add(view).grow();
|
||||||
@@ -388,7 +396,7 @@ public class MapEditorDialog extends Dialog{
|
|||||||
private void addBlockSelection(Table table){
|
private void addBlockSelection(Table table){
|
||||||
Table content = new Table();
|
Table content = new Table();
|
||||||
pane = new ScrollPane(content, "volume");
|
pane = new ScrollPane(content, "volume");
|
||||||
pane.setScrollingDisabled(true, false);
|
//pane.setScrollingDisabled(true, false);
|
||||||
pane.setFadeScrollBars(false);
|
pane.setFadeScrollBars(false);
|
||||||
pane.setOverscroll(true, false);
|
pane.setOverscroll(true, false);
|
||||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||||
@@ -396,12 +404,26 @@ public class MapEditorDialog extends Dialog{
|
|||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for(BlockPair pair : ColorMapper.getPairs()){
|
for(Block block : Block.getAllBlocks()){
|
||||||
Block block = pair.wall == Blocks.air ? pair.floor : pair.wall;
|
TextureRegion[] regions;
|
||||||
|
try {
|
||||||
|
regions = block.getCompactIcon();
|
||||||
|
}catch (Exception e){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stack stack = new Stack();
|
||||||
|
|
||||||
|
for(TextureRegion region : regions){
|
||||||
|
stack.add(new Image(region));
|
||||||
|
}
|
||||||
|
|
||||||
ImageButton button = new ImageButton(Draw.hasRegion(block.name) ? Draw.region(block.name) : Draw.region(block.name + "1"), "toggle");
|
ImageButton button = new ImageButton("white", "toggle");
|
||||||
button.clicked(() -> editor.setDrawBlock(block));
|
button.clicked(() -> editor.setDrawBlock(block));
|
||||||
button.resizeImage(8*4f);
|
button.resizeImage(8*4f);
|
||||||
|
button.getImageCell().setActor(stack);
|
||||||
|
button.addChild(stack);
|
||||||
|
button.getImage().remove();
|
||||||
group.add(button);
|
group.add(button);
|
||||||
content.add(button).pad(4f).size(53f, 58f);
|
content.add(button).pad(4f).size(53f, 58f);
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ import com.badlogic.gdx.utils.IntSet.IntSetIterator;
|
|||||||
import io.anuke.mindustry.io.MapTileData.TileDataWriter;
|
import io.anuke.mindustry.io.MapTileData.TileDataWriter;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.blocks.Blocks;
|
import io.anuke.mindustry.world.blocks.Blocks;
|
||||||
|
import io.anuke.ucore.core.Core;
|
||||||
import io.anuke.ucore.core.Graphics;
|
import io.anuke.ucore.core.Graphics;
|
||||||
import io.anuke.ucore.graphics.CacheBatch;
|
import io.anuke.ucore.graphics.CacheBatch;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.tilesize;
|
||||||
|
|
||||||
@@ -25,19 +27,27 @@ public class MapRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void resize(int width, int height){
|
public void resize(int width, int height){
|
||||||
batch = new CacheBatch(width * height * 3);
|
if(batch != null) batch.dispose();
|
||||||
|
batch = new CacheBatch(width * height * 5);
|
||||||
chunks = new int[width / chunksize][height / chunksize];
|
chunks = new int[width / chunksize][height / chunksize];
|
||||||
updates.clear();
|
updates.clear();
|
||||||
|
|
||||||
|
for(int x = 0; x < width / chunksize; x ++){
|
||||||
|
for(int y = 0; y < height / chunksize; y ++){
|
||||||
|
chunks[x][y] = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateAll();
|
updateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(){
|
public void draw(float tx, float ty, float tw, float th){
|
||||||
Graphics.end();
|
Graphics.end();
|
||||||
Graphics.useBatch(batch);
|
Graphics.useBatch(batch);
|
||||||
|
|
||||||
IntSetIterator it = updates.iterator();
|
IntSetIterator it = updates.iterator();
|
||||||
int i = it.next();
|
while(it.hasNext){
|
||||||
for(; it.hasNext; i = it.next()){
|
int i = it.next();
|
||||||
int x = i % chunks.length;
|
int x = i % chunks.length;
|
||||||
int y = i / chunks.length;
|
int y = i / chunks.length;
|
||||||
render(x, y, chunks[x][y]);
|
render(x, y, chunks[x][y]);
|
||||||
@@ -48,12 +58,19 @@ public class MapRenderer {
|
|||||||
|
|
||||||
Gdx.gl.glEnable(GL20.GL_BLEND);
|
Gdx.gl.glEnable(GL20.GL_BLEND);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
batch.getTransformMatrix().setToTranslation(tx, ty, 0).scl(tw / (chunks.length * chunksize * tilesize),
|
||||||
|
th / (chunks[0].length * chunksize * tilesize), 1f);
|
||||||
|
batch.setProjectionMatrix(Core.batch.getProjectionMatrix());
|
||||||
batch.beginDraw();
|
batch.beginDraw();
|
||||||
|
|
||||||
for(int x = 0; x < chunks.length; x ++){
|
for(int x = 0; x < chunks.length; x ++){
|
||||||
for(int y = 0; y < chunks[0].length; y ++){
|
for(int y = 0; y < chunks[0].length; y ++){
|
||||||
int id = chunks[x][y];
|
int id = chunks[x][y];
|
||||||
batch.drawCache(id);
|
if(id != -1){
|
||||||
|
batch.drawCache(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,15 +82,20 @@ public class MapRenderer {
|
|||||||
public void updatePoint(int x, int y){
|
public void updatePoint(int x, int y){
|
||||||
x /= chunksize;
|
x /= chunksize;
|
||||||
y /= chunksize;
|
y /= chunksize;
|
||||||
updates.add(x + y * chunks.length);
|
if(Mathf.inBounds(x, y, chunks))
|
||||||
|
updates.add(x + y * chunks.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAll(){
|
public void updateAll(){
|
||||||
|
Graphics.useBatch(batch);
|
||||||
|
|
||||||
for(int x = 0; x < chunks.length; x ++){
|
for(int x = 0; x < chunks.length; x ++){
|
||||||
for(int y = 0; y < chunks[0].length; y ++){
|
for(int y = 0; y < chunks[0].length; y ++){
|
||||||
render(x, y, chunks[x][y]);
|
render(x, y, chunks[x][y]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Graphics.popBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void render(int chunkx, int chunky, int previousID){
|
private void render(int chunkx, int chunky, int previousID){
|
||||||
@@ -83,21 +105,40 @@ public class MapRenderer {
|
|||||||
batch.begin(previousID);
|
batch.begin(previousID);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int x = 0; x < chunkx; x ++){
|
for(int i = 0; i < 2; i ++) {
|
||||||
for(int y = 0; y < chunky; y ++){
|
for(int x = 0; x < chunksize; x ++){
|
||||||
int wx = chunkx*chunksize + x;
|
for(int y = 0; y < chunksize; y ++){
|
||||||
int wy = chunky*chunksize + y;
|
|
||||||
|
|
||||||
TileDataWriter data = editor.getMap().readAt(wx, wy);
|
int wx = chunkx*chunksize + x;
|
||||||
Block floor = Block.getByID(data.floor);
|
int wy = chunky*chunksize + y;
|
||||||
Block wall = Block.getByID(data.wall);
|
|
||||||
|
|
||||||
if(floor != Blocks.air) Draw.rect(floor.name, wx * tilesize, wy * tilesize);
|
TileDataWriter data = editor.getMap().readAt(wx, wy);
|
||||||
if(floor != Blocks.air) Draw.rect(wall.name, wx * tilesize, wy * tilesize);
|
Block floor = Block.getByID(data.floor);
|
||||||
|
Block wall = Block.getByID(data.wall);
|
||||||
|
|
||||||
|
if(i == 0) {
|
||||||
|
String fregion = Draw.hasRegion(floor.name) ? floor.name : floor.name + "1";
|
||||||
|
|
||||||
|
if (floor != Blocks.air && Draw.hasRegion(fregion)) {
|
||||||
|
Draw.crect(fregion, wx * tilesize, wy * tilesize);
|
||||||
|
} else {
|
||||||
|
Draw.rect("blank", wx * tilesize, wy * tilesize, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
String wregion = Draw.hasRegion(wall.name) ? wall.name : wall.name + "1";
|
||||||
|
|
||||||
|
if (wall != Blocks.air && Draw.hasRegion(wregion)) {
|
||||||
|
Draw.crect(wregion, wx * tilesize, wy * tilesize);
|
||||||
|
} else {
|
||||||
|
Draw.rect("blank", wx * tilesize, wy * tilesize, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.end();
|
batch.end();
|
||||||
chunks[chunkx][chunky] = batch.getLastCache();
|
if(previousID == -1) chunks[chunkx][chunky] = batch.getLastCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ public class MapView extends Element implements GestureListener{
|
|||||||
float sclheight = size * zoom * ratio;
|
float sclheight = size * zoom * ratio;
|
||||||
x = (x - getWidth()/2 + sclwidth/2 - offsetx*zoom) / sclwidth * editor.getMap().width();
|
x = (x - getWidth()/2 + sclwidth/2 - offsetx*zoom) / sclwidth * editor.getMap().width();
|
||||||
y = (y - getHeight()/2 + sclheight/2 - offsety*zoom) / sclheight * editor.getMap().height();
|
y = (y - getHeight()/2 + sclheight/2 - offsety*zoom) / sclheight * editor.getMap().height();
|
||||||
return Tmp.g1.set((int)x, editor.getMap().height() - 1 - (int)y);
|
return Tmp.g1.set((int)x, (int)y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector2 unproject(int x, int y){
|
private Vector2 unproject(int x, int y){
|
||||||
@@ -189,7 +189,7 @@ public class MapView extends Element implements GestureListener{
|
|||||||
float sclwidth = size * zoom;
|
float sclwidth = size * zoom;
|
||||||
float sclheight = size * zoom * ratio;
|
float sclheight = size * zoom * ratio;
|
||||||
float px = ((float)x / editor.getMap().width()) * sclwidth + offsetx*zoom - sclwidth/2 + getWidth()/2;
|
float px = ((float)x / editor.getMap().width()) * sclwidth + offsetx*zoom - sclwidth/2 + getWidth()/2;
|
||||||
float py = (float)((float)(editor.getMap().height() - 1 - y) / editor.getMap().height()) * sclheight
|
float py = (float)((float)(y) / editor.getMap().height()) * sclheight
|
||||||
+ offsety*zoom - sclheight/2 + getHeight()/2;
|
+ offsety*zoom - sclheight/2 + getHeight()/2;
|
||||||
return vec.set(px, py);
|
return vec.set(px, py);
|
||||||
}
|
}
|
||||||
@@ -210,6 +210,11 @@ public class MapView extends Element implements GestureListener{
|
|||||||
|
|
||||||
//batch.draw(editor.texture(), centerx - sclwidth/2, centery - sclheight/2, sclwidth, sclheight);
|
//batch.draw(editor.texture(), centerx - sclwidth/2, centery - sclheight/2, sclwidth, sclheight);
|
||||||
//TODO actually render the map here?
|
//TODO actually render the map here?
|
||||||
|
Draw.color(Color.LIGHT_GRAY);
|
||||||
|
Lines.stroke(-2f);
|
||||||
|
Lines.rect(centerx - sclwidth/2 - 1, centery - sclheight/2 - 1, sclwidth + 2, sclheight + 2);
|
||||||
|
editor.renderer().draw(centerx - sclwidth/2, centery - sclheight/2, sclwidth, sclheight);
|
||||||
|
Draw.reset();
|
||||||
|
|
||||||
if(grid){
|
if(grid){
|
||||||
Draw.color(Color.GRAY);
|
Draw.color(Color.GRAY);
|
||||||
|
|||||||
@@ -184,6 +184,8 @@ public class Block extends BaseBlock {
|
|||||||
public TextureRegion[] getIcon(){
|
public TextureRegion[] getIcon(){
|
||||||
if(Draw.hasRegion(name + "-icon")){
|
if(Draw.hasRegion(name + "-icon")){
|
||||||
return new TextureRegion[]{Draw.region(name + "-icon")};
|
return new TextureRegion[]{Draw.region(name + "-icon")};
|
||||||
|
}else if(Draw.hasRegion(name + "1")){
|
||||||
|
return new TextureRegion[]{Draw.region(name+ "1")};
|
||||||
}else{
|
}else{
|
||||||
return new TextureRegion[]{Draw.region(name)};
|
return new TextureRegion[]{Draw.region(name)};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user