Merge pull request #117 from hellomouse/feature-blockpreview
Added Placement Preview
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -12,13 +12,14 @@ 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.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.core.Settings;
|
||||||
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 java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
@@ -27,6 +28,8 @@ 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 static float storeX = 0;
|
||||||
|
private static float storeY = 0;
|
||||||
|
|
||||||
private int[][][] cache;
|
private int[][][] cache;
|
||||||
private CacheBatch cbatch;
|
private CacheBatch cbatch;
|
||||||
@@ -49,7 +52,7 @@ public class BlockRenderer{
|
|||||||
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();
|
||||||
@@ -65,11 +68,11 @@ public class BlockRenderer{
|
|||||||
|
|
||||||
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;
|
||||||
@@ -89,16 +92,16 @@ public class BlockRenderer{
|
|||||||
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);
|
||||||
}
|
}
|
||||||
@@ -120,7 +123,7 @@ public class BlockRenderer{
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@@ -129,14 +132,14 @@ public class BlockRenderer{
|
|||||||
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){
|
||||||
@@ -162,11 +165,11 @@ public class BlockRenderer{
|
|||||||
|
|
||||||
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);
|
||||||
@@ -174,24 +177,24 @@ public class BlockRenderer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
@@ -199,7 +202,7 @@ public class BlockRenderer{
|
|||||||
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);
|
||||||
@@ -215,7 +218,7 @@ public class BlockRenderer{
|
|||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,35 +226,35 @@ public class BlockRenderer{
|
|||||||
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);
|
||||||
@@ -269,15 +272,60 @@ public class BlockRenderer{
|
|||||||
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.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())) {
|
||||||
|
|
||||||
|
if(block.isMultiblock()) {
|
||||||
|
float halfBlockWidth = (block.width * tilesize) / 2;
|
||||||
|
float halfBlockHeight = (block.height * tilesize) / 2;
|
||||||
|
if((storeX == 0 && storeY == 0)) {
|
||||||
|
storeX = drawx;
|
||||||
|
storeY = drawy;
|
||||||
|
}
|
||||||
|
if((storeX == drawx - halfBlockWidth || storeX == drawx + halfBlockWidth || storeY == drawy - halfBlockHeight || storeY == drawy + halfBlockHeight) &&
|
||||||
|
((tiley - control.input().getBlockY()) % block.height != 0 || (tilex - control.input().getBlockX()) % block.width != 0)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
storeX = drawx;
|
||||||
|
storeY = drawy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float opacity = (float) Settings.getInt("previewopacity") / 100f;
|
||||||
|
Draw.color(Color.WHITE);
|
||||||
|
Draw.alpha(opacity);
|
||||||
|
|
||||||
|
if(block instanceof Turret) {
|
||||||
|
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);
|
||||||
|
|
||||||
|
Draw.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,20 +29,22 @@ public enum PlaceMode{
|
|||||||
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;
|
||||||
|
|
||||||
|
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(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){
|
if(control.input().recipe.result.rotate){
|
||||||
|
|
||||||
Draw.color(Colors.get("placeRotate"));
|
Draw.color(Colors.get("placeRotate"));
|
||||||
tr.trns(control.input().rotation * 90, 7, 0);
|
tr.trns(control.input().rotation * 90, 7, 0);
|
||||||
Lines.line(x, y, x + tr.x, y + tr.y);
|
Lines.line(x, y, x + tr.x, y + tr.y);
|
||||||
@@ -126,9 +128,9 @@ public enum PlaceMode{
|
|||||||
|
|
||||||
process(tilex, tiley, endx, endy);
|
process(tilex, tiley, endx, endy);
|
||||||
|
|
||||||
tilex = this.tilex; tiley = this.tiley;
|
tilex = this.tilex; tiley = this.tiley;
|
||||||
endx = this.endx; endy = this.endy;
|
endx = this.endx; endy = this.endy;
|
||||||
float x = this.tilex * t, y = this.tiley * t,
|
float x = this.tilex * t, y = this.tiley * t,
|
||||||
x2 = this.endx * t, y2 = this.endy * t;
|
x2 = this.endx * t, y2 = this.endy * t;
|
||||||
|
|
||||||
if(x2 >= x){
|
if(x2 >= x){
|
||||||
@@ -150,7 +152,7 @@ public enum PlaceMode{
|
|||||||
tile = tile.getLinked();
|
tile = tile.getLinked();
|
||||||
if(tile != null && control.input().validBreak(tile.x, tile.y)){
|
if(tile != null && control.input().validBreak(tile.x, tile.y)){
|
||||||
Lines.crect(tile.drawx(), tile.drawy(),
|
Lines.crect(tile.drawx(), tile.drawy(),
|
||||||
tile.block().width * t, tile.block().height * t);
|
tile.block().width * t, tile.block().height * t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,9 +167,9 @@ public enum PlaceMode{
|
|||||||
|
|
||||||
public void released(int tilex, int tiley, int endx, int endy){
|
public void released(int tilex, int tiley, int endx, int endy){
|
||||||
process(tilex, tiley, endx, endy);
|
process(tilex, tiley, endx, endy);
|
||||||
tilex = this.tilex; tiley = this.tiley;
|
tilex = this.tilex; tiley = this.tiley;
|
||||||
endx = this.endx; endy = this.endy;
|
endx = this.endx; endy = this.endy;
|
||||||
|
|
||||||
if(android){
|
if(android){
|
||||||
ToolFragment t = ui.toolfrag;
|
ToolFragment t = ui.toolfrag;
|
||||||
if(!t.confirming || t.px != tilex || t.py != tiley || t.px2 != endx || t.py2 != endy) {
|
if(!t.confirming || t.px != tilex || t.py != tiley || t.px2 != endx || t.py2 != endy) {
|
||||||
@@ -244,9 +246,9 @@ public enum PlaceMode{
|
|||||||
|
|
||||||
process(tilex, tiley, endx, endy);
|
process(tilex, tiley, endx, endy);
|
||||||
int tx = tilex, ty = tiley, ex = endx, ey = endy;
|
int tx = tilex, ty = tiley, ex = endx, ey = endy;
|
||||||
tilex = this.tilex; tiley = this.tiley;
|
tilex = this.tilex; tiley = this.tiley;
|
||||||
endx = this.endx; endy = this.endy;
|
endx = this.endx; endy = this.endy;
|
||||||
float x = this.tilex * t, y = this.tiley * t,
|
float x = this.tilex * t, y = this.tiley * t,
|
||||||
x2 = this.endx * t, y2 = this.endy * t;
|
x2 = this.endx * t, y2 = this.endy * t;
|
||||||
|
|
||||||
if(x2 >= x){
|
if(x2 >= x){
|
||||||
@@ -272,17 +274,19 @@ public enum PlaceMode{
|
|||||||
Lines.rect(x, y, x2 - x, y2 - y);
|
Lines.rect(x, y, x2 - x, y2 - y);
|
||||||
Draw.alpha(0.3f);
|
Draw.alpha(0.3f);
|
||||||
Draw.crect("blank", x, y, x2 - x, y2 - y);
|
Draw.crect("blank", x, y, x2 - x, y2 - y);
|
||||||
|
|
||||||
Draw.color(Colors.get("placeInvalid"));
|
|
||||||
|
|
||||||
int amount = 1;
|
int amount = 1;
|
||||||
for(int cx = 0; cx <= Math.abs(endx - tilex); cx ++){
|
for(int cx = 0; cx <= Math.abs(endx - tilex); cx ++){
|
||||||
for(int cy = 0; cy <= Math.abs(endy - tiley); cy ++){
|
for(int cy = 0; cy <= Math.abs(endy - tiley); cy ++){
|
||||||
int px = tx + cx * Mathf.sign(ex - tx),
|
int px = tx + cx * Mathf.sign(ex - tx),
|
||||||
py = ty + cy * Mathf.sign(ey - ty);
|
py = ty + cy * Mathf.sign(ey - ty);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
if(!control.input().validPlace(px, py, control.input().recipe.result)
|
if(!control.input().validPlace(px, py, control.input().recipe.result)
|
||||||
|| !state.inventory.hasItems(control.input().recipe.requirements, amount)){
|
|| !state.inventory.hasItems(control.input().recipe.requirements, amount)){
|
||||||
|
Lines.stroke(2f);
|
||||||
|
Draw.color(Colors.get("placeInvalid"));
|
||||||
Lines.crect(px * t + offset.x, py * t + offset.y, t*block.width, t*block.height);
|
Lines.crect(px * t + offset.x, py * t + offset.y, t*block.width, t*block.height);
|
||||||
}
|
}
|
||||||
amount ++;
|
amount ++;
|
||||||
@@ -291,6 +295,7 @@ public enum PlaceMode{
|
|||||||
|
|
||||||
if(control.input().recipe.result.rotate){
|
if(control.input().recipe.result.rotate){
|
||||||
float cx = tx * t, cy = ty * t;
|
float cx = tx * t, cy = ty * t;
|
||||||
|
Lines.stroke(2f);
|
||||||
Draw.color(Colors.get("placeRotate"));
|
Draw.color(Colors.get("placeRotate"));
|
||||||
tr.trns(rotation * 90, 7, 0);
|
tr.trns(rotation * 90, 7, 0);
|
||||||
Lines.line(cx, cy, cx + tr.x, cy + tr.y);
|
Lines.line(cx, cy, cx + tr.x, cy + tr.y);
|
||||||
@@ -308,7 +313,7 @@ public enum PlaceMode{
|
|||||||
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){
|
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){
|
||||||
for(int y = 0; y <= Math.abs(this.endy - this.tiley); y ++){
|
for(int y = 0; y <= Math.abs(this.endy - this.tiley); y ++){
|
||||||
if(control.input().tryPlaceBlock(
|
if(control.input().tryPlaceBlock(
|
||||||
tilex + x * Mathf.sign(endx - tilex),
|
tilex + x * Mathf.sign(endx - tilex),
|
||||||
tiley + y * Mathf.sign(endy - tiley), first)){
|
tiley + y * Mathf.sign(endy - tiley), first)){
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
@@ -340,7 +345,7 @@ public enum PlaceMode{
|
|||||||
rotation = 1;
|
rotation = 1;
|
||||||
else if(endy < tiley)
|
else if(endy < tiley)
|
||||||
rotation = 3;
|
rotation = 3;
|
||||||
else
|
else
|
||||||
rotation = control.input().rotation;
|
rotation = control.input().rotation;
|
||||||
|
|
||||||
if(endx < tilex){
|
if(endx < tilex){
|
||||||
@@ -367,23 +372,23 @@ public enum PlaceMode{
|
|||||||
public boolean showCancel;
|
public boolean showCancel;
|
||||||
public boolean delete = false;
|
public boolean delete = false;
|
||||||
public boolean both = false;
|
public boolean both = false;
|
||||||
|
|
||||||
private static final Translator tr = new Translator();
|
private static final Translator tr = new Translator();
|
||||||
|
|
||||||
public void draw(int tilex, int tiley, int endx, int endy){
|
public void draw(int tilex, int tiley, int endx, int endy){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void released(int tilex, int tiley, int endx, int endy){
|
public void released(int tilex, int tiley, int endx, int endy){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tapped(int x, int y){
|
public void tapped(int x, int y){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return Bundles.get("placemode."+name().toLowerCase()+".name");
|
return Bundles.get("placemode."+name().toLowerCase()+".name");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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 -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user