Place menu scrolling, fixed some settings menu bugs
This commit is contained in:
@@ -34,6 +34,7 @@ import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.input.PlaceMode.none;
|
||||
|
||||
public class AndroidInput extends InputHandler implements GestureListener{
|
||||
private static Rectangle r1 = new Rectangle(), r2 = new Rectangle();
|
||||
@@ -63,6 +64,8 @@ public class AndroidInput extends InputHandler implements GestureListener{
|
||||
private boolean selecting;
|
||||
/**Whether the player is currently in line-place mode.*/
|
||||
private boolean lineMode;
|
||||
/**Current place mode.*/
|
||||
private PlaceMode mode = none;
|
||||
|
||||
public AndroidInput(Player player){
|
||||
super(player);
|
||||
@@ -164,7 +167,7 @@ public class AndroidInput extends InputHandler implements GestureListener{
|
||||
removals.addAll(placement);
|
||||
placement.clear();
|
||||
selecting = false;
|
||||
});
|
||||
}).cell.disabled(i -> placement.size == 0);
|
||||
|
||||
//Add a rotate button
|
||||
new imagebutton("icon-arrow", 16 * 2f, () -> rotation = Mathf.mod(rotation + 1, 4))
|
||||
@@ -173,7 +176,7 @@ public class AndroidInput extends InputHandler implements GestureListener{
|
||||
i.getImage().setOrigin(Align.center);
|
||||
}).cell.disabled(i -> recipe == null || !recipe.result.rotate);
|
||||
}}.end();
|
||||
}}.visible(() -> isPlacing() && placement.size > 0).end();
|
||||
}}.visible(this::isPlacing).end();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -266,24 +269,14 @@ public class AndroidInput extends InputHandler implements GestureListener{
|
||||
|
||||
Tile linked = cursor.target();
|
||||
|
||||
//show-hide configuration fragment for blocks
|
||||
if(linked.block().isConfigurable(linked)){
|
||||
frag.config.showConfig(linked);
|
||||
}else if(!frag.config.hasConfigMouse()){
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
|
||||
//when tapping a build block, select it
|
||||
if(linked.block() instanceof BuildBlock){
|
||||
BuildEntity entity = linked.entity();
|
||||
|
||||
player.replaceBuilding(linked.x, linked.y, linked.getRotation(), entity.recipe);
|
||||
}else if(pointer == 0 && !selecting){
|
||||
tileTapped(cursor);
|
||||
}
|
||||
|
||||
//call tapped() event
|
||||
//TODO net event for block tapped
|
||||
linked.block().tapped(linked, player);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import io.anuke.ucore.scene.utils.Cursors;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.input.DesktopInput.PlaceMode.*;
|
||||
import static io.anuke.mindustry.input.PlaceMode.*;
|
||||
|
||||
public class DesktopInput extends InputHandler{
|
||||
//controller info
|
||||
@@ -43,28 +43,7 @@ public class DesktopInput extends InputHandler{
|
||||
this.section = "player_" + (player.playerIndex + 1);
|
||||
}
|
||||
|
||||
void tileTapped(Tile tile){
|
||||
|
||||
//check if tapped block is configurable
|
||||
if(tile.block().isConfigurable(tile)){
|
||||
if((!frag.config.isShown() //if the config fragment is hidden, show
|
||||
//alternatively, the current selected block can 'agree' to switch config tiles
|
||||
|| frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), tile))) {
|
||||
frag.config.showConfig(tile);
|
||||
}
|
||||
//otherwise...
|
||||
}else if(!frag.config.hasConfigMouse()){ //make sure a configuration fragment isn't on the cursor
|
||||
//then, if it's shown and the current block 'agrees' to hide, hide it.
|
||||
if(frag.config.isShown() && frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), tile)) {
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO network event!
|
||||
//call tapped event
|
||||
tile.block().tapped(tile, player);
|
||||
}
|
||||
|
||||
/**Draws a placement icon for a specific block.*/
|
||||
void drawPlace(int x, int y, Block block, int rotation){
|
||||
if(validPlace(x, y, block, rotation)){
|
||||
Draw.color();
|
||||
@@ -87,7 +66,7 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
if(cursor == null) return;
|
||||
|
||||
//draw selection
|
||||
//draw selection(s)
|
||||
if(mode == placing) {
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength);
|
||||
|
||||
@@ -189,8 +168,7 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
if(cursor == null) return false;
|
||||
|
||||
//if left, begin placing or tap a tile
|
||||
if(button == Buttons.LEFT) {
|
||||
if(button == Buttons.LEFT) { //left = begin placing
|
||||
if (isPlacing()) {
|
||||
selectX = cursor.x;
|
||||
selectY = cursor.y;
|
||||
@@ -198,11 +176,11 @@ public class DesktopInput extends InputHandler{
|
||||
} else {
|
||||
tileTapped(cursor);
|
||||
}
|
||||
}else if(button == Buttons.RIGHT){
|
||||
}else if(button == Buttons.RIGHT){ //right = begin breaking
|
||||
selectX = cursor.x;
|
||||
selectY = cursor.y;
|
||||
mode = breaking;
|
||||
}else if(button == Buttons.MIDDLE){
|
||||
}else if(button == Buttons.MIDDLE){ //middle button = cancel placing
|
||||
recipe = null;
|
||||
mode = none;
|
||||
}
|
||||
@@ -221,7 +199,8 @@ public class DesktopInput extends InputHandler{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(mode == placing){
|
||||
|
||||
if(mode == placing){ //touch up while placing, place everything in selection
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength);
|
||||
|
||||
for(int i = 0; i <= result.getLength(); i += recipe.result.size){
|
||||
@@ -232,7 +211,7 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
tryPlaceBlock(x, y);
|
||||
}
|
||||
}else if(mode == breaking){
|
||||
}else if(mode == breaking){ //touch up while breaking, break everything in selection
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, false, maxLength);
|
||||
|
||||
for(int x = 0; x <= Math.abs(result.x2 - result.x); x ++ ){
|
||||
@@ -310,8 +289,4 @@ public class DesktopInput extends InputHandler{
|
||||
controly = control.gdxInput().getY();
|
||||
}
|
||||
}
|
||||
|
||||
enum PlaceMode{
|
||||
none, breaking, placing;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,29 @@ public abstract class InputHandler extends InputAdapter{
|
||||
|
||||
}
|
||||
|
||||
/**Handles tile tap events that are not platform specific.*/
|
||||
public void tileTapped(Tile tile){
|
||||
|
||||
//check if tapped block is configurable
|
||||
if(tile.block().isConfigurable(tile)){
|
||||
if((!frag.config.isShown() //if the config fragment is hidden, show
|
||||
//alternatively, the current selected block can 'agree' to switch config tiles
|
||||
|| frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), tile))) {
|
||||
frag.config.showConfig(tile);
|
||||
}
|
||||
//otherwise...
|
||||
}else if(!frag.config.hasConfigMouse()){ //make sure a configuration fragment isn't on the cursor
|
||||
//then, if it's shown and the current block 'agrees' to hide, hide it.
|
||||
if(frag.config.isShown() && frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), tile)) {
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO network event!
|
||||
//call tapped event
|
||||
tile.block().tapped(tile, player);
|
||||
}
|
||||
|
||||
//utility methods
|
||||
|
||||
/**Returns the tile at the specified MOUSE coordinates.*/
|
||||
@@ -170,7 +193,6 @@ public abstract class InputHandler extends InputAdapter{
|
||||
|
||||
public void tryPlaceBlock(int x, int y){
|
||||
if(recipe != null && validPlace(x, y, recipe.result, rotation) && cursorNear()){
|
||||
|
||||
placeBlock(x, y, recipe, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
5
core/src/io/anuke/mindustry/input/PlaceMode.java
Normal file
5
core/src/io/anuke/mindustry/input/PlaceMode.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package io.anuke.mindustry.input;
|
||||
|
||||
enum PlaceMode{
|
||||
none, breaking, placing;
|
||||
}
|
||||
Reference in New Issue
Block a user