Massive amount of refactoring for local multiplayer, annotations
This commit is contained in:
@@ -46,9 +46,9 @@ public class AndroidInput extends InputHandler{
|
||||
}
|
||||
|
||||
if(placing && pointer == 0 && !placeMode.pan && !breaking()){
|
||||
placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
placeMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}else if(pointer == 0 && !breakMode.pan && breaking() && drawPlace()){
|
||||
breakMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
breakMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
|
||||
placing = false;
|
||||
@@ -79,9 +79,9 @@ public class AndroidInput extends InputHandler{
|
||||
if(cursor != null && !ui.hasMouse(screenX, screenY)){
|
||||
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
|
||||
if(linked != null && linked.block().isConfigurable(linked)){
|
||||
ui.configfrag.showConfig(linked);
|
||||
}else if(!ui.configfrag.hasConfigMouse()){
|
||||
ui.configfrag.hideConfig();
|
||||
frag.config.showConfig(linked);
|
||||
}else if(!frag.config.hasConfigMouse()){
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
|
||||
if(linked != null) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.input;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Buttons;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
@@ -8,13 +9,10 @@ import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.core.Inputs.DeviceType;
|
||||
import io.anuke.ucore.core.KeyBinds;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.scene.utils.Cursors;
|
||||
import io.anuke.ucore.util.Input;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
@@ -22,8 +20,10 @@ import static io.anuke.mindustry.Vars.*;
|
||||
public class DesktopInput extends InputHandler{
|
||||
float mousex, mousey;
|
||||
float endx, endy;
|
||||
private float controlx, controly;
|
||||
private boolean enableHold = false;
|
||||
private boolean beganBreak;
|
||||
private boolean controlling;
|
||||
|
||||
public DesktopInput(Player player){
|
||||
super(player);
|
||||
@@ -37,14 +37,17 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
updateController();
|
||||
|
||||
if(player.isDead()) return;
|
||||
|
||||
if(Inputs.keyRelease("select")){
|
||||
placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
placeMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease("break") && !beganBreak){
|
||||
breakMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
breakMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
|
||||
if(!Inputs.keyDown("select")){
|
||||
@@ -104,7 +107,7 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
if(Inputs.keyTap("weapon_" + keyIndex)){
|
||||
player.weapon = (Weapon) player.upgrades.get(i);
|
||||
if(Net.active()) NetEvents.handleWeaponSwitch();
|
||||
if(Net.active()) NetEvents.handleWeaponSwitch(player);
|
||||
}
|
||||
|
||||
keyIndex ++;
|
||||
@@ -126,13 +129,13 @@ public class DesktopInput extends InputHandler{
|
||||
showCursor = true;
|
||||
if(Inputs.keyTap("select")){
|
||||
canBeginShoot = false;
|
||||
ui.blockinvfrag.showFor(target);
|
||||
frag.inv.showFor(target);
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
}
|
||||
|
||||
if(!ui.hasMouse() && (target == null || !target.block().isAccessible()) && Inputs.keyTap("select")){
|
||||
ui.blockinvfrag.hide();
|
||||
frag.inv.hide();
|
||||
}
|
||||
|
||||
if(target != null && target.block().isConfigurable(target)){
|
||||
@@ -141,14 +144,14 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
if(target != null && Inputs.keyTap("select") && !ui.hasMouse()){
|
||||
if(target.block().isConfigurable(target)){
|
||||
if((!ui.configfrag.isShown()
|
||||
|| ui.configfrag.getSelectedTile().block().onConfigureTileTapped(ui.configfrag.getSelectedTile(), cursor))) {
|
||||
ui.configfrag.showConfig(target);
|
||||
if((!frag.config.isShown()
|
||||
|| frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), cursor))) {
|
||||
frag.config.showConfig(target);
|
||||
canBeginShoot = false;
|
||||
}
|
||||
}else if(!ui.configfrag.hasConfigMouse()){
|
||||
if(ui.configfrag.isShown() && ui.configfrag.getSelectedTile().block().onConfigureTileTapped(ui.configfrag.getSelectedTile(), cursor)) {
|
||||
ui.configfrag.hideConfig();
|
||||
}else if(!frag.config.hasConfigMouse()){
|
||||
if(frag.config.isShown() && frag.config.getSelectedTile().block().onConfigureTileTapped(frag.config.getSelectedTile(), cursor)) {
|
||||
frag.config.hideConfig();
|
||||
canBeginShoot = false;
|
||||
}
|
||||
}
|
||||
@@ -158,7 +161,7 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
|
||||
if(Inputs.keyTap("break")){
|
||||
ui.configfrag.hideConfig();
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease("break")){
|
||||
@@ -196,8 +199,63 @@ public class DesktopInput extends InputHandler{
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMouseX() {
|
||||
return controlx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMouseY() {
|
||||
return controly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCursorVisible() {
|
||||
return controlling;
|
||||
}
|
||||
|
||||
void updateController(){
|
||||
boolean mousemove = Gdx.input.getDeltaX() > 1 || Gdx.input.getDeltaY() > 1;
|
||||
|
||||
if(KeyBinds.getSection("default").device.type == DeviceType.controller && !mousemove){
|
||||
if(Inputs.keyTap("select")){
|
||||
Inputs.getProcessor().touchDown(Gdx.input.getX(), Gdx.input.getY(), player.playerIndex, Buttons.LEFT);
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease("select")){
|
||||
Inputs.getProcessor().touchUp(Gdx.input.getX(), Gdx.input.getY(), player.playerIndex, Buttons.LEFT);
|
||||
}
|
||||
|
||||
float xa = Inputs.getAxis("cursor_x");
|
||||
float ya = Inputs.getAxis("cursor_y");
|
||||
|
||||
if(Math.abs(xa) > controllerMin || Math.abs(ya) > controllerMin) {
|
||||
float scl = Settings.getInt("sensitivity")/100f * Unit.dp.scl(1f);
|
||||
controlx += xa*baseControllerSpeed*scl;
|
||||
controly -= ya*baseControllerSpeed*scl;
|
||||
controlling = true;
|
||||
|
||||
Gdx.input.setCursorCatched(true);
|
||||
|
||||
Inputs.getProcessor().touchDragged(Gdx.input.getX(), Gdx.input.getY(), player.playerIndex);
|
||||
}
|
||||
|
||||
controlx = Mathf.clamp(controlx, 0, Gdx.graphics.getWidth());
|
||||
controly = Mathf.clamp(controly, 0, Gdx.graphics.getHeight());
|
||||
}else{
|
||||
controlling = false;
|
||||
Gdx.input.setCursorCatched(false);
|
||||
}
|
||||
|
||||
if(!controlling){
|
||||
controlx = control.gdxInput().getX();
|
||||
controly = control.gdxInput().getY();
|
||||
}
|
||||
}
|
||||
|
||||
public int tilex(){
|
||||
return (recipe != null && recipe.result.isMultiblock() &&
|
||||
recipe.result.size % 2 == 0) ?
|
||||
|
||||
@@ -30,30 +30,30 @@ public class GestureHandler extends GestureAdapter{
|
||||
public boolean tap (float x, float y, int count, int button) {
|
||||
if(ui.hasMouse() || input.brokeBlock) return false;
|
||||
|
||||
if(!control.input().placeMode.pan || control.input().recipe == null){
|
||||
if(!input.placeMode.pan || input.recipe == null){
|
||||
input.mousex = x;
|
||||
input.mousey = y;
|
||||
|
||||
if(control.input().recipe == null)
|
||||
control.input().breakMode.tapped(input.getBlockX(), input.getBlockY());
|
||||
if(input.recipe == null)
|
||||
input.breakMode.tapped(input, input.getBlockX(), input.getBlockY());
|
||||
else
|
||||
control.input().placeMode.tapped(input.getBlockX(), input.getBlockY());
|
||||
input.placeMode.tapped(input, input.getBlockX(), input.getBlockY());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY){
|
||||
if(control.showCursor() && !Inputs.keyDown("select")) return false;
|
||||
if(input.isCursorVisible() && !Inputs.keyDown("select")) return false;
|
||||
|
||||
if(!control.showCursor() && !(control.input().recipe != null
|
||||
&& control.input().placeMode.lockCamera && state.inventory.hasItems(control.input().recipe.requirements)) &&
|
||||
!(control.input().recipe == null && control.input().breakMode.lockCamera)){
|
||||
if(!input.isCursorVisible() && !(input.recipe != null
|
||||
&& input.placeMode.lockCamera && state.inventory.hasItems(input.recipe.requirements)) &&
|
||||
!(input.recipe == null && input.breakMode.lockCamera)){
|
||||
float dx = deltaX*Core.camera.zoom/Core.cameraScale, dy = deltaY*Core.camera.zoom/Core.cameraScale;
|
||||
player.x -= dx;
|
||||
player.y += dy;
|
||||
player.targetAngle = Mathf.atan2(dx, -dy) + 180f;
|
||||
}else if(control.input().placeMode.lockCamera && (control.input().placeMode.pan && control.input().recipe != null)){
|
||||
input.player.x -= dx;
|
||||
input.player.y += dy;
|
||||
input.player.targetAngle = Mathf.atan2(dx, -dy) + 180f;
|
||||
}else if(input.placeMode.lockCamera && (input.placeMode.pan && input.recipe != null)){
|
||||
input.mousex += deltaX;
|
||||
input.mousey += deltaY;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class GestureHandler extends GestureAdapter{
|
||||
|
||||
@Override
|
||||
public boolean pinch (Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
|
||||
if(control.input().recipe == null && !control.input().breakMode.lockCamera)
|
||||
if(input.recipe == null && !input.breakMode.lockCamera)
|
||||
return false;
|
||||
|
||||
if(pinch1.x < 0){
|
||||
@@ -72,9 +72,9 @@ public class GestureHandler extends GestureAdapter{
|
||||
}
|
||||
|
||||
Vector2 vec = (vector.set(pointer1).add(pointer2).scl(0.5f)).sub(pinch1.add(pinch2).scl(0.5f));
|
||||
|
||||
player.x -= vec.x*Core.camera.zoom/Core.cameraScale;
|
||||
player.y += vec.y*Core.camera.zoom/Core.cameraScale;
|
||||
|
||||
input.player.x -= vec.x*Core.camera.zoom/Core.cameraScale;
|
||||
input.player.y += vec.y*Core.camera.zoom/Core.cameraScale;
|
||||
|
||||
pinch1.set(pointer1);
|
||||
pinch2.set(pointer2);
|
||||
|
||||
@@ -10,10 +10,13 @@ import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Recipe;
|
||||
import io.anuke.mindustry.ui.fragments.OverlayFragment;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Placement;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
@@ -23,6 +26,9 @@ import io.anuke.ucore.util.Translator;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public abstract class InputHandler extends InputAdapter{
|
||||
public final static float playerSelectRange = Unit.dp.scl(60f);
|
||||
private final static Translator stackTrns = new Translator();
|
||||
|
||||
public float breaktime = 0;
|
||||
public Recipe recipe;
|
||||
public int rotation;
|
||||
@@ -33,12 +39,11 @@ public abstract class InputHandler extends InputAdapter{
|
||||
public PlaceMode lastBreakMode = breakMode;
|
||||
public boolean droppingItem, transferring;
|
||||
public boolean shooting;
|
||||
public float playerSelectRange = Unit.dp.scl(60f);
|
||||
|
||||
private Translator stackTrns = new Translator();
|
||||
public OverlayFragment frag = new OverlayFragment(this);
|
||||
|
||||
public InputHandler(Player player){
|
||||
this.player = player;
|
||||
Timers.run(1f, () -> frag.build(Core.scene.getRoot()));
|
||||
}
|
||||
|
||||
public abstract void update();
|
||||
@@ -46,11 +51,19 @@ public abstract class InputHandler extends InputAdapter{
|
||||
public abstract float getCursorY();
|
||||
public abstract float getCursorEndX();
|
||||
public abstract float getCursorEndY();
|
||||
public int getBlockX(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).x, tilesize, round2()); }
|
||||
public float getMouseX(){ return Gdx.input.getX(); };
|
||||
public float getMouseY(){ return Gdx.input.getY(); };
|
||||
public int getBlockX(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).x, tilesize, round2()); }
|
||||
public int getBlockY(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).y, tilesize, round2()); }
|
||||
public int getBlockEndX(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).x, tilesize, round2()); }
|
||||
public int getBlockEndY(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).y, tilesize, round2()); }
|
||||
public void resetCursor(){}
|
||||
public boolean isCursorVisible(){ return false; }
|
||||
|
||||
public void remove(){
|
||||
Inputs.removeProcessor(this);
|
||||
frag.remove();
|
||||
}
|
||||
|
||||
public boolean canShoot(){
|
||||
return recipe == null && !ui.hasMouse() && !onConfigurable() && !isDroppingItem();
|
||||
@@ -183,7 +196,7 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
|
||||
if(Net.active()){
|
||||
NetEvents.handlePlace(x, y, result, rotation);
|
||||
NetEvents.handlePlace(player, x, y, result, rotation);
|
||||
}
|
||||
|
||||
if(!Net.client()){
|
||||
|
||||
@@ -24,35 +24,33 @@ public enum PlaceMode{
|
||||
pan = true;
|
||||
}
|
||||
|
||||
public void draw(int tilex, int tiley, int endx, int endy){
|
||||
public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||
float x = tilex * tilesize;
|
||||
float y = tiley * tilesize;
|
||||
|
||||
boolean valid = control.input().validPlace(tilex, tiley, control.input().recipe.result) && (mobile || control.input().cursorNear());
|
||||
boolean valid = input.validPlace(tilex, tiley, input.recipe.result) && (mobile || input.cursorNear());
|
||||
|
||||
Vector2 offset = control.input().recipe.result.getPlaceOffset();
|
||||
Vector2 offset = input.recipe.result.getPlaceOffset();
|
||||
|
||||
float si = MathUtils.sin(Timers.time() / 6f) + 1.5f;
|
||||
|
||||
renderer.getBlocks().handlePreview(control.input().recipe.result, control.input().recipe.result.rotate ? control.input().rotation * 90 : 0f, x + offset.x, y + offset.y, tilex, tiley);
|
||||
|
||||
Draw.color(valid ? Colors.get("place") : Colors.get("placeInvalid"));
|
||||
Lines.stroke(2f);
|
||||
Lines.crect(x + offset.x, y + offset.y, tilesize * control.input().recipe.result.size + si,
|
||||
tilesize * control.input().recipe.result.size + si);
|
||||
Lines.crect(x + offset.x, y + offset.y, tilesize * input.recipe.result.size + si,
|
||||
tilesize * input.recipe.result.size + si);
|
||||
|
||||
control.input().recipe.result.drawPlace(tilex, tiley, control.input().rotation, valid);
|
||||
input.recipe.result.drawPlace(tilex, tiley, input.rotation, valid);
|
||||
|
||||
if(control.input().recipe.result.rotate){
|
||||
if(input.recipe.result.rotate){
|
||||
|
||||
Draw.color(Colors.get("placeRotate"));
|
||||
tr.trns(control.input().rotation * 90, 7, 0);
|
||||
tr.trns(input.rotation * 90, 7, 0);
|
||||
Lines.line(x, y, x + tr.x, y + tr.y);
|
||||
}
|
||||
}
|
||||
|
||||
public void tapped(int tilex, int tiley){
|
||||
control.input().tryPlaceBlock(tilex, tiley, true);
|
||||
public void tapped(InputHandler input, int tilex, int tiley){
|
||||
input.tryPlaceBlock(tilex, tiley, true);
|
||||
}
|
||||
},
|
||||
touch{
|
||||
@@ -63,8 +61,8 @@ public enum PlaceMode{
|
||||
showCancel = true;
|
||||
}
|
||||
|
||||
public void tapped(int x, int y){
|
||||
control.input().tryPlaceBlock(x, y, true);
|
||||
public void tapped(InputHandler input, int x, int y){
|
||||
input.tryPlaceBlock(x, y, true);
|
||||
}
|
||||
},
|
||||
none{
|
||||
@@ -81,15 +79,15 @@ public enum PlaceMode{
|
||||
both = true;
|
||||
}
|
||||
|
||||
public void draw(int tilex, int tiley, int endx, int endy){
|
||||
public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||
Tile tile = world.tile(tilex, tiley);
|
||||
|
||||
if(tile != null && control.input().validBreak(tilex, tiley)){
|
||||
if(tile != null && input.validBreak(tilex, tiley)){
|
||||
if(tile.isLinked())
|
||||
tile = tile.getLinked();
|
||||
float fin = control.input().breaktime / tile.getBreakTime();
|
||||
float fin = input.breaktime / tile.getBreakTime();
|
||||
|
||||
if(mobile && control.input().breaktime > 0){
|
||||
if(mobile && input.breaktime > 0){
|
||||
Draw.color(Colors.get("breakStart"), Colors.get("break"), fin);
|
||||
Lines.poly(tile.drawx(), tile.drawy(), 25, 4 + (1f - fin) * 26);
|
||||
}
|
||||
@@ -106,8 +104,8 @@ public enum PlaceMode{
|
||||
delete = true;
|
||||
}
|
||||
|
||||
public void tapped(int x, int y){
|
||||
control.input().tryDeleteBlock(x, y, true);
|
||||
public void tapped(InputHandler input, int x, int y){
|
||||
input.tryDeleteBlock(x, y, true);
|
||||
}
|
||||
},
|
||||
areaDelete{
|
||||
@@ -123,7 +121,7 @@ public enum PlaceMode{
|
||||
delete = true;
|
||||
}
|
||||
|
||||
public void draw(int tilex, int tiley, int endx, int endy){
|
||||
public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||
float t = tilesize;
|
||||
|
||||
process(tilex, tiley, endx, endy);
|
||||
@@ -150,7 +148,7 @@ public enum PlaceMode{
|
||||
Tile tile = world.tile(cx, cy);
|
||||
if(tile != null && tile.getLinked() != null)
|
||||
tile = tile.getLinked();
|
||||
if(tile != null && control.input().validBreak(tile.x, tile.y)){
|
||||
if(tile != null && input.validBreak(tile.x, tile.y)){
|
||||
Lines.crect(tile.drawx(), tile.drawy(),
|
||||
tile.block().size * t, tile.block().size * t);
|
||||
}
|
||||
@@ -158,20 +156,20 @@ public enum PlaceMode{
|
||||
}
|
||||
|
||||
Lines.stroke(2f);
|
||||
Draw.color(control.input().cursorNear() ? Colors.get("break") : Colors.get("breakInvalid"));
|
||||
Draw.color(input.cursorNear() ? Colors.get("break") : Colors.get("breakInvalid"));
|
||||
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(int tilex, int tiley, int endx, int endy){
|
||||
public void released(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||
process(tilex, tiley, endx, endy);
|
||||
tilex = this.tilex; tiley = this.tiley;
|
||||
endx = this.endx; endy = this.endy;
|
||||
|
||||
if(mobile){
|
||||
ToolFragment t = ui.toolfrag;
|
||||
ToolFragment t = input.frag.tool;
|
||||
if(!t.confirming || t.px != tilex || t.py != tiley || t.px2 != endx || t.py2 != endy) {
|
||||
t.confirming = true;
|
||||
t.px = tilex;
|
||||
@@ -186,7 +184,7 @@ public enum PlaceMode{
|
||||
|
||||
for(int cx = tilex; cx <= endx; cx ++){
|
||||
for(int cy = tiley; cy <= endy; cy ++){
|
||||
if(control.input().tryDeleteBlock(cx, cy, first)){
|
||||
if(input.tryDeleteBlock(cx, cy, first)){
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
@@ -235,16 +233,16 @@ public enum PlaceMode{
|
||||
showRotate = true;
|
||||
}
|
||||
|
||||
public void draw(int tilex, int tiley, int endx, int endy){
|
||||
if(mobile && !Gdx.input.isTouched(0) && !control.showCursor()){
|
||||
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 = control.input().recipe.result;
|
||||
Block block = input.recipe.result;
|
||||
Vector2 offset = block.getPlaceOffset();
|
||||
|
||||
process(tilex, tiley, endx, endy);
|
||||
process(input, tilex, tiley, endx, endy);
|
||||
int tx = tilex, ty = tiley, ex = endx, ey = endy;
|
||||
tilex = this.tilex; tiley = this.tiley;
|
||||
endx = this.endx; endy = this.endy;
|
||||
@@ -267,10 +265,10 @@ public enum PlaceMode{
|
||||
y2 += offset.y;
|
||||
|
||||
if(tilex == endx && tiley == endy){
|
||||
cursor.draw(tilex, tiley, endx, endy);
|
||||
cursor.draw(input, tilex, tiley, endx, endy);
|
||||
}else{
|
||||
Lines.stroke(2f);
|
||||
Draw.color(control.input().cursorNear() ? "place" : "placeInvalid");
|
||||
Draw.color(input.cursorNear() ? "place" : "placeInvalid");
|
||||
Lines.rect(x, y, x2 - x, y2 - y);
|
||||
Draw.alpha(0.3f);
|
||||
Draw.crect("blank", x, y, x2 - x, y2 - y);
|
||||
@@ -285,9 +283,7 @@ public enum PlaceMode{
|
||||
py = ty + cy * Mathf.sign(ey - ty);
|
||||
|
||||
//step by the block size if it's valid
|
||||
if(control.input().validPlace(px, py, control.input().recipe.result) && state.inventory.hasItems(control.input().recipe.requirements, amount)){
|
||||
|
||||
renderer.getBlocks().handlePreview(control.input().recipe.result, block.rotate ? rotation * 90 : 0f, px * t + offset.x, py * t + offset.y, px, py);
|
||||
if(input.validPlace(px, py, input.recipe.result) && state.inventory.hasItems(input.recipe.requirements, amount)){
|
||||
|
||||
if(isX){
|
||||
cx += block.size;
|
||||
@@ -296,7 +292,7 @@ public enum PlaceMode{
|
||||
}
|
||||
amount ++;
|
||||
}else{ //otherwise, step by 1 until it is valid
|
||||
if(control.input().cursorNear()){
|
||||
if(input.cursorNear()){
|
||||
Lines.stroke(2f);
|
||||
Draw.color("placeInvalid");
|
||||
Lines.crect(
|
||||
@@ -316,7 +312,7 @@ public enum PlaceMode{
|
||||
}
|
||||
}
|
||||
|
||||
if(control.input().recipe.result.rotate){
|
||||
if(input.recipe.result.rotate){
|
||||
float cx = tx * t, cy = ty * t;
|
||||
Lines.stroke(2f);
|
||||
Draw.color(Colors.get("placeRotate"));
|
||||
@@ -327,15 +323,15 @@ public enum PlaceMode{
|
||||
}
|
||||
}
|
||||
|
||||
public void released(int tilex, int tiley, int endx, int endy){
|
||||
process(tilex, tiley, endx, endy);
|
||||
public void released(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||
process(input, tilex, tiley, endx, endy);
|
||||
|
||||
control.input().rotation = this.rotation;
|
||||
input.rotation = this.rotation;
|
||||
|
||||
boolean first = true;
|
||||
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){
|
||||
for(int y = 0; y <= Math.abs(this.endy - this.tiley); y ++){
|
||||
if(control.input().tryPlaceBlock(
|
||||
if(input.tryPlaceBlock(
|
||||
tilex + x * Mathf.sign(endx - tilex),
|
||||
tiley + y * Mathf.sign(endy - tiley), first)){
|
||||
first = false;
|
||||
@@ -345,7 +341,7 @@ public enum PlaceMode{
|
||||
}
|
||||
}
|
||||
|
||||
void process(int tilex, int tiley, int endx, int endy){
|
||||
void process(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||
if(Math.abs(tilex - endx) > Math.abs(tiley - endy)){
|
||||
endy = tiley;
|
||||
}else{
|
||||
@@ -369,7 +365,7 @@ public enum PlaceMode{
|
||||
else if(endy < tiley)
|
||||
rotation = 3;
|
||||
else
|
||||
rotation = control.input().rotation;
|
||||
rotation = input.rotation;
|
||||
|
||||
if(endx < tilex){
|
||||
int t = endx;
|
||||
@@ -398,17 +394,9 @@ public enum PlaceMode{
|
||||
|
||||
private static final Translator tr = new Translator();
|
||||
|
||||
public void draw(int tilex, int tiley, int endx, int endy){
|
||||
|
||||
}
|
||||
|
||||
public void released(int tilex, int tiley, int endx, int endy){
|
||||
|
||||
}
|
||||
|
||||
public void tapped(int x, int y){
|
||||
|
||||
}
|
||||
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(){
|
||||
|
||||
Reference in New Issue
Block a user