diff --git a/core/assets-raw/sprites/blocks/extra/place-arrow.png b/core/assets-raw/sprites/blocks/extra/place-arrow.png new file mode 100644 index 0000000000..3fc6718d29 Binary files /dev/null and b/core/assets-raw/sprites/blocks/extra/place-arrow.png differ diff --git a/core/assets/sprites/sprites.atlas b/core/assets/sprites/sprites.atlas index 0f9cc3ca30..1b6dbb647e 100644 --- a/core/assets/sprites/sprites.atlas +++ b/core/assets/sprites/sprites.atlas @@ -251,70 +251,70 @@ overflowgate index: -1 poweredconveyor rotate: false - xy: 686, 269 + xy: 296, 37 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 poweredconveyormove rotate: false - xy: 296, 37 + xy: 306, 37 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 pulseconduit-bottom rotate: false - xy: 306, 27 + xy: 316, 29 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 pulseconduit-top rotate: false - xy: 316, 29 + xy: 326, 33 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 router rotate: false - xy: 624, 120 + xy: 634, 120 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 sortedunloader rotate: false - xy: 296, 17 + xy: 306, 17 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 sorter rotate: false - xy: 306, 17 + xy: 295, 7 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 splitter rotate: false - xy: 305, 7 + xy: 316, 9 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 steelconveyor rotate: false - xy: 316, 9 + xy: 326, 3 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 steelconveyormove rotate: false - xy: 326, 3 + xy: 574, 110 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -328,7 +328,7 @@ teleporter-top index: -1 unloader rotate: false - xy: 929, 399 + xy: 939, 399 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -706,56 +706,56 @@ oiledge index: -1 rock1 rotate: false - xy: 604, 120 + xy: 614, 120 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 rock2 rotate: false - xy: 614, 120 + xy: 624, 120 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 sand1 rotate: false - xy: 564, 117 + xy: 554, 115 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 sand2 rotate: false - xy: 554, 115 + xy: 654, 115 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 sand3 rotate: false - xy: 654, 115 + xy: 664, 115 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 sandblock1 rotate: false - xy: 664, 115 + xy: 674, 115 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 sandblock2 rotate: false - xy: 674, 115 + xy: 236, 21 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 sandblock3 rotate: false - xy: 236, 21 + xy: 246, 21 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -769,56 +769,56 @@ sandedge index: -1 shrub rotate: false - xy: 235, 1 + xy: 245, 11 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 shrubshadow rotate: false - xy: 245, 11 + xy: 245, 1 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 snow1 rotate: false - xy: 255, 1 + xy: 265, 11 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 snow2 rotate: false - xy: 265, 11 + xy: 265, 1 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 snow3 rotate: false - xy: 265, 1 + xy: 275, 11 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 snowblock1 rotate: false - xy: 275, 11 + xy: 275, 1 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 snowblock2 rotate: false - xy: 275, 1 + xy: 285, 11 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 snowblock3 rotate: false - xy: 285, 11 + xy: 285, 1 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -832,7 +832,7 @@ snowedge index: -1 space rotate: false - xy: 295, 7 + xy: 305, 7 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -846,42 +846,42 @@ spaceedge index: -1 stone1 rotate: false - xy: 614, 110 + xy: 624, 110 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stone2 rotate: false - xy: 624, 110 + xy: 634, 110 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stone3 rotate: false - xy: 634, 110 + xy: 644, 110 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stoneblock1 rotate: false - xy: 644, 110 + xy: 564, 107 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stoneblock2 rotate: false - xy: 564, 107 + xy: 654, 105 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stoneblock3 rotate: false - xy: 654, 105 + xy: 664, 105 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -895,49 +895,49 @@ stoneedge index: -1 thorium1 rotate: false - xy: 594, 100 + xy: 604, 100 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 thorium2 rotate: false - xy: 604, 100 + xy: 614, 100 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 thorium3 rotate: false - xy: 614, 100 + xy: 624, 100 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 titanium1 rotate: false - xy: 624, 100 + xy: 634, 100 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 titanium2 rotate: false - xy: 634, 100 + xy: 644, 100 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 titanium3 rotate: false - xy: 644, 100 + xy: 654, 95 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 water rotate: false - xy: 959, 399 + xy: 969, 399 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -1026,13 +1026,20 @@ nuclearreactor-shadow orig: 26, 26 offset: 0, 0 index: -1 -playerspawn +place-arrow rotate: false xy: 674, 125 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 +playerspawn + rotate: false + xy: 686, 269 + size: 8, 8 + orig: 8, 8 + offset: 0, 0 + index: -1 ripples rotate: false xy: 338, 89 @@ -1245,14 +1252,14 @@ nuclearreactor-lights index: -1 powerinfinite rotate: false - xy: 306, 37 + xy: 316, 39 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 powernode rotate: false - xy: 316, 39 + xy: 296, 27 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -1273,28 +1280,28 @@ powernodelarge-shadow index: -1 powervoid rotate: false - xy: 296, 27 + xy: 306, 27 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 rtgenerator rotate: false - xy: 634, 120 + xy: 644, 120 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 rtgenerator-top rotate: false - xy: 644, 120 + xy: 564, 117 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 shieldgenerator rotate: false - xy: 266, 21 + xy: 276, 21 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -1308,7 +1315,7 @@ shieldprojector index: -1 solarpanel rotate: false - xy: 285, 1 + xy: 296, 17 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -1329,7 +1336,7 @@ teleporter-top index: -1 thermalgenerator rotate: false - xy: 584, 100 + xy: 594, 100 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -1686,63 +1693,63 @@ siliconsmelter-top index: -1 pulverizer rotate: false - xy: 326, 33 + xy: 326, 23 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 pulverizer-rotator rotate: false - xy: 326, 23 + xy: 316, 19 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 pump rotate: false - xy: 316, 19 + xy: 326, 13 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 reinforceddrill rotate: false - xy: 326, 13 + xy: 430, 122 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 reinforceddrill-rotator rotate: false - xy: 430, 122 + xy: 440, 122 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 reinforceddrill-top rotate: false - xy: 440, 122 + xy: 574, 120 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 separator rotate: false - xy: 246, 21 + xy: 256, 21 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 separator-liquid rotate: false - xy: 256, 21 + xy: 266, 21 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 siliconextractor rotate: false - xy: 245, 1 + xy: 255, 11 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -1756,56 +1763,56 @@ siliconsmelter index: -1 smelter rotate: false - xy: 255, 11 + xy: 255, 1 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 steeldrill rotate: false - xy: 574, 110 + xy: 584, 110 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 steeldrill-rotator rotate: false - xy: 584, 110 + xy: 594, 110 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 steeldrill-top rotate: false - xy: 594, 110 + xy: 604, 110 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stonedrill rotate: false - xy: 664, 105 + xy: 674, 105 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 stoneformer rotate: false - xy: 674, 105 + xy: 574, 100 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 titaniumdrill rotate: false - xy: 654, 95 + xy: 664, 95 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 titaniumdrill-top rotate: false - xy: 664, 95 + xy: 674, 95 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -2078,21 +2085,21 @@ walkerfactory-top-open index: -1 repairpoint rotate: false - xy: 574, 120 + xy: 584, 120 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 repairpoint-turret rotate: false - xy: 584, 120 + xy: 594, 120 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 resupplypoint rotate: false - xy: 594, 120 + xy: 604, 120 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -2155,7 +2162,7 @@ ironwall index: -1 steelwall rotate: false - xy: 604, 110 + xy: 614, 110 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -2169,21 +2176,21 @@ steelwall-large index: -1 stonewall rotate: false - xy: 574, 100 + xy: 584, 100 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 titaniumshieldwall rotate: false - xy: 674, 95 + xy: 889, 399 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 titaniumwall rotate: false - xy: 889, 399 + xy: 899, 399 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -2288,7 +2295,7 @@ shell-back index: -1 shot rotate: false - xy: 235, 11 + xy: 235, 1 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -2302,7 +2309,7 @@ transfer index: -1 transfer-arrow rotate: false - xy: 899, 399 + xy: 909, 399 size: 8, 8 orig: 8, 8 offset: 0, 0 @@ -3604,42 +3611,42 @@ clustergun-equip index: -1 shockgun rotate: false - xy: 276, 21 + xy: 286, 21 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 shockgun-equip rotate: false - xy: 286, 21 + xy: 235, 11 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 triblaster rotate: false - xy: 909, 399 + xy: 919, 399 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 triblaster-equip rotate: false - xy: 919, 399 + xy: 929, 399 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 vulcan rotate: false - xy: 939, 399 + xy: 949, 399 size: 8, 8 orig: 8, 8 offset: 0, 0 index: -1 vulcan-equip rotate: false - xy: 949, 399 + xy: 959, 399 size: 8, 8 orig: 8, 8 offset: 0, 0 diff --git a/core/assets/sprites/sprites.png b/core/assets/sprites/sprites.png index a3b68dfb17..3401a6c11a 100644 Binary files a/core/assets/sprites/sprites.png and b/core/assets/sprites/sprites.png differ diff --git a/core/src/io/anuke/mindustry/graphics/Palette.java b/core/src/io/anuke/mindustry/graphics/Palette.java index 476ddc2fbb..35c0dd1f59 100644 --- a/core/src/io/anuke/mindustry/graphics/Palette.java +++ b/core/src/io/anuke/mindustry/graphics/Palette.java @@ -42,7 +42,7 @@ public class Palette { public static final Color accent = Color.valueOf("f4ba6e"); public static final Color place = Color.valueOf("6335f8"); public static final Color remove = Color.valueOf("e55454"); - public static final Color placeRotate = Color.ORANGE; + public static final Color placeRotate = accent; public static final Color breakInvalid = Color.valueOf("d44b3d"); public static final Color range = Color.valueOf("f4ba6e"); public static final Color power = Color.valueOf("fbd367"); diff --git a/core/src/io/anuke/mindustry/input/AndroidInput.java b/core/src/io/anuke/mindustry/input/AndroidInput.java index 5470322d38..96edca8985 100644 --- a/core/src/io/anuke/mindustry/input/AndroidInput.java +++ b/core/src/io/anuke/mindustry/input/AndroidInput.java @@ -200,7 +200,7 @@ public class AndroidInput extends InputHandler implements GestureListener{ if(tile == null) continue; - if(validPlace(tile.x, tile.y, request.recipe.result)){ + if(validPlace(tile.x, tile.y, request.recipe.result, request.rotation)){ request.scale = Mathf.lerpDelta(request.scale, 1f, 0.2f); request.redness = Mathf.lerpDelta(request.redness, 0f, 0.2f); }else{ @@ -231,7 +231,7 @@ public class AndroidInput extends InputHandler implements GestureListener{ int x = lineStartX + i * Mathf.sign(tile.x - lineStartX) * Mathf.bool(result.isX()); int y = lineStartY + i * Mathf.sign(tile.y - lineStartY) * Mathf.bool(!result.isX()); - if(!checkOverlapPlacement(x, y, recipe.result) && validPlace(x, y, recipe.result)){ + if(!checkOverlapPlacement(x, y, recipe.result) && validPlace(x, y, recipe.result, result.rotation)){ Draw.color(); TextureRegion[] regions = recipe.result.getBlockIcon(); @@ -306,7 +306,7 @@ public class AndroidInput extends InputHandler implements GestureListener{ int x = lineStartX + i * Mathf.sign(tile.x - lineStartX) * Mathf.bool(result.isX()); int y = lineStartY + i * Mathf.sign(tile.y - lineStartY) * Mathf.bool(!result.isX()); - if(!checkOverlapPlacement(x, y, recipe.result) && validPlace(x, y, recipe.result)){ + if(!checkOverlapPlacement(x, y, recipe.result) && validPlace(x, y, recipe.result, result.rotation)){ PlaceRequest request = new PlaceRequest(x * tilesize, y * tilesize, recipe, result.rotation); request.scale = 1f; placement.add(request); @@ -352,7 +352,7 @@ public class AndroidInput extends InputHandler implements GestureListener{ //remove if request present if(hasRequest(cursor)) { removeRequest(getRequest(cursor)); - }else if(isPlacing() && validPlace(cursor.x, cursor.y, recipe.result) && !checkOverlapPlacement(cursor.x, cursor.y, recipe.result)){ + }else if(isPlacing() && validPlace(cursor.x, cursor.y, recipe.result, rotation) && !checkOverlapPlacement(cursor.x, cursor.y, recipe.result)){ //add to placement queue if it's a valid place position placement.add(new PlaceRequest(cursor.worldx(), cursor.worldy(), recipe, rotation)); } diff --git a/core/src/io/anuke/mindustry/input/DesktopInput.java b/core/src/io/anuke/mindustry/input/DesktopInput.java index e9712a5baf..a6033b20e6 100644 --- a/core/src/io/anuke/mindustry/input/DesktopInput.java +++ b/core/src/io/anuke/mindustry/input/DesktopInput.java @@ -2,14 +2,19 @@ package io.anuke.mindustry.input; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Buttons; +import com.badlogic.gdx.graphics.g2d.TextureRegion; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.Player; -import io.anuke.mindustry.input.PlaceUtils.NormalizeDrawResult; +import io.anuke.mindustry.graphics.Palette; +import io.anuke.mindustry.input.PlaceUtils.NormalizeResult; +import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; import io.anuke.ucore.core.Inputs; import io.anuke.ucore.core.Inputs.DeviceType; import io.anuke.ucore.core.KeyBinds; import io.anuke.ucore.core.Settings; +import io.anuke.ucore.graphics.Draw; +import io.anuke.ucore.graphics.Lines; import io.anuke.ucore.scene.ui.layout.Unit; import io.anuke.ucore.scene.utils.Cursors; import io.anuke.ucore.util.Mathf; @@ -20,7 +25,7 @@ public class DesktopInput extends InputHandler{ //controller info private float controlx, controly; private boolean controlling; - private boolean showCursor = false; + private boolean handCursor; private final String section; /**Position where the player started dragging a line.*/ @@ -57,6 +62,22 @@ public class DesktopInput extends InputHandler{ tile.block().tapped(tile, player); } + void drawPlace(int x, int y, Block block, int rotation){ + if(validPlace(x, y, block, rotation)){ + Draw.color(); + + TextureRegion[] regions = block.getBlockIcon(); + + for(TextureRegion region : regions){ + Draw.rect(region, x *tilesize + block.offset(), y * tilesize + block.offset(), + region.getRegionWidth() * selectScale, region.getRegionHeight() * selectScale, block.rotate ? rotation * 90 : 0); + } + }else{ + Draw.color(Palette.remove); + Lines.square(x*tilesize + block.offset(), y*tilesize + block.offset(), block.size * tilesize/2f); + } + } + @Override public void drawBottom(){ Tile cursor = tileAt(control.gdxInput().getX(), control.gdxInput().getY()); @@ -65,10 +86,32 @@ public class DesktopInput extends InputHandler{ //draw selection if(selecting){ - NormalizeDrawResult result = PlaceUtils.normalizeDrawArea(recipe.result, selectX, selectY, cursor.x, cursor.y, true, maxLength, selectScale); + NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength); + for(int i = 0; i <= result.getLength(); i += recipe.result.size){ + int x = selectX + i * Mathf.sign(cursor.x - selectX) * Mathf.bool(result.isX()); + int y = selectY + i * Mathf.sign(cursor.y - selectY) * Mathf.bool(!result.isX()); - } + if(i + recipe.result.size > result.getLength() && recipe.result.rotate){ + Draw.color(!validPlace(x, y, recipe.result, result.rotation) ? Palette.remove : Palette.placeRotate); + Draw.grect("place-arrow", x * tilesize + recipe.result.offset(), + y * tilesize + recipe.result.offset(), result.rotation * 90 - 90); + } + + drawPlace(x, y, recipe.result, result.rotation); + } + + Draw.reset(); + }else if(isPlacing()){ + if(recipe.result.rotate){ + Draw.color(!validPlace(cursor.x, cursor.y, recipe.result, rotation) ? Palette.remove : Palette.placeRotate); + Draw.grect("place-arrow", cursor.worldx() + recipe.result.offset(), + cursor.worldy() + recipe.result.offset(), rotation * 90 - 90); + } + drawPlace(cursor.x, cursor.y, recipe.result, rotation); + } + + Draw.reset(); } @Override @@ -80,8 +123,8 @@ public class DesktopInput extends InputHandler{ selecting = false; } - //update select animation - if(selecting){ + if(isPlacing()){ + handCursor = true; selectScale = Mathf.lerpDelta(selectScale, 1f, 0.2f); }else{ selectScale = 0f; @@ -100,18 +143,18 @@ public class DesktopInput extends InputHandler{ Tile cursor = tileAt(control.gdxInput().getX(), control.gdxInput().getY()); if(cursor != null && cursor.block().isConfigurable(cursor)){ - showCursor = true; + handCursor = true; } if(!ui.hasMouse()) { - if (showCursor) { + if (handCursor) { Cursors.setHand(); }else { Cursors.restoreCursor(); } } - showCursor = false; + handCursor = false; } @Override @@ -137,6 +180,26 @@ public class DesktopInput extends InputHandler{ public boolean touchUp (int screenX, int screenY, int pointer, int button) { if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return false; + Tile cursor = tileAt(screenX, screenY); + + if(cursor == null){ + selecting = false; + return false; + } + + if(selecting){ + NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength); + + for(int i = 0; i <= result.getLength(); i += recipe.result.size){ + int x = selectX + i * Mathf.sign(cursor.x - selectX) * Mathf.bool(result.isX()); + int y = selectY + i * Mathf.sign(cursor.y - selectY) * Mathf.bool(!result.isX()); + + rotation = result.rotation; + + tryPlaceBlock(x, y); + } + } + selecting = false; return false; diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index 394b7e6f4c..668ee49f93 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -169,7 +169,7 @@ public abstract class InputHandler extends InputAdapter{ } public boolean tryPlaceBlock(int x, int y){ - if(recipe != null && validPlace(x, y, recipe.result) && cursorNear()){ + if(recipe != null && validPlace(x, y, recipe.result, rotation) && cursorNear()){ placeBlock(x, y, recipe, rotation); @@ -186,7 +186,7 @@ public abstract class InputHandler extends InputAdapter{ return false; } - public boolean validPlace(int x, int y, Block type){ + public boolean validPlace(int x, int y, Block type, int rotation){ for(Tile tile : state.teams.get(player.team).cores){ if(tile.distanceTo(x * tilesize, y * tilesize) < coreBuildRange){ return Build.validPlace(player.team, x, y, type, rotation) && diff --git a/core/src/io/anuke/mindustry/input/PlaceMode.java b/core/src/io/anuke/mindustry/input/PlaceMode.java deleted file mode 100644 index 5d3d7b7ac5..0000000000 --- a/core/src/io/anuke/mindustry/input/PlaceMode.java +++ /dev/null @@ -1,359 +0,0 @@ -package io.anuke.mindustry.input; - -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.g2d.TextureRegion; -import com.badlogic.gdx.math.MathUtils; -import io.anuke.mindustry.graphics.Palette; -import io.anuke.mindustry.graphics.Shaders; -import io.anuke.mindustry.world.Block; -import io.anuke.mindustry.world.Build; -import io.anuke.mindustry.world.Tile; -import io.anuke.ucore.core.Graphics; -import io.anuke.ucore.core.Timers; -import io.anuke.ucore.graphics.Draw; -import io.anuke.ucore.graphics.Fill; -import io.anuke.ucore.graphics.Lines; -import io.anuke.ucore.util.Bundles; -import io.anuke.ucore.util.Mathf; -import io.anuke.ucore.util.Translator; - -import static io.anuke.mindustry.Vars.*; - -public enum PlaceMode{ - cursor{ - { - shown = true; - lockCamera = true; - pan = true; - } - - public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){ - float x = tilex * tilesize; - float y = tiley * tilesize; - - boolean valid = input.validPlace(tilex, tiley, input.recipe.result) && (mobile || input.cursorNear()); - - float offset = input.recipe.result.offset(); - - float si = MathUtils.sin(Timers.time() / 6f) + 1.5f; - - Draw.color(valid ? Palette.place : Palette.remove); - Lines.stroke(2f); - Lines.crect(x + offset, y + offset, tilesize * input.recipe.result.size + si, - tilesize * input.recipe.result.size + si); - - input.recipe.result.drawPlace(tilex, tiley, input.rotation, valid); - - if(input.recipe.result.rotate){ - - Draw.color(Palette.placeRotate); - tr.trns(input.rotation * 90, 7, 0); - Lines.line(x, y, x + tr.x, y + tr.y); - } - } - - public void tapped(InputHandler input, int tilex, int tiley){ - input.tryPlaceBlock(tilex, tiley); - } - }, - touch{ - { - shown = true; - lockCamera = false; - showRotate = true; - showCancel = true; - } - - public void tapped(InputHandler input, int x, int y){ - input.tryPlaceBlock(x, y); - } - }, - none{ - { - delete = true; - shown = true; - both = true; - } - }, - touchDelete{ - { - shown = true; - lockCamera = false; - showRotate = true; - showCancel = true; - delete = true; - } - - public void tapped(InputHandler input, int x, int y){ - input.tryDeleteBlock(x, y); - } - }, - areaDelete{ - int rtilex; - int rtiley; - int rendx; - int rendy; - - { - shown = true; - lockCamera = true; - delete = true; - } - - public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){ - float t = tilesize; - - process(tilex, tiley, endx, endy); - - tilex = this.rtilex; tiley = this.rtiley; - endx = this.rendx; endy = this.rendy; - float x = this.rtilex * t, y = this.rtiley * t, - x2 = this.rendx * t, y2 = this.rendy * t; - - if(x2 >= x){ - x -= t/2; - x2 += t/2; - } - - if(y2 >= y){ - y -= t/2; - y2 += t/2; - } - - Draw.color(Palette.remove); - Lines.stroke(1f); - for(int cx = tilex; cx <= endx; cx ++){ - for(int cy = tiley; cy <= endy; cy ++){ - Tile tile = world.tile(cx, cy); - if(tile != null && tile.getLinked() != null) - tile = tile.getLinked(); - if(tile != null && input.validBreak(tile.x, tile.y)){ - Lines.crect(tile.drawx(), tile.drawy(), - tile.block().size * t, tile.block().size * t); - } - } - } - - Lines.stroke(2f); - Draw.color(Palette.remove); - Lines.rect(x, y, x2 - x, y2 - y); - Draw.alpha(0.3f); - Draw.crect("blank", x, y, x2 - x, y2 - y); - Draw.reset(); - } - - public void released(InputHandler input, int tilex, int tiley, int endx, int endy){ - process(tilex, tiley, endx, endy); - tilex = this.rtilex; tiley = this.rtiley; - endx = this.rendx; endy = this.rendy; - - input.player.clearBuilding(); - - for(int cx = tilex; cx <= endx; cx ++){ - for(int cy = tiley; cy <= endy; cy ++){ - input.tryDeleteBlock(cx, cy); - } - } - } - - void process(int tilex, int tiley, int endx, int endy){ - /* - if(Math.abs(x2 - tilex) > maxlen){ - x2 = Mathf.sign(x2 - tilex) * maxlen + tilex; - } - - if(Math.abs(y2 - tiley) > maxlen){ - y2 = Mathf.sign(y2 - tiley) * maxlen + tiley; - }*/ - - if(endx < tilex){ - int t = endx; - endx = tilex; - tilex = t; - } - if(endy < tiley){ - int t = endy; - endy = tiley; - tiley = t; - } - - this.rendx = endx; - this.rendy = endy; - this.rtilex = tilex; - this.rtiley = tiley; - } - }, - hold{ - int rtilex; - int rtiley; - int rendx; - int rendy; - int rotation; - - { - lockCamera = true; - shown = true; - showCancel = true; - showRotate = true; - } - - public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){ - if(mobile && !Gdx.input.isTouched(0) && !input.isCursorVisible()){ - return; - } - - float t = tilesize; - Block block = input.recipe.result; - float offset = block.offset(); - - process(input, tilex, tiley, endx, endy); - float x = rtilex * t, y = rtiley * t, - x2 = rendx * t, y2 = rendy * t; - - if(x2 >= x){ - x -= block.size * t/2; - x2 += block.size * t/2; - } - - if(y2 >= y){ - y -= block.size * t/2; - y2 += block.size * t/2; - } - - x += offset; - y += offset; - x2 += offset; - y2 += offset; - - if(tilex == endx && tiley == endy){ - cursor.draw(input, tilex, tiley, endx, endy); - }else{ - Draw.color(Palette.place); - Lines.stroke(1f); - Lines.rect(x, y, x2 - x, y2 - y); - Draw.alpha(0.3f); - Fill.crect(x, y, x2 - x, y2 - y); - Draw.alpha(0f); - - Graphics.shader(Shaders.blockpreview, false); - - for(int py = 0; py <= Math.abs(this.rendy - this.rtiley); py += block.size){ - for(int px = 0; px <= Math.abs(this.rendx - this.rtilex); px += block.size){ - - int wx = tilex + px * Mathf.sign(endx - tilex), - wy = tiley + py * Mathf.sign(endy - tiley); - if(!Build.validPlace(input.player.team, wx, wy, block, rotation)){ - Draw.color(Palette.remove); - }else{ - Draw.color(Palette.accent); - } - - drawPreview(block, wx * t + offset, wy * t + offset); - } - } - - Graphics.shader(); - Draw.reset(); - } - } - - public void drawPreview(Block block, float x, float y){ - for(TextureRegion region : block.getBlockIcon()){ - Shaders.blockpreview.region = region; - Shaders.blockpreview.color.set(Palette.accent); - Shaders.blockpreview.apply(); - - Draw.rect(region, x, y); - - Graphics.flush(); - } - } - - public void released(InputHandler input, int tilex, int tiley, int endx, int endy){ - process(input, tilex, tiley, endx, endy); - - input.rotation = this.rotation; - input.player.clearBuilding(); - - boolean first = true; - for(int x = 0; x <= Math.abs(this.rendx - this.rtilex); x += input.recipe.result.size){ - for(int y = 0; y <= Math.abs(this.rendy - this.rtiley); y += input.recipe.result.size){ - input.tryPlaceBlock( - tilex + x * Mathf.sign(endx - tilex), - tiley + y * Mathf.sign(endy - tiley)); - } - } - } - - void process(InputHandler input, int tilex, int tiley, int endx, int endy){ - - //todo hold shift to snap - /* - if(Math.abs(tilex - x2) > Math.abs(tiley - y2)){ - y2 = tiley; - }else{ - x2 = tilex; - } - - if(Math.abs(x2 - tilex) > maxlen){ - x2 = Mathf.sign(x2 - tilex) * maxlen + tilex; - } - - if(Math.abs(y2 - tiley) > maxlen){ - y2 = Mathf.sign(y2 - tiley) * maxlen + tiley; - }*/ - - int dx = endx - tilex, dy = endy - tiley; - - if(Math.abs(dx) > Math.abs(dy)){ - if(dx >= 0){ - rotation = 0; - }else{ - rotation = 2; - } - }else if(Math.abs(dx) < Math.abs(dy)){ - if(dy >= 0){ - rotation = 1; - }else{ - rotation = 3; - } - }else{ - rotation = input.rotation; - } - - if(endx < tilex){ - int t = endx; - endx = tilex; - tilex = t; - } - if(endy < tiley){ - int t = endy; - endy = tiley; - tiley = t; - } - - this.rendx = endx; - this.rendy = endy; - this.rtilex = tilex; - this.rtiley = tiley; - } - }; - public boolean lockCamera; - public boolean pan = false; - public boolean shown = false; - public boolean showRotate; - public boolean showCancel; - public boolean delete = false; - public boolean both = false; - - private static final Translator tr = new Translator(); - - public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){} - public void released(InputHandler input, int tilex, int tiley, int endx, int endy){} - public void tapped(InputHandler input, int x, int y){} - - @Override - public String toString(){ - return Bundles.get("placemode."+name().toLowerCase()+".name"); - } -} \ No newline at end of file