mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-30 22:49:06 +07:00
Snake cleanup
This commit is contained in:
@ -6,7 +6,6 @@ import io.anuke.arc.Graphics.Cursor.SystemCursor;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Lines;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.math.geom.Geometry;
|
||||
import io.anuke.arc.math.geom.Point2;
|
||||
@ -21,7 +20,6 @@ import io.anuke.mindustry.input.PlaceUtils.NormalizeDrawResult;
|
||||
import io.anuke.mindustry.input.PlaceUtils.NormalizeResult;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Block.Icon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
@ -45,15 +43,20 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
|
||||
/**Draws a placement icon for a specific block.*/
|
||||
void drawPlace(int x, int y, Block block, int rotation){
|
||||
void drawPlace(int x, int y, Block block, int rotation, PlaceRequest prev){
|
||||
if(validPlace(x, y, block, rotation)){
|
||||
if(prev != null){
|
||||
block.getPlaceDraw(placeDraw, rotation, prev.x - x, prev.y - y, prev.rotation);
|
||||
}else{
|
||||
block.getPlaceDraw(placeDraw, rotation, 0, 0, rotation);
|
||||
}
|
||||
|
||||
Draw.color();
|
||||
|
||||
TextureRegion region = block.icon(Icon.full);
|
||||
|
||||
Draw.rect(region, x * tilesize + block.offset(), y * tilesize + block.offset(),
|
||||
region.getWidth() * selectScale * Draw.scl,
|
||||
region.getHeight() * selectScale * Draw.scl, block.rotate ? rotation * 90 : 0);
|
||||
Draw.rect(placeDraw.region, x * tilesize + block.offset(), y * tilesize + block.offset(),
|
||||
placeDraw.region.getWidth() * selectScale * Draw.scl * placeDraw.scalex,
|
||||
placeDraw.region.getHeight() * selectScale * Draw.scl * placeDraw.scaley,
|
||||
block.rotate ? placeDraw.rotation * 90 : 0);
|
||||
|
||||
Draw.color(Pal.accent);
|
||||
for(int i = 0; i < 4; i++){
|
||||
@ -84,6 +87,7 @@ public class DesktopInput extends InputHandler{
|
||||
//draw selection(s)
|
||||
if(mode == placing && block != null){
|
||||
int i = 0;
|
||||
PlaceRequest prev = null;
|
||||
for(PlaceRequest request : requests){
|
||||
int x = request.x, y = request.y;
|
||||
|
||||
@ -103,7 +107,8 @@ public class DesktopInput extends InputHandler{
|
||||
Core.atlas.find("place-arrow").getHeight() * Draw.scl, request.rotation * 90 - 90);
|
||||
}
|
||||
|
||||
drawPlace(request.x, request.y, block, request.rotation);
|
||||
drawPlace(request.x, request.y, block, request.rotation, prev);
|
||||
prev = request;
|
||||
}
|
||||
|
||||
}else if(mode == breaking){
|
||||
@ -143,7 +148,7 @@ public class DesktopInput extends InputHandler{
|
||||
Core.atlas.find("place-arrow").getWidth() * Draw.scl,
|
||||
Core.atlas.find("place-arrow").getHeight() * Draw.scl, rotation * 90 - 90);
|
||||
}
|
||||
drawPlace(cursorX, cursorY, block, rotation);
|
||||
drawPlace(cursorX, cursorY, block, rotation, null);
|
||||
block.drawPlace(cursorX, cursorY, rotation, validPlace(cursorX, cursorY, block, rotation));
|
||||
}
|
||||
|
||||
@ -385,7 +390,7 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
}
|
||||
|
||||
class PlaceRequest{
|
||||
private class PlaceRequest{
|
||||
int x, y, rotation;
|
||||
|
||||
public PlaceRequest(int x, int y, int rotation){
|
||||
@ -393,15 +398,6 @@ public class DesktopInput extends InputHandler{
|
||||
this.y = y;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "PlaceRequest{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
", rotation=" + rotation +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.input.InputProcessor;
|
||||
import io.anuke.arc.math.Angles;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
@ -50,6 +51,7 @@ public abstract class InputHandler implements InputProcessor{
|
||||
protected Bresenham2 bres = new Bresenham2();
|
||||
protected Array<Point2> points = new Array<>();
|
||||
protected Array<Point2> outPoints = new Array<>();
|
||||
protected PlaceDraw placeDraw = new PlaceDraw();
|
||||
|
||||
public InputHandler(Player player){
|
||||
this.player = player;
|
||||
@ -344,4 +346,8 @@ public abstract class InputHandler implements InputProcessor{
|
||||
player.addBuildRequest(new BuildRequest(tile.x, tile.y));
|
||||
}
|
||||
|
||||
public class PlaceDraw{
|
||||
public int rotation, scalex, scaley;
|
||||
public TextureRegion region;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ import io.anuke.mindustry.input.PlaceUtils.NormalizeDrawResult;
|
||||
import io.anuke.mindustry.input.PlaceUtils.NormalizeResult;
|
||||
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Block.Icon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
@ -63,6 +62,8 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
/** Animation data for crosshair. */
|
||||
private float crosshairScale;
|
||||
private TargetTrait lastTarget;
|
||||
/** Used for shifting build requests.*/
|
||||
private float shiftDeltaX, shiftDeltaY;
|
||||
|
||||
/** List of currently selected tiles to place. */
|
||||
private Array<PlaceRequest> selection = new Array<>();
|
||||
@ -168,21 +169,27 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
removals.add(request);
|
||||
}
|
||||
|
||||
void drawRequest(PlaceRequest request){
|
||||
void drawRequest(PlaceRequest request, PlaceRequest prev){
|
||||
Tile tile = request.tile();
|
||||
|
||||
if(!request.remove){
|
||||
if(prev != null){
|
||||
block.getPlaceDraw(placeDraw, request.rotation, prev.x - request.x, prev.y - request.y, prev.rotation);
|
||||
}else{
|
||||
block.getPlaceDraw(placeDraw, request.rotation, 0, 0, request.rotation);
|
||||
}
|
||||
|
||||
//draw placing request
|
||||
float offset = request.block.offset();
|
||||
TextureRegion region = request.block.icon(Icon.full);
|
||||
TextureRegion region = placeDraw.region;
|
||||
|
||||
Draw.mixcol(Pal.accent, Mathf.clamp((1f - request.scale) / 0.5f));
|
||||
Draw.tint(Color.WHITE, Pal.breakInvalid, request.redness);
|
||||
|
||||
Draw.rect(region, tile.worldx() + offset, tile.worldy() + offset,
|
||||
region.getWidth() * request.scale * Draw.scl,
|
||||
region.getHeight() * request.scale * Draw.scl,
|
||||
request.block.rotate ? request.rotation * 90 : 0);
|
||||
region.getWidth() * request.scale * Draw.scl * placeDraw.scalex,
|
||||
region.getHeight() * request.scale * Draw.scl * placeDraw.scaley,
|
||||
request.block.rotate ? placeDraw.rotation * 90 : 0);
|
||||
|
||||
Draw.mixcol(Pal.accent, 1f);
|
||||
for(int i = 0; i < 4; i++){
|
||||
@ -315,9 +322,11 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
request.scale = Mathf.lerpDelta(request.scale, 0f, 0.2f);
|
||||
request.redness = Mathf.lerpDelta(request.redness, 0f, 0.2f);
|
||||
|
||||
drawRequest(request);
|
||||
drawRequest(request, null);
|
||||
}
|
||||
|
||||
PlaceRequest last = null;
|
||||
|
||||
//draw list of requests
|
||||
for(PlaceRequest request : selection){
|
||||
Tile tile = request.tile();
|
||||
@ -341,13 +350,15 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
|
||||
Draw.mixcol(Tmp.c1, 1f);
|
||||
drawRequest(request);
|
||||
drawRequest(request, last);
|
||||
|
||||
//draw last placed request
|
||||
if(!request.remove && request == lastPlaced && request.block != null){
|
||||
Draw.mixcol();
|
||||
request.block.drawPlace(tile.x, tile.y, rotation, validPlace(tile.x, tile.y, request.block, rotation));
|
||||
}
|
||||
|
||||
last = request;
|
||||
}
|
||||
|
||||
Draw.mixcol();
|
||||
@ -461,7 +472,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
tar = tar.target();
|
||||
|
||||
if(!hasRequest(world.tile(tar.x, tar.y)) && validBreak(tar.x, tar.y)){
|
||||
PlaceRequest request = new PlaceRequest(tar.worldx(), tar.worldy());
|
||||
PlaceRequest request = new PlaceRequest(tar.x, tar.y);
|
||||
request.scale = 1f;
|
||||
selection.add(request);
|
||||
}
|
||||
@ -500,7 +511,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
Effects.effect(Fx.tapBlock, cursor.worldx(), cursor.worldy(), 1f);
|
||||
}else if(block != null){
|
||||
Effects.effect(Fx.tapBlock, cursor.worldx() + block.offset(), cursor.worldy() + block.offset(), block.size);
|
||||
selection.add(new PlaceRequest(cursor.worldx(), cursor.worldy(), block, rotation));
|
||||
selection.add(new PlaceRequest(cursor.x, cursor.y, block, rotation));
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -525,11 +536,11 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
removeRequest(getRequest(cursor));
|
||||
}else if(mode == placing && isPlacing() && validPlace(cursor.x, cursor.y, block, rotation) && !checkOverlapPlacement(cursor.x, cursor.y, block)){
|
||||
//add to selection queue if it's a valid place position
|
||||
selection.add(lastPlaced = new PlaceRequest(cursor.worldx() + block.offset(), cursor.worldy() + block.offset(), block, rotation));
|
||||
selection.add(lastPlaced = new PlaceRequest(cursor.x, cursor.y, block, rotation));
|
||||
}else if(mode == breaking && validBreak(cursor.target().x, cursor.target().y) && !hasRequest(cursor.target())){
|
||||
//add to selection queue if it's a valid BREAK position
|
||||
cursor = cursor.target();
|
||||
selection.add(new PlaceRequest(cursor.worldx(), cursor.worldy()));
|
||||
selection.add(new PlaceRequest(cursor.x, cursor.y));
|
||||
}else if(!canTapPlayer(worldx, worldy) && !tileTapped(cursor.target())){
|
||||
tryBeginMine(cursor);
|
||||
}
|
||||
@ -669,16 +680,14 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
return;
|
||||
}
|
||||
|
||||
Tile ltile = last.tile();
|
||||
|
||||
int rel = ltile == null ? -1 : Tile.relativeTo(ltile.x, ltile.y, point.x, point.y);
|
||||
int rel = Tile.relativeTo(last.x, last.y, point.x, point.y);
|
||||
|
||||
if(rel != -1){
|
||||
last.rotation = rel;
|
||||
rotation = rel;
|
||||
}
|
||||
|
||||
selection.add(new PlaceRequest(point.x * tilesize, point.y * tilesize, block, rotation));
|
||||
selection.add(new PlaceRequest(point.x, point.y, block, rotation));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -695,10 +704,21 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
|
||||
if(selecting){ //pan all requests
|
||||
for(PlaceRequest req : selection){
|
||||
if(req.remove) continue; //don't shift removal requests
|
||||
req.x += deltaX;
|
||||
req.y += deltaY;
|
||||
shiftDeltaX += deltaX;
|
||||
shiftDeltaY += deltaY;
|
||||
|
||||
int shiftedX = (int)(shiftDeltaX / tilesize);
|
||||
int shiftedY = (int)(shiftDeltaY / tilesize);
|
||||
|
||||
if(Math.abs(shiftedX) > 0 || Math.abs(shiftedY) > 0){
|
||||
for(PlaceRequest req : selection){
|
||||
if(req.remove) continue; //don't shift removal requests
|
||||
req.x += shiftedX;
|
||||
req.y += shiftedY;
|
||||
}
|
||||
|
||||
shiftDeltaX %= tilesize;
|
||||
shiftDeltaY %= tilesize;
|
||||
}
|
||||
}else{
|
||||
//pan player
|
||||
@ -709,6 +729,12 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean panStop(float x, float y, int pointer, KeyCode button){
|
||||
shiftDeltaX = shiftDeltaY = 0f;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean zoom(float initialDistance, float distance){
|
||||
if(lastDistance == -1) lastDistance = initialDistance;
|
||||
@ -721,8 +747,8 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
|
||||
//endregion
|
||||
|
||||
class PlaceRequest{
|
||||
float x, y;
|
||||
private class PlaceRequest{
|
||||
int x, y;
|
||||
Block block;
|
||||
int rotation;
|
||||
boolean remove;
|
||||
@ -731,7 +757,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
float scale;
|
||||
float redness;
|
||||
|
||||
PlaceRequest(float x, float y, Block block, int rotation){
|
||||
PlaceRequest(int x, int y, Block block, int rotation){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.block = block;
|
||||
@ -739,14 +765,14 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
this.remove = false;
|
||||
}
|
||||
|
||||
PlaceRequest(float x, float y){
|
||||
PlaceRequest(int x, int y){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.remove = true;
|
||||
}
|
||||
|
||||
Tile tile(){
|
||||
return world.tileWorld(x - (block == null ? 0 : block.offset()), y - (block == null ? 0 : block.offset()));
|
||||
return world.tile(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.mindustry.graphics.CacheLayer;
|
||||
import io.anuke.mindustry.graphics.Layer;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.input.InputHandler.PlaceDraw;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.ui.Bar;
|
||||
import io.anuke.mindustry.ui.ContentDisplay;
|
||||
@ -547,6 +548,12 @@ public class Block extends BlockStorage{
|
||||
return icons[icon.ordinal()];
|
||||
}
|
||||
|
||||
public void getPlaceDraw(PlaceDraw draw, int rotation, int prevX, int prevY, int prevRotation){
|
||||
draw.region = icon(Icon.full);
|
||||
draw.scalex = draw.scaley = 1;
|
||||
draw.rotation = rotation;
|
||||
}
|
||||
|
||||
/**Never use outside of the editor!*/
|
||||
public TextureRegion editorIcon(){
|
||||
if(editorIcon == null) editorIcon = Core.atlas.find(name + "-icon-editor");
|
||||
|
@ -6,6 +6,7 @@ import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.math.geom.Geometry;
|
||||
import io.anuke.arc.math.geom.Point2;
|
||||
import io.anuke.arc.math.geom.Vector2;
|
||||
import io.anuke.arc.util.Log;
|
||||
import io.anuke.arc.util.Pack;
|
||||
@ -13,6 +14,7 @@ import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.entities.type.Unit;
|
||||
import io.anuke.mindustry.graphics.Layer;
|
||||
import io.anuke.mindustry.input.InputHandler.PlaceDraw;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@ -89,7 +91,6 @@ public class Conveyor extends Block{
|
||||
ConveyorEntity entity = tile.entity();
|
||||
entity.blendbits = 0;
|
||||
entity.blendsclx = entity.blendscly = 1;
|
||||
entity.blendshadowrot = -1;
|
||||
|
||||
if(blends(tile, 2) && blends(tile, 1) && blends(tile, 3)){
|
||||
entity.blendbits = 3;
|
||||
@ -103,13 +104,34 @@ public class Conveyor extends Block{
|
||||
}else if(blends(tile, 1)){
|
||||
entity.blendbits = 1;
|
||||
entity.blendscly = -1;
|
||||
entity.blendshadowrot = 0;
|
||||
}else if(blends(tile, 3)){
|
||||
entity.blendbits = 1;
|
||||
entity.blendshadowrot = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPlaceDraw(PlaceDraw draw, int rotation, int prevX, int prevY, int prevRotation){
|
||||
draw.rotation = rotation;
|
||||
draw.scalex = draw.scaley = 1;
|
||||
|
||||
int blendbits = 0;
|
||||
|
||||
if(blends(rotation, 1, prevX, prevY, prevRotation)){
|
||||
blendbits = 1;
|
||||
draw.scaley = -1;
|
||||
}else if(blends(rotation, 3, prevX, prevY, prevRotation)){
|
||||
blendbits = 1;
|
||||
}
|
||||
|
||||
draw.rotation = rotation;
|
||||
draw.region = regions[blendbits][0];
|
||||
}
|
||||
|
||||
private boolean blends(int rotation, int offset, int prevX, int prevY, int prevRotation){
|
||||
Point2 left = Geometry.d4(rotation - offset);
|
||||
return left.equals(prevX, prevY) && prevRotation == Mathf.mod(rotation + offset, 4);
|
||||
}
|
||||
|
||||
private boolean blends(Tile tile, int direction){
|
||||
Tile other = tile.getNearby(Mathf.mod(tile.getRotation() - direction, 4));
|
||||
if(other != null) other = other.target();
|
||||
@ -343,7 +365,6 @@ public class Conveyor extends Block{
|
||||
byte lastInserted;
|
||||
float minitem = 1;
|
||||
|
||||
int blendshadowrot = -1;
|
||||
int blendbits;
|
||||
int blendsclx, blendscly;
|
||||
|
||||
|
Reference in New Issue
Block a user