Formatting
This commit is contained in:
@@ -3,8 +3,10 @@ package io.anuke.mindustry.input;
|
||||
import io.anuke.ucore.function.Callable;
|
||||
import io.anuke.ucore.scene.utils.Cursors;
|
||||
|
||||
/**Type of cursor for displaying on desktop.*/
|
||||
public enum CursorType {
|
||||
/**
|
||||
* Type of cursor for displaying on desktop.
|
||||
*/
|
||||
public enum CursorType{
|
||||
normal(Cursors::restoreCursor),
|
||||
hand(Cursors::setHand),
|
||||
drill(() -> Cursors.set("drill")),
|
||||
@@ -16,7 +18,9 @@ public enum CursorType {
|
||||
this.call = call;
|
||||
}
|
||||
|
||||
/**Sets the current system cursor to this.*/
|
||||
/**
|
||||
* Sets the current system cursor to this.
|
||||
*/
|
||||
void set(){
|
||||
call.run();
|
||||
}
|
||||
|
||||
@@ -8,58 +8,58 @@ import io.anuke.ucore.core.KeyBinds;
|
||||
import io.anuke.ucore.core.KeyBinds.Category;
|
||||
import io.anuke.ucore.input.Input;
|
||||
|
||||
public class DefaultKeybinds {
|
||||
public class DefaultKeybinds{
|
||||
|
||||
public static void load(){
|
||||
String[] sections = {"player_1"};
|
||||
|
||||
for(String section : sections) {
|
||||
for(String section : sections){
|
||||
|
||||
KeyBinds.defaultSection(section, DeviceType.keyboard,
|
||||
new Category("General"),
|
||||
"move_x", new Axis(Input.A, Input.D),
|
||||
"move_y", new Axis(Input.S, Input.W),
|
||||
//"select", Input.MOUSE_LEFT,
|
||||
//"break", Input.MOUSE_RIGHT,
|
||||
//"shoot", Input.MOUSE_LEFT,
|
||||
"rotate", new Axis(Input.SCROLL),
|
||||
"dash", Input.SHIFT_LEFT,
|
||||
"drop_unit", Input.SHIFT_LEFT,
|
||||
new Category("View"),
|
||||
"zoom_hold", Input.CONTROL_LEFT,
|
||||
"zoom", new Axis(Input.SCROLL),
|
||||
"zoom_minimap", new Axis(Input.MINUS, Input.PLUS),
|
||||
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
|
||||
"pause", Input.SPACE,
|
||||
"toggle_menus", Input.C,
|
||||
new Category("Multiplayer"),
|
||||
"player_list", Input.TAB,
|
||||
"chat", Input.ENTER,
|
||||
"chat_history_prev", Input.UP,
|
||||
"chat_history_next", Input.DOWN,
|
||||
"chat_scroll", new Axis(Input.SCROLL),
|
||||
"console", Input.GRAVE
|
||||
new Category("General"),
|
||||
"move_x", new Axis(Input.A, Input.D),
|
||||
"move_y", new Axis(Input.S, Input.W),
|
||||
//"select", Input.MOUSE_LEFT,
|
||||
//"break", Input.MOUSE_RIGHT,
|
||||
//"shoot", Input.MOUSE_LEFT,
|
||||
"rotate", new Axis(Input.SCROLL),
|
||||
"dash", Input.SHIFT_LEFT,
|
||||
"drop_unit", Input.SHIFT_LEFT,
|
||||
new Category("View"),
|
||||
"zoom_hold", Input.CONTROL_LEFT,
|
||||
"zoom", new Axis(Input.SCROLL),
|
||||
"zoom_minimap", new Axis(Input.MINUS, Input.PLUS),
|
||||
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
|
||||
"pause", Input.SPACE,
|
||||
"toggle_menus", Input.C,
|
||||
new Category("Multiplayer"),
|
||||
"player_list", Input.TAB,
|
||||
"chat", Input.ENTER,
|
||||
"chat_history_prev", Input.UP,
|
||||
"chat_history_next", Input.DOWN,
|
||||
"chat_scroll", new Axis(Input.SCROLL),
|
||||
"console", Input.GRAVE
|
||||
);
|
||||
|
||||
KeyBinds.defaultSection(section, DeviceType.controller,
|
||||
new Category("General"),
|
||||
"move_x", new Axis(Input.CONTROLLER_L_STICK_HORIZONTAL_AXIS),
|
||||
"move_y", new Axis(Input.CONTROLLER_L_STICK_VERTICAL_AXIS),
|
||||
"cursor_x", new Axis(Input.CONTROLLER_R_STICK_HORIZONTAL_AXIS),
|
||||
"cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS),
|
||||
//"select", Input.CONTROLLER_R_BUMPER,
|
||||
//"break", Input.CONTROLLER_L_BUMPER,
|
||||
//"shoot", Input.CONTROLLER_R_TRIGGER,
|
||||
"dash", Input.CONTROLLER_Y,
|
||||
"rotate_alt", new Axis(Input.CONTROLLER_DPAD_RIGHT, Input.CONTROLLER_DPAD_LEFT),
|
||||
"rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B),
|
||||
new Category("View"),
|
||||
"zoom_hold", Input.ANY_KEY,
|
||||
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
|
||||
"menu", Input.CONTROLLER_X,
|
||||
"pause", Input.CONTROLLER_L_TRIGGER,
|
||||
new Category("Multiplayer"),
|
||||
"player_list", Input.CONTROLLER_START
|
||||
new Category("General"),
|
||||
"move_x", new Axis(Input.CONTROLLER_L_STICK_HORIZONTAL_AXIS),
|
||||
"move_y", new Axis(Input.CONTROLLER_L_STICK_VERTICAL_AXIS),
|
||||
"cursor_x", new Axis(Input.CONTROLLER_R_STICK_HORIZONTAL_AXIS),
|
||||
"cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS),
|
||||
//"select", Input.CONTROLLER_R_BUMPER,
|
||||
//"break", Input.CONTROLLER_L_BUMPER,
|
||||
//"shoot", Input.CONTROLLER_R_TRIGGER,
|
||||
"dash", Input.CONTROLLER_Y,
|
||||
"rotate_alt", new Axis(Input.CONTROLLER_DPAD_RIGHT, Input.CONTROLLER_DPAD_LEFT),
|
||||
"rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B),
|
||||
new Category("View"),
|
||||
"zoom_hold", Input.ANY_KEY,
|
||||
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
|
||||
"menu", Input.CONTROLLER_X,
|
||||
"pause", Input.CONTROLLER_L_TRIGGER,
|
||||
new Category("Multiplayer"),
|
||||
"player_list", Input.CONTROLLER_START
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -27,40 +27,49 @@ import static io.anuke.mindustry.input.CursorType.*;
|
||||
import static io.anuke.mindustry.input.PlaceMode.*;
|
||||
|
||||
public class DesktopInput extends InputHandler{
|
||||
//controller info
|
||||
private float controlx, controly;
|
||||
private boolean controlling;
|
||||
private final String section;
|
||||
|
||||
/**Current cursor type.*/
|
||||
//controller info
|
||||
private float controlx, controly;
|
||||
private boolean controlling;
|
||||
/**
|
||||
* Current cursor type.
|
||||
*/
|
||||
private CursorType cursorType = normal;
|
||||
|
||||
/**Position where the player started dragging a line.*/
|
||||
/**
|
||||
* Position where the player started dragging a line.
|
||||
*/
|
||||
private int selectX, selectY;
|
||||
/**Whether selecting mode is active.*/
|
||||
/**
|
||||
* Whether selecting mode is active.
|
||||
*/
|
||||
private PlaceMode mode;
|
||||
/**Animation scale for line.*/
|
||||
/**
|
||||
* Animation scale for line.
|
||||
*/
|
||||
private float selectScale;
|
||||
|
||||
public DesktopInput(Player player){
|
||||
super(player);
|
||||
this.section = "player_" + (player.playerIndex + 1);
|
||||
public DesktopInput(Player player){
|
||||
super(player);
|
||||
this.section = "player_" + (player.playerIndex + 1);
|
||||
}
|
||||
|
||||
/**Draws a placement icon for a specific block.*/
|
||||
void drawPlace(int x, int y, Block block, int rotation){
|
||||
/**
|
||||
* 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();
|
||||
|
||||
TextureRegion[] regions = block.getBlockIcon();
|
||||
|
||||
for(TextureRegion region : regions){
|
||||
Draw.rect(region, x *tilesize + block.offset(), y * tilesize + block.offset(),
|
||||
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);
|
||||
Lines.square(x * tilesize + block.offset(), y * tilesize + block.offset(), block.size * tilesize / 2f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,15 +84,15 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
if(cursor == null) return;
|
||||
|
||||
//draw selection(s)
|
||||
if(mode == placing) {
|
||||
//draw selection(s)
|
||||
if(mode == placing){
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength);
|
||||
|
||||
for (int i = 0; i <= result.getLength(); i += recipe.result.size) {
|
||||
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) {
|
||||
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);
|
||||
@@ -99,37 +108,37 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
Draw.color(Palette.remove);
|
||||
|
||||
for(int x = dresult.x; x <= dresult.x2; x ++){
|
||||
for(int y = dresult.y; y <= dresult.y2; y ++){
|
||||
for(int x = dresult.x; x <= dresult.x2; x++){
|
||||
for(int y = dresult.y; y <= dresult.y2; y++){
|
||||
Tile tile = world.tile(x, y);
|
||||
if(tile == null || !validBreak(tile.x, tile.y)) continue;
|
||||
tile = tile.target();
|
||||
|
||||
Lines.poly(tile.drawx(), tile.drawy(), 4, tile.block().size * tilesize/2f, 45 + 15);
|
||||
Lines.poly(tile.drawx(), tile.drawy(), 4, tile.block().size * tilesize / 2f, 45 + 15);
|
||||
}
|
||||
}
|
||||
|
||||
Lines.rect(result.x, result.y, result.x2 - result.x, result.y2 - result.y);
|
||||
}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(),
|
||||
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);
|
||||
recipe.result.drawPlace(cursor.x, cursor.y, rotation, validPlace(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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
@Override
|
||||
public void update(){
|
||||
if(Net.active() && Inputs.keyTap("player_list")){
|
||||
ui.listfrag.toggle();
|
||||
}
|
||||
|
||||
if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return;
|
||||
if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return;
|
||||
|
||||
if(recipe != null && !Settings.getBool("desktop-place-help", false)){
|
||||
ui.showInfo("Desktop controls have been changed.\nTo deselect a block or stop building, [accent]use the middle mouse button[].");
|
||||
@@ -137,40 +146,40 @@ public class DesktopInput extends InputHandler{
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
player.isBoosting = Inputs.keyDown("dash");
|
||||
player.isBoosting = Inputs.keyDown("dash");
|
||||
|
||||
//deslect if not placing
|
||||
if(!isPlacing() && mode == placing){
|
||||
mode = none;
|
||||
//deslect if not placing
|
||||
if(!isPlacing() && mode == placing){
|
||||
mode = none;
|
||||
}
|
||||
|
||||
if(player.isShooting && !canShoot()){
|
||||
player.isShooting = false;
|
||||
player.isShooting = false;
|
||||
}
|
||||
|
||||
if(isPlacing()){
|
||||
cursorType = hand;
|
||||
selectScale = Mathf.lerpDelta(selectScale, 1f, 0.2f);
|
||||
}else{
|
||||
selectScale = 0f;
|
||||
selectScale = 0f;
|
||||
}
|
||||
|
||||
boolean controller = KeyBinds.getSection(section).device.type == DeviceType.controller;
|
||||
boolean controller = KeyBinds.getSection(section).device.type == DeviceType.controller;
|
||||
|
||||
//zoom and rotate things
|
||||
if(Inputs.getAxisActive("zoom") && (Inputs.keyDown(section,"zoom_hold") || controller)){
|
||||
renderer.scaleCamera((int) Inputs.getAxisTapped(section, "zoom"));
|
||||
}
|
||||
//zoom and rotate things
|
||||
if(Inputs.getAxisActive("zoom") && (Inputs.keyDown(section, "zoom_hold") || controller)){
|
||||
renderer.scaleCamera((int) Inputs.getAxisTapped(section, "zoom"));
|
||||
}
|
||||
|
||||
renderer.minimap().zoomBy(-(int)Inputs.getAxisTapped(section,"zoom_minimap"));
|
||||
rotation = Mathf.mod(rotation + (int)Inputs.getAxisTapped(section,"rotate"), 4);
|
||||
renderer.minimap().zoomBy(-(int) Inputs.getAxisTapped(section, "zoom_minimap"));
|
||||
rotation = Mathf.mod(rotation + (int) Inputs.getAxisTapped(section, "rotate"), 4);
|
||||
|
||||
Tile cursor = tileAt(control.gdxInput().getX(), control.gdxInput().getY());
|
||||
Tile cursor = tileAt(control.gdxInput().getX(), control.gdxInput().getY());
|
||||
|
||||
if(player.isDead()){
|
||||
if(player.isDead()){
|
||||
cursorType = normal;
|
||||
}else if(cursor != null){
|
||||
cursor = cursor.target();
|
||||
cursor = cursor.target();
|
||||
|
||||
cursorType = cursor.block().getCursor(cursor);
|
||||
|
||||
@@ -187,15 +196,15 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
}
|
||||
|
||||
if(!ui.hasMouse()) {
|
||||
cursorType.set();
|
||||
}
|
||||
if(!ui.hasMouse()){
|
||||
cursorType.set();
|
||||
}
|
||||
|
||||
cursorType = normal;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDown (int screenX, int screenY, int pointer, int button) {
|
||||
@Override
|
||||
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
||||
if(player.isDead() || state.is(State.menu) || ui.hasDialog() || ui.hasMouse()) return false;
|
||||
|
||||
Tile cursor = tileAt(screenX, screenY);
|
||||
@@ -203,12 +212,12 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
float worldx = Graphics.world(screenX, screenY).x, worldy = Graphics.world(screenX, screenY).y;
|
||||
|
||||
if(button == Buttons.LEFT) { //left = begin placing
|
||||
if (isPlacing()) {
|
||||
if(button == Buttons.LEFT){ //left = begin placing
|
||||
if(isPlacing()){
|
||||
selectX = cursor.x;
|
||||
selectY = cursor.y;
|
||||
mode = placing;
|
||||
} else {
|
||||
}else{
|
||||
//only begin shooting if there's no cursor event
|
||||
if(!tileTapped(cursor) && !tryTapPlayer(worldx, worldy) && player.getPlaceQueue().size == 0 && !droppingItem &&
|
||||
!tryBeginMine(cursor) && player.getMineTile() == null){
|
||||
@@ -232,7 +241,7 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchUp (int screenX, int screenY, int pointer, int button) {
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
||||
if(button == Buttons.LEFT){
|
||||
player.isShooting = false;
|
||||
}
|
||||
@@ -260,8 +269,8 @@ public class DesktopInput extends InputHandler{
|
||||
}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 ++ ){
|
||||
for(int y = 0; y <= Math.abs(result.y2 - result.y); y ++){
|
||||
for(int x = 0; x <= Math.abs(result.x2 - result.x); x++){
|
||||
for(int y = 0; y <= Math.abs(result.y2 - result.y); y++){
|
||||
int wx = selectX + x * Mathf.sign(cursor.x - selectX);
|
||||
int wy = selectY + y * Mathf.sign(cursor.y - selectY);
|
||||
|
||||
@@ -278,23 +287,23 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMouseX() {
|
||||
public float getMouseX(){
|
||||
return !controlling ? control.gdxInput().getX() : controlx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMouseY() {
|
||||
public float getMouseY(){
|
||||
return !controlling ? control.gdxInput().getY() : controly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCursorVisible() {
|
||||
public boolean isCursorVisible(){
|
||||
return controlling;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateController(){
|
||||
boolean mousemove = Gdx.input.getDeltaX() > 1 || Gdx.input.getDeltaY() > 1;
|
||||
boolean mousemove = Gdx.input.getDeltaX() > 1 || Gdx.input.getDeltaY() > 1;
|
||||
|
||||
if(KeyBinds.getSection(section).device.type == DeviceType.controller && (!mousemove || player.playerIndex > 0)){
|
||||
if(player.playerIndex > 0){
|
||||
@@ -312,17 +321,17 @@ public class DesktopInput extends InputHandler{
|
||||
float xa = Inputs.getAxis(section, "cursor_x");
|
||||
float ya = Inputs.getAxis(section, "cursor_y");
|
||||
|
||||
if(Math.abs(xa) > controllerMin || Math.abs(ya) > controllerMin) {
|
||||
float scl = Settings.getInt("sensitivity", 100)/100f * Unit.dp.scl(1f);
|
||||
controlx += xa*baseControllerSpeed*scl;
|
||||
controly -= ya*baseControllerSpeed*scl;
|
||||
if(Math.abs(xa) > controllerMin || Math.abs(ya) > controllerMin){
|
||||
float scl = Settings.getInt("sensitivity", 100) / 100f * Unit.dp.scl(1f);
|
||||
controlx += xa * baseControllerSpeed * scl;
|
||||
controly -= ya * baseControllerSpeed * scl;
|
||||
controlling = true;
|
||||
|
||||
if(player.playerIndex == 0){
|
||||
Gdx.input.setCursorCatched(true);
|
||||
}
|
||||
|
||||
Inputs.getProcessor().touchDragged((int)getMouseX(), (int)getMouseY(), player.playerIndex);
|
||||
Inputs.getProcessor().touchDragged((int) getMouseX(), (int) getMouseY(), player.playerIndex);
|
||||
}
|
||||
|
||||
controlx = Mathf.clamp(controlx, 0, Gdx.graphics.getWidth());
|
||||
|
||||
@@ -33,226 +33,307 @@ import io.anuke.ucore.util.Translator;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public abstract class InputHandler extends InputAdapter{
|
||||
/**Used for dropping items.*/
|
||||
/**
|
||||
* Used for dropping items.
|
||||
*/
|
||||
final static float playerSelectRange = mobile ? 17f : 11f;
|
||||
/**Maximum line length.*/
|
||||
final static int maxLength = 100;
|
||||
/**
|
||||
* Maximum line length.
|
||||
*/
|
||||
final static int maxLength = 100;
|
||||
final static Translator stackTrns = new Translator();
|
||||
/**Distance on the back from where items originate.*/
|
||||
final static float backTrns = 3f;
|
||||
/**
|
||||
* Distance on the back from where items originate.
|
||||
*/
|
||||
final static float backTrns = 3f;
|
||||
|
||||
public final Player player;
|
||||
public final String section;
|
||||
public final OverlayFragment frag = new OverlayFragment(this);
|
||||
public final Player player;
|
||||
public final String section;
|
||||
public final OverlayFragment frag = new OverlayFragment(this);
|
||||
|
||||
public Recipe recipe;
|
||||
public int rotation;
|
||||
public boolean droppingItem;
|
||||
public Recipe recipe;
|
||||
public int rotation;
|
||||
public boolean droppingItem;
|
||||
|
||||
public InputHandler(Player player){
|
||||
this.player = player;
|
||||
this.section = "player_" + (player.playerIndex + 1);
|
||||
Timers.run(1f, () -> frag.build(Core.scene.getRoot()));
|
||||
public InputHandler(Player player){
|
||||
this.player = player;
|
||||
this.section = "player_" + (player.playerIndex + 1);
|
||||
Timers.run(1f, () -> frag.build(Core.scene.getRoot()));
|
||||
}
|
||||
|
||||
//methods to override
|
||||
|
||||
public void update(){
|
||||
@Remote(targets = Loc.client, called = Loc.server, in = In.entities)
|
||||
public static void dropItem(Player player, float angle){
|
||||
if(Net.server() && !player.inventory.hasItem()){
|
||||
throw new ValidateException(player, "Player cannot drop an item.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public float getMouseX(){
|
||||
return control.gdxInput().getX();
|
||||
}
|
||||
|
||||
public float getMouseY(){
|
||||
return control.gdxInput().getY();
|
||||
ItemDrop.create(player.inventory.getItem().item, player.inventory.getItem().amount, player.x, player.y, angle);
|
||||
player.inventory.clearItem();
|
||||
}
|
||||
|
||||
public void resetCursor(){
|
||||
@Remote(targets = Loc.both, forward = true, called = Loc.server, in = In.blocks)
|
||||
public static void transferInventory(Player player, Tile tile){
|
||||
if(Net.server() && (!player.inventory.hasItem() || player.isTransferring)){
|
||||
throw new ValidateException(player, "Player cannot transfer an item.");
|
||||
}
|
||||
|
||||
}
|
||||
threads.run(() -> {
|
||||
if(player == null || tile.entity == null) return;
|
||||
|
||||
public boolean isCursorVisible(){
|
||||
return false;
|
||||
}
|
||||
player.isTransferring = true;
|
||||
|
||||
public void buildUI(Group group){
|
||||
ItemStack stack = player.inventory.getItem();
|
||||
int accepted = tile.block().acceptStack(stack.item, stack.amount, tile, player);
|
||||
|
||||
}
|
||||
boolean clear = stack.amount == accepted;
|
||||
int sent = Mathf.clamp(accepted / 4, 1, 8);
|
||||
int removed = accepted / sent;
|
||||
int[] remaining = {accepted, accepted};
|
||||
|
||||
public void updateController(){
|
||||
for(int i = 0; i < sent; i++){
|
||||
boolean end = i == sent - 1;
|
||||
Timers.run(i * 3, () -> {
|
||||
tile.block().getStackOffset(stack.item, tile, stackTrns);
|
||||
|
||||
}
|
||||
ItemTransfer.create(stack.item,
|
||||
player.x + Angles.trnsx(player.rotation + 180f, backTrns), player.y + Angles.trnsy(player.rotation + 180f, backTrns),
|
||||
new Translator(tile.drawx() + stackTrns.x, tile.drawy() + stackTrns.y), () -> {
|
||||
|
||||
public void drawOutlined(){
|
||||
tile.block().handleStack(stack.item, removed, tile, player);
|
||||
remaining[1] -= removed;
|
||||
|
||||
}
|
||||
if(end && remaining[1] > 0){
|
||||
tile.block().handleStack(stack.item, remaining[1], tile, player);
|
||||
}
|
||||
});
|
||||
|
||||
public void drawTop(){
|
||||
stack.amount -= removed;
|
||||
remaining[0] -= removed;
|
||||
|
||||
}
|
||||
if(end){
|
||||
stack.amount -= remaining[0];
|
||||
if(clear){
|
||||
player.inventory.clearItem();
|
||||
}
|
||||
player.isTransferring = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isDrawing(){
|
||||
return false;
|
||||
}
|
||||
@Remote(targets = Loc.both, called = Loc.server, forward = true, in = In.blocks)
|
||||
public static void onTileTapped(Player player, Tile tile){
|
||||
if(tile == null || player == null) return;
|
||||
tile.block().tapped(tile, player);
|
||||
}
|
||||
|
||||
/**Handles tile tap events that are not platform specific.*/
|
||||
boolean tileTapped(Tile tile){
|
||||
tile = tile.target();
|
||||
public void update(){
|
||||
|
||||
boolean consumed = false, showedInventory = false, showedConsume = false;
|
||||
}
|
||||
|
||||
//check if tapped block is configurable
|
||||
if(tile.block().configurable && tile.getTeam() == player.getTeam()){
|
||||
consumed = true;
|
||||
if(((!frag.config.isShown() && tile.block().shouldShowConfigure(tile, player)) //if the config fragment is hidden, show
|
||||
//alternatively, the current selected block can 'agree' to switch config tiles
|
||||
|| (frag.config.isShown() && 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)) {
|
||||
consumed = true;
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
}
|
||||
public float getMouseX(){
|
||||
return control.gdxInput().getX();
|
||||
}
|
||||
|
||||
//call tapped event
|
||||
if(tile.getTeam() == player.getTeam()){
|
||||
CallBlocks.onTileTapped(player, tile);
|
||||
}
|
||||
public float getMouseY(){
|
||||
return control.gdxInput().getY();
|
||||
}
|
||||
|
||||
//consume tap event if necessary
|
||||
if(tile.getTeam() == player.getTeam() && tile.block().consumesTap){
|
||||
consumed = true;
|
||||
}else if(tile.getTeam() == player.getTeam() && tile.block().synthetic() && !consumed) {
|
||||
if(tile.block().hasItems && tile.entity.items.total() > 0) {
|
||||
frag.inv.showFor(tile);
|
||||
consumed = true;
|
||||
showedInventory = true;
|
||||
}
|
||||
public void resetCursor(){
|
||||
|
||||
if(tile.block().consumes.hasAny()){
|
||||
frag.consume.show(tile);
|
||||
consumed = true;
|
||||
showedConsume = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!showedInventory){
|
||||
frag.inv.hide();
|
||||
}
|
||||
public boolean isCursorVisible(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public void buildUI(Group group){
|
||||
|
||||
}
|
||||
|
||||
public void updateController(){
|
||||
|
||||
}
|
||||
|
||||
public void drawOutlined(){
|
||||
|
||||
}
|
||||
|
||||
public void drawTop(){
|
||||
|
||||
}
|
||||
|
||||
public boolean isDrawing(){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles tile tap events that are not platform specific.
|
||||
*/
|
||||
boolean tileTapped(Tile tile){
|
||||
tile = tile.target();
|
||||
|
||||
boolean consumed = false, showedInventory = false, showedConsume = false;
|
||||
|
||||
//check if tapped block is configurable
|
||||
if(tile.block().configurable && tile.getTeam() == player.getTeam()){
|
||||
consumed = true;
|
||||
if(((!frag.config.isShown() && tile.block().shouldShowConfigure(tile, player)) //if the config fragment is hidden, show
|
||||
//alternatively, the current selected block can 'agree' to switch config tiles
|
||||
|| (frag.config.isShown() && 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)){
|
||||
consumed = true;
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
}
|
||||
|
||||
//call tapped event
|
||||
if(tile.getTeam() == player.getTeam()){
|
||||
CallBlocks.onTileTapped(player, tile);
|
||||
}
|
||||
|
||||
//consume tap event if necessary
|
||||
if(tile.getTeam() == player.getTeam() && tile.block().consumesTap){
|
||||
consumed = true;
|
||||
}else if(tile.getTeam() == player.getTeam() && tile.block().synthetic() && !consumed){
|
||||
if(tile.block().hasItems && tile.entity.items.total() > 0){
|
||||
frag.inv.showFor(tile);
|
||||
consumed = true;
|
||||
showedInventory = true;
|
||||
}
|
||||
|
||||
if(tile.block().consumes.hasAny()){
|
||||
frag.consume.show(tile);
|
||||
consumed = true;
|
||||
showedConsume = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!showedInventory){
|
||||
frag.inv.hide();
|
||||
}
|
||||
|
||||
if(!showedConsume){
|
||||
frag.consume.hide();
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
/**Tries to select the player to drop off items, returns true if successful.*/
|
||||
boolean tryTapPlayer(float x, float y){
|
||||
if(canTapPlayer(x, y)){
|
||||
droppingItem = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Tries to select the player to drop off items, returns true if successful.
|
||||
*/
|
||||
boolean tryTapPlayer(float x, float y){
|
||||
if(canTapPlayer(x, y)){
|
||||
droppingItem = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean canTapPlayer(float x, float y){
|
||||
return Vector2.dst(x, y, player.x, player.y) <= playerSelectRange && player.inventory.hasItem();
|
||||
}
|
||||
boolean canTapPlayer(float x, float y){
|
||||
return Vector2.dst(x, y, player.x, player.y) <= playerSelectRange && player.inventory.hasItem();
|
||||
}
|
||||
|
||||
/**Tries to begin mining a tile, returns true if successful.*/
|
||||
boolean tryBeginMine(Tile tile){
|
||||
if(canMine(tile)){
|
||||
//if a block is clicked twice, reset it
|
||||
player.setMineTile(player.getMineTile() == tile ? null : tile);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Tries to begin mining a tile, returns true if successful.
|
||||
*/
|
||||
boolean tryBeginMine(Tile tile){
|
||||
if(canMine(tile)){
|
||||
//if a block is clicked twice, reset it
|
||||
player.setMineTile(player.getMineTile() == tile ? null : tile);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean canMine(Tile tile){
|
||||
return !ui.hasMouse()
|
||||
&& tile.floor().drops != null && tile.floor().drops.item.hardness <= player.mech.drillPower
|
||||
&& !tile.floor().playerUnmineable
|
||||
&& player.inventory.canAcceptItem(tile.floor().drops.item)
|
||||
&& Units.getClosestEnemy(player.getTeam(), tile.worldx(), tile.worldy(), 40f, e -> true) == null //don't being mining when an enemy is near
|
||||
&& tile.block() == Blocks.air && player.distanceTo(tile.worldx(), tile.worldy()) <= Player.mineDistance;
|
||||
}
|
||||
boolean canMine(Tile tile){
|
||||
return !ui.hasMouse()
|
||||
&& tile.floor().drops != null && tile.floor().drops.item.hardness <= player.mech.drillPower
|
||||
&& !tile.floor().playerUnmineable
|
||||
&& player.inventory.canAcceptItem(tile.floor().drops.item)
|
||||
&& Units.getClosestEnemy(player.getTeam(), tile.worldx(), tile.worldy(), 40f, e -> true) == null //don't being mining when an enemy is near
|
||||
&& tile.block() == Blocks.air && player.distanceTo(tile.worldx(), tile.worldy()) <= Player.mineDistance;
|
||||
}
|
||||
|
||||
/**Returns the tile at the specified MOUSE coordinates.*/
|
||||
Tile tileAt(float x, float y){
|
||||
Vector2 vec = Graphics.world(x, y);
|
||||
if(isPlacing()){
|
||||
vec.sub(recipe.result.offset(), recipe.result.offset());
|
||||
}
|
||||
return world.tileWorld(vec.x, vec.y);
|
||||
}
|
||||
/**
|
||||
* Returns the tile at the specified MOUSE coordinates.
|
||||
*/
|
||||
Tile tileAt(float x, float y){
|
||||
Vector2 vec = Graphics.world(x, y);
|
||||
if(isPlacing()){
|
||||
vec.sub(recipe.result.offset(), recipe.result.offset());
|
||||
}
|
||||
return world.tileWorld(vec.x, vec.y);
|
||||
}
|
||||
|
||||
public boolean isPlacing(){
|
||||
return recipe != null;
|
||||
}
|
||||
public boolean isPlacing(){
|
||||
return recipe != null;
|
||||
}
|
||||
|
||||
public float mouseAngle(float x, float y){
|
||||
public float mouseAngle(float x, float y){
|
||||
return Graphics.world(getMouseX(), getMouseY()).sub(x, y).angle();
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
Inputs.removeProcessor(this);
|
||||
frag.remove();
|
||||
public void remove(){
|
||||
Inputs.removeProcessor(this);
|
||||
frag.remove();
|
||||
}
|
||||
|
||||
public boolean canShoot(){
|
||||
return recipe == null && !ui.hasMouse() && !onConfigurable() && !isDroppingItem();
|
||||
}
|
||||
|
||||
public boolean onConfigurable(){
|
||||
return false;
|
||||
}
|
||||
public boolean canShoot(){
|
||||
return recipe == null && !ui.hasMouse() && !onConfigurable() && !isDroppingItem();
|
||||
}
|
||||
|
||||
public boolean isDroppingItem(){
|
||||
return droppingItem;
|
||||
}
|
||||
public boolean onConfigurable(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public void tryDropItems(Tile tile, float x, float y){
|
||||
if(!droppingItem || !player.inventory.hasItem() || canTapPlayer(x, y)){
|
||||
droppingItem = false;
|
||||
return;
|
||||
}
|
||||
public boolean isDroppingItem(){
|
||||
return droppingItem;
|
||||
}
|
||||
|
||||
droppingItem = false;
|
||||
public void tryDropItems(Tile tile, float x, float y){
|
||||
if(!droppingItem || !player.inventory.hasItem() || canTapPlayer(x, y)){
|
||||
droppingItem = false;
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = player.inventory.getItem();
|
||||
droppingItem = false;
|
||||
|
||||
if(tile.block().acceptStack(stack.item, stack.amount, tile, player) > 0 && tile.block().hasItems){
|
||||
CallBlocks.transferInventory(player, tile);
|
||||
}else{
|
||||
CallEntity.dropItem(player.angleTo(x, y));
|
||||
}
|
||||
}
|
||||
ItemStack stack = player.inventory.getItem();
|
||||
|
||||
public boolean cursorNear(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public void tryPlaceBlock(int x, int y){
|
||||
if(recipe != null && validPlace(x, y, recipe.result, rotation) && cursorNear()){
|
||||
placeBlock(x, y, recipe, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
public void tryBreakBlock(int x, int y){
|
||||
if(cursorNear() && validBreak(x, y)){
|
||||
breakBlock(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validPlace(int x, int y, Block type, int rotation){
|
||||
if(tile.block().acceptStack(stack.item, stack.amount, tile, player) > 0 && tile.block().hasItems){
|
||||
CallBlocks.transferInventory(player, tile);
|
||||
}else{
|
||||
CallEntity.dropItem(player.angleTo(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean cursorNear(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public void tryPlaceBlock(int x, int y){
|
||||
if(recipe != null && validPlace(x, y, recipe.result, rotation) && cursorNear()){
|
||||
placeBlock(x, y, recipe, rotation);
|
||||
}
|
||||
}
|
||||
|
||||
public void tryBreakBlock(int x, int y){
|
||||
if(cursorNear() && validBreak(x, y)){
|
||||
breakBlock(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validPlace(int x, int y, Block type, int rotation){
|
||||
for(Tile tile : state.teams.get(player.getTeam()).cores){
|
||||
if(tile.distanceTo(x * tilesize, y * tilesize) < coreBuildRange){
|
||||
return Build.validPlace(player.getTeam(), x, y, type, rotation) &&
|
||||
@@ -261,89 +342,22 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean validBreak(int x, int y){
|
||||
return Build.validBreak(player.getTeam(), x, y);
|
||||
}
|
||||
|
||||
public void placeBlock(int x, int y, Recipe recipe, int rotation){
|
||||
}
|
||||
|
||||
public boolean validBreak(int x, int y){
|
||||
return Build.validBreak(player.getTeam(), x, y);
|
||||
}
|
||||
|
||||
public void placeBlock(int x, int y, Recipe recipe, int rotation){
|
||||
//todo multiplayer support
|
||||
player.addBuildRequest(new BuildRequest(x, y, rotation, recipe));
|
||||
}
|
||||
}
|
||||
|
||||
public void breakBlock(int x, int y){
|
||||
public void breakBlock(int x, int y){
|
||||
|
||||
//todo multiplayer support
|
||||
Tile tile = world.tile(x, y).target();
|
||||
player.addBuildRequest(new BuildRequest(tile.x, tile.y));
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.client, called = Loc.server, in = In.entities)
|
||||
public static void dropItem(Player player, float angle){
|
||||
if(Net.server() && !player.inventory.hasItem()){
|
||||
throw new ValidateException(player, "Player cannot drop an item.");
|
||||
}
|
||||
|
||||
ItemDrop.create(player.inventory.getItem().item, player.inventory.getItem().amount, player.x, player.y, angle);
|
||||
player.inventory.clearItem();
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.both, forward = true, called = Loc.server, in = In.blocks)
|
||||
public static void transferInventory(Player player, Tile tile){
|
||||
if(Net.server() && (!player.inventory.hasItem() || player.isTransferring)) {
|
||||
throw new ValidateException(player, "Player cannot transfer an item.");
|
||||
}
|
||||
|
||||
threads.run(() -> {
|
||||
if (player == null || tile.entity == null) return;
|
||||
|
||||
player.isTransferring = true;
|
||||
|
||||
ItemStack stack = player.inventory.getItem();
|
||||
int accepted = tile.block().acceptStack(stack.item, stack.amount, tile, player);
|
||||
|
||||
boolean clear = stack.amount == accepted;
|
||||
int sent = Mathf.clamp(accepted / 4, 1, 8);
|
||||
int removed = accepted / sent;
|
||||
int[] remaining = {accepted, accepted};
|
||||
|
||||
for (int i = 0; i < sent; i++) {
|
||||
boolean end = i == sent - 1;
|
||||
Timers.run(i * 3, () -> {
|
||||
tile.block().getStackOffset(stack.item, tile, stackTrns);
|
||||
|
||||
ItemTransfer.create(stack.item,
|
||||
player.x + Angles.trnsx(player.rotation + 180f, backTrns), player.y + Angles.trnsy(player.rotation + 180f, backTrns),
|
||||
new Translator(tile.drawx() + stackTrns.x, tile.drawy() + stackTrns.y), () -> {
|
||||
|
||||
tile.block().handleStack(stack.item, removed, tile, player);
|
||||
remaining[1] -= removed;
|
||||
|
||||
if (end && remaining[1] > 0) {
|
||||
tile.block().handleStack(stack.item, remaining[1], tile, player);
|
||||
}
|
||||
});
|
||||
|
||||
stack.amount -= removed;
|
||||
remaining[0] -= removed;
|
||||
|
||||
if (end) {
|
||||
stack.amount -= remaining[0];
|
||||
if (clear) {
|
||||
player.inventory.clearItem();
|
||||
}
|
||||
player.isTransferring = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.both, called = Loc.server, forward = true, in = In.blocks)
|
||||
public static void onTileTapped(Player player, Tile tile){
|
||||
if(tile == null || player == null) return;
|
||||
tile.block().tapped(tile, player);
|
||||
}
|
||||
//todo multiplayer support
|
||||
Tile tile = world.tile(x, y).target();
|
||||
player.addBuildRequest(new BuildRequest(tile.x, tile.y));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,11 +39,14 @@ import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.input.PlaceMode.*;
|
||||
|
||||
public class MobileInput extends InputHandler implements GestureListener{
|
||||
private static Rectangle r1 = new Rectangle(), r2 = new Rectangle();
|
||||
|
||||
/**Maximum speed the player can pan.*/
|
||||
/**
|
||||
* Maximum speed the player can pan.
|
||||
*/
|
||||
private static final float maxPanSpeed = 1.3f;
|
||||
/**Distance to edge of screen to start panning.*/
|
||||
private static Rectangle r1 = new Rectangle(), r2 = new Rectangle();
|
||||
/**
|
||||
* Distance to edge of screen to start panning.
|
||||
*/
|
||||
private final float edgePan = io.anuke.ucore.scene.ui.layout.Unit.dp.scl(60f);
|
||||
|
||||
//gesture data
|
||||
@@ -51,64 +54,92 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
private Vector2 vector = new Vector2();
|
||||
private float initzoom = -1;
|
||||
private boolean zoomed = false;
|
||||
/**Set of completed guides.*/
|
||||
/**
|
||||
* Set of completed guides.
|
||||
*/
|
||||
private ObjectSet<String> guides = new ObjectSet<>();
|
||||
|
||||
/**Position where the player started dragging a line.*/
|
||||
/**
|
||||
* Position where the player started dragging a line.
|
||||
*/
|
||||
private int lineStartX, lineStartY;
|
||||
|
||||
/**Animation scale for line.*/
|
||||
/**
|
||||
* Animation scale for line.
|
||||
*/
|
||||
private float lineScale;
|
||||
/**Animation data for crosshair.*/
|
||||
/**
|
||||
* Animation data for crosshair.
|
||||
*/
|
||||
private float crosshairScale;
|
||||
private TargetTrait lastTarget;
|
||||
|
||||
/**List of currently selected tiles to place.*/
|
||||
/**
|
||||
* List of currently selected tiles to place.
|
||||
*/
|
||||
private Array<PlaceRequest> selection = new Array<>();
|
||||
/**Place requests to be removed.*/
|
||||
/**
|
||||
* Place requests to be removed.
|
||||
*/
|
||||
private Array<PlaceRequest> removals = new Array<>();
|
||||
/**Whether or not the player is currently shifting all placed tiles.*/
|
||||
/**
|
||||
* Whether or not the player is currently shifting all placed tiles.
|
||||
*/
|
||||
private boolean selecting;
|
||||
/**Whether the player is currently in line-place mode.*/
|
||||
/**
|
||||
* Whether the player is currently in line-place mode.
|
||||
*/
|
||||
private boolean lineMode;
|
||||
/**Current place mode.*/
|
||||
/**
|
||||
* Current place mode.
|
||||
*/
|
||||
private PlaceMode mode = none;
|
||||
/**Whether no recipe was available when switching to break mode.*/
|
||||
/**
|
||||
* Whether no recipe was available when switching to break mode.
|
||||
*/
|
||||
private Recipe lastRecipe;
|
||||
/**Last placed request. Used for drawing block overlay.*/
|
||||
/**
|
||||
* Last placed request. Used for drawing block overlay.
|
||||
*/
|
||||
private PlaceRequest lastPlaced;
|
||||
|
||||
public MobileInput(Player player){
|
||||
super(player);
|
||||
Inputs.addProcessor(new GestureDetector(20, 0.5f, 0.4f, 0.15f, this));
|
||||
}
|
||||
|
||||
//region utility methods
|
||||
public MobileInput(Player player){
|
||||
super(player);
|
||||
Inputs.addProcessor(new GestureDetector(20, 0.5f, 0.4f, 0.15f, this));
|
||||
}
|
||||
|
||||
/**Check and assign targets for a specific position.*/
|
||||
//region utility methods
|
||||
|
||||
/**
|
||||
* Check and assign targets for a specific position.
|
||||
*/
|
||||
void checkTargets(float x, float y){
|
||||
synchronized (Entities.entityLock) {
|
||||
synchronized(Entities.entityLock){
|
||||
Unit unit = Units.getClosestEnemy(player.getTeam(), x, y, 20f, u -> true);
|
||||
|
||||
if (unit != null) {
|
||||
if(unit != null){
|
||||
player.target = unit;
|
||||
} else {
|
||||
}else{
|
||||
Tile tile = world.tileWorld(x, y);
|
||||
if (tile != null) tile = tile.target();
|
||||
if(tile != null) tile = tile.target();
|
||||
|
||||
if (tile != null && state.teams.areEnemies(player.getTeam(), tile.getTeam())) {
|
||||
if(tile != null && state.teams.areEnemies(player.getTeam(), tile.getTeam())){
|
||||
player.target = tile.entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**Returns whether this tile is in the list of requests, or at least colliding with one.*/
|
||||
boolean hasRequest(Tile tile){
|
||||
/**
|
||||
* Returns whether this tile is in the list of requests, or at least colliding with one.
|
||||
*/
|
||||
boolean hasRequest(Tile tile){
|
||||
return getRequest(tile) != null;
|
||||
}
|
||||
|
||||
/**Returns whether this block overlaps any selection requests.*/
|
||||
/**
|
||||
* Returns whether this block overlaps any selection requests.
|
||||
*/
|
||||
boolean checkOverlapPlacement(int x, int y, Block block){
|
||||
r2.setSize(block.size * tilesize);
|
||||
r2.setCenter(x * tilesize + block.offset(), y * tilesize + block.offset());
|
||||
@@ -125,13 +156,15 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**Returns the selection request that overlaps this tile, or null.*/
|
||||
/**
|
||||
* Returns the selection request that overlaps this tile, or null.
|
||||
*/
|
||||
PlaceRequest getRequest(Tile tile){
|
||||
r2.setSize(tilesize);
|
||||
r2.setCenter(tile.worldx(), tile.worldy());
|
||||
r2.setSize(tilesize);
|
||||
r2.setCenter(tile.worldx(), tile.worldy());
|
||||
|
||||
for(PlaceRequest req : selection){
|
||||
Tile other = req.tile();
|
||||
@@ -142,15 +175,15 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
r1.setSize(req.recipe.result.size * tilesize);
|
||||
r1.setCenter(other.worldx() + req.recipe.result.offset(), other.worldy() + req.recipe.result.offset());
|
||||
|
||||
if (r2.overlaps(r1)) {
|
||||
if(r2.overlaps(r1)){
|
||||
return req;
|
||||
}
|
||||
}else {
|
||||
}else{
|
||||
|
||||
r1.setSize(other.block().size * tilesize);
|
||||
r1.setCenter(other.worldx() + other.block().offset(), other.worldy() + other.block().offset());
|
||||
|
||||
if (r2.overlaps(r1)) {
|
||||
if(r2.overlaps(r1)){
|
||||
return req;
|
||||
}
|
||||
}
|
||||
@@ -166,7 +199,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
void drawRequest(PlaceRequest request){
|
||||
Tile tile = request.tile();
|
||||
|
||||
if(!request.remove) {
|
||||
if(!request.remove){
|
||||
//draw placing request
|
||||
float offset = request.recipe.result.offset();
|
||||
TextureRegion[] regions = request.recipe.result.getBlockIcon();
|
||||
@@ -174,7 +207,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
Draw.alpha(Mathf.clamp((1f - request.scale) / 0.5f));
|
||||
Draw.tint(Color.WHITE, Palette.breakInvalid, request.redness);
|
||||
|
||||
for (TextureRegion region : regions) {
|
||||
for(TextureRegion region : regions){
|
||||
Draw.rect(region, tile.worldx() + offset, tile.worldy() + offset,
|
||||
region.getRegionWidth() * request.scale, region.getRegionHeight() * request.scale,
|
||||
request.recipe.result.rotate ? request.rotation * 90 : 0);
|
||||
@@ -182,7 +215,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}else{
|
||||
Draw.color(Palette.remove);
|
||||
//draw removing request
|
||||
Lines.poly(tile.drawx(), tile.drawy(), 4, tile.block().size * tilesize/2f * request.scale, 45 + 15);
|
||||
Lines.poly(tile.drawx(), tile.drawy(), 4, tile.block().size * tilesize / 2f * request.scale, 45 + 15);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,9 +240,9 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
//region UI and drawing
|
||||
|
||||
@Override
|
||||
public void buildUI(Group group) {
|
||||
public void buildUI(Group group){
|
||||
|
||||
//Create confirm/cancel table
|
||||
//Create confirm/cancel table
|
||||
new table(){{
|
||||
abottom().aleft();
|
||||
|
||||
@@ -227,12 +260,12 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
|
||||
//Add an accept button, which places everything.
|
||||
new imagebutton("icon-check", 16 * 2f, () -> {
|
||||
for (PlaceRequest request : selection) {
|
||||
for(PlaceRequest request : selection){
|
||||
Tile tile = request.tile();
|
||||
|
||||
//actually place/break all selected blocks
|
||||
if (tile != null) {
|
||||
if(!request.remove) {
|
||||
if(tile != null){
|
||||
if(!request.remove){
|
||||
rotation = request.rotation;
|
||||
recipe = request.recipe;
|
||||
tryPlaceBlock(tile.x, tile.y);
|
||||
@@ -292,12 +325,12 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlacing() {
|
||||
public boolean isPlacing(){
|
||||
return super.isPlacing() && mode == placing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOutlined(){
|
||||
public void drawOutlined(){
|
||||
|
||||
//Draw.color(Palette.placing);
|
||||
//Lines.poly(player.x, player.y, 100, Player.placeDistance);
|
||||
@@ -324,11 +357,11 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
|
||||
if(tile == null) continue;
|
||||
|
||||
if ((!request.remove && validPlace(tile.x, tile.y, request.recipe.result, request.rotation))
|
||||
|| (request.remove && validBreak(tile.x, tile.y))) {
|
||||
if((!request.remove && validPlace(tile.x, tile.y, request.recipe.result, 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);
|
||||
} else {
|
||||
}else{
|
||||
request.scale = Mathf.lerpDelta(request.scale, 0.5f, 0.1f);
|
||||
request.redness = Mathf.lerpDelta(request.redness, 1f, 0.2f);
|
||||
}
|
||||
@@ -353,7 +386,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
if(tile != null){
|
||||
|
||||
//draw placing
|
||||
if(mode == placing && recipe != null) {
|
||||
if(mode == placing && recipe != null){
|
||||
NormalizeDrawResult dresult = PlaceUtils.normalizeDrawArea(recipe.result, lineStartX, lineStartY, tile.x, tile.y, true, maxLength, lineScale);
|
||||
|
||||
Lines.rect(dresult.x, dresult.y, dresult.x2 - dresult.x, dresult.y2 - dresult.y);
|
||||
@@ -361,20 +394,20 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(lineStartX, lineStartY, tile.x, tile.y, rotation, true, maxLength);
|
||||
|
||||
//go through each cell and draw the block to place if valid
|
||||
for (int i = 0; i <= result.getLength(); i += recipe.result.size) {
|
||||
for(int i = 0; i <= result.getLength(); i += recipe.result.size){
|
||||
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, result.rotation)) {
|
||||
if(!checkOverlapPlacement(x, y, recipe.result) && validPlace(x, y, recipe.result, result.rotation)){
|
||||
Draw.color();
|
||||
|
||||
TextureRegion[] regions = recipe.result.getBlockIcon();
|
||||
|
||||
for (TextureRegion region : regions) {
|
||||
for(TextureRegion region : regions){
|
||||
Draw.rect(region, x * tilesize + recipe.result.offset(), y * tilesize + recipe.result.offset(),
|
||||
region.getRegionWidth() * lineScale, region.getRegionHeight() * lineScale, recipe.result.rotate ? result.rotation * 90 : 0);
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
Draw.color(Palette.breakInvalid);
|
||||
Lines.square(x * tilesize + recipe.result.offset(), y * tilesize + recipe.result.offset(), recipe.result.size * tilesize / 2f);
|
||||
}
|
||||
@@ -390,13 +423,13 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
Draw.alpha(0.6f);
|
||||
Draw.alpha(1f);
|
||||
|
||||
for(int x = dresult.x; x <= dresult.x2; x ++){
|
||||
for(int y = dresult.y; y <= dresult.y2; y ++){
|
||||
for(int x = dresult.x; x <= dresult.x2; x++){
|
||||
for(int y = dresult.y; y <= dresult.y2; y++){
|
||||
Tile other = world.tile(x, y);
|
||||
if(other == null || !validBreak(other.x, other.y)) continue;
|
||||
other = other.target();
|
||||
|
||||
Lines.poly(other.drawx(), other.drawy(), 4, other.block().size * tilesize/2f, 45 + 15);
|
||||
Lines.poly(other.drawx(), other.drawy(), 4, other.block().size * tilesize / 2f, 45 + 15);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,8 +453,8 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
|
||||
float radius = Interpolation.swingIn.apply(crosshairScale);
|
||||
|
||||
Lines.poly(player.target.getX(), player.target.getY(), 4, 7f * radius, Timers.time()*1.5f);
|
||||
Lines.spikes(player.target.getX(), player.target.getY(), 3f * radius, 6f * radius, 4, Timers.time()*1.5f);
|
||||
Lines.poly(player.target.getX(), player.target.getY(), 4, 7f * radius, Timers.time() * 1.5f);
|
||||
Lines.spikes(player.target.getX(), player.target.getY(), 3f * radius, 6f * radius, 4, Timers.time() * 1.5f);
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
@@ -431,9 +464,9 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
|
||||
//region input events
|
||||
|
||||
@Override
|
||||
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
||||
if(state.is(State.menu)) return false;
|
||||
@Override
|
||||
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
||||
if(state.is(State.menu)) return false;
|
||||
|
||||
//get tile on cursor
|
||||
Tile cursor = tileAt(screenX, screenY);
|
||||
@@ -453,19 +486,19 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
||||
|
||||
//place down a line if in line mode
|
||||
if(lineMode) {
|
||||
if(lineMode){
|
||||
Tile tile = tileAt(screenX, screenY);
|
||||
|
||||
if (tile == null) return false;
|
||||
if(tile == null) return false;
|
||||
|
||||
if(mode == placing && recipe != null) {
|
||||
if(mode == placing && recipe != null){
|
||||
|
||||
//normalize area
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(lineStartX, lineStartY, tile.x, tile.y, rotation, true, 100);
|
||||
@@ -473,11 +506,11 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
rotation = result.rotation;
|
||||
|
||||
//place blocks on line
|
||||
for (int i = 0; i <= result.getLength(); i += recipe.result.size) {
|
||||
for(int i = 0; i <= result.getLength(); i += recipe.result.size){
|
||||
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, result.rotation)) {
|
||||
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;
|
||||
selection.add(request);
|
||||
@@ -492,8 +525,8 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(lineStartX, lineStartY, tile.x, tile.y, rotation, false, maxLength);
|
||||
|
||||
//break everything in area
|
||||
for(int x = 0; x <= Math.abs(result.x2 - result.x); x ++ ){
|
||||
for(int y = 0; y <= Math.abs(result.y2 - result.y); y ++){
|
||||
for(int x = 0; x <= Math.abs(result.x2 - result.x); x++){
|
||||
for(int y = 0; y <= Math.abs(result.y2 - result.y); y++){
|
||||
int wx = lineStartX + x * Mathf.sign(tile.x - lineStartX);
|
||||
int wy = lineStartY + y * Mathf.sign(tile.y - lineStartY);
|
||||
|
||||
@@ -503,7 +536,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
|
||||
tar = tar.target();
|
||||
|
||||
if (!hasRequest(world.tile(tar.x, tar.y)) && validBreak(tar.x, tar.y)) {
|
||||
if(!hasRequest(world.tile(tar.x, tar.y)) && validBreak(tar.x, tar.y)){
|
||||
PlaceRequest request = new PlaceRequest(tar.worldx(), tar.worldy());
|
||||
request.scale = 1f;
|
||||
selection.add(request);
|
||||
@@ -516,7 +549,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}else{
|
||||
Tile tile = tileAt(screenX, screenY);
|
||||
|
||||
if (tile == null) return false;
|
||||
if(tile == null) return false;
|
||||
|
||||
tryDropItems(tile.target(), Graphics.world(screenX, screenY).x, Graphics.world(screenX, screenY).y);
|
||||
}
|
||||
@@ -524,7 +557,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean longPress(float x, float y) {
|
||||
public boolean longPress(float x, float y){
|
||||
if(state.is(State.menu) || mode == none) return false;
|
||||
|
||||
//get tile on cursor
|
||||
@@ -545,11 +578,11 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
Effects.effect(Fx.tapBlock, cursor.worldx() + recipe.result.offset(), cursor.worldy() + recipe.result.offset(), recipe.result.size);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count, int button) {
|
||||
public boolean tap(float x, float y, int count, int button){
|
||||
if(state.is(State.menu) || lineMode) return false;
|
||||
|
||||
float worldx = Graphics.world(x, y).x, worldy = Graphics.world(x, y).y;
|
||||
@@ -563,12 +596,12 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
if(cursor == null || ui.hasMouse(x, y)) return false;
|
||||
|
||||
//remove if request present
|
||||
if(hasRequest(cursor)) {
|
||||
if(hasRequest(cursor)){
|
||||
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(lastPlaced = new PlaceRequest(cursor.worldx(), cursor.worldy(), recipe, rotation));
|
||||
}else if(mode == breaking && validBreak(cursor.target().x, cursor.target().y) && !hasRequest(cursor.target())) {
|
||||
}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()));
|
||||
@@ -588,24 +621,24 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
//reset state when not placing
|
||||
if(mode == none){
|
||||
selecting = false;
|
||||
lineMode = false;
|
||||
removals.addAll(selection);
|
||||
selection.clear();
|
||||
if(mode == none){
|
||||
selecting = false;
|
||||
lineMode = false;
|
||||
removals.addAll(selection);
|
||||
selection.clear();
|
||||
}
|
||||
|
||||
if(lineMode && mode == placing && recipe == null){
|
||||
lineMode = false;
|
||||
lineMode = false;
|
||||
}
|
||||
|
||||
//if there is no mode and there's a recipe, switch to placing
|
||||
if(recipe != null && mode == none){
|
||||
mode = placing;
|
||||
mode = placing;
|
||||
}
|
||||
|
||||
if(recipe != null){
|
||||
@@ -615,13 +648,13 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
//automatically switch to placing after a new recipe is selected
|
||||
if(lastRecipe != recipe && mode == breaking && recipe != null){
|
||||
mode = placing;
|
||||
lastRecipe = recipe;
|
||||
lastRecipe = recipe;
|
||||
}
|
||||
|
||||
if(lineMode){
|
||||
lineScale = Mathf.lerpDelta(lineScale, 1f, 0.1f);
|
||||
lineScale = Mathf.lerpDelta(lineScale, 1f, 0.1f);
|
||||
|
||||
//When in line mode, pan when near screen edges automatically
|
||||
//When in line mode, pan when near screen edges automatically
|
||||
if(Gdx.input.isTouched(0) && lineMode){
|
||||
float screenX = Graphics.mouse().x, screenY = Graphics.mouse().y;
|
||||
|
||||
@@ -651,19 +684,19 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
Core.camera.position.y += vector.y;
|
||||
}
|
||||
}else{
|
||||
lineScale = 0f;
|
||||
lineScale = 0f;
|
||||
}
|
||||
|
||||
//remove place requests that have disappeared
|
||||
for(int i = removals.size - 1; i >= 0; i --){
|
||||
for(int i = removals.size - 1; i >= 0; i--){
|
||||
PlaceRequest request = removals.get(i);
|
||||
|
||||
if(request.scale <= 0.0001f){
|
||||
removals.removeIndex(i);
|
||||
i --;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY){
|
||||
@@ -676,14 +709,14 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
|
||||
float dx = deltaX * Core.camera.zoom / Core.cameraScale, dy = deltaY * Core.camera.zoom / Core.cameraScale;
|
||||
|
||||
if(selecting){ //pan all requests
|
||||
if(selecting){ //pan all requests
|
||||
for(PlaceRequest req : selection){
|
||||
if(req.remove) continue; //don't shift removal requests
|
||||
req.x += dx;
|
||||
req.y -= dy;
|
||||
}
|
||||
}else{
|
||||
//pan player
|
||||
//pan player
|
||||
Core.camera.position.x -= dx;
|
||||
Core.camera.position.y += dy;
|
||||
}
|
||||
@@ -692,12 +725,12 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean panStop(float x, float y, int pointer, int button) {
|
||||
public boolean panStop(float x, float y, int pointer, int button){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pinch (Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
|
||||
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2){
|
||||
if(pinch1.x < 0){
|
||||
pinch1.set(initialPointer1);
|
||||
pinch2.set(initialPointer2);
|
||||
@@ -727,28 +760,35 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pinchStop () {
|
||||
public void pinchStop(){
|
||||
initzoom = -1;
|
||||
pinch2.set(pinch1.set(-1, -1));
|
||||
zoomed = false;
|
||||
}
|
||||
|
||||
@Override public boolean touchDown(float x, float y, int pointer, int button) { return false; }
|
||||
@Override public boolean fling(float velocityX, float velocityY, int button) { return false; }
|
||||
@Override
|
||||
public boolean touchDown(float x, float y, int pointer, int button){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fling(float velocityX, float velocityY, int button){
|
||||
return false;
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
class PlaceRequest{
|
||||
float x, y;
|
||||
Recipe recipe;
|
||||
int rotation;
|
||||
boolean remove;
|
||||
float x, y;
|
||||
Recipe recipe;
|
||||
int rotation;
|
||||
boolean remove;
|
||||
|
||||
//animation variables
|
||||
float scale;
|
||||
float redness;
|
||||
//animation variables
|
||||
float scale;
|
||||
float redness;
|
||||
|
||||
PlaceRequest(float x, float y, Recipe recipe, int rotation) {
|
||||
PlaceRequest(float x, float y, Recipe recipe, int rotation){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.recipe = recipe;
|
||||
@@ -756,14 +796,14 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
this.remove = false;
|
||||
}
|
||||
|
||||
PlaceRequest(float x, float y) {
|
||||
PlaceRequest(float x, float y){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.remove = true;
|
||||
}
|
||||
|
||||
Tile tile(){
|
||||
return world.tileWorld(x - (recipe == null ? 0 : recipe.result.offset()), y - (recipe == null ? 0 : recipe.result.offset()));
|
||||
return world.tileWorld(x - (recipe == null ? 0 : recipe.result.offset()), y - (recipe == null ? 0 : recipe.result.offset()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@ import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
public class PlaceUtils {
|
||||
public class PlaceUtils{
|
||||
private static final NormalizeResult result = new NormalizeResult();
|
||||
private static final NormalizeDrawResult drawResult = new NormalizeDrawResult();
|
||||
|
||||
/**Normalizes a placement area and returns the result, ready to be used for drawing a rectangle.
|
||||
/**
|
||||
* Normalizes a placement area and returns the result, ready to be used for drawing a rectangle.
|
||||
* Returned x2 and y2 will <i>always</i> be greater than x and y.
|
||||
*
|
||||
* @param block block that will be drawn
|
||||
@@ -30,12 +31,12 @@ public class PlaceUtils {
|
||||
drawResult.x2 = result.x2 * tilesize;
|
||||
drawResult.y2 = result.y2 * tilesize;
|
||||
|
||||
drawResult.x -= block.size * scaling * tilesize/2;
|
||||
drawResult.x2 += block.size * scaling * tilesize/2;
|
||||
drawResult.x -= block.size * scaling * tilesize / 2;
|
||||
drawResult.x2 += block.size * scaling * tilesize / 2;
|
||||
|
||||
|
||||
drawResult.y -= block.size * scaling * tilesize/2;
|
||||
drawResult.y2 += block.size * scaling * tilesize/2;
|
||||
drawResult.y -= block.size * scaling * tilesize / 2;
|
||||
drawResult.y2 += block.size * scaling * tilesize / 2;
|
||||
|
||||
drawResult.x += offset;
|
||||
drawResult.y += offset;
|
||||
@@ -45,7 +46,8 @@ public class PlaceUtils {
|
||||
return drawResult;
|
||||
}
|
||||
|
||||
/**Normalizes a placement area and returns the result.
|
||||
/**
|
||||
* Normalizes a placement area and returns the result.
|
||||
* Returned x2 and y2 will <i>always</i> be greater than x and y.
|
||||
*
|
||||
* @param tilex starting X coordinate
|
||||
@@ -58,18 +60,18 @@ public class PlaceUtils {
|
||||
*/
|
||||
public static NormalizeResult normalizeArea(int tilex, int tiley, int endx, int endy, int rotation, boolean snap, int maxLength){
|
||||
|
||||
if(snap) {
|
||||
if (Math.abs(tilex - endx) > Math.abs(tiley - endy)) {
|
||||
if(snap){
|
||||
if(Math.abs(tilex - endx) > Math.abs(tiley - endy)){
|
||||
endy = tiley;
|
||||
} else {
|
||||
}else{
|
||||
endx = tilex;
|
||||
}
|
||||
|
||||
if (Math.abs(endx - tilex) > maxLength) {
|
||||
if(Math.abs(endx - tilex) > maxLength){
|
||||
endx = Mathf.sign(endx - tilex) * maxLength + tilex;
|
||||
}
|
||||
|
||||
if (Math.abs(endy - tiley) > maxLength) {
|
||||
if(Math.abs(endy - tiley) > maxLength){
|
||||
endy = Mathf.sign(endy - tiley) * maxLength + tiley;
|
||||
}
|
||||
}
|
||||
@@ -110,7 +112,7 @@ public class PlaceUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
static class NormalizeDrawResult {
|
||||
static class NormalizeDrawResult{
|
||||
float x, y, x2, y2;
|
||||
}
|
||||
|
||||
@@ -121,17 +123,23 @@ public class PlaceUtils {
|
||||
return Math.abs(x2 - x) > Math.abs(y2 - y);
|
||||
}
|
||||
|
||||
/**Returns length of greater edge of the selection.*/
|
||||
/**
|
||||
* Returns length of greater edge of the selection.
|
||||
*/
|
||||
int getLength(){
|
||||
return Math.max(x2 - x, y2 - y);
|
||||
}
|
||||
|
||||
/**Returns the X position of a specific index along this area as a line.*/
|
||||
/**
|
||||
* Returns the X position of a specific index along this area as a line.
|
||||
*/
|
||||
int getScaledX(int i){
|
||||
return x + (x2 - x > y2 - y ? i : 0);
|
||||
}
|
||||
|
||||
/**Returns the Y position of a specific index along this area as a line.*/
|
||||
/**
|
||||
* Returns the Y position of a specific index along this area as a line.
|
||||
*/
|
||||
int getScaledY(int i){
|
||||
return y + (x2 - x > y2 - y ? 0 : i);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user