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);
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);
if(control.input().recipe.result.rotate){
Draw.color(Colors.get("placeRotate")); if(control.input().recipe.result.rotate){
tr.trns(control.input().rotation * 90, 7, 0);
Lines.line(x, y, x + tr.x, y + tr.y); Draw.color(Colors.get("placeRotate"));
} tr.trns(control.input().rotation * 90, 7, 0);
} Lines.stroke(2f);
Lines.line(x, y, x + tr.x, y + tr.y);
public void tapped(int tilex, int tiley){ }
control.input().tryPlaceBlock(tilex, tiley, true); }
}
}, public void tapped(int tilex, int tiley){
touch{ control.input().tryPlaceBlock(tilex, tiley, true);
{ }
shown = true; },
lockCamera = false; touch{
showRotate = true; {
showCancel = true; shown = true;
} lockCamera = false;
showRotate = true;
public void tapped(int x, int y){ showCancel = true;
control.input().tryPlaceBlock(x, y, true); }
}
}, public void tapped(int x, int y){
none{ control.input().tryPlaceBlock(x, y, true);
{ }
delete = true; },
shown = true; none{
both = true; {
} delete = true;
}, shown = true;
holdDelete{ both = true;
{ }
delete = true; },
shown = true; holdDelete{
both = true; {
} delete = true;
shown = true;
public void draw(int tilex, int tiley, int endx, int endy){ both = true;
Tile tile = world.tile(tilex, tiley); }
if(tile != null && control.input().validBreak(tilex, tiley)){ public void draw(int tilex, int tiley, int endx, int endy){
if(tile.isLinked()) Tile tile = world.tile(tilex, tiley);
tile = tile.getLinked();
float fin = control.input().breaktime / tile.getBreakTime(); if(tile != null && control.input().validBreak(tilex, tiley)){
if(tile.isLinked())
if(android && control.input().breaktime > 0){ tile = tile.getLinked();
Draw.color(Colors.get("breakStart"), Colors.get("break"), fin); float fin = control.input().breaktime / tile.getBreakTime();
Lines.poly(tile.drawx(), tile.drawy(), 25, 4 + (1f - fin) * 26);
} if(android && control.input().breaktime > 0){
Draw.reset(); Draw.color(Colors.get("breakStart"), Colors.get("break"), fin);
} Lines.poly(tile.drawx(), tile.drawy(), 25, 4 + (1f - fin) * 26);
} }
}, Draw.reset();
touchDelete{ }
{ }
shown = true; },
lockCamera = false; touchDelete{
showRotate = true; {
showCancel = true; shown = true;
delete = true; lockCamera = false;
} showRotate = true;
showCancel = true;
public void tapped(int x, int y){ delete = true;
control.input().tryDeleteBlock(x, y, true); }
}
}, public void tapped(int x, int y){
areaDelete{ control.input().tryDeleteBlock(x, y, true);
int maxlen = 20; }
int tilex; },
int tiley; areaDelete{
int endx; int maxlen = 20;
int endy; int tilex;
int tiley;
{ int endx;
shown = true; int endy;
lockCamera = true;
delete = true; {
} shown = true;
lockCamera = true;
public void draw(int tilex, int tiley, int endx, int endy){ delete = true;
float t = tilesize; }
process(tilex, tiley, endx, endy); public void draw(int tilex, int tiley, int endx, int endy){
float t = tilesize;
tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy; process(tilex, tiley, endx, endy);
float x = this.tilex * t, y = this.tiley * t,
x2 = this.endx * t, y2 = this.endy * t; tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy;
if(x2 >= x){ float x = this.tilex * t, y = this.tiley * t,
x -= t/2; x2 = this.endx * t, y2 = this.endy * t;
x2 += t/2;
} if(x2 >= x){
x -= t/2;
if(y2 >= y){ x2 += t/2;
y -= t/2; }
y2 += t/2;
} if(y2 >= y){
y -= t/2;
Draw.color(Colors.get("break")); y2 += t/2;
Lines.stroke(1f); }
for(int cx = tilex; cx <= endx; cx ++){
for(int cy = tiley; cy <= endy; cy ++){ Draw.color(Colors.get("break"));
Tile tile = world.tile(cx, cy); Lines.stroke(1f);
if(tile != null && tile.getLinked() != null) for(int cx = tilex; cx <= endx; cx ++){
tile = tile.getLinked(); for(int cy = tiley; cy <= endy; cy ++){
if(tile != null && control.input().validBreak(tile.x, tile.y)){ Tile tile = world.tile(cx, cy);
Lines.crect(tile.drawx(), tile.drawy(), if(tile != null && tile.getLinked() != null)
tile.block().width * t, tile.block().height * t); 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); }
Draw.color(control.input().cursorNear() ? Colors.get("break") : Colors.get("breakInvalid")); }
Lines.rect(x, y, x2 - x, y2 - y);
Draw.alpha(0.3f); Lines.stroke(2f);
Draw.crect("blank", x, y, x2 - x, y2 - y); Draw.color(control.input().cursorNear() ? Colors.get("break") : Colors.get("breakInvalid"));
Draw.reset(); Lines.rect(x, y, x2 - x, y2 - y);
} Draw.alpha(0.3f);
Draw.crect("blank", x, y, x2 - x, y2 - y);
public void released(int tilex, int tiley, int endx, int endy){ Draw.reset();
process(tilex, tiley, endx, endy); }
tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy; public void released(int tilex, int tiley, int endx, int endy){
process(tilex, tiley, endx, endy);
if(android){ tilex = this.tilex; tiley = this.tiley;
ToolFragment t = ui.toolfrag; endx = this.endx; endy = this.endy;
if(!t.confirming || t.px != tilex || t.py != tiley || t.px2 != endx || t.py2 != endy) {
t.confirming = true; if(android){
t.px = tilex; ToolFragment t = ui.toolfrag;
t.py = tiley; if(!t.confirming || t.px != tilex || t.py != tiley || t.px2 != endx || t.py2 != endy) {
t.px2 = endx; t.confirming = true;
t.py2 = endy; t.px = tilex;
return; t.py = tiley;
} t.px2 = endx;
} t.py2 = endy;
return;
boolean first = true; }
}
for(int cx = tilex; cx <= endx; cx ++){
for(int cy = tiley; cy <= endy; cy ++){ boolean first = true;
if(control.input().tryDeleteBlock(cx, cy, first)){
first = false; for(int cx = tilex; cx <= endx; cx ++){
} for(int cy = tiley; cy <= endy; cy ++){
} if(control.input().tryDeleteBlock(cx, cy, first)){
} first = false;
} }
}
void process(int tilex, int tiley, int endx, int endy){ }
}
if(Math.abs(endx - tilex) > maxlen){
endx = Mathf.sign(endx - tilex) * maxlen + tilex; void process(int tilex, int tiley, int endx, int endy){
}
if(Math.abs(endx - tilex) > maxlen){
if(Math.abs(endy - tiley) > maxlen){ endx = Mathf.sign(endx - tilex) * maxlen + tilex;
endy = Mathf.sign(endy - tiley) * maxlen + tiley; }
}
if(Math.abs(endy - tiley) > maxlen){
if(endx < tilex){ endy = Mathf.sign(endy - tiley) * maxlen + tiley;
int t = endx; }
endx = tilex;
tilex = t; if(endx < tilex){
} int t = endx;
if(endy < tiley){ endx = tilex;
int t = endy; tilex = t;
endy = tiley; }
tiley = t; if(endy < tiley){
} int t = endy;
endy = tiley;
this.endx = endx; tiley = t;
this.endy = endy; }
this.tilex = tilex;
this.tiley = tiley; this.endx = endx;
} this.endy = endy;
}, this.tilex = tilex;
hold{ this.tiley = tiley;
int maxlen = 20; }
int tilex; },
int tiley; hold{
int endx; int maxlen = 20;
int endy; int tilex;
int rotation; int tiley;
int endx;
{ int endy;
lockCamera = true; int rotation;
shown = true;
showCancel = true; {
showRotate = true; lockCamera = true;
} shown = true;
showCancel = true;
public void draw(int tilex, int tiley, int endx, int endy){ showRotate = true;
if(android && !Gdx.input.isTouched(0) && !control.showCursor()){ }
return;
} public void draw(int tilex, int tiley, int endx, int endy){
if(android && !Gdx.input.isTouched(0) && !control.showCursor()){
float t = tilesize; return;
Block block = control.input().recipe.result; }
Vector2 offset = block.getPlaceOffset();
float t = tilesize;
process(tilex, tiley, endx, endy); Block block = control.input().recipe.result;
int tx = tilex, ty = tiley, ex = endx, ey = endy; Vector2 offset = block.getPlaceOffset();
tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy; process(tilex, tiley, endx, endy);
float x = this.tilex * t, y = this.tiley * t, int tx = tilex, ty = tiley, ex = endx, ey = endy;
x2 = this.endx * t, y2 = this.endy * t; tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy;
if(x2 >= x){ float x = this.tilex * t, y = this.tiley * t,
x -= block.width * t/2; x2 = this.endx * t, y2 = this.endy * t;
x2 += block.width * t/2;
} if(x2 >= x){
x -= block.width * t/2;
if(y2 >= y){ x2 += block.width * t/2;
y -= block.height * t/2; }
y2 += block.height * t/2;
} if(y2 >= y){
y -= block.height * t/2;
x += offset.x; y2 += block.height * t/2;
y += offset.y; }
x2 += offset.x;
y2 += offset.y; x += offset.x;
y += offset.y;
if(tilex == endx && tiley == endy){ x2 += offset.x;
cursor.draw(tilex, tiley, endx, endy); y2 += offset.y;
}else{
Lines.stroke(2f); if(tilex == endx && tiley == endy){
Draw.color(control.input().cursorNear() ? Colors.get("place") : Colors.get("placeInvalid")); cursor.draw(tilex, tiley, endx, endy);
Lines.rect(x, y, x2 - x, y2 - y); }else{
Draw.alpha(0.3f); Lines.stroke(2f);
Draw.crect("blank", x, y, x2 - x, y2 - y); Draw.color(control.input().cursorNear() ? Colors.get("place") : Colors.get("placeInvalid"));
Lines.rect(x, y, x2 - x, y2 - y);
Draw.color(Colors.get("placeInvalid")); Draw.alpha(0.3f);
Draw.crect("blank", x, y, x2 - x, y2 - y);
int amount = 1;
for(int cx = 0; cx <= Math.abs(endx - tilex); cx ++){ Draw.color(Colors.get("placeInvalid"));
for(int cy = 0; cy <= Math.abs(endy - tiley); cy ++){
int px = tx + cx * Mathf.sign(ex - tx), int amount = 1;
py = ty + cy * Mathf.sign(ey - ty); for(int cx = 0; cx <= Math.abs(endx - tilex); cx ++){
for(int cy = 0; cy <= Math.abs(endy - tiley); cy ++){
if(!control.input().validPlace(px, py, control.input().recipe.result) int px = tx + cx * Mathf.sign(ex - tx),
|| !state.inventory.hasItems(control.input().recipe.requirements, amount)){ py = ty + cy * Mathf.sign(ey - ty);
Lines.crect(px * t + offset.x, py * t + offset.y, t*block.width, t*block.height);
} 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);
amount ++;
} 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);
if(control.input().recipe.result.rotate){
float cx = tx * t, cy = ty * t; amount ++;
Draw.color(Colors.get("placeRotate")); }
tr.trns(rotation * 90, 7, 0); }
Lines.line(cx, cy, cx + tr.x, cy + tr.y);
} if(control.input().recipe.result.rotate){
Draw.reset(); float cx = tx * t, cy = ty * t;
} Lines.stroke(2f);
} Draw.color(Colors.get("placeRotate"));
tr.trns(rotation * 90, 7, 0);
public void released(int tilex, int tiley, int endx, int endy){ Lines.line(cx, cy, cx + tr.x, cy + tr.y);
process(tilex, tiley, endx, endy); }
Draw.reset();
control.input().rotation = this.rotation; }
}
boolean first = true;
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){ public void released(int tilex, int tiley, int endx, int endy){
for(int y = 0; y <= Math.abs(this.endy - this.tiley); y ++){ process(tilex, tiley, endx, endy);
if(control.input().tryPlaceBlock(
tilex + x * Mathf.sign(endx - tilex), control.input().rotation = this.rotation;
tiley + y * Mathf.sign(endy - tiley), first)){
first = false; boolean first = true;
} 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;
void process(int tilex, int tiley, int endx, int endy){ }
if(Math.abs(tilex - endx) > Math.abs(tiley - endy)){
endy = tiley; }
}else{ }
endx = tilex; }
}
void process(int tilex, int tiley, int endx, int endy){
if(Math.abs(endx - tilex) > maxlen){ if(Math.abs(tilex - endx) > Math.abs(tiley - endy)){
endx = Mathf.sign(endx - tilex) * maxlen + tilex; endy = tiley;
} }else{
endx = tilex;
if(Math.abs(endy - tiley) > maxlen){ }
endy = Mathf.sign(endy - tiley) * maxlen + tiley;
} if(Math.abs(endx - tilex) > maxlen){
endx = Mathf.sign(endx - tilex) * maxlen + tilex;
if(endx > tilex) }
rotation = 0;
else if(endx < tilex) if(Math.abs(endy - tiley) > maxlen){
rotation = 2; endy = Mathf.sign(endy - tiley) * maxlen + tiley;
else if(endy > tiley) }
rotation = 1;
else if(endy < tiley) if(endx > tilex)
rotation = 3; rotation = 0;
else else if(endx < tilex)
rotation = control.input().rotation; rotation = 2;
else if(endy > tiley)
if(endx < tilex){ rotation = 1;
int t = endx; else if(endy < tiley)
endx = tilex; rotation = 3;
tilex = t; else
} rotation = control.input().rotation;
if(endy < tiley){
int t = endy; if(endx < tilex){
endy = tiley; int t = endx;
tiley = t; endx = tilex;
} tilex = t;
}
this.endx = endx; if(endy < tiley){
this.endy = endy; int t = endy;
this.tilex = tilex; endy = tiley;
this.tiley = tiley; tiley = t;
} }
};
public boolean lockCamera; this.endx = endx;
public boolean pan = false; this.endy = endy;
public boolean shown = false; this.tilex = tilex;
public boolean showRotate; this.tiley = tiley;
public boolean showCancel; }
public boolean delete = false; };
public boolean both = false; public boolean lockCamera;
public boolean pan = false;
private static final Translator tr = new Translator(); public boolean shown = false;
public boolean showRotate;
public void draw(int tilex, int tiley, int endx, int endy){ public boolean showCancel;
public boolean delete = false;
} public boolean both = false;
public void released(int tilex, int tiley, int endx, int endy){ private static final Translator tr = new Translator();
} public void draw(int tilex, int tiley, int endx, int endy){
public void tapped(int x, int y){ }
} public void released(int tilex, int tiley, int endx, int endy){
@Override }
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 -> {