Added Placement Preview

This commit is contained in:
Commodore64x
2018-04-15 19:40:22 +10:00
parent 02ab945ab8
commit c17b34c70d
4 changed files with 677 additions and 626 deletions

View File

@@ -270,6 +270,7 @@ setting.multithread.name=Multithreading
setting.fps.name=Show FPS setting.fps.name=Show FPS
setting.vsync.name=VSync setting.vsync.name=VSync
setting.lasers.name=Show Power Lasers setting.lasers.name=Show Power Lasers
setting.previewopacity.name = Placing Preview Opacity
setting.healthbars.name=Show Entity Health bars setting.healthbars.name=Show Entity Health bars
setting.pixelate.name=Pixelate Screen setting.pixelate.name=Pixelate Screen
setting.musicvol.name=Music Volume setting.musicvol.name=Music Volume

View File

@@ -12,12 +12,16 @@ import io.anuke.mindustry.world.Layer;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks; import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.types.StaticBlock; import io.anuke.mindustry.world.blocks.types.StaticBlock;
import io.anuke.mindustry.world.blocks.types.defense.Turret;
import io.anuke.mindustry.world.blocks.types.production.Drill;
import io.anuke.mindustry.world.blocks.types.production.Pump;
import io.anuke.ucore.core.Core; 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.graphics.Lines; import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.core.*;
import java.util.Arrays; import java.util.Arrays;
@@ -25,259 +29,297 @@ import static io.anuke.mindustry.Vars.*;
import static io.anuke.ucore.core.Core.camera; import static io.anuke.ucore.core.Core.camera;
public class BlockRenderer{ public class BlockRenderer{
private final static int chunksize = 32; private final static int chunksize = 32;
private final static int initialRequests = 32*32; private final static int initialRequests = 32*32;
private int[][][] cache; private int[][][] cache;
private CacheBatch cbatch; private CacheBatch cbatch;
private Array<BlockRequest> requests = new Array<BlockRequest>(initialRequests); private Array<BlockRequest> requests = new Array<BlockRequest>(initialRequests);
private int requestidx = 0; private int requestidx = 0;
private int iterateidx = 0; private int iterateidx = 0;
public BlockRenderer(){ public BlockRenderer(){
for(int i = 0; i < requests.size; i ++){ for(int i = 0; i < requests.size; i ++){
requests.set(i, new BlockRequest()); requests.set(i, new BlockRequest());
} }
} }
private class BlockRequest implements Comparable<BlockRequest>{ private class BlockRequest implements Comparable<BlockRequest>{
Tile tile; Tile tile;
Layer layer; Layer layer;
@Override @Override
public int compareTo(BlockRequest other){ public int compareTo(BlockRequest other){
return layer.compareTo(other.layer); return layer.compareTo(other.layer);
} }
@Override @Override
public String toString(){ public String toString(){
return tile.block().name + ":" + layer.toString(); return tile.block().name + ":" + layer.toString();
} }
} }
/**Process all blocks to draw, simultaneously drawing block shadows and static blocks.*/ /**Process all blocks to draw, simultaneously drawing block shadows and static blocks.*/
public void processBlocks(){ public void processBlocks(){
requestidx = 0; requestidx = 0;
int crangex = (int) (camera.viewportWidth / (chunksize * tilesize)) + 1; int crangex = (int) (camera.viewportWidth / (chunksize * tilesize)) + 1;
int crangey = (int) (camera.viewportHeight / (chunksize * tilesize)) + 1; int crangey = (int) (camera.viewportHeight / (chunksize * tilesize)) + 1;
int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2)+2; int rangex = (int) (camera.viewportWidth * camera.zoom / tilesize / 2)+2;
int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2)+2; int rangey = (int) (camera.viewportHeight * camera.zoom / tilesize / 2)+2;
int expandr = 3; int expandr = 3;
Graphics.surface(renderer.shadowSurface); Graphics.surface(renderer.shadowSurface);
for(int x = -rangex - expandr; x <= rangex + expandr; x++){ for(int x = -rangex - expandr; x <= rangex + expandr; x++){
for(int y = -rangey - expandr; y <= rangey + expandr; y++){ for(int y = -rangey - expandr; y <= rangey + expandr; y++){
int worldx = Mathf.scl(camera.position.x, tilesize) + x; int worldx = Mathf.scl(camera.position.x, tilesize) + x;
int worldy = Mathf.scl(camera.position.y, tilesize) + y; int worldy = Mathf.scl(camera.position.y, tilesize) + y;
boolean expanded = (x < -rangex || x > rangex || y < -rangey || y > rangey); boolean expanded = (x < -rangex || x > rangex || y < -rangey || y > rangey);
Tile tile = world.tile(worldx, worldy); Tile tile = world.tile(worldx, worldy);
if(tile != null){ if(tile != null){
Block block = tile.block(); Block block = tile.block();
if(!expanded && block != Blocks.air && world.isAccessible(worldx, worldy)){ if(!expanded && block != Blocks.air && world.isAccessible(worldx, worldy)){
block.drawShadow(tile); block.drawShadow(tile);
} }
if(!(block instanceof StaticBlock)){ if(!(block instanceof StaticBlock)){
if(block == Blocks.air){ if(block == Blocks.air){
if(!state.is(State.paused)) tile.floor().update(tile); if(!state.is(State.paused)) tile.floor().update(tile);
}else{ }else{
if(!expanded){ if(!expanded){
addRequest(tile, Layer.block); addRequest(tile, Layer.block);
} }
if(block.expanded || !expanded){ if(block.expanded || !expanded){
if(block.layer != null && block.isLayer(tile)){ if(block.layer != null && block.isLayer(tile)){
addRequest(tile, block.layer); addRequest(tile, block.layer);
} }
if(block.layer2 != null && block.isLayer2(tile)){ if(block.layer2 != null && block.isLayer2(tile)){
addRequest(tile, block.layer2); addRequest(tile, block.layer2);
} }
} }
} }
} }
} }
} }
} }
Draw.color(0, 0, 0, 0.15f); Draw.color(0, 0, 0, 0.15f);
Graphics.flushSurface(); Graphics.flushSurface();
Draw.color(); Draw.color();
Graphics.end(); Graphics.end();
drawCache(1, crangex, crangey); drawCache(1, crangex, crangey);
Graphics.begin(); Graphics.begin();
Arrays.sort(requests.items, 0, requestidx); Arrays.sort(requests.items, 0, requestidx);
iterateidx = 0; iterateidx = 0;
} }
public int getRequests(){ public int getRequests(){
return requestidx; return requestidx;
} }
public void drawBlocks(boolean top){ public void drawBlocks(boolean top){
Layer stopAt = top ? Layer.laser : Layer.overlay; Layer stopAt = top ? Layer.laser : Layer.overlay;
for(; iterateidx < requestidx; iterateidx ++){ for(; iterateidx < requestidx; iterateidx ++){
if(iterateidx < requests.size - 1 && requests.get(iterateidx).layer.ordinal() > stopAt.ordinal()){ if(iterateidx < requests.size - 1 && requests.get(iterateidx).layer.ordinal() > stopAt.ordinal()){
break; break;
} }
BlockRequest req = requests.get(iterateidx); BlockRequest req = requests.get(iterateidx);
Block block = req.tile.block(); Block block = req.tile.block();
if(req.layer == Layer.block){ if(req.layer == Layer.block){
block.draw(req.tile); block.draw(req.tile);
}else if(req.layer == block.layer){ }else if(req.layer == block.layer){
block.drawLayer(req.tile); block.drawLayer(req.tile);
}else if(req.layer == block.layer2){ }else if(req.layer == block.layer2){
block.drawLayer2(req.tile); block.drawLayer2(req.tile);
} }
} }
} }
private void addRequest(Tile tile, Layer layer){ private void addRequest(Tile tile, Layer layer){
if(requestidx >= requests.size){ if(requestidx >= requests.size){
requests.add(new BlockRequest()); requests.add(new BlockRequest());
} }
BlockRequest r = requests.get(requestidx); BlockRequest r = requests.get(requestidx);
if(r == null){ if(r == null){
requests.set(requestidx, r = new BlockRequest()); requests.set(requestidx, r = new BlockRequest());
} }
r.tile = tile; r.tile = tile;
r.layer = layer; r.layer = layer;
requestidx ++; requestidx ++;
} }
public void drawFloor(){ public void drawFloor(){
int chunksx = world.width() / chunksize, chunksy = world.height() / chunksize; int chunksx = world.width() / chunksize, chunksy = world.height() / chunksize;
//render the entire map //render the entire map
if(cache == null || cache.length != chunksx || cache[0].length != chunksy){ if(cache == null || cache.length != chunksx || cache[0].length != chunksy){
cache = new int[chunksx][chunksy][2]; cache = new int[chunksx][chunksy][2];
for(int x = 0; x < chunksx; x++){ for(int x = 0; x < chunksx; x++){
for(int y = 0; y < chunksy; y++){ for(int y = 0; y < chunksy; y++){
cacheChunk(x, y, true); cacheChunk(x, y, true);
cacheChunk(x, y, false); cacheChunk(x, y, false);
} }
} }
} }
OrthographicCamera camera = Core.camera; OrthographicCamera camera = Core.camera;
if(Graphics.drawing()) Graphics.end(); if(Graphics.drawing()) Graphics.end();
int crangex = (int)(camera.viewportWidth * camera.zoom / (chunksize * tilesize))+1; int crangex = (int)(camera.viewportWidth * camera.zoom / (chunksize * tilesize))+1;
int crangey = (int)(camera.viewportHeight * camera.zoom / (chunksize * tilesize))+1; int crangey = (int)(camera.viewportHeight * camera.zoom / (chunksize * tilesize))+1;
drawCache(0, crangex, crangey); drawCache(0, crangex, crangey);
Graphics.begin(); Graphics.begin();
Draw.reset(); Draw.reset();
if(showPaths && debug){ if(showPaths && debug){
drawPaths(); drawPaths();
} }
if(debug && debugChunks){ if(debug && debugChunks){
Draw.color(Color.YELLOW); Draw.color(Color.YELLOW);
Lines.stroke(1f); Lines.stroke(1f);
for(int x = -crangex; x <= crangex; x++){ for(int x = -crangex; x <= crangex; x++){
for(int y = -crangey; y <= crangey; y++){ for(int y = -crangey; y <= crangey; y++){
int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x; int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x;
int worldy = Mathf.scl(camera.position.y, chunksize * tilesize) + y; int worldy = Mathf.scl(camera.position.y, chunksize * tilesize) + y;
if(!Mathf.inBounds(worldx, worldy, cache)) if(!Mathf.inBounds(worldx, worldy, cache))
continue; continue;
Lines.rect(worldx * chunksize * tilesize, worldy * chunksize * tilesize, chunksize * tilesize, chunksize * tilesize); Lines.rect(worldx * chunksize * tilesize, worldy * chunksize * tilesize, chunksize * tilesize, chunksize * tilesize);
} }
} }
Draw.reset(); Draw.reset();
} }
} }
void drawPaths(){ void drawPaths(){
Draw.color(Color.RED); Draw.color(Color.RED);
for(SpawnPoint point : world.getSpawns()){ for(SpawnPoint point : world.getSpawns()){
if(point.pathTiles != null){ if(point.pathTiles != null){
for(int i = 1; i < point.pathTiles.length; i ++){ for(int i = 1; i < point.pathTiles.length; i ++){
Lines.line(point.pathTiles[i-1].worldx(), point.pathTiles[i-1].worldy(), Lines.line(point.pathTiles[i-1].worldx(), point.pathTiles[i-1].worldy(),
point.pathTiles[i].worldx(), point.pathTiles[i].worldy()); point.pathTiles[i].worldx(), point.pathTiles[i].worldy());
Lines.circle(point.pathTiles[i-1].worldx(), point.pathTiles[i-1].worldy(), 6f); Lines.circle(point.pathTiles[i-1].worldx(), point.pathTiles[i-1].worldy(), 6f);
} }
} }
} }
Draw.reset(); Draw.reset();
} }
void drawCache(int layer, int crangex, int crangey){ void drawCache(int layer, int crangex, int crangey){
Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glEnable(GL20.GL_BLEND);
cbatch.setProjectionMatrix(Core.camera.combined); cbatch.setProjectionMatrix(Core.camera.combined);
cbatch.beginDraw(); cbatch.beginDraw();
for(int x = -crangex; x <= crangex; x++){ for(int x = -crangex; x <= crangex; x++){
for(int y = -crangey; y <= crangey; y++){ for(int y = -crangey; y <= crangey; y++){
int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x; int worldx = Mathf.scl(camera.position.x, chunksize * tilesize) + x;
int worldy = Mathf.scl(camera.position.y, chunksize * tilesize) + y; int worldy = Mathf.scl(camera.position.y, chunksize * tilesize) + y;
if(!Mathf.inBounds(worldx, worldy, cache)) if(!Mathf.inBounds(worldx, worldy, cache))
continue; continue;
cbatch.drawCache(cache[worldx][worldy][layer]); cbatch.drawCache(cache[worldx][worldy][layer]);
} }
} }
cbatch.endDraw(); cbatch.endDraw();
} }
void cacheChunk(int cx, int cy, boolean floor){ void cacheChunk(int cx, int cy, boolean floor){
if(cbatch == null){ if(cbatch == null){
createBatch(); createBatch();
} }
cbatch.begin(); cbatch.begin();
Graphics.useBatch(cbatch); Graphics.useBatch(cbatch);
for(int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++){ for(int tilex = cx * chunksize; tilex < (cx + 1) * chunksize; tilex++){
for(int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++){ for(int tiley = cy * chunksize; tiley < (cy + 1) * chunksize; tiley++){
Tile tile = world.tile(tilex, tiley); Tile tile = world.tile(tilex, tiley);
if(tile == null) continue; if(tile == null) continue;
if(floor){ if(floor){
if(!(tile.block() instanceof StaticBlock)){ if(!(tile.block() instanceof StaticBlock)){
tile.floor().draw(tile); tile.floor().draw(tile);
} }
}else if(tile.block() instanceof StaticBlock){ }else if(tile.block() instanceof StaticBlock){
tile.block().draw(tile); tile.block().draw(tile);
} }
} }
} }
Graphics.popBatch(); Graphics.popBatch();
cbatch.end(); cbatch.end();
cache[cx][cy][floor ? 0 : 1] = cbatch.getLastCache(); cache[cx][cy][floor ? 0 : 1] = cbatch.getLastCache();
} }
public void clearTiles(){ public void clearTiles(){
cache = null; cache = null;
createBatch(); createBatch();
} }
private void createBatch(){ private void createBatch(){
if(cbatch != null) if(cbatch != null)
cbatch.dispose(); cbatch.dispose();
cbatch = new CacheBatch(world.width() * world.height() * 4); cbatch = new CacheBatch(world.width() * world.height() * 4);
} }
public void drawPreview(Block block, float drawx, float drawy, float rotation, float opacity) {
Draw.reset();
Draw.alpha(opacity);
Draw.rect(block.name(), drawx, drawy, rotation);
}
public void handlePreview(Block block, float rotation, float drawx, float drawy, int tilex, int tiley) {
if(control.input().recipe != null && state.inventory.hasItems(control.input().recipe.requirements)
&& control.input().validPlace(tilex, tiley, block) && (android || control.input().cursorNear())) {
float opacity = (float)Settings.getInt("previewopacity")/100f;
if(block.isMultiblock()) {
if((tiley - control.input().getBlockY()) % block.height != 0
|| (tilex - control.input().getBlockX()) % block.width != 0) return;
}
if(block instanceof Turret) {
Draw.alpha(opacity);
if (block.isMultiblock()) {
Draw.rect("block-" + block.width + "x" + block.height, drawx, drawy);
} else {
Draw.rect("block", drawx, drawy);
}
}
drawPreview(block, drawx, drawy, rotation, opacity);
Tile tile = world.tile(tilex, tiley);
if((block instanceof Drill || block instanceof Pump) && block.isLayer(tile)) {
block.drawLayer(tile);
}
Draw.reset();
}
}
} }

View File

@@ -7,6 +7,7 @@ import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.ui.fragments.ToolFragment; import io.anuke.mindustry.ui.fragments.ToolFragment;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.production.Drill;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines; import io.anuke.ucore.graphics.Lines;
@@ -17,373 +18,379 @@ import io.anuke.ucore.util.Translator;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
public enum PlaceMode{ public enum PlaceMode{
cursor{ cursor{
{ {
shown = true; shown = true;
lockCamera = true; lockCamera = true;
pan = true; pan = true;
} }
public void draw(int tilex, int tiley, int endx, int endy){ public void draw(int tilex, int tiley, int endx, int endy){
float x = tilex * tilesize; float x = tilex * tilesize;
float y = tiley * tilesize; float y = tiley * tilesize;
boolean valid = control.input().validPlace(tilex, tiley, control.input().recipe.result) && (android || control.input().cursorNear()); boolean valid = control.input().validPlace(tilex, tiley, control.input().recipe.result) && (android || control.input().cursorNear());
Vector2 offset = control.input().recipe.result.getPlaceOffset(); Vector2 offset = control.input().recipe.result.getPlaceOffset();
float si = MathUtils.sin(Timers.time() / 6f) + 1.5f; float si = MathUtils.sin(Timers.time() / 6f) + 1.5f;
Draw.color(valid ? Colors.get("place") : Colors.get("placeInvalid")); Draw.color(valid ? Colors.get("place") : Colors.get("placeInvalid"));
Lines.stroke(2f); Lines.stroke(2f);
Lines.crect(x + offset.x, y + offset.y, tilesize * control.input().recipe.result.width + si, Lines.crect(x + offset.x, y + offset.y, tilesize * control.input().recipe.result.width + si,
tilesize * control.input().recipe.result.height + si); tilesize * control.input().recipe.result.height + si);
control.input().recipe.result.drawPlace(tilex, tiley, control.input().rotation, valid); control.input().recipe.result.drawPlace(tilex, tiley, control.input().rotation, valid);
Lines.stroke(2f);
if(control.input().recipe.result.rotate){ renderer.getBlocks().handlePreview(control.input().recipe.result, control.input().recipe.result.rotate ? control.input().rotation * 90 : 0f, x + offset.x, y + offset.y, tilex, tiley);
Draw.color(Colors.get("placeRotate"));
tr.trns(control.input().rotation * 90, 7, 0);
Lines.line(x, y, x + tr.x, y + tr.y);
}
}
public void tapped(int tilex, int tiley){ if(control.input().recipe.result.rotate){
control.input().tryPlaceBlock(tilex, tiley, true);
}
},
touch{
{
shown = true;
lockCamera = false;
showRotate = true;
showCancel = true;
}
public void tapped(int x, int y){ Draw.color(Colors.get("placeRotate"));
control.input().tryPlaceBlock(x, y, true); tr.trns(control.input().rotation * 90, 7, 0);
} Lines.stroke(2f);
}, Lines.line(x, y, x + tr.x, y + tr.y);
none{ }
{ }
delete = true;
shown = true;
both = true;
}
},
holdDelete{
{
delete = true;
shown = true;
both = true;
}
public void draw(int tilex, int tiley, int endx, int endy){ public void tapped(int tilex, int tiley){
Tile tile = world.tile(tilex, tiley); control.input().tryPlaceBlock(tilex, tiley, true);
}
},
touch{
{
shown = true;
lockCamera = false;
showRotate = true;
showCancel = true;
}
if(tile != null && control.input().validBreak(tilex, tiley)){ public void tapped(int x, int y){
if(tile.isLinked()) control.input().tryPlaceBlock(x, y, true);
tile = tile.getLinked(); }
float fin = control.input().breaktime / tile.getBreakTime(); },
none{
{
delete = true;
shown = true;
both = true;
}
},
holdDelete{
{
delete = true;
shown = true;
both = true;
}
if(android && control.input().breaktime > 0){ public void draw(int tilex, int tiley, int endx, int endy){
Draw.color(Colors.get("breakStart"), Colors.get("break"), fin); Tile tile = world.tile(tilex, tiley);
Lines.poly(tile.drawx(), tile.drawy(), 25, 4 + (1f - fin) * 26);
}
Draw.reset();
}
}
},
touchDelete{
{
shown = true;
lockCamera = false;
showRotate = true;
showCancel = true;
delete = true;
}
public void tapped(int x, int y){ if(tile != null && control.input().validBreak(tilex, tiley)){
control.input().tryDeleteBlock(x, y, true); if(tile.isLinked())
} tile = tile.getLinked();
}, float fin = control.input().breaktime / tile.getBreakTime();
areaDelete{
int maxlen = 20;
int tilex;
int tiley;
int endx;
int endy;
{ if(android && control.input().breaktime > 0){
shown = true; Draw.color(Colors.get("breakStart"), Colors.get("break"), fin);
lockCamera = true; Lines.poly(tile.drawx(), tile.drawy(), 25, 4 + (1f - fin) * 26);
delete = true; }
} Draw.reset();
}
}
},
touchDelete{
{
shown = true;
lockCamera = false;
showRotate = true;
showCancel = true;
delete = true;
}
public void draw(int tilex, int tiley, int endx, int endy){ public void tapped(int x, int y){
float t = tilesize; control.input().tryDeleteBlock(x, y, true);
}
},
areaDelete{
int maxlen = 20;
int tilex;
int tiley;
int endx;
int endy;
process(tilex, tiley, endx, endy); {
shown = true;
lockCamera = true;
delete = true;
}
tilex = this.tilex; tiley = this.tiley; public void draw(int tilex, int tiley, int endx, int endy){
endx = this.endx; endy = this.endy; float t = tilesize;
float x = this.tilex * t, y = this.tiley * t,
x2 = this.endx * t, y2 = this.endy * t;
if(x2 >= x){ process(tilex, tiley, endx, endy);
x -= t/2;
x2 += t/2;
}
if(y2 >= y){ tilex = this.tilex; tiley = this.tiley;
y -= t/2; endx = this.endx; endy = this.endy;
y2 += t/2; float x = this.tilex * t, y = this.tiley * t,
} x2 = this.endx * t, y2 = this.endy * t;
Draw.color(Colors.get("break")); if(x2 >= x){
Lines.stroke(1f); x -= t/2;
for(int cx = tilex; cx <= endx; cx ++){ x2 += t/2;
for(int cy = tiley; cy <= endy; cy ++){ }
Tile tile = world.tile(cx, cy);
if(tile != null && tile.getLinked() != null)
tile = tile.getLinked();
if(tile != null && control.input().validBreak(tile.x, tile.y)){
Lines.crect(tile.drawx(), tile.drawy(),
tile.block().width * t, tile.block().height * t);
}
}
}
Lines.stroke(2f); if(y2 >= y){
Draw.color(control.input().cursorNear() ? Colors.get("break") : Colors.get("breakInvalid")); y -= t/2;
Lines.rect(x, y, x2 - x, y2 - y); y2 += t/2;
Draw.alpha(0.3f); }
Draw.crect("blank", x, y, x2 - x, y2 - y);
Draw.reset();
}
public void released(int tilex, int tiley, int endx, int endy){ Draw.color(Colors.get("break"));
process(tilex, tiley, endx, endy); Lines.stroke(1f);
tilex = this.tilex; tiley = this.tiley; for(int cx = tilex; cx <= endx; cx ++){
endx = this.endx; endy = this.endy; for(int cy = tiley; cy <= endy; cy ++){
Tile tile = world.tile(cx, cy);
if(tile != null && tile.getLinked() != null)
tile = tile.getLinked();
if(tile != null && control.input().validBreak(tile.x, tile.y)){
Lines.crect(tile.drawx(), tile.drawy(),
tile.block().width * t, tile.block().height * t);
}
}
}
if(android){ Lines.stroke(2f);
ToolFragment t = ui.toolfrag; Draw.color(control.input().cursorNear() ? Colors.get("break") : Colors.get("breakInvalid"));
if(!t.confirming || t.px != tilex || t.py != tiley || t.px2 != endx || t.py2 != endy) { Lines.rect(x, y, x2 - x, y2 - y);
t.confirming = true; Draw.alpha(0.3f);
t.px = tilex; Draw.crect("blank", x, y, x2 - x, y2 - y);
t.py = tiley; Draw.reset();
t.px2 = endx; }
t.py2 = endy;
return;
}
}
boolean first = true; public void released(int tilex, int tiley, int endx, int endy){
process(tilex, tiley, endx, endy);
tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy;
for(int cx = tilex; cx <= endx; cx ++){ if(android){
for(int cy = tiley; cy <= endy; cy ++){ ToolFragment t = ui.toolfrag;
if(control.input().tryDeleteBlock(cx, cy, first)){ if(!t.confirming || t.px != tilex || t.py != tiley || t.px2 != endx || t.py2 != endy) {
first = false; t.confirming = true;
} t.px = tilex;
} t.py = tiley;
} t.px2 = endx;
} t.py2 = endy;
return;
}
}
void process(int tilex, int tiley, int endx, int endy){ boolean first = true;
if(Math.abs(endx - tilex) > maxlen){ for(int cx = tilex; cx <= endx; cx ++){
endx = Mathf.sign(endx - tilex) * maxlen + tilex; for(int cy = tiley; cy <= endy; cy ++){
} if(control.input().tryDeleteBlock(cx, cy, first)){
first = false;
}
}
}
}
if(Math.abs(endy - tiley) > maxlen){ void process(int tilex, int tiley, int endx, int endy){
endy = Mathf.sign(endy - tiley) * maxlen + tiley;
}
if(endx < tilex){ if(Math.abs(endx - tilex) > maxlen){
int t = endx; endx = Mathf.sign(endx - tilex) * maxlen + tilex;
endx = tilex; }
tilex = t;
}
if(endy < tiley){
int t = endy;
endy = tiley;
tiley = t;
}
this.endx = endx; if(Math.abs(endy - tiley) > maxlen){
this.endy = endy; endy = Mathf.sign(endy - tiley) * maxlen + tiley;
this.tilex = tilex; }
this.tiley = tiley;
}
},
hold{
int maxlen = 20;
int tilex;
int tiley;
int endx;
int endy;
int rotation;
{ if(endx < tilex){
lockCamera = true; int t = endx;
shown = true; endx = tilex;
showCancel = true; tilex = t;
showRotate = true; }
} if(endy < tiley){
int t = endy;
endy = tiley;
tiley = t;
}
public void draw(int tilex, int tiley, int endx, int endy){ this.endx = endx;
if(android && !Gdx.input.isTouched(0) && !control.showCursor()){ this.endy = endy;
return; this.tilex = tilex;
} this.tiley = tiley;
}
},
hold{
int maxlen = 20;
int tilex;
int tiley;
int endx;
int endy;
int rotation;
float t = tilesize; {
Block block = control.input().recipe.result; lockCamera = true;
Vector2 offset = block.getPlaceOffset(); shown = true;
showCancel = true;
showRotate = true;
}
process(tilex, tiley, endx, endy); public void draw(int tilex, int tiley, int endx, int endy){
int tx = tilex, ty = tiley, ex = endx, ey = endy; if(android && !Gdx.input.isTouched(0) && !control.showCursor()){
tilex = this.tilex; tiley = this.tiley; return;
endx = this.endx; endy = this.endy; }
float x = this.tilex * t, y = this.tiley * t,
x2 = this.endx * t, y2 = this.endy * t;
if(x2 >= x){ float t = tilesize;
x -= block.width * t/2; Block block = control.input().recipe.result;
x2 += block.width * t/2; Vector2 offset = block.getPlaceOffset();
}
if(y2 >= y){ process(tilex, tiley, endx, endy);
y -= block.height * t/2; int tx = tilex, ty = tiley, ex = endx, ey = endy;
y2 += block.height * t/2; tilex = this.tilex; tiley = this.tiley;
} endx = this.endx; endy = this.endy;
float x = this.tilex * t, y = this.tiley * t,
x2 = this.endx * t, y2 = this.endy * t;
x += offset.x; if(x2 >= x){
y += offset.y; x -= block.width * t/2;
x2 += offset.x; x2 += block.width * t/2;
y2 += offset.y; }
if(tilex == endx && tiley == endy){ if(y2 >= y){
cursor.draw(tilex, tiley, endx, endy); y -= block.height * t/2;
}else{ y2 += block.height * t/2;
Lines.stroke(2f); }
Draw.color(control.input().cursorNear() ? Colors.get("place") : Colors.get("placeInvalid"));
Lines.rect(x, y, x2 - x, y2 - y);
Draw.alpha(0.3f);
Draw.crect("blank", x, y, x2 - x, y2 - y);
Draw.color(Colors.get("placeInvalid")); x += offset.x;
y += offset.y;
x2 += offset.x;
y2 += offset.y;
int amount = 1; if(tilex == endx && tiley == endy){
for(int cx = 0; cx <= Math.abs(endx - tilex); cx ++){ cursor.draw(tilex, tiley, endx, endy);
for(int cy = 0; cy <= Math.abs(endy - tiley); cy ++){ }else{
int px = tx + cx * Mathf.sign(ex - tx), Lines.stroke(2f);
py = ty + cy * Mathf.sign(ey - ty); Draw.color(control.input().cursorNear() ? Colors.get("place") : Colors.get("placeInvalid"));
Lines.rect(x, y, x2 - x, y2 - y);
Draw.alpha(0.3f);
Draw.crect("blank", x, y, x2 - x, y2 - y);
if(!control.input().validPlace(px, py, control.input().recipe.result) Draw.color(Colors.get("placeInvalid"));
|| !state.inventory.hasItems(control.input().recipe.requirements, amount)){
Lines.crect(px * t + offset.x, py * t + offset.y, t*block.width, t*block.height);
}
amount ++;
}
}
if(control.input().recipe.result.rotate){ int amount = 1;
float cx = tx * t, cy = ty * t; for(int cx = 0; cx <= Math.abs(endx - tilex); cx ++){
Draw.color(Colors.get("placeRotate")); for(int cy = 0; cy <= Math.abs(endy - tiley); cy ++){
tr.trns(rotation * 90, 7, 0); int px = tx + cx * Mathf.sign(ex - tx),
Lines.line(cx, cy, cx + tr.x, cy + tr.y); py = ty + cy * Mathf.sign(ey - ty);
}
Draw.reset();
}
}
public void released(int tilex, int tiley, int endx, int endy){ renderer.getBlocks().handlePreview(control.input().recipe.result, control.input().recipe.result.rotate ? rotation * 90 : 0f, px * t + offset.x, py * t + offset.y, px, py);
process(tilex, tiley, endx, endy);
control.input().rotation = this.rotation; if(!control.input().validPlace(px, py, control.input().recipe.result)
|| !state.inventory.hasItems(control.input().recipe.requirements, amount))
Lines.crect(px * t + offset.x, py * t + offset.y, t*block.width, t*block.height);
boolean first = true; amount ++;
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){ }
for(int y = 0; y <= Math.abs(this.endy - this.tiley); y ++){ }
if(control.input().tryPlaceBlock(
tilex + x * Mathf.sign(endx - tilex),
tiley + y * Mathf.sign(endy - tiley), first)){
first = false;
}
} if(control.input().recipe.result.rotate){
} float cx = tx * t, cy = ty * t;
} Lines.stroke(2f);
Draw.color(Colors.get("placeRotate"));
tr.trns(rotation * 90, 7, 0);
Lines.line(cx, cy, cx + tr.x, cy + tr.y);
}
Draw.reset();
}
}
void process(int tilex, int tiley, int endx, int endy){ public void released(int tilex, int tiley, int endx, int endy){
if(Math.abs(tilex - endx) > Math.abs(tiley - endy)){ process(tilex, tiley, endx, endy);
endy = tiley;
}else{
endx = tilex;
}
if(Math.abs(endx - tilex) > maxlen){ control.input().rotation = this.rotation;
endx = Mathf.sign(endx - tilex) * maxlen + tilex;
}
if(Math.abs(endy - tiley) > maxlen){ boolean first = true;
endy = Mathf.sign(endy - tiley) * maxlen + tiley; for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){
} for(int y = 0; y <= Math.abs(this.endy - this.tiley); y ++){
if(control.input().tryPlaceBlock(
tilex + x * Mathf.sign(endx - tilex),
tiley + y * Mathf.sign(endy - tiley), first)){
first = false;
}
if(endx > tilex) }
rotation = 0; }
else if(endx < tilex) }
rotation = 2;
else if(endy > tiley)
rotation = 1;
else if(endy < tiley)
rotation = 3;
else
rotation = control.input().rotation;
if(endx < tilex){ void process(int tilex, int tiley, int endx, int endy){
int t = endx; if(Math.abs(tilex - endx) > Math.abs(tiley - endy)){
endx = tilex; endy = tiley;
tilex = t; }else{
} endx = tilex;
if(endy < tiley){ }
int t = endy;
endy = tiley;
tiley = t;
}
this.endx = endx; if(Math.abs(endx - tilex) > maxlen){
this.endy = endy; endx = Mathf.sign(endx - tilex) * maxlen + tilex;
this.tilex = tilex; }
this.tiley = tiley;
}
};
public boolean lockCamera;
public boolean pan = false;
public boolean shown = false;
public boolean showRotate;
public boolean showCancel;
public boolean delete = false;
public boolean both = false;
private static final Translator tr = new Translator(); if(Math.abs(endy - tiley) > maxlen){
endy = Mathf.sign(endy - tiley) * maxlen + tiley;
}
public void draw(int tilex, int tiley, int endx, int endy){ if(endx > tilex)
rotation = 0;
else if(endx < tilex)
rotation = 2;
else if(endy > tiley)
rotation = 1;
else if(endy < tiley)
rotation = 3;
else
rotation = control.input().rotation;
} if(endx < tilex){
int t = endx;
endx = tilex;
tilex = t;
}
if(endy < tiley){
int t = endy;
endy = tiley;
tiley = t;
}
public void released(int tilex, int tiley, int endx, int endy){ this.endx = endx;
this.endy = endy;
this.tilex = tilex;
this.tiley = tiley;
}
};
public boolean lockCamera;
public boolean pan = false;
public boolean shown = false;
public boolean showRotate;
public boolean showCancel;
public boolean delete = false;
public boolean both = false;
} private static final Translator tr = new Translator();
public void tapped(int x, int y){ public void draw(int tilex, int tiley, int endx, int endy){
} }
@Override public void released(int tilex, int tiley, int endx, int endy){
public String toString(){
return Bundles.get("placemode."+name().toLowerCase()+".name"); }
}
public void tapped(int x, int y){
}
@Override
public String toString(){
return Bundles.get("placemode."+name().toLowerCase()+".name");
}
} }

View File

@@ -139,6 +139,7 @@ public class SettingsMenuDialog extends SettingsDialog{
graphics.checkPref("fps", false); graphics.checkPref("fps", false);
graphics.checkPref("lasers", true); graphics.checkPref("lasers", true);
graphics.sliderPref("previewopacity", 50, 0, 100, i -> i + "%");
graphics.checkPref("indicators", true); graphics.checkPref("indicators", true);
graphics.checkPref("healthbars", true); graphics.checkPref("healthbars", true);
graphics.checkPref("pixelate", true, b -> { graphics.checkPref("pixelate", true, b -> {