Major refactoring of building input in progress
This commit is contained in:
@@ -12,6 +12,7 @@ public enum Binding implements KeyBind{
|
||||
select(KeyCode.MOUSE_LEFT),
|
||||
deselect(KeyCode.MOUSE_RIGHT),
|
||||
break_block(KeyCode.MOUSE_RIGHT),
|
||||
clear_building(KeyCode.Q),
|
||||
rotate(new Axis(KeyCode.SCROLL)),
|
||||
rotateplaced(KeyCode.R),
|
||||
diagonal_placement(KeyCode.CONTROL_LEFT),
|
||||
|
||||
@@ -5,15 +5,16 @@ import io.anuke.arc.Graphics.*;
|
||||
import io.anuke.arc.Graphics.Cursor.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.scene.*;
|
||||
import io.anuke.arc.scene.ui.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.core.GameState.*;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait.*;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.graphics.*;
|
||||
import io.anuke.mindustry.input.PlaceUtils.*;
|
||||
import io.anuke.mindustry.ui.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
|
||||
import static io.anuke.arc.Core.scene;
|
||||
@@ -23,50 +24,28 @@ import static io.anuke.mindustry.input.PlaceMode.*;
|
||||
public class DesktopInput extends InputHandler{
|
||||
/** Current cursor type. */
|
||||
private Cursor cursorType = SystemCursor.arrow;
|
||||
|
||||
/** Position where the player started dragging a line. */
|
||||
private int selectX, selectY;
|
||||
/** Last known line positions.*/
|
||||
private int lastLineX, lastLineY;
|
||||
/** Whether selecting mode is active. */
|
||||
private PlaceMode mode;
|
||||
/** Animation scale for line. */
|
||||
private float selectScale;
|
||||
|
||||
private int prevX, prevY, prevRotation;
|
||||
|
||||
/** Draws a placement icon for a specific block. */
|
||||
void drawPlace(int x, int y, Block block, int rotation, int prevX, int prevY, int prevRotation){
|
||||
if(validPlace(x, y, block, rotation)){
|
||||
block.getPlaceDraw(placeDraw, rotation, prevX, prevY, prevRotation);
|
||||
|
||||
Draw.color();
|
||||
Draw.mixcol(Pal.accent, 0.12f + Mathf.absin(Time.time(), 8f, 0.35f));
|
||||
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++){
|
||||
Point2 p = Geometry.d8edge[i];
|
||||
float offset = -Math.max(block.size - 1, 0) / 2f * tilesize;
|
||||
if(i % 2 == 0)
|
||||
Draw.rect("block-select", x * tilesize + block.offset() + offset * p.x, y * tilesize + block.offset() + offset * p.y, i * 90);
|
||||
}
|
||||
Draw.color();
|
||||
Draw.mixcol();
|
||||
}else{
|
||||
Draw.color(Pal.removeBack);
|
||||
Lines.square(x * tilesize + block.offset(), y * tilesize + block.offset() - 1, block.size * tilesize / 2f - 1);
|
||||
Draw.color(Pal.remove);
|
||||
Lines.square(x * tilesize + block.offset(), y * tilesize + block.offset(), block.size * tilesize / 2f - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDrawing(){
|
||||
return mode != none || block != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildUI(Group group){
|
||||
group.fill(t -> {
|
||||
t.bottom().update(() -> t.getColor().a = Mathf.lerpDelta(t.getColor().a, player.isBuilding() ? 1f : 0f, 0.1f));
|
||||
t.table(Styles.black6, b -> b.add(Core.bundle.format("cancelbuilding", Core.keybinds.get(Binding.clear_building).key.name())).style(Styles.outlineLabel)).margin(10f);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOutlined(){
|
||||
Lines.stroke(1f);
|
||||
@@ -75,21 +54,13 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
//draw selection(s)
|
||||
if(mode == placing && block != null){
|
||||
prevX = selectX;
|
||||
prevY = selectY;
|
||||
prevRotation = rotation;
|
||||
|
||||
iterateLine(selectX, selectY, cursorX, cursorY, l -> {
|
||||
if(l.last && block.rotate){
|
||||
drawArrow(block, l.x, l.y, l.rotation);
|
||||
for(int i = 0; i < lineRequests.size; i++){
|
||||
BuildRequest req = lineRequests.get(i);
|
||||
if(i == lineRequests.size - 1){
|
||||
drawArrow(block, req.x, req.y, req.rotation);
|
||||
}
|
||||
drawPlace(l.x, l.y, block, l.rotation, prevX - l.x, prevY - l.y, prevRotation);
|
||||
|
||||
prevX = l.x;
|
||||
prevY = l.y;
|
||||
prevRotation = l.rotation;
|
||||
});
|
||||
|
||||
drawRequest(lineRequests.get(i));
|
||||
}
|
||||
}else if(mode == breaking){
|
||||
NormalizeDrawResult result = PlaceUtils.normalizeDrawArea(Blocks.air, selectX, selectY, cursorX, cursorY, false, maxLength, 1f);
|
||||
NormalizeResult dresult = PlaceUtils.normalizeArea(selectX, selectY, cursorX, cursorY, rotation, false, maxLength);
|
||||
@@ -114,7 +85,7 @@ public class DesktopInput extends InputHandler{
|
||||
if(block.rotate){
|
||||
drawArrow(block, cursorX, cursorY, rotation);
|
||||
}
|
||||
drawPlace(cursorX, cursorY, block, rotation, cursorX, cursorY, rotation);
|
||||
drawRequest(cursorX, cursorY, block, rotation);
|
||||
block.drawPlace(cursorX, cursorY, rotation, validPlace(cursorX, cursorY, block, rotation));
|
||||
}
|
||||
|
||||
@@ -211,11 +182,28 @@ public class DesktopInput extends InputHandler{
|
||||
player.setMineTile(null);
|
||||
}
|
||||
|
||||
if(Core.input.keyTap(Binding.clear_building)){
|
||||
player.clearBuilding();
|
||||
}
|
||||
|
||||
if(block == null || mode != placing){
|
||||
lineRequests.clear();
|
||||
}
|
||||
|
||||
if((cursorX != lastLineX || cursorY != lastLineY) && isPlacing() && mode == placing){
|
||||
updateLine(selectX, selectY);
|
||||
lastLineX = cursorX;
|
||||
lastLineY = cursorY;
|
||||
}
|
||||
|
||||
if(Core.input.keyTap(Binding.select) && !Core.scene.hasMouse()){
|
||||
if(isPlacing()){
|
||||
selectX = cursorX;
|
||||
selectY = cursorY;
|
||||
lastLineX = cursorX;
|
||||
lastLineY = cursorY;
|
||||
mode = placing;
|
||||
updateLine(selectX, selectY);
|
||||
}else if(selected != null){
|
||||
//only begin shooting if there's no cursor event
|
||||
if(!tileTapped(selected) && !tryTapPlayer(Core.input.mouseWorld().x, Core.input.mouseWorld().y) && player.buildQueue().size == 0 && !droppingItem &&
|
||||
@@ -227,10 +215,6 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
}else if(Core.input.keyTap(Binding.deselect) && (block != null || mode != none || player.isBuilding()) &&
|
||||
!(player.buildRequest() != null && player.buildRequest().breaking && Core.keybinds.get(Binding.deselect) == Core.keybinds.get(Binding.break_block))){
|
||||
if(block == null){
|
||||
player.clearBuilding();
|
||||
}
|
||||
|
||||
block = null;
|
||||
mode = none;
|
||||
}else if(Core.input.keyTap(Binding.break_block) && !Core.scene.hasMouse()){
|
||||
@@ -240,7 +224,7 @@ public class DesktopInput extends InputHandler{
|
||||
selectY = tileY(Core.input.mouseY());
|
||||
}
|
||||
|
||||
if (mode == placing && block != null){
|
||||
if(mode == placing && block != null){
|
||||
if (!overrideLineRotation && !Core.input.keyDown(Binding.diagonal_placement) && (selectX != cursorX || selectY != cursorY) && ((int) Core.input.axisTap(Binding.rotate) != 0)){
|
||||
rotation = ((int)((Angles.angle(selectX, selectY, cursorX, cursorY) + 45) / 90f)) % 4;
|
||||
overrideLineRotation = true;
|
||||
@@ -252,10 +236,8 @@ public class DesktopInput extends InputHandler{
|
||||
if(Core.input.keyRelease(Binding.break_block) || Core.input.keyRelease(Binding.select)){
|
||||
|
||||
if(mode == placing && block != null){ //touch up while placing, place everything in selection
|
||||
iterateLine(selectX, selectY, cursorX, cursorY, l -> {
|
||||
rotation = l.rotation;
|
||||
tryPlaceBlock(l.x, l.y);
|
||||
});
|
||||
flushRequests(lineRequests);
|
||||
lineRequests.clear();
|
||||
Events.fire(new LineConfirmEvent());
|
||||
}else if(mode == breaking){ //touch up while breaking, break everything in selection
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursorX, cursorY, rotation, false, maxLength);
|
||||
|
||||
@@ -7,8 +7,11 @@ import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.input.*;
|
||||
import io.anuke.arc.input.GestureDetector.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.scene.*;
|
||||
import io.anuke.arc.scene.event.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
@@ -26,7 +29,7 @@ import io.anuke.mindustry.world.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public abstract class InputHandler implements InputProcessor{
|
||||
public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
/** Used for dropping items. */
|
||||
final static float playerSelectRange = mobile ? 17f : 11f;
|
||||
/** Maximum line length. */
|
||||
@@ -41,9 +44,13 @@ public abstract class InputHandler implements InputProcessor{
|
||||
public boolean overrideLineRotation;
|
||||
public int rotation;
|
||||
public boolean droppingItem;
|
||||
public Group uiGroup;
|
||||
|
||||
protected PlaceDraw placeDraw = new PlaceDraw();
|
||||
private PlaceLine line = new PlaceLine();
|
||||
protected GestureDetector detector;
|
||||
protected PlaceLine line = new PlaceLine();
|
||||
protected BuildRequest brequest = new BuildRequest();
|
||||
protected Array<BuildRequest> lineRequests = new Array<>();
|
||||
protected Array<BuildRequest> selectRequests = new Array<>();
|
||||
|
||||
//methods to override
|
||||
|
||||
@@ -134,6 +141,14 @@ public abstract class InputHandler implements InputProcessor{
|
||||
tile.block().configured(tile, player, value);
|
||||
}
|
||||
|
||||
public Eachable<BuildRequest> allRequests(){
|
||||
return cons -> {
|
||||
for(BuildRequest request : player.buildQueue()) cons.accept(request);
|
||||
for(BuildRequest request : selectRequests) cons.accept(request);
|
||||
for(BuildRequest request : lineRequests) cons.accept(request);
|
||||
};
|
||||
}
|
||||
|
||||
public OverlayFragment getFrag(){
|
||||
return frag;
|
||||
}
|
||||
@@ -150,7 +165,11 @@ public abstract class InputHandler implements InputProcessor{
|
||||
return Core.input.mouseY();
|
||||
}
|
||||
|
||||
public void buildUI(Table table){
|
||||
public void buildPlacementUI(Table table){
|
||||
|
||||
}
|
||||
|
||||
public void buildUI(Group group){
|
||||
|
||||
}
|
||||
|
||||
@@ -170,6 +189,32 @@ public abstract class InputHandler implements InputProcessor{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void flushRequests(Array<BuildRequest> requests){
|
||||
for(BuildRequest req : requests){
|
||||
if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){
|
||||
player.addBuildRequest(req);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawRequest(BuildRequest request){
|
||||
drawRequest(request.x, request.y, request.block, request.rotation);
|
||||
}
|
||||
|
||||
/** Draws a placement icon for a specific block. */
|
||||
protected void drawRequest(int x, int y, Block block, int rotation){
|
||||
brequest.set(x, y, rotation, block);
|
||||
block.drawRequest(brequest, allRequests(), validPlace(x, y, block, rotation));
|
||||
}
|
||||
|
||||
protected void updateLine(int selectX, int selectY){
|
||||
lineRequests.clear();
|
||||
iterateLine(selectX, selectY, tileX(getMouseX()), tileY(getMouseY()), l -> {
|
||||
rotation = l.rotation;
|
||||
lineRequests.add(new BuildRequest(l.x, l.y, l.rotation, block));
|
||||
});
|
||||
}
|
||||
|
||||
/** Handles tile tap events that are not platform specific. */
|
||||
boolean tileTapped(Tile tile){
|
||||
tile = tile.link();
|
||||
@@ -216,7 +261,7 @@ public abstract class InputHandler implements InputProcessor{
|
||||
|
||||
//clear when the player taps on something else
|
||||
if(!consumed && !mobile && player.isBuilding() && block == null){
|
||||
player.clearBuilding();
|
||||
//player.clearBuilding();
|
||||
block = null;
|
||||
return true;
|
||||
}
|
||||
@@ -301,16 +346,30 @@ public abstract class InputHandler implements InputProcessor{
|
||||
table.clear();
|
||||
}
|
||||
}
|
||||
if(detector != null){
|
||||
Core.input.removeProcessor(detector);
|
||||
}
|
||||
if(uiGroup != null){
|
||||
uiGroup.remove();
|
||||
uiGroup = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void add(){
|
||||
Core.input.addProcessor(detector = new GestureDetector(20, 0.5f, 0.4f, 0.15f, this));
|
||||
Core.input.addProcessor(this);
|
||||
if(Core.scene != null){
|
||||
Table table = (Table)Core.scene.find("inputTable");
|
||||
if(table != null){
|
||||
table.clear();
|
||||
buildUI(table);
|
||||
buildPlacementUI(table);
|
||||
}
|
||||
|
||||
uiGroup = new WidgetGroup();
|
||||
uiGroup.touchable(Touchable.childrenOnly);
|
||||
uiGroup.setFillParent(true);
|
||||
ui.hudGroup.addChild(uiGroup);
|
||||
buildUI(uiGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,6 +415,15 @@ public abstract class InputHandler implements InputProcessor{
|
||||
}
|
||||
|
||||
public boolean validPlace(int x, int y, Block type, int rotation){
|
||||
return validPlace(x, y, type, rotation, null);
|
||||
}
|
||||
|
||||
public boolean validPlace(int x, int y, Block type, int rotation, BuildRequest ignore){
|
||||
for(BuildRequest req : player.buildQueue()){
|
||||
if(req != ignore && !req.breaking && req.block.bounds(req.x, req.y, Tmp.r1).overlaps(type.bounds(x, y, Tmp.r2))){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return Build.validPlace(player.getTeam(), x, y, type, rotation);
|
||||
}
|
||||
|
||||
@@ -435,13 +503,6 @@ public abstract class InputHandler implements InputProcessor{
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlaceDraw{
|
||||
public int rotation, scalex, scaley;
|
||||
public TextureRegion region;
|
||||
|
||||
public static final PlaceDraw instance = new PlaceDraw();
|
||||
}
|
||||
|
||||
class PlaceLine{
|
||||
public int x, y, rotation;
|
||||
public boolean last;
|
||||
|
||||
@@ -2,12 +2,12 @@ package io.anuke.mindustry.input;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.input.*;
|
||||
import io.anuke.arc.input.GestureDetector.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.math.geom.*;
|
||||
import io.anuke.arc.scene.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
@@ -36,7 +36,6 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
//gesture data
|
||||
private Vector2 vector = new Vector2();
|
||||
private float lastZoom = -1;
|
||||
private GestureDetector detector;
|
||||
|
||||
/** Position where the player started dragging a line. */
|
||||
private int lineStartX, lineStartY;
|
||||
@@ -50,9 +49,9 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
private float shiftDeltaX, shiftDeltaY;
|
||||
|
||||
/** List of currently selected tiles to place. */
|
||||
private Array<PlaceRequest> selection = new Array<>();
|
||||
private Array<BuildRequest> selection = new Array<>();
|
||||
/** Place requests to be removed. */
|
||||
private Array<PlaceRequest> removals = new Array<>();
|
||||
private Array<BuildRequest> removals = new Array<>();
|
||||
/** Whether or not the player is currently shifting all placed tiles. */
|
||||
private boolean selecting;
|
||||
/** Whether the player is currently in line-place mode. */
|
||||
@@ -62,9 +61,9 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
/** Whether no recipe was available when switching to break mode. */
|
||||
private Block lastBlock;
|
||||
/** Last placed request. Used for drawing block overlay. */
|
||||
private PlaceRequest lastPlaced;
|
||||
|
||||
private int prevX, prevY, prevRotation;
|
||||
private BuildRequest lastPlaced;
|
||||
/** Down tracking for panning.*/
|
||||
private boolean down = false;
|
||||
|
||||
//region utility methods
|
||||
|
||||
@@ -99,10 +98,10 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
r2.setSize(block.size * tilesize);
|
||||
r2.setCenter(x * tilesize + block.offset(), y * tilesize + block.offset());
|
||||
|
||||
for(PlaceRequest req : selection){
|
||||
for(BuildRequest req : selection){
|
||||
Tile other = req.tile();
|
||||
|
||||
if(other == null || req.remove) continue;
|
||||
if(other == null || req.breaking) continue;
|
||||
|
||||
r1.setSize(req.block.size * tilesize);
|
||||
r1.setCenter(other.worldx() + req.block.offset(), other.worldy() + req.block.offset());
|
||||
@@ -128,16 +127,16 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
|
||||
/** Returns the selection request that overlaps this tile, or null. */
|
||||
PlaceRequest getRequest(Tile tile){
|
||||
BuildRequest getRequest(Tile tile){
|
||||
r2.setSize(tilesize);
|
||||
r2.setCenter(tile.worldx(), tile.worldy());
|
||||
|
||||
for(PlaceRequest req : selection){
|
||||
for(BuildRequest req : selection){
|
||||
Tile other = req.tile();
|
||||
|
||||
if(other == null) continue;
|
||||
|
||||
if(!req.remove){
|
||||
if(!req.breaking){
|
||||
r1.setSize(req.block.size * tilesize);
|
||||
r1.setCenter(other.worldx() + req.block.offset(), other.worldy() + req.block.offset());
|
||||
|
||||
@@ -156,7 +155,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
return null;
|
||||
}
|
||||
|
||||
void removeRequest(PlaceRequest request){
|
||||
void removeRequest(BuildRequest request){
|
||||
selection.removeValue(request, true);
|
||||
removals.add(request);
|
||||
}
|
||||
@@ -172,80 +171,8 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
//endregion
|
||||
//region UI and drawing
|
||||
|
||||
void drawRequest(PlaceRequest request, PlaceRequest prev){
|
||||
Tile tile = request.tile();
|
||||
|
||||
if(!request.remove){
|
||||
if(prev != null){
|
||||
request.block.getPlaceDraw(placeDraw, request.rotation, prev.x - request.x, prev.y - request.y, prev.rotation);
|
||||
}else{
|
||||
request.block.getPlaceDraw(placeDraw, request.rotation, 0, 0, request.rotation);
|
||||
}
|
||||
|
||||
//draw placing request
|
||||
float offset = request.block.offset();
|
||||
TextureRegion region = placeDraw.region;
|
||||
|
||||
Draw.mixcol(Pal.accent, Mathf.clamp((1f - request.scale) / 0.5f + 0.12f + Mathf.absin(Time.time(), 8f, 0.35f)));
|
||||
Draw.tint(Color.white, Pal.breakInvalid, request.redness);
|
||||
|
||||
Draw.rect(region, tile.worldx() + offset, tile.worldy() + offset,
|
||||
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++){
|
||||
Point2 p = Geometry.d8edge[i];
|
||||
float poffset = -Math.max(request.block.size - 1, 0) / 2f * tilesize;
|
||||
TextureRegion find = Core.atlas.find("block-select");
|
||||
if(i % 2 == 0)
|
||||
Draw.rect("block-select", request.tile().x * tilesize + request.block.offset() + poffset * p.x, request.tile().y * tilesize + request.block.offset() + poffset * p.y,
|
||||
find.getWidth() * Draw.scl * request.scale, find.getHeight() * Draw.scl * request.scale, i * 90);
|
||||
}
|
||||
Draw.color();
|
||||
}else{
|
||||
float rad = Math.max((tile.block().size * tilesize / 2f - 1) * request.scale, 1f);
|
||||
|
||||
if(rad <= 1.01f) return;
|
||||
Draw.mixcol();
|
||||
//draw removing request
|
||||
Draw.tint(Pal.removeBack);
|
||||
Lines.square(tile.drawx(), tile.drawy() - 1, rad);
|
||||
Draw.tint(Pal.remove);
|
||||
Lines.square(tile.drawx(), tile.drawy(), rad);
|
||||
}
|
||||
}
|
||||
|
||||
/** Draws a placement icon for a specific block. */
|
||||
void drawPlace(int x, int y, Block block, int rotation, int prevX, int prevY, int prevRotation){
|
||||
if(validPlace(x, y, block, rotation) && !checkOverlapPlacement(x, y, block)){
|
||||
block.getPlaceDraw(placeDraw, rotation, prevX, prevY, prevRotation);
|
||||
|
||||
Draw.color();
|
||||
Draw.rect(placeDraw.region, x * tilesize + block.offset(), y * tilesize + block.offset(),
|
||||
placeDraw.region.getWidth() * Draw.scl * placeDraw.scalex,
|
||||
placeDraw.region.getHeight() * Draw.scl * placeDraw.scaley,
|
||||
block.rotate ? placeDraw.rotation * 90 : 0);
|
||||
|
||||
Draw.color(Pal.accent);
|
||||
for(int i = 0; i < 4; i++){
|
||||
Point2 p = Geometry.d8edge[i];
|
||||
float offset = -Math.max(block.size - 1, 0) / 2f * tilesize;
|
||||
if(i % 2 == 0)
|
||||
Draw.rect("block-select", x * tilesize + block.offset() + offset * p.x, y * tilesize + block.offset() + offset * p.y, i * 90);
|
||||
}
|
||||
Draw.color();
|
||||
}else{
|
||||
Draw.color(Pal.removeBack);
|
||||
Lines.square(x * tilesize + block.offset(), y * tilesize + block.offset() - 1, block.size * tilesize / 2f - 1);
|
||||
Draw.color(Pal.remove);
|
||||
Lines.square(x * tilesize + block.offset(), y * tilesize + block.offset(), block.size * tilesize / 2f - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildUI(Table table){
|
||||
public void buildPlacementUI(Table table){
|
||||
table.addImage().color(Pal.gray).height(4f).colspan(4).growX();
|
||||
table.row();
|
||||
table.left().margin(0f).defaults().size(48f);
|
||||
@@ -267,12 +194,12 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
|
||||
//confirm button
|
||||
table.addImageButton(Icon.checkSmall, Styles.clearPartiali, () -> {
|
||||
for(PlaceRequest request : selection){
|
||||
for(BuildRequest request : selection){
|
||||
Tile tile = request.tile();
|
||||
|
||||
//actually place/break all selected blocks
|
||||
if(tile != null){
|
||||
if(!request.remove){
|
||||
if(!request.breaking){
|
||||
rotation = request.rotation;
|
||||
Block before = block;
|
||||
block = request.block;
|
||||
@@ -289,15 +216,17 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
selection.clear();
|
||||
selecting = false;
|
||||
}).visible(() -> !selection.isEmpty()).name("confirmplace");
|
||||
}
|
||||
|
||||
Core.scene.table(t -> {
|
||||
t.setName("cancelMobile");
|
||||
t.bottom().left().visible(() -> (player.isBuilding() || block != null || mode == breaking) && !state.is(State.menu));
|
||||
t.addImageTextButton("$cancel", Icon.cancelSmall, () -> {
|
||||
player.clearBuilding();
|
||||
mode = none;
|
||||
block = null;
|
||||
}).width(155f);
|
||||
@Override
|
||||
public void buildUI(Group group){
|
||||
group.fill(t -> {
|
||||
t.bottom().left().visible(() -> (player.isBuilding() || block != null || mode == breaking) && !state.is(State.menu));
|
||||
t.addImageTextButton("$cancel", Icon.cancelSmall, () -> {
|
||||
player.clearBuilding();
|
||||
mode = none;
|
||||
block = null;
|
||||
}).width(155f);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -316,46 +245,46 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
Lines.stroke(1f);
|
||||
|
||||
//draw removals
|
||||
for(PlaceRequest request : removals){
|
||||
for(BuildRequest request : removals){
|
||||
Tile tile = request.tile();
|
||||
|
||||
if(tile == null) continue;
|
||||
|
||||
request.scale = Mathf.lerpDelta(request.scale, 0f, 0.2f);
|
||||
request.redness = Mathf.lerpDelta(request.redness, 0f, 0.2f);
|
||||
request.animScale = Mathf.lerpDelta(request.animScale, 0f, 0.2f);
|
||||
request.animInvalid = Mathf.lerpDelta(request.animInvalid, 0f, 0.2f);
|
||||
|
||||
drawRequest(request, null);
|
||||
drawRequest(request);
|
||||
}
|
||||
|
||||
PlaceRequest last = null;
|
||||
BuildRequest last = null;
|
||||
|
||||
//draw list of requests
|
||||
for(PlaceRequest request : selection){
|
||||
for(BuildRequest request : selection){
|
||||
Tile tile = request.tile();
|
||||
|
||||
if(tile == null) continue;
|
||||
|
||||
if((!request.remove && validPlace(tile.x, tile.y, request.block, request.rotation))
|
||||
|| (request.remove && validBreak(tile.x, tile.y))){
|
||||
request.scale = Mathf.lerpDelta(request.scale, 1f, 0.2f);
|
||||
request.redness = Mathf.lerpDelta(request.redness, 0f, 0.2f);
|
||||
if((!request.breaking && validPlace(tile.x, tile.y, request.block, request.rotation))
|
||||
|| (request.breaking && validBreak(tile.x, tile.y))){
|
||||
request.animScale = Mathf.lerpDelta(request.animScale, 1f, 0.2f);
|
||||
request.animInvalid = Mathf.lerpDelta(request.animInvalid, 0f, 0.2f);
|
||||
}else{
|
||||
request.scale = Mathf.lerpDelta(request.scale, 0.6f, 0.1f);
|
||||
request.redness = Mathf.lerpDelta(request.redness, 0.9f, 0.2f);
|
||||
request.animScale = Mathf.lerpDelta(request.animScale, 0.6f, 0.1f);
|
||||
request.animInvalid = Mathf.lerpDelta(request.animInvalid, 0.9f, 0.2f);
|
||||
}
|
||||
|
||||
Tmp.c1.set(Draw.getMixColor());
|
||||
|
||||
if(!request.remove && request == lastPlaced && request.block != null){
|
||||
if(!request.breaking && request == lastPlaced && request.block != null){
|
||||
Draw.mixcol();
|
||||
if(request.block.rotate) drawArrow(request.block, tile.x, tile.y, request.rotation);
|
||||
}
|
||||
|
||||
Draw.mixcol(Tmp.c1, 1f);
|
||||
drawRequest(request, last);
|
||||
drawRequest(request);
|
||||
|
||||
//draw last placed request
|
||||
if(!request.remove && request == lastPlaced && request.block != null){
|
||||
if(!request.breaking && request == lastPlaced && request.block != null){
|
||||
Draw.mixcol();
|
||||
request.block.drawPlace(tile.x, tile.y, rotation, validPlace(tile.x, tile.y, request.block, rotation));
|
||||
}
|
||||
@@ -374,20 +303,13 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
if(mode == placing && block != null){
|
||||
//draw placing
|
||||
|
||||
prevX = lineStartX;
|
||||
prevY = lineStartY;
|
||||
prevRotation = rotation;
|
||||
|
||||
iterateLine(lineStartX, lineStartY, tileX, tileY, l -> {
|
||||
if(l.last && block.rotate){
|
||||
drawArrow(block, l.x, l.y, l.rotation);
|
||||
}
|
||||
drawPlace(l.x, l.y, block, l.rotation, prevX - l.x, prevY - l.y, prevRotation);
|
||||
drawRequest(l.x, l.y, block, l.rotation);
|
||||
|
||||
rotation = l.rotation;
|
||||
prevX = l.x;
|
||||
prevY = l.y;
|
||||
prevRotation = l.rotation;
|
||||
});
|
||||
}else if(mode == breaking){
|
||||
//draw breaking
|
||||
@@ -441,28 +363,12 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
//endregion
|
||||
//region input events
|
||||
|
||||
@Override
|
||||
public void add(){
|
||||
Core.input.addProcessor(detector = new GestureDetector(20, 0.5f, 0.4f, 0.15f, this));
|
||||
super.add();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(){
|
||||
super.remove();
|
||||
if(detector != null){
|
||||
Core.input.removeProcessor(detector);
|
||||
}
|
||||
|
||||
if(Core.scene != null && Core.scene.find("cancelMobile") != null){
|
||||
Core.scene.find("cancelMobile").remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDown(int screenX, int screenY, int pointer, KeyCode button){
|
||||
if(state.is(State.menu) || player.isDead()) return false;
|
||||
|
||||
down = true;
|
||||
|
||||
//get tile on cursor
|
||||
Tile cursor = tileAt(screenX, screenY);
|
||||
|
||||
@@ -489,6 +395,10 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, KeyCode button){
|
||||
lastZoom = renderer.getScale();
|
||||
|
||||
if(!Core.input.isTouched()){
|
||||
down = false;
|
||||
}
|
||||
|
||||
//place down a line if in line mode
|
||||
if(lineMode){
|
||||
int tileX = tileX(screenX);
|
||||
@@ -501,8 +411,8 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
return;
|
||||
}
|
||||
|
||||
PlaceRequest request = new PlaceRequest(l.x, l.y, block, l.rotation);
|
||||
request.scale = 1f;
|
||||
BuildRequest request = new BuildRequest(l.x, l.y, l.rotation, block);
|
||||
request.animScale = 1f;
|
||||
selection.add(request);
|
||||
});
|
||||
Events.fire(new LineConfirmEvent());
|
||||
@@ -521,8 +431,8 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
if(tar == null) continue;
|
||||
|
||||
if(!hasRequest(world.tile(tar.x, tar.y)) && validBreak(tar.x, tar.y)){
|
||||
PlaceRequest request = new PlaceRequest(tar.x, tar.y);
|
||||
request.scale = 1f;
|
||||
BuildRequest request = new BuildRequest(tar.x, tar.y);
|
||||
request.animScale = 1f;
|
||||
selection.add(request);
|
||||
}
|
||||
}
|
||||
@@ -584,11 +494,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.x, cursor.y, block, rotation));
|
||||
selection.add(lastPlaced = new BuildRequest(cursor.x, cursor.y, rotation, block));
|
||||
}else if(mode == breaking && validBreak(cursor.link().x, cursor.link().y) && !hasRequest(cursor.link())){
|
||||
//add to selection queue if it's a valid BREAK position
|
||||
cursor = cursor.link();
|
||||
selection.add(new PlaceRequest(cursor.x, cursor.y));
|
||||
selection.add(new BuildRequest(cursor.x, cursor.y));
|
||||
}else if(!canTapPlayer(worldx, worldy) && !tileTapped(cursor.link())){
|
||||
tryBeginMine(cursor);
|
||||
}
|
||||
@@ -690,9 +600,9 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
|
||||
//remove place requests that have disappeared
|
||||
for(int i = removals.size - 1; i >= 0; i--){
|
||||
PlaceRequest request = removals.get(i);
|
||||
BuildRequest request = removals.get(i);
|
||||
|
||||
if(request.scale <= 0.0001f){
|
||||
if(request.animScale <= 0.0001f){
|
||||
removals.remove(i);
|
||||
i--;
|
||||
}
|
||||
@@ -712,6 +622,8 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!down) return false;
|
||||
|
||||
if(selecting){ //pan all requests
|
||||
shiftDeltaX += deltaX;
|
||||
shiftDeltaY += deltaY;
|
||||
@@ -720,8 +632,8 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
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
|
||||
for(BuildRequest req : selection){
|
||||
if(req.breaking) continue; //don't shift removal requests
|
||||
req.x += shiftedX;
|
||||
req.y += shiftedY;
|
||||
}
|
||||
@@ -756,33 +668,4 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
private class PlaceRequest{
|
||||
int x, y;
|
||||
Block block;
|
||||
int rotation;
|
||||
boolean remove;
|
||||
|
||||
//animation variables
|
||||
float scale;
|
||||
float redness;
|
||||
|
||||
PlaceRequest(int x, int y, Block block, int rotation){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.block = block;
|
||||
this.rotation = rotation;
|
||||
this.remove = false;
|
||||
}
|
||||
|
||||
PlaceRequest(int x, int y){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.remove = true;
|
||||
}
|
||||
|
||||
Tile tile(){
|
||||
return world.tile(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user