mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-24 13:31:45 -08:00
Fixed place area being deselected near map edges
This commit is contained in:
parent
175d6b1fc5
commit
9e188aaf03
3 changed files with 110 additions and 98 deletions
|
|
@ -69,17 +69,16 @@ public class DesktopInput extends InputHandler{
|
|||
|
||||
@Override
|
||||
public void drawOutlined(){
|
||||
Tile cursor = tileAt(Gdx.input.getX(), Gdx.input.getY());
|
||||
|
||||
if(cursor == null) return;
|
||||
int cursorX = tileX(Gdx.input.getX());
|
||||
int cursorY = tileY(Gdx.input.getY());
|
||||
|
||||
//draw selection(s)
|
||||
if(mode == placing && recipe != null){
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength);
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursorX, cursorY, rotation, true, maxLength);
|
||||
|
||||
for(int i = 0; i <= result.getLength(); i += recipe.result.size){
|
||||
int x = selectX + i * Mathf.sign(cursor.x - selectX) * Mathf.bool(result.isX());
|
||||
int y = selectY + i * Mathf.sign(cursor.y - selectY) * Mathf.bool(!result.isX());
|
||||
int x = selectX + i * Mathf.sign(cursorX - selectX) * Mathf.bool(result.isX());
|
||||
int y = selectY + i * Mathf.sign(cursorY - selectY) * Mathf.bool(!result.isX());
|
||||
|
||||
if(i + recipe.result.size > result.getLength() && recipe.result.rotate){
|
||||
Draw.color(!validPlace(x, y, recipe.result, result.rotation) ? Palette.remove : Palette.placeRotate);
|
||||
|
|
@ -92,8 +91,8 @@ public class DesktopInput extends InputHandler{
|
|||
|
||||
Draw.reset();
|
||||
}else if(mode == breaking){
|
||||
NormalizeDrawResult result = PlaceUtils.normalizeDrawArea(Blocks.air, selectX, selectY, cursor.x, cursor.y, false, maxLength, 1f);
|
||||
NormalizeResult dresult = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, false, maxLength);
|
||||
NormalizeDrawResult result = PlaceUtils.normalizeDrawArea(Blocks.air, selectX, selectY, cursorX, cursorY, false, maxLength, 1f);
|
||||
NormalizeResult dresult = PlaceUtils.normalizeArea(selectX, selectY, cursorX, cursorY, rotation, false, maxLength);
|
||||
|
||||
Draw.color(Palette.remove);
|
||||
|
||||
|
|
@ -110,12 +109,12 @@ public class DesktopInput extends InputHandler{
|
|||
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(),
|
||||
cursor.worldy() + recipe.result.offset(), rotation * 90 - 90);
|
||||
Draw.color(!validPlace(cursorX, cursorY, recipe.result, rotation) ? Palette.remove : Palette.placeRotate);
|
||||
Draw.grect("place-arrow", cursorX * tilesize + recipe.result.offset(),
|
||||
cursorY * tilesize + 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));
|
||||
drawPlace(cursorX, cursorY, recipe.result, rotation);
|
||||
recipe.result.drawPlace(cursorX, cursorY, rotation, validPlace(cursorX, cursorY, recipe.result, rotation));
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
|
|
@ -200,11 +199,12 @@ public class DesktopInput extends InputHandler{
|
|||
}
|
||||
|
||||
void pollInput(){
|
||||
Tile cursor = tileAt(Gdx.input.getX(), Gdx.input.getY());
|
||||
if(cursor == null){
|
||||
mode = none;
|
||||
return;
|
||||
}
|
||||
Tile selected = tileAt(Gdx.input.getX(), Gdx.input.getY());
|
||||
int cursorX = tileX(Gdx.input.getX());
|
||||
int cursorY = tileY(Gdx.input.getY());
|
||||
//if(cursor == null){
|
||||
// return;
|
||||
//}
|
||||
|
||||
if(Inputs.keyTap(section, "deselect")){
|
||||
player.setMineTile(null);
|
||||
|
|
@ -212,15 +212,17 @@ public class DesktopInput extends InputHandler{
|
|||
|
||||
if(Inputs.keyTap(section, "select") && !ui.hasMouse()){
|
||||
if(isPlacing()){
|
||||
selectX = cursor.x;
|
||||
selectY = cursor.y;
|
||||
selectX = cursorX;
|
||||
selectY = cursorY;
|
||||
mode = placing;
|
||||
}else{
|
||||
}else if(selected != null){
|
||||
//only begin shooting if there's no cursor event
|
||||
if (!tileTapped(cursor) && !tryTapPlayer(Graphics.mouseWorld().x, Graphics.mouseWorld().y) && player.getPlaceQueue().size == 0 && !droppingItem &&
|
||||
!tryBeginMine(cursor) && player.getMineTile() == null) {
|
||||
if (!tileTapped(selected) && !tryTapPlayer(Graphics.mouseWorld().x, Graphics.mouseWorld().y) && player.getPlaceQueue().size == 0 && !droppingItem &&
|
||||
!tryBeginMine(selected) && player.getMineTile() == null) {
|
||||
player.isShooting = true;
|
||||
}
|
||||
}else{ //if it's out of bounds, shooting is just fine
|
||||
player.isShooting = true;
|
||||
}
|
||||
}else if(Inputs.keyTap(section, "deselect") && (recipe != null || mode != none || player.isBuilding())){
|
||||
if(recipe == null){
|
||||
|
|
@ -230,8 +232,8 @@ public class DesktopInput extends InputHandler{
|
|||
recipe = null;
|
||||
mode = none;
|
||||
}else if(Inputs.keyTap(section, "break") && !ui.hasMouse()){
|
||||
selectX = cursor.x;
|
||||
selectY = cursor.y;
|
||||
selectX = cursorX;
|
||||
selectY = cursorY;
|
||||
mode = breaking;
|
||||
}
|
||||
|
||||
|
|
@ -239,29 +241,31 @@ public class DesktopInput extends InputHandler{
|
|||
if(Inputs.keyRelease(section, "break") || Inputs.keyRelease(section, "select")){
|
||||
|
||||
if(mode == placing){ //touch up while placing, place everything in selection
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursor.x, cursor.y, rotation, true, maxLength);
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursorX, cursorY, rotation, true, maxLength);
|
||||
|
||||
for(int i = 0; i <= result.getLength(); i += recipe.result.size){
|
||||
int x = selectX + i * Mathf.sign(cursor.x - selectX) * Mathf.bool(result.isX());
|
||||
int y = selectY + i * Mathf.sign(cursor.y - selectY) * Mathf.bool(!result.isX());
|
||||
int x = selectX + i * Mathf.sign(cursorX - selectX) * Mathf.bool(result.isX());
|
||||
int y = selectY + i * Mathf.sign(cursorY - selectY) * Mathf.bool(!result.isX());
|
||||
|
||||
rotation = result.rotation;
|
||||
|
||||
tryPlaceBlock(x, y);
|
||||
}
|
||||
}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);
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(selectX, selectY, cursorX, cursorY, 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++){
|
||||
int wx = selectX + x * Mathf.sign(cursor.x - selectX);
|
||||
int wy = selectY + y * Mathf.sign(cursor.y - selectY);
|
||||
int wx = selectX + x * Mathf.sign(cursorX - selectX);
|
||||
int wy = selectY + y * Mathf.sign(cursorY - selectY);
|
||||
|
||||
tryBreakBlock(wx, wy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tryDropItems(cursor.target(), Graphics.mouseWorld().x, Graphics.mouseWorld().y);
|
||||
if(selected != null){
|
||||
tryDropItems(selected.target(), Graphics.mouseWorld().x, Graphics.mouseWorld().y);
|
||||
}
|
||||
|
||||
mode = none;
|
||||
}
|
||||
|
|
@ -285,6 +289,8 @@ public class DesktopInput extends InputHandler{
|
|||
|
||||
@Override
|
||||
public void updateController(){
|
||||
//TODO no controller support
|
||||
//TODO move controller input to new class, ControllerInput
|
||||
boolean mousemove = Gdx.input.getDeltaX() > 1 || Gdx.input.getDeltaY() > 1;
|
||||
|
||||
if(state.is(State.menu)){
|
||||
|
|
@ -295,14 +301,6 @@ public class DesktopInput extends InputHandler{
|
|||
if(player.playerIndex > 0){
|
||||
controlling = true;
|
||||
}
|
||||
/*
|
||||
if(Inputs.keyTap(section,"select")){
|
||||
Inputs.getProcessor().touchDown((int)getMouseX(), (int)getMouseY(), player.playerIndex, Buttons.LEFT);
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease(section,"select")){
|
||||
Inputs.getProcessor().touchUp((int)getMouseX(), (int)getMouseY(), player.playerIndex, Buttons.LEFT);
|
||||
}*/
|
||||
|
||||
float xa = Inputs.getAxis(section, "cursor_x");
|
||||
float ya = Inputs.getAxis(section, "cursor_y");
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import io.anuke.annotations.Annotations.Loc;
|
|||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.content.fx.EnvironmentFx;
|
||||
import io.anuke.mindustry.core.World;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.entities.effect.ItemTransfer;
|
||||
|
|
@ -21,7 +22,10 @@ import io.anuke.mindustry.ui.fragments.OverlayFragment;
|
|||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Build;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
|
@ -262,11 +266,23 @@ public abstract class InputHandler extends InputAdapter{
|
|||
* Returns the tile at the specified MOUSE coordinates.
|
||||
*/
|
||||
Tile tileAt(float x, float y){
|
||||
Vector2 vec = Graphics.world(x, y);
|
||||
return world.tile(tileX(x), tileY(y));
|
||||
}
|
||||
|
||||
int tileX(float cursorX){
|
||||
Vector2 vec = Graphics.world(cursorX, 0);
|
||||
if(isPlacing()){
|
||||
vec.sub(recipe.result.offset(), recipe.result.offset());
|
||||
}
|
||||
return world.tileWorld(vec.x, vec.y);
|
||||
return world.toTile(vec.x);
|
||||
}
|
||||
|
||||
int tileY(float cursorY){
|
||||
Vector2 vec = Graphics.world(0, cursorY);
|
||||
if(isPlacing()){
|
||||
vec.sub(recipe.result.offset(), recipe.result.offset());
|
||||
}
|
||||
return world.toTile(vec.y);
|
||||
}
|
||||
|
||||
public boolean isPlacing(){
|
||||
|
|
|
|||
|
|
@ -338,62 +338,61 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
|
||||
//Draw lines
|
||||
if(lineMode){
|
||||
Tile tile = tileAt(Gdx.input.getX(), Gdx.input.getY());
|
||||
int tileX = tileX(Gdx.input.getX());
|
||||
int tileY = tileY(Gdx.input.getY());
|
||||
|
||||
//draw placing
|
||||
if(mode == placing && recipe != null){
|
||||
NormalizeDrawResult dresult = PlaceUtils.normalizeDrawArea(recipe.result, lineStartX, lineStartY, tileX, tileY, true, maxLength, lineScale);
|
||||
|
||||
if(tile != null){
|
||||
Lines.rect(dresult.x, dresult.y, dresult.x2 - dresult.x, dresult.y2 - dresult.y);
|
||||
|
||||
//draw placing
|
||||
if(mode == placing && recipe != null){
|
||||
NormalizeDrawResult dresult = PlaceUtils.normalizeDrawArea(recipe.result, lineStartX, lineStartY, tile.x, tile.y, true, maxLength, lineScale);
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(lineStartX, lineStartY, tileX, tileY, rotation, true, maxLength);
|
||||
|
||||
Lines.rect(dresult.x, dresult.y, dresult.x2 - dresult.x, dresult.y2 - dresult.y);
|
||||
//go through each cell and draw the block to place if valid
|
||||
for(int i = 0; i <= result.getLength(); i += recipe.result.size){
|
||||
int x = lineStartX + i * Mathf.sign(tileX - lineStartX) * Mathf.bool(result.isX());
|
||||
int y = lineStartY + i * Mathf.sign(tileY - lineStartY) * Mathf.bool(!result.isX());
|
||||
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(lineStartX, lineStartY, tile.x, tile.y, rotation, true, maxLength);
|
||||
if(!checkOverlapPlacement(x, y, recipe.result) && validPlace(x, y, recipe.result, result.rotation)){
|
||||
Draw.color();
|
||||
|
||||
//go through each cell and draw the block to place if valid
|
||||
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());
|
||||
TextureRegion[] regions = recipe.result.getBlockIcon();
|
||||
|
||||
if(!checkOverlapPlacement(x, y, recipe.result) && validPlace(x, y, recipe.result, result.rotation)){
|
||||
Draw.color();
|
||||
|
||||
TextureRegion[] regions = recipe.result.getBlockIcon();
|
||||
|
||||
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{
|
||||
Draw.color(Palette.breakInvalid);
|
||||
Lines.square(x * tilesize + recipe.result.offset(), y * tilesize + recipe.result.offset(), recipe.result.size * tilesize / 2f);
|
||||
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{
|
||||
Draw.color(Palette.breakInvalid);
|
||||
Lines.square(x * tilesize + recipe.result.offset(), y * tilesize + recipe.result.offset(), recipe.result.size * tilesize / 2f);
|
||||
}
|
||||
|
||||
}else if(mode == breaking){
|
||||
//draw breaking
|
||||
NormalizeDrawResult result = PlaceUtils.normalizeDrawArea(Blocks.air, lineStartX, lineStartY, tile.x, tile.y, false, maxLength, 1f);
|
||||
NormalizeResult dresult = PlaceUtils.normalizeArea(lineStartX, lineStartY, tile.x, tile.y, rotation, false, maxLength);
|
||||
|
||||
Draw.color(Palette.remove);
|
||||
|
||||
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++){
|
||||
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.rect(result.x, result.y, result.x2 - result.x, result.y2 - result.y);
|
||||
|
||||
}
|
||||
|
||||
}else if(mode == breaking){
|
||||
//draw breaking
|
||||
NormalizeDrawResult result = PlaceUtils.normalizeDrawArea(Blocks.air, lineStartX, lineStartY, tileX, tileY, false, maxLength, 1f);
|
||||
NormalizeResult dresult = PlaceUtils.normalizeArea(lineStartX, lineStartY, tileX, tileY, rotation, false, maxLength);
|
||||
|
||||
Draw.color(Palette.remove);
|
||||
|
||||
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++){
|
||||
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.rect(result.x, result.y, result.x2 - result.x, result.y2 - result.y);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TargetTrait target = player.target;
|
||||
|
|
@ -451,21 +450,20 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
|
||||
//place down a line if in line mode
|
||||
if(lineMode){
|
||||
Tile tile = tileAt(screenX, screenY);
|
||||
|
||||
if(tile == null) return false;
|
||||
int tileX = tileX(screenX);
|
||||
int tileY = tileY(screenY);
|
||||
|
||||
if(mode == placing && recipe != null){
|
||||
|
||||
//normalize area
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(lineStartX, lineStartY, tile.x, tile.y, rotation, true, 100);
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(lineStartX, lineStartY, tileX, tileY, rotation, true, 100);
|
||||
|
||||
rotation = result.rotation;
|
||||
|
||||
//place blocks on line
|
||||
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());
|
||||
int x = lineStartX + i * Mathf.sign(tileX - lineStartX) * Mathf.bool(result.isX());
|
||||
int y = lineStartY + i * Mathf.sign(tileY - lineStartY) * Mathf.bool(!result.isX());
|
||||
|
||||
if(!checkOverlapPlacement(x, y, recipe.result) && validPlace(x, y, recipe.result, result.rotation)){
|
||||
PlaceRequest request = new PlaceRequest(x * tilesize + recipe.result.offset(), y * tilesize + recipe.result.offset(), recipe, result.rotation);
|
||||
|
|
@ -479,13 +477,13 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||
|
||||
}else if(mode == breaking){
|
||||
//normalize area
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(lineStartX, lineStartY, tile.x, tile.y, rotation, false, maxLength);
|
||||
NormalizeResult result = PlaceUtils.normalizeArea(lineStartX, lineStartY, tileX, tileY, 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++){
|
||||
int wx = lineStartX + x * Mathf.sign(tile.x - lineStartX);
|
||||
int wy = lineStartY + y * Mathf.sign(tile.y - lineStartY);
|
||||
int wx = lineStartX + x * Mathf.sign(tileX - lineStartX);
|
||||
int wy = lineStartY + y * Mathf.sign(tileY - lineStartY);
|
||||
|
||||
Tile tar = world.tile(wx, wy);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue