Add line tool and undo tools

This commit is contained in:
Anuken
2017-12-21 13:40:57 -05:00
parent 443b4436ce
commit 295ddc42aa
22 changed files with 476 additions and 268 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 82 KiB

View File

@@ -35,8 +35,6 @@ import io.anuke.ucore.modules.Module;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
public class Control extends Module{ public class Control extends Module{
int targetscale = baseCameraScale;
Tutorial tutorial = new Tutorial(); Tutorial tutorial = new Tutorial();
boolean hiscore = false; boolean hiscore = false;
@@ -48,7 +46,7 @@ public class Control extends Module{
public final EntityGroup<Bullet> bulletGroup = Entities.addGroup(Bullet.class); public final EntityGroup<Bullet> bulletGroup = Entities.addGroup(Bullet.class);
public final EntityGroup<Shield> shieldGroup = Entities.addGroup(Shield.class); public final EntityGroup<Shield> shieldGroup = Entities.addGroup(Shield.class);
Array<EnemySpawn> spawns = new Array<>(); Array<EnemySpawn> spawns;
int wave = 1; int wave = 1;
int lastUpdated = -1; int lastUpdated = -1;
float wavetime; float wavetime;
@@ -429,7 +427,7 @@ public class Control extends Module{
Entities.initPhysics(); Entities.initPhysics();
Entities.setCollider(tilesize, (x, y)-> world.solid(x, y)); Entities.setCollider(tilesize, (x, y) -> world.solid(x, y));
} }
@Override @Override
@@ -451,13 +449,6 @@ public class Control extends Module{
wavetime = 0f; wavetime = 0f;
} }
if(Inputs.keyUp(Keys.C)){
//crash cause:
//map is null.
//core is null.
//tiles are null.
}
if(Inputs.keyUp(Keys.U)){ if(Inputs.keyUp(Keys.U)){
Vars.showUI = !Vars.showUI; Vars.showUI = !Vars.showUI;
} }

View File

@@ -397,7 +397,7 @@ public class Renderer extends RendererModule{
drawHealth(entity); drawHealth(entity);
} }
if(!Vars.android && Vars.showPlayer) if(!Vars.android && Vars.showPlayer && !player.isDead())
drawHealth(player); drawHealth(player);
} }
} }

View File

@@ -253,7 +253,7 @@ public class World extends Module{
TileEntity e = other.entity; TileEntity e = other.entity;
if(damaged && ((TileEntity) e).health >= ((TileEntity) e).tile.block().health) if(damaged && e.health >= e.tile.block().health)
continue; continue;
float ndst = Vector2.dst(x, y, e.x, e.y); float ndst = Vector2.dst(x, y, e.x, e.y);
@@ -276,11 +276,9 @@ public class World extends Module{
* Input is in block coordinates, not world coordinates. * Input is in block coordinates, not world coordinates.
* @return null if no collisions found, block position otherwise. * @return null if no collisions found, block position otherwise.
*/ */
public GridPoint2 raycast(int x0f, int y0f, int x1f, int y1f){ public GridPoint2 raycast(int x0f, int y0f, int x1, int y1){
int x0 = (int)x0f; int x0 = x0f;
int y0 = (int)y0f; int y0 = y0f;
int x1 = (int)x1f;
int y1 = (int)y1f;
int dx = Math.abs(x1 - x0); int dx = Math.abs(x1 - x0);
int dy = Math.abs(y1 - y0); int dy = Math.abs(y1 - y0);

View File

@@ -10,6 +10,8 @@ import io.anuke.mindustry.input.PlaceMode;
import io.anuke.mindustry.resource.Mech; import io.anuke.mindustry.resource.Mech;
import io.anuke.mindustry.resource.Recipe; import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.resource.Weapon; import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.ucore.core.*; import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.DestructibleEntity; import io.anuke.ucore.entities.DestructibleEntity;
import io.anuke.ucore.util.Angles; import io.anuke.ucore.util.Angles;
@@ -75,6 +77,11 @@ public class Player extends DestructibleEntity{
if(health < maxhealth && Timers.get(this, "regen", 50)) if(health < maxhealth && Timers.get(this, "regen", 50))
health ++; health ++;
Tile tile = world.tileWorld(x, y);
if(tile != null && tile.floor().liquid && tile.block() == Blocks.air){
damage(health+1); //drown
}
vector.set(0, 0); vector.set(0, 0);
if(Inputs.keyDown("up")) if(Inputs.keyDown("up"))

View File

@@ -54,18 +54,20 @@ public class TileEntity extends Entity{
} }
public void onDeath(){ public void onDeath(){
dead = true;
if(tile.block() == ProductionBlocks.core){ if(tile.block() == ProductionBlocks.core){
Vars.control.coreDestroyed(); Vars.control.coreDestroyed();
} }
Block block = tile.block(); if(!dead) {
dead = true;
Block block = tile.block();
block.onDestroyed(tile); block.onDestroyed(tile);
Vars.world.removeBlock(tile); Vars.world.removeBlock(tile);
remove(); remove();
}
} }
public void collision(Bullet other){ public void collision(Bullet other){

View File

@@ -9,11 +9,14 @@ import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.graphics.Shaders; import io.anuke.mindustry.graphics.Shaders;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.ucore.UCore; import io.anuke.ucore.UCore;
import io.anuke.ucore.core.*; import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.*; import io.anuke.ucore.entities.*;
import io.anuke.ucore.util.*; import io.anuke.ucore.util.*;
import static io.anuke.mindustry.Vars.world;
public class Enemy extends DestructibleEntity{ public class Enemy extends DestructibleEntity{
public final static Color[] tierColors = { Color.valueOf("ffe451"), Color.valueOf("f48e20"), Color.valueOf("ff6757"), Color.valueOf("ff2d86") }; public final static Color[] tierColors = { Color.valueOf("ffe451"), Color.valueOf("f48e20"), Color.valueOf("ff6757"), Color.valueOf("ff2d86") };
public final static int maxtier = 4; public final static int maxtier = 4;
@@ -212,6 +215,11 @@ public class Enemy extends DestructibleEntity{
idletime = 0; idletime = 0;
} }
Tile tile = world.tileWorld(x, y);
if(tile != null && tile.floor().liquid && tile.block() == Blocks.air){
damage(health+1); //drown
}
if(Float.isNaN(angle)){ if(Float.isNaN(angle)){
angle = 0; angle = 0;
} }

View File

@@ -1,14 +1,40 @@
package io.anuke.mindustry.mapeditor; package io.anuke.mindustry.mapeditor;
import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.utils.Disposable;
import io.anuke.ucore.graphics.Pixmaps;
public abstract class DrawOperation{ public class DrawOperation implements Disposable{
protected Pixmap pixmap; Pixmap from, to, pixmap;
public DrawOperation(Pixmap pixmap){ public DrawOperation(Pixmap pixmap){
this.pixmap = pixmap; this.pixmap = pixmap;
} }
public abstract void undo(); public void add(Pixmap from, Pixmap to) {
public abstract void redo(); this.from = from;
this.to = to;
}
public void undo() {
pixmap.drawPixmap(from, 0, 0);
}
public void redo() {
pixmap.drawPixmap(to, 0, 0);
}
@Override
public void dispose() {
if(!Pixmaps.isDisposed(from))
from.dispose();
if(!Pixmaps.isDisposed(to))
to.dispose();
}
public void disposeFrom(){
from.dispose();
}
} }

View File

@@ -12,6 +12,15 @@ import io.anuke.mindustry.world.ColorMapper;
import io.anuke.mindustry.world.ColorMapper.BlockPair; import io.anuke.mindustry.world.ColorMapper.BlockPair;
public enum EditorTool{ public enum EditorTool{
pick{
public void touched(MapEditor editor, int x, int y){
BlockPair pair = ColorMapper.get(editor.pixmap().getPixel(x, y));
if(pair == null) return;
Block block = pair.dominant();
editor.setDrawBlock(block);
Vars.ui.getEditorDialog().updateSelectedBlock();
}
},
pencil{ pencil{
{ {
edit = true; edit = true;
@@ -21,6 +30,12 @@ public enum EditorTool{
editor.draw(x, y); editor.draw(x, y);
} }
}, },
line{
{
}
},
fill{ fill{
{ {
edit = true; edit = true;
@@ -64,15 +79,6 @@ public enum EditorTool{
return a == b; return a == b;
} }
}, },
pick{
public void touched(MapEditor editor, int x, int y){
BlockPair pair = ColorMapper.get(editor.pixmap().getPixel(x, y));
if(pair == null) return;
Block block = pair.dominant();
editor.setDrawBlock(block);
Vars.ui.getEditorDialog().updateSelectedBlock();
}
},
zoom; zoom;
boolean edit; boolean edit;

View File

@@ -61,6 +61,7 @@ public class MapEditor{
if(filterPixmap == null){ if(filterPixmap == null){
filterPixmap = Pixmaps.copy(pixmap); filterPixmap = Pixmaps.copy(pixmap);
filter.process(filterPixmap); filter.process(filterPixmap);
filterTexture = new Texture(filterPixmap); filterTexture = new Texture(filterPixmap);
}else{ }else{
@@ -110,6 +111,10 @@ public class MapEditor{
this.brushSize = size; this.brushSize = size;
} }
public int getBrushSize() {
return brushSize;
}
public void draw(int dx, int dy){ public void draw(int dx, int dy){
if(dx < 0 || dy < 0 || dx >= pixmap.getWidth() || dy >= pixmap.getHeight()){ if(dx < 0 || dy < 0 || dx >= pixmap.getWidth() || dy >= pixmap.getHeight()){
return; return;

View File

@@ -4,6 +4,7 @@ import java.util.Arrays;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
@@ -226,19 +227,33 @@ public class MapEditorDialog extends Dialog{
tools.padTop(0).padBottom(6); tools.padTop(0).padBottom(6);
ButtonGroup<ImageButton> group = new ButtonGroup<>(); ButtonGroup<ImageButton> group = new ButtonGroup<>();
int i = 0; int i = 1;
tools.defaults().size(53f, 58f).padBottom(-6);
ImageButton undo = tools.addIButton("icon-undo", 16*2f, () -> view.undo()).get();
ImageButton redo = tools.addIButton("icon-redo", 16*2f, () -> view.redo()).get();
ImageButton grid = tools.addIButton("toggle", "icon-grid", 16*2f, () -> view.setGrid(!view.isGrid())).get();
undo.setDisabled(() -> !view.getStack().canUndo());
redo.setDisabled(() -> !view.getStack().canRedo());
undo.update(() -> undo.getImage().setColor(undo.isDisabled() ? Color.GRAY : Color.WHITE));
redo.update(() -> redo.getImage().setColor(redo.isDisabled() ? Color.GRAY : Color.WHITE));
for(EditorTool tool : EditorTool.values()){ for(EditorTool tool : EditorTool.values()){
ImageButton button = new ImageButton("icon-" + tool.name(), "toggle"); ImageButton button = new ImageButton("icon-" + tool.name(), "toggle");
button.clicked(() -> view.setTool(tool)); button.clicked(() -> view.setTool(tool));
button.resizeImage(16*2f); button.resizeImage(16*2f);
group.add(button); group.add(button);
if (tool == EditorTool.pencil)
button.setChecked(true);
tools.add(button).size(80f, 85f).padBottom(-6f); tools.add(button).padBottom(-6f);
if(i++ % 2 == 1) tools.row(); if(i++ % 4 == 1) tools.row();
} }
add(tools).width(160f).padBottom(-6); add(tools).width(53*4).padBottom(-6);
row(); row();
@@ -330,12 +345,10 @@ public class MapEditorDialog extends Dialog{
} }
} }
content.padLeft(-5f);
group.getButtons().get(2).setChecked(true); group.getButtons().get(2).setChecked(true);
Table extra = new Table("button"); Table extra = new Table("button");
extra.labelWrap(() -> editor.getDrawBlock().name).width(120f).center(); extra.labelWrap(() -> editor.getDrawBlock().name).width(180f).center();
table.add(extra).growX(); table.add(extra).growX();
table.row(); table.row();
table.add(pane).growY().fillX(); table.add(pane).growY().fillX();

View File

@@ -45,6 +45,7 @@ public class MapFilter{
public MapFilter(){ public MapFilter(){
prefs.get("replace").enabled = true; prefs.get("replace").enabled = true;
prefs.get("terrain").enabled = true; prefs.get("terrain").enabled = true;
randomize();
} }
public void randomize(){ public void randomize(){

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.mapeditor; package io.anuke.mindustry.mapeditor;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Scaling; import com.badlogic.gdx.utils.Scaling;
@@ -9,6 +10,7 @@ import io.anuke.mindustry.mapeditor.MapFilter.GenPref;
import io.anuke.mindustry.ui.BorderImage; import io.anuke.mindustry.ui.BorderImage;
import io.anuke.mindustry.ui.FloatingDialog; import io.anuke.mindustry.ui.FloatingDialog;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Pixmaps;
import io.anuke.ucore.scene.style.TextureRegionDrawable; import io.anuke.ucore.scene.style.TextureRegionDrawable;
import io.anuke.ucore.scene.ui.CheckBox; import io.anuke.ucore.scene.ui.CheckBox;
import io.anuke.ucore.scene.ui.Image; import io.anuke.ucore.scene.ui.Image;
@@ -72,10 +74,11 @@ public class MapGenerateDialog extends FloatingDialog{
Vars.ui.showLoading(); Vars.ui.showLoading();
Timers.run(3f, () ->{ Timers.run(3f, () ->{
Pixmap copy = Pixmaps.copy(editor.pixmap());
editor.applyFilter(); editor.applyFilter();
Vars.ui.getEditorDialog().getView().push(copy, Pixmaps.copy(editor.pixmap()));
Vars.ui.hideLoading(); Vars.ui.hideLoading();
Vars.ui.getEditorDialog().resetSaved(); Vars.ui.getEditorDialog().resetSaved();
Vars.ui.getEditorDialog().getView().clearStack();
hide(); hide();
}); });
}); });

View File

@@ -1,6 +1,8 @@
package io.anuke.mindustry.mapeditor; package io.anuke.mindustry.mapeditor;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Colors; import com.badlogic.gdx.graphics.Colors;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.input.GestureDetector; import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.input.GestureDetector.GestureListener; import com.badlogic.gdx.input.GestureDetector.GestureListener;
@@ -11,7 +13,11 @@ import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.ui.GridImage;
import io.anuke.mindustry.world.ColorMapper;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.*; import io.anuke.ucore.core.*;
import io.anuke.ucore.graphics.Pixmaps;
import io.anuke.ucore.scene.Element; import io.anuke.ucore.scene.Element;
import io.anuke.ucore.scene.event.InputEvent; import io.anuke.ucore.scene.event.InputEvent;
import io.anuke.ucore.scene.event.InputListener; import io.anuke.ucore.scene.event.InputListener;
@@ -24,10 +30,18 @@ public class MapView extends Element implements GestureListener{
private MapEditor editor; private MapEditor editor;
private EditorTool tool = EditorTool.pencil; private EditorTool tool = EditorTool.pencil;
private OperationStack stack = new OperationStack(); private OperationStack stack = new OperationStack();
private PixelOperation op; private DrawOperation op;
private Pixmap current;
private Bresenham2 br = new Bresenham2(); private Bresenham2 br = new Bresenham2();
private boolean updated = false;
private float offsetx, offsety; private float offsetx, offsety;
private float zoom = 1f; private float zoom = 1f;
private boolean grid = false;
private GridImage image = new GridImage(0, 0);
private boolean drawing;
private int lastx, lasty;
private int startx, starty;
public void setTool(EditorTool tool){ public void setTool(EditorTool tool){
this.tool = tool; this.tool = tool;
@@ -35,6 +49,41 @@ public class MapView extends Element implements GestureListener{
public void clearStack(){ public void clearStack(){
stack.clear(); stack.clear();
current = null;
}
public OperationStack getStack() {
return stack;
}
public void setGrid(boolean grid) {
this.grid = grid;
}
public boolean isGrid() {
return grid;
}
public void push(Pixmap previous, Pixmap add){
DrawOperation op = new DrawOperation(editor.pixmap());
op.add(previous, add);
stack.add(op);
this.current = add;
}
public void undo(){
if(stack.canUndo()){
stack.undo();
editor.updateTexture();
}
}
public void redo(){
if(stack.canRedo()){
stack.redo();
editor.updateTexture();
}
} }
public MapView(MapEditor editor){ public MapView(MapEditor editor){
@@ -44,24 +93,31 @@ public class MapView extends Element implements GestureListener{
setTouchable(Touchable.enabled); setTouchable(Touchable.enabled);
addListener(new InputListener(){ addListener(new InputListener(){
int lastx, lasty;
boolean drawing;
@Override @Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
if(pointer != 0){ if(pointer != 0){
return false; return false;
} }
if(current == null){
current = Pixmaps.copy(editor.pixmap());
}
updated = false;
GridPoint2 p = project(x, y); GridPoint2 p = project(x, y);
lastx = p.x; lastx = p.x;
lasty = p.y; lasty = p.y;
startx = p.x;
starty = p.y;
tool.touched(editor, p.x, p.y); tool.touched(editor, p.x, p.y);
if(tool.edit){ if(tool.edit){
updated = true;
Vars.ui.getEditorDialog().resetSaved(); Vars.ui.getEditorDialog().resetSaved();
} }
op = new PixelOperation(editor.pixmap()); op = new DrawOperation(editor.pixmap());
drawing = true; drawing = true;
return true; return true;
@@ -70,8 +126,25 @@ public class MapView extends Element implements GestureListener{
@Override @Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button) { public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
drawing = false; drawing = false;
stack.add(op);
op = null; GridPoint2 p = project(x, y);
if(tool == EditorTool.line){
Vars.ui.getEditorDialog().resetSaved();
Array<GridPoint2> points = br.line(startx, starty, p.x, p.y);
for(GridPoint2 point : points){
editor.draw(point.x, point.y);
}
updated = true;
}
if(updated){
Pixmap next = Pixmaps.copy(editor.pixmap());
op.add(current, next);
current = next;
stack.add(op);
op = null;
}
} }
@Override @Override
@@ -84,6 +157,7 @@ public class MapView extends Element implements GestureListener{
for(GridPoint2 point : points){ for(GridPoint2 point : points){
editor.draw(point.x, point.y); editor.draw(point.x, point.y);
} }
updated = true;
} }
lastx = p.x; lastx = p.x;
lasty = p.y; lasty = p.y;
@@ -119,6 +193,17 @@ public class MapView extends Element implements GestureListener{
return Tmp.g1.set((int)x, editor.texture().getHeight() - 1 - (int)y); return Tmp.g1.set((int)x, editor.texture().getHeight() - 1 - (int)y);
} }
private Vector2 unproject(int x, int y){
float ratio = 1f / ((float)editor.pixmap().getWidth() / editor.pixmap().getHeight());
float size = Math.min(width, height);
float sclwidth = size * zoom;
float sclheight = size * zoom * ratio;
float px = ((float)x / editor.texture().getWidth()) * sclwidth + offsetx*zoom - sclwidth/2 + getWidth()/2;
float py = (float)((float)(editor.texture().getHeight() - 1 - y) / editor.texture().getHeight()) * sclheight
+ offsety*zoom - sclheight/2 + getHeight()/2;
return Tmp.v1.set(px, py);
}
@Override @Override
public void draw(Batch batch, float alpha){ public void draw(Batch batch, float alpha){
float ratio = 1f / ((float)editor.pixmap().getWidth() / editor.pixmap().getHeight()); float ratio = 1f / ((float)editor.pixmap().getWidth() / editor.pixmap().getHeight());
@@ -128,16 +213,37 @@ public class MapView extends Element implements GestureListener{
float centerx = x + width/2 + offsetx * zoom; float centerx = x + width/2 + offsetx * zoom;
float centery = y + height/2 + offsety * zoom; float centery = y + height/2 + offsety * zoom;
image.setImageSize(editor.pixmap().getWidth(), editor.pixmap().getHeight());
batch.flush(); batch.flush();
boolean pop = ScissorStack.pushScissors(Tmp.r1.set(x + width/2 - size/2, y + height/2 - size/2, size, size)); boolean pop = ScissorStack.pushScissors(Tmp.r1.set(x + width/2 - size/2, y + height/2 - size/2, size, size));
batch.draw(editor.texture(), centerx - sclwidth/2, centery - sclheight/2, sclwidth, sclheight); batch.draw(editor.texture(), centerx - sclwidth/2, centery - sclheight/2, sclwidth, sclheight);
if(grid){
image.setBounds(centerx - sclwidth/2, centery - sclheight/2, sclwidth, sclheight);
image.draw(batch, alpha);
}
if(tool == EditorTool.line && drawing){
Vector2 v1 = unproject(startx, starty).add(x, y);
float sx = v1.x, sy = v1.y;
Vector2 v2 = unproject(lastx, lasty).add(x, y);
Draw.color(Tmp.c1.set(ColorMapper.getColor(editor.getDrawBlock())));
Draw.thick(Unit.dp.scl(3f * zoom));
Draw.line(sx, sy, v2.x, v2.y);
Draw.polygon(40, sx, sy, editor.getBrushSize() * zoom * 3);
Draw.polygon(40, v2.x, v2.y, editor.getBrushSize() * zoom * 3);
}
batch.flush(); batch.flush();
if(pop) ScissorStack.popScissors(); if(pop) ScissorStack.popScissors();
Draw.color(Colors.get("accent")); Draw.color(Colors.get("accent"));
Draw.thick(3f); Draw.thick(Unit.dp.scl(3f));
Draw.linerect(x + width/2 - size/2, y + height/2 - size/2, size, size); Draw.linerect(x + width/2 - size/2, y + height/2 - size/2, size, size);
Draw.reset(); Draw.reset();
} }

View File

@@ -1,8 +1,12 @@
package io.anuke.mindustry.mapeditor; package io.anuke.mindustry.mapeditor;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.graphics.Pixmaps;
public class OperationStack{ public class OperationStack{
private final static int maxSize = 10;
private Array<DrawOperation> stack = new Array<>(); private Array<DrawOperation> stack = new Array<>();
private int index = 0; private int index = 0;
@@ -11,6 +15,9 @@ public class OperationStack{
} }
public void clear(){ public void clear(){
for(DrawOperation op : stack){
op.dispose();
}
stack.clear(); stack.clear();
index = 0; index = 0;
} }
@@ -19,6 +26,11 @@ public class OperationStack{
stack.truncate(stack.size + index); stack.truncate(stack.size + index);
index = 0; index = 0;
stack.add(action); stack.add(action);
if(stack.size > maxSize){
stack.get(0).disposeFrom();
stack.removeIndex(0);
}
} }
public boolean canUndo(){ public boolean canUndo(){
@@ -43,8 +55,4 @@ public class OperationStack{
stack.get(stack.size - 1 + index).redo(); stack.get(stack.size - 1 + index).redo();
} }
public void dispose(){
//TODO
}
} }

View File

@@ -1,24 +0,0 @@
package io.anuke.mindustry.mapeditor;
import com.badlogic.gdx.graphics.Pixmap;
public class PixelOperation extends DrawOperation {
public PixelOperation(Pixmap pixmap){
super(pixmap);
}
public void add() {
}
@Override
public void undo() {
}
@Override
public void redo() {
}
}

View File

@@ -0,0 +1,37 @@
package io.anuke.mindustry.ui;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.scene.Element;
public class GridImage extends Element{
private int imageWidth, imageHeight;
public GridImage(int w, int h){
this.imageWidth = w;
this.imageHeight = h;
}
public void draw(Batch batch, float alpha){
TextureRegion blank = Draw.region("white");
float xspace = (getWidth() / imageWidth);
float yspace = (getHeight() / imageHeight);
float s = 1f;
for(int x = 0; x <= imageWidth; x ++){
batch.draw(blank, (int)(getX() + xspace * x - s), getY() - s, 2, getHeight()+ (x == imageWidth ? 1: 0));
}
for(int y = 0; y <= imageHeight; y ++){
batch.draw(blank, getX() - s, (int)(getY() + y * yspace - s), getWidth(), 2);
}
}
public void setImageSize(int w, int h){
this.imageWidth = w;
this.imageHeight = h;
}
}

View File

@@ -39,12 +39,14 @@ public class Block{
public boolean destructible; public boolean destructible;
/**whether this is solid*/ /**whether this is solid*/
public boolean solid; public boolean solid;
/**whethe this block CAN be solid.*/ /**whether this block CAN be solid.*/
public boolean solidifes; public boolean solidifes;
/**whether this is rotateable*/ /**whether this is rotateable*/
public boolean rotate; public boolean rotate;
/**whether you can break this with rightblick*/ /**whether you can break this with rightclick*/
public boolean breakable; public boolean breakable;
/**whether this block can be drowned in*/
public boolean liquid;
/**time it takes to break*/ /**time it takes to break*/
public float breaktime = 18; public float breaktime = 18;
/**tile entity health*/ /**tile entity health*/

View File

@@ -159,7 +159,7 @@ public class Tile{
public boolean solid(){ public boolean solid(){
Block block = block(); Block block = block();
Block floor = floor(); Block floor = floor();
return block.solid || (floor.solid && block == Blocks.air) || block.isSolidFor(this); return block.solid || (floor.solid && (block == Blocks.air || block.solidifes)) || block.isSolidFor(this);
} }
public boolean breakable(){ public boolean breakable(){

View File

@@ -28,12 +28,14 @@ public class Blocks{
variants = 0; variants = 0;
solid = true; solid = true;
liquidDrop = Liquid.water; liquidDrop = Liquid.water;
liquid = true;
}}, }},
water = new Floor("water"){{ water = new Floor("water"){{
variants = 0; variants = 0;
solid = true; solid = true;
liquidDrop = Liquid.water; liquidDrop = Liquid.water;
liquid = true;
}}, }},
lava = new Floor("lava"){ lava = new Floor("lava"){
@@ -41,6 +43,7 @@ public class Blocks{
variants = 0; variants = 0;
solid = true; solid = true;
liquidDrop = Liquid.lava; liquidDrop = Liquid.lava;
liquid = true;
} }
@Override @Override
@@ -60,6 +63,7 @@ public class Blocks{
variants = 0; variants = 0;
solid = true; solid = true;
liquidDrop = Liquid.oil; liquidDrop = Liquid.oil;
liquid = true;
} }
@Override @Override

View File

@@ -31,6 +31,7 @@ public class Door extends Wall implements Configurable{
public Door(String name) { public Door(String name) {
super(name); super(name);
solid = false; solid = false;
solidifes = true;
} }
@Override @Override