From c7bc6e9128713586f170619bd9d116fa49b93788 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 25 Jun 2018 20:38:42 -0400 Subject: [PATCH] Added range indicators, mobile build cancel button --- .../io/anuke/mindustry/content/Recipes.java | 4 +++ .../content/blocks/UpgradeBlocks.java | 7 ++++- .../io/anuke/mindustry/graphics/Palette.java | 1 + .../anuke/mindustry/input/AndroidInput.java | 26 +++++++++++++++++-- .../anuke/mindustry/input/DesktopInput.java | 1 + .../world/blocks/defense/turrets/Turret.java | 2 +- .../world/blocks/distribution/ItemBridge.java | 6 ++--- .../world/blocks/power/PowerDistributor.java | 2 +- 8 files changed, 41 insertions(+), 8 deletions(-) diff --git a/core/src/io/anuke/mindustry/content/Recipes.java b/core/src/io/anuke/mindustry/content/Recipes.java index 8599a9e415..748cbc1137 100644 --- a/core/src/io/anuke/mindustry/content/Recipes.java +++ b/core/src/io/anuke/mindustry/content/Recipes.java @@ -90,6 +90,10 @@ public class Recipes implements ContentList{ //UNITS //bodies + + new Recipe(units, UpgradeBlocks.tridentFactory, new ItemStack(Items.lead, 150), new ItemStack(Items.silicon, 200), new ItemStack(Items.titanium, 240)) + .setDesktop(); //trident is desktop only, because it's the starter mobile ship + //new Recipe(units, UpgradeBlocks.deltaFactory, new ItemStack(Items.tungsten, 30), new ItemStack(Items.lead, 50), new ItemStack(Items.silicon, 30)); //actual unit related stuff diff --git a/core/src/io/anuke/mindustry/content/blocks/UpgradeBlocks.java b/core/src/io/anuke/mindustry/content/blocks/UpgradeBlocks.java index 924e189ecb..4237162b56 100644 --- a/core/src/io/anuke/mindustry/content/blocks/UpgradeBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/UpgradeBlocks.java @@ -5,7 +5,7 @@ import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.blocks.production.MechFactory; public class UpgradeBlocks extends BlockList { - public static Block deltaFactory, tauFactory, omegaFactory, tridentFactory, javelinFactory, halberdFactory; + public static Block deltaFactory, tauFactory, omegaFactory, dartFactory, tridentFactory, javelinFactory, halberdFactory; @Override public void load() { @@ -24,6 +24,11 @@ public class UpgradeBlocks extends BlockList { size = 3; }}; + dartFactory = new MechFactory("dart-ship-factory"){{ + mech = Mechs.dart; + size = 2; + }}; + tridentFactory = new MechFactory("trident-ship-factory"){{ mech = Mechs.trident; size = 2; diff --git a/core/src/io/anuke/mindustry/graphics/Palette.java b/core/src/io/anuke/mindustry/graphics/Palette.java index 2dcfc4450b..2631f3cf29 100644 --- a/core/src/io/anuke/mindustry/graphics/Palette.java +++ b/core/src/io/anuke/mindustry/graphics/Palette.java @@ -49,6 +49,7 @@ public class Palette { public static final Color breakInvalid = Color.valueOf("d44b3d"); public static final Color range = Color.valueOf("f4ba6e"); public static final Color power = Color.valueOf("fbd367"); + public static final Color placing = Color.valueOf("616161"); public static final Color redSpark = Color.valueOf("fbb97f"); public static final Color orangeSpark = Color.valueOf("d2b29c"); diff --git a/core/src/io/anuke/mindustry/input/AndroidInput.java b/core/src/io/anuke/mindustry/input/AndroidInput.java index f639a9255f..eb23fe76a3 100644 --- a/core/src/io/anuke/mindustry/input/AndroidInput.java +++ b/core/src/io/anuke/mindustry/input/AndroidInput.java @@ -71,6 +71,8 @@ public class AndroidInput extends InputHandler implements GestureListener{ private PlaceMode mode = none; /**Whether no recipe was available when switching to break mode.*/ private Recipe lastRecipe; + /**Last placed request. Used for drawing block overlay.*/ + private PlaceRequest lastPlaced; public AndroidInput(Player player){ super(player); @@ -191,6 +193,18 @@ public class AndroidInput extends InputHandler implements GestureListener{ new table(){{ abottom().aleft(); + new table("pane"){{ + margin(5); + defaults().size(60f); + + //Add a 'cancel building' button. + new imagebutton("icon-cancel", "toggle", 16 * 2f, () -> player.clearBuilding()); + + visible(() -> player.getPlaceQueue().size > 0); + }}.left().colspan(2).end(); + + row(); + new table("pane"){{ margin(5); defaults().size(60f); @@ -268,7 +282,7 @@ public class AndroidInput extends InputHandler implements GestureListener{ drawRequest(request); } - //draw normals + //draw list of requests for(PlaceRequest request : selection){ Tile tile = request.tile(); @@ -285,6 +299,11 @@ public class AndroidInput extends InputHandler implements GestureListener{ drawRequest(request); + + //draw last placed request + if(!request.remove && request == lastPlaced){ + recipe.result.drawPlace(tile.x, tile.y, rotation, validPlace(tile.x, tile.y, recipe.result, rotation)); + } } Graphics.shader(); @@ -427,6 +446,9 @@ public class AndroidInput extends InputHandler implements GestureListener{ } } + //reset last placed for convenience + lastPlaced = null; + }else if(mode == breaking){ //normalize area NormalizeResult result = PlaceUtils.normalizeArea(lineStartX, lineStartY, tile.x, tile.y, rotation, false, maxLength); @@ -501,7 +523,7 @@ public class AndroidInput extends InputHandler implements GestureListener{ removeRequest(getRequest(cursor)); }else if(mode == placing && isPlacing() && validPlace(cursor.x, cursor.y, recipe.result, rotation) && !checkOverlapPlacement(cursor.x, cursor.y, recipe.result)){ //add to selection queue if it's a valid place position - selection.add(new PlaceRequest(cursor.worldx(), cursor.worldy(), recipe, rotation)); + selection.add(lastPlaced = new PlaceRequest(cursor.worldx(), cursor.worldy(), recipe, rotation)); }else if(mode == breaking && validBreak(cursor.x, cursor.y) && !hasRequest(cursor)){ //add to selection queue if it's a valid BREAK position selection.add(new PlaceRequest(cursor.worldx(), cursor.worldy())); diff --git a/core/src/io/anuke/mindustry/input/DesktopInput.java b/core/src/io/anuke/mindustry/input/DesktopInput.java index 20b7b761d3..9a86be92cd 100644 --- a/core/src/io/anuke/mindustry/input/DesktopInput.java +++ b/core/src/io/anuke/mindustry/input/DesktopInput.java @@ -118,6 +118,7 @@ public class DesktopInput extends InputHandler{ cursor.worldy() + recipe.result.offset(), rotation * 90 - 90); } drawPlace(cursor.x, cursor.y, recipe.result, rotation); + recipe.result.drawPlace(cursor.x, cursor.y, rotation, validPlace(cursor.x, cursor.y, recipe.result, rotation)); } Draw.reset(); diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java index ff97d4fd34..dcc88852bd 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java @@ -140,7 +140,7 @@ public abstract class Turret extends Block{ @Override public void drawPlace(int x, int y, int rotation, boolean valid){ - Draw.color(Palette.place); + Draw.color(Palette.placing); Lines.stroke(1f); Lines.dashCircle(x * tilesize + offset(), y * tilesize + offset(), range); } diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java index 84a18a77c9..b07b13c57a 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java @@ -65,11 +65,11 @@ public class ItemBridge extends Block { @Override public void drawPlace(int x, int y, int rotation, boolean valid) { Lines.stroke(2f); - Draw.color(Palette.place); + Draw.color(Palette.placing); for(int i = 0; i < 4; i ++){ Lines.dashLine( - x * tilesize + Geometry.d4[i].x * tilesize/2f, - y * tilesize + Geometry.d4[i].y * tilesize/2f, + x * tilesize + Geometry.d4[i].x * (tilesize/2f + 2), + y * tilesize + Geometry.d4[i].y * (tilesize/2f + 2), x * tilesize + Geometry.d4[i].x * range * tilesize, y * tilesize + Geometry.d4[i].y * range * tilesize, range); diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java index d29cc19349..ad9cc8f29e 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java @@ -146,7 +146,7 @@ public class PowerDistributor extends PowerBlock{ @Override public void drawPlace(int x, int y, int rotation, boolean valid){ - Draw.color(Palette.place); + Draw.color(Palette.placing); Lines.stroke(1f); Lines.poly(Edges.getPixelPolygon(laserRange), x * tilesize - tilesize/2, y * tilesize - tilesize/2, tilesize);