Merge branch 'master' of https://github.com/Anuken/Mindustry into 4.0
# Conflicts: # core/assets-raw/sprites/blocks/chainturret-icon.png # core/assets-raw/sprites/blocks/chainturret.png # core/assets-raw/sprites/blocks/titancannon-icon.png # core/assets-raw/sprites/blocks/titancannon.png # core/assets/sprites/sprites.atlas # core/assets/sprites/sprites.png # core/assets/version.properties # core/src/io/anuke/mindustry/entities/effect/TeslaOrb.java # core/src/io/anuke/mindustry/graphics/BlockRenderer.java # core/src/io/anuke/mindustry/input/InputHandler.java # core/src/io/anuke/mindustry/input/PlaceMode.java
This commit is contained in:
@@ -100,7 +100,7 @@ public class Vars{
|
||||
public static final int tilesize = 8;
|
||||
|
||||
public static final Locale[] locales = {new Locale("en"), new Locale("fr", "FR"), new Locale("ru"), new Locale("uk", "UA"), new Locale("pl", "PL"),
|
||||
new Locale("de"), new Locale("es", "LA"), new Locale("pt", "BR"), new Locale("ko"), new Locale("in", "ID")};
|
||||
new Locale("de"), new Locale("es", "LA"), new Locale("pt", "BR"), new Locale("ko"), new Locale("in", "ID"), new Locale("ita")};
|
||||
|
||||
public static final Color[] playerColors = {
|
||||
Color.valueOf("82759a"),
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package io.anuke.mindustry.graphics;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.StaticBlock;
|
||||
import io.anuke.mindustry.world.blocks.types.defense.Turret;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.ucore.core.Core.camera;
|
||||
|
||||
public class BlockRenderer{
|
||||
private final static int chunksize = 32;
|
||||
private final static int initialRequests = 32*32;
|
||||
|
||||
private FloorRenderer floorRenderer;
|
||||
@@ -25,6 +26,8 @@ public class BlockRenderer{
|
||||
private Layer lastLayer;
|
||||
private int requestidx = 0;
|
||||
private int iterateidx = 0;
|
||||
|
||||
private float storeX, storeY;
|
||||
|
||||
public BlockRenderer(){
|
||||
floorRenderer = new FloorRenderer();
|
||||
@@ -81,12 +84,12 @@ public class BlockRenderer{
|
||||
if(!expanded){
|
||||
addRequest(tile, Layer.block);
|
||||
}
|
||||
|
||||
|
||||
if(block.expanded || !expanded){
|
||||
if(block.layer != null && block.isLayer(tile)){
|
||||
addRequest(tile, block.layer);
|
||||
}
|
||||
|
||||
|
||||
if(block.layer2 != null && block.isLayer2(tile)){
|
||||
addRequest(tile, block.layer2);
|
||||
}
|
||||
@@ -206,4 +209,49 @@ public class BlockRenderer{
|
||||
r.layer = layer;
|
||||
requestidx ++;
|
||||
}
|
||||
|
||||
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.size * tilesize) / 2;
|
||||
float halfBlockHeight = (block.size * 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.size != 0 || (tilex - control.input().getBlockX()) % block.size != 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.size + "x" + block.size, drawx, drawy);
|
||||
} else {
|
||||
Draw.rect("block", drawx, drawy);
|
||||
}
|
||||
}
|
||||
|
||||
drawPreview(block, drawx, drawy, rotation, opacity);
|
||||
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class GestureHandler extends GestureAdapter{
|
||||
if(control.showCursor() && !Inputs.keyDown("select")) return false;
|
||||
|
||||
if(!control.showCursor() && !(control.input().recipe != null
|
||||
&& control.input().placeMode.lockCamera) &&
|
||||
&& control.input().placeMode.lockCamera && state.inventory.hasItems(control.input().recipe.requirements)) &&
|
||||
!(control.input().recipe == null && control.input().breakMode.lockCamera)){
|
||||
float dx = deltaX*Core.camera.zoom/Core.cameraScale, dy = deltaY*Core.camera.zoom/Core.cameraScale;
|
||||
player.x -= dx;
|
||||
|
||||
@@ -129,9 +129,10 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean cursorNear(){
|
||||
return Vector2.dst(player.x, player.y, getBlockX() * tilesize, getBlockY() * tilesize) <= placerange || debug;
|
||||
return Vector2.dst(player.x, player.y, getBlockX() * tilesize, getBlockY() * tilesize) <= placerange ||
|
||||
state.mode.infiniteResources || debug;
|
||||
}
|
||||
|
||||
public boolean tryPlaceBlock(int x, int y, boolean sound){
|
||||
|
||||
@@ -34,15 +34,17 @@ public enum PlaceMode{
|
||||
|
||||
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"));
|
||||
Lines.stroke(2f);
|
||||
Lines.crect(x + offset.x, y + offset.y, tilesize * control.input().recipe.result.size + si,
|
||||
tilesize * control.input().recipe.result.size + si);
|
||||
|
||||
control.input().recipe.result.drawPlace(tilex, tiley, control.input().rotation, valid);
|
||||
Lines.stroke(2f);
|
||||
|
||||
if(control.input().recipe.result.rotate){
|
||||
|
||||
Draw.color(Colors.get("placeRotate"));
|
||||
tr.trns(control.input().rotation * 90, 7, 0);
|
||||
Lines.line(x, y, x + tr.x, y + tr.y);
|
||||
@@ -126,9 +128,9 @@ public enum PlaceMode{
|
||||
|
||||
process(tilex, tiley, endx, endy);
|
||||
|
||||
tilex = this.tilex; tiley = this.tiley;
|
||||
tilex = this.tilex; tiley = this.tiley;
|
||||
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;
|
||||
|
||||
if(x2 >= x){
|
||||
@@ -150,7 +152,7 @@ public enum PlaceMode{
|
||||
tile = tile.getLinked();
|
||||
if(tile != null && control.input().validBreak(tile.x, tile.y)){
|
||||
Lines.crect(tile.drawx(), tile.drawy(),
|
||||
tile.block().size* t, tile.block().size * t);
|
||||
tile.block().size * t, tile.block().size * t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,7 +167,7 @@ public enum PlaceMode{
|
||||
|
||||
public void released(int tilex, int tiley, int endx, int endy){
|
||||
process(tilex, tiley, endx, endy);
|
||||
tilex = this.tilex; tiley = this.tiley;
|
||||
tilex = this.tilex; tiley = this.tiley;
|
||||
endx = this.endx; endy = this.endy;
|
||||
|
||||
if(android){
|
||||
@@ -237,16 +239,16 @@ public enum PlaceMode{
|
||||
if(android && !Gdx.input.isTouched(0) && !control.showCursor()){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
float t = tilesize;
|
||||
Block block = control.input().recipe.result;
|
||||
Vector2 offset = block.getPlaceOffset();
|
||||
|
||||
process(tilex, tiley, endx, 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;
|
||||
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;
|
||||
|
||||
if(x2 >= x){
|
||||
@@ -268,29 +270,55 @@ public enum PlaceMode{
|
||||
cursor.draw(tilex, tiley, endx, endy);
|
||||
}else{
|
||||
Lines.stroke(2f);
|
||||
Draw.color(control.input().cursorNear() ? Colors.get("place") : Colors.get("placeInvalid"));
|
||||
Draw.color(control.input().cursorNear() ? "place" : "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"));
|
||||
|
||||
int amount = 1;
|
||||
for(int cx = 0; cx <= Math.abs(endx - tilex); cx ++){
|
||||
for(int cy = 0; cy <= Math.abs(endy - tiley); cy ++){
|
||||
int px = tx + cx * Mathf.sign(ex - tx),
|
||||
py = ty + cy * Mathf.sign(ey - ty);
|
||||
|
||||
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.size, t*block.size);
|
||||
boolean isX = Math.abs(endx - tilex) >= Math.abs(endy - tiley);
|
||||
|
||||
for(int cx = 0; cx <= Math.abs(endx - tilex); cx += (isX ? 0 : 1)){
|
||||
for(int cy = 0; cy <= Math.abs(endy - tiley); cy += (isX ? 1 : 0)){
|
||||
|
||||
int px = tx + cx * Mathf.sign(ex - tx),
|
||||
py = ty + cy * Mathf.sign(ey - ty);
|
||||
|
||||
//step by the block size if it's valid
|
||||
if(control.input().validPlace(px, py, control.input().recipe.result) && state.inventory.hasItems(control.input().recipe.requirements, amount)){
|
||||
|
||||
renderer.getBlocks().handlePreview(control.input().recipe.result, block.rotate ? rotation * 90 : 0f, px * t + offset.x, py * t + offset.y, px, py);
|
||||
|
||||
if(isX){
|
||||
cx += block.size;
|
||||
}else{
|
||||
cy += block.size;
|
||||
}
|
||||
amount ++;
|
||||
}else{ //otherwise, step by 1 until it is valid
|
||||
if(control.input().cursorNear()){
|
||||
Lines.stroke(2f);
|
||||
Draw.color("placeInvalid");
|
||||
Lines.crect(
|
||||
px * t + (isX ? 0 : offset.x) + (ex < tx && isX ? t : 0) - (block.size == 3 && ex > tx && isX ? t : 0),
|
||||
py * t + (isX ? offset.y : 0) + (ey < ty && !isX ? t : 0) - (block.size == 3 && ey > ty && !isX ? t : 0),
|
||||
t*(isX ? 1 : block.size),
|
||||
t*(isX ? block.size : 1));
|
||||
Draw.color("place");
|
||||
}
|
||||
|
||||
if(isX){
|
||||
cx += 1;
|
||||
}else{
|
||||
cy += 1;
|
||||
}
|
||||
}
|
||||
amount ++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
@@ -308,7 +336,7 @@ public enum PlaceMode{
|
||||
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),
|
||||
tilex + x * Mathf.sign(endx - tilex),
|
||||
tiley + y * Mathf.sign(endy - tiley), first)){
|
||||
first = false;
|
||||
}
|
||||
@@ -340,7 +368,7 @@ public enum PlaceMode{
|
||||
rotation = 1;
|
||||
else if(endy < tiley)
|
||||
rotation = 3;
|
||||
else
|
||||
else
|
||||
rotation = control.input().rotation;
|
||||
|
||||
if(endx < tilex){
|
||||
@@ -371,19 +399,19 @@ public enum PlaceMode{
|
||||
private static final Translator tr = new Translator();
|
||||
|
||||
public void draw(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){
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return Bundles.get("placemode."+name().toLowerCase()+".name");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,15 @@ public class SaveIO{
|
||||
}
|
||||
|
||||
public static void load(FileHandle file){
|
||||
load(file.read());
|
||||
try {
|
||||
load(file.read());
|
||||
}catch (RuntimeException e){
|
||||
e.printStackTrace();
|
||||
FileHandle backup = file.sibling(file.name() + "-backup." + file.extension());
|
||||
if(backup.exists()){
|
||||
load(backup.read());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void load(InputStream is){
|
||||
|
||||
@@ -52,6 +52,7 @@ public class Saves {
|
||||
|
||||
exec.submit(() -> {
|
||||
SaveIO.saveToSlot(current.index);
|
||||
current.meta = SaveIO.getData(current.index);
|
||||
saving = false;
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -10,9 +10,13 @@ import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.scene.Element;
|
||||
import io.anuke.ucore.scene.event.InputEvent;
|
||||
import io.anuke.ucore.scene.event.InputListener;
|
||||
import io.anuke.ucore.scene.ui.Image;
|
||||
import io.anuke.ucore.scene.ui.ScrollPane;
|
||||
import io.anuke.ucore.scene.ui.SettingsDialog;
|
||||
import io.anuke.ucore.scene.ui.Slider;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
@@ -91,6 +95,24 @@ public class SettingsMenuDialog extends SettingsDialog{
|
||||
prefs.add(menu);
|
||||
|
||||
ScrollPane pane = new ScrollPane(prefs, "clear");
|
||||
pane.addCaptureListener(new InputListener() {
|
||||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
|
||||
Element actor = pane.hit(x, y, true);
|
||||
if (actor instanceof Slider) {
|
||||
pane.setFlickScroll(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.touchDown(event, x, y, pointer, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
|
||||
pane.setFlickScroll(true);
|
||||
super.touchUp(event, x, y, pointer, button);
|
||||
}
|
||||
});
|
||||
pane.setFadeScrollBars(false);
|
||||
|
||||
row();
|
||||
@@ -138,6 +160,7 @@ public class SettingsMenuDialog extends SettingsDialog{
|
||||
|
||||
graphics.checkPref("fps", false);
|
||||
graphics.checkPref("lasers", true);
|
||||
graphics.sliderPref("previewopacity", 50, 0, 100, i -> i + "%");
|
||||
graphics.checkPref("indicators", true);
|
||||
graphics.checkPref("healthbars", true);
|
||||
graphics.checkPref("pixelate", true, b -> {
|
||||
|
||||
@@ -30,6 +30,7 @@ public class Junction extends Block{
|
||||
|
||||
for(int i = 0; i < 2; i ++){
|
||||
Buffer buffer = (i == 0 ? entity.bx : entity.by);
|
||||
|
||||
if(buffer.index > 0){
|
||||
if(buffer.index > buffer.items.length) buffer.index = buffer.items.length;
|
||||
long l = buffer.items[0];
|
||||
@@ -43,7 +44,13 @@ public class Junction extends Block{
|
||||
int direction = Bits.getRightShort(val);
|
||||
Tile dest = tile.getNearby(direction);
|
||||
|
||||
if(dest == null || !dest.block().acceptItem(item, dest, tile)) continue;
|
||||
if(dest == null || !dest.block().acceptItem(item, dest, tile)){
|
||||
if(buffer.index > 1){
|
||||
System.arraycopy(buffer.items, 1, buffer.items, 0, buffer.index - 1);
|
||||
buffer.index --;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
dest.block().handleItem(item, dest, tile);
|
||||
System.arraycopy(buffer.items, 1, buffer.items, 0, buffer.index - 1);
|
||||
|
||||
Reference in New Issue
Block a user