mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-13 11:29:48 +07:00
Some mobile fixes
This commit is contained in:
parent
9fdc4a2c45
commit
a2dfa6368d
@ -303,6 +303,14 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
Lines.rect(result.x, result.y, result.x2 - result.x, result.y2 - result.y);
|
||||
}
|
||||
|
||||
protected void flushSelectRequests(Array<BuildRequest> requests){
|
||||
for(BuildRequest req : requests){
|
||||
if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){
|
||||
selectRequests.add(req);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void flushRequests(Array<BuildRequest> requests){
|
||||
for(BuildRequest req : requests){
|
||||
if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){
|
||||
@ -354,14 +362,18 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateLine(int selectX, int selectY){
|
||||
protected void updateLine(int x1, int y1, int x2, int y2){
|
||||
lineRequests.clear();
|
||||
iterateLine(selectX, selectY, tileX(getMouseX()), tileY(getMouseY()), l -> {
|
||||
iterateLine(x1, y1, x2, y2, l -> {
|
||||
rotation = l.rotation;
|
||||
lineRequests.add(new BuildRequest(l.x, l.y, l.rotation, block));
|
||||
});
|
||||
}
|
||||
|
||||
protected void updateLine(int x1, int y1){
|
||||
updateLine(x1, y1, tileX(getMouseX()), tileY(getMouseY()));
|
||||
}
|
||||
|
||||
/** Handles tile tap events that are not platform specific. */
|
||||
boolean tileTapped(Tile tile){
|
||||
tile = tile.link();
|
||||
|
@ -37,7 +37,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
private float lastZoom = -1;
|
||||
|
||||
/** Position where the player started dragging a line. */
|
||||
private int lineStartX, lineStartY;
|
||||
private int lineStartX, lineStartY, lastLineX, lastLineY;
|
||||
|
||||
/** Animation scale for line. */
|
||||
private float lineScale;
|
||||
@ -227,11 +227,6 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDrawing(){
|
||||
return selectRequests.size > 0 || removals.size > 0 || lineMode || player.target != null || mode != PlaceMode.none;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlacing(){
|
||||
return super.isPlacing() && mode == placing;
|
||||
@ -293,19 +288,16 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
int tileX = tileX(Core.input.mouseX());
|
||||
int tileY = tileY(Core.input.mouseY());
|
||||
|
||||
/*if(mode == placing && block != null){
|
||||
if(mode == placing && block != null){
|
||||
//draw placing
|
||||
|
||||
iterateLine(lineStartX, lineStartY, tileX, tileY, l -> {
|
||||
if(l.last && block.rotate){
|
||||
drawArrow(block, l.x, l.y, l.rotation);
|
||||
for(int i = 0; i < lineRequests.size; i++){
|
||||
BuildRequest req = lineRequests.get(i);
|
||||
if(i == lineRequests.size - 1 && req.block.rotate){
|
||||
drawArrow(block, req.x, req.y, req.rotation);
|
||||
}
|
||||
drawRequest(l.x, l.y, block, l.rotation);
|
||||
|
||||
rotation = l.rotation;
|
||||
});
|
||||
}else */
|
||||
if(mode == breaking){
|
||||
drawRequest(lineRequests.get(i));
|
||||
}
|
||||
}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);
|
||||
@ -398,16 +390,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
int tileY = tileY(screenY);
|
||||
|
||||
if(mode == placing && isPlacing()){
|
||||
iterateLine(lineStartX, lineStartY, tileX, tileY, l -> {
|
||||
Tile tile = world.tile(l.x, l.y);
|
||||
if(tile != null && checkOverlapPlacement(tile.x, tile.y, block)){
|
||||
return;
|
||||
}
|
||||
|
||||
BuildRequest request = new BuildRequest(l.x, l.y, l.rotation, block);
|
||||
request.animScale = 1f;
|
||||
selectRequests.add(request);
|
||||
});
|
||||
flushSelectRequests(lineRequests);
|
||||
Events.fire(new LineConfirmEvent());
|
||||
}else if(mode == breaking){
|
||||
//normalize area
|
||||
@ -457,6 +440,9 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
//long pressing enables line mode otherwise
|
||||
lineStartX = cursor.x;
|
||||
lineStartY = cursor.y;
|
||||
lastLineX = cursor.x;
|
||||
lastLineY = cursor.y;
|
||||
updateLine(lineStartX, lineStartY, cursor.x, cursor.y);
|
||||
lineMode = true;
|
||||
|
||||
if(mode == breaking){
|
||||
@ -559,7 +545,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
lineScale = Mathf.lerpDelta(lineScale, 1f, 0.1f);
|
||||
|
||||
//When in line mode, pan when near screen edges automatically
|
||||
if(Core.input.isTouched(0) && lineMode){
|
||||
if(Core.input.isTouched(0)){
|
||||
float screenX = Core.input.mouseX(), screenY = Core.input.mouseY();
|
||||
|
||||
float panX = 0, panY = 0;
|
||||
@ -587,7 +573,16 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
Core.camera.position.x += vector.x;
|
||||
Core.camera.position.y += vector.y;
|
||||
}
|
||||
|
||||
int lx = tileX(Core.input.mouseX()), ly = tileY(Core.input.mouseY());
|
||||
|
||||
if(lastLineX != lx || lastLineY != ly){
|
||||
lastLineX = lx;
|
||||
lastLineY = ly;
|
||||
updateLine(lineStartX, lineStartY, lx, ly);
|
||||
}
|
||||
}else{
|
||||
lineRequests.clear();
|
||||
lineScale = 0f;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=92070bb15802eb8a37b9c0734caffc6fecb557fc
|
||||
archash=c4556cc2ecff581d9c0e06f826bc10e7cacbabd0
|
||||
|
Loading…
Reference in New Issue
Block a user