Double-tap to mine, tap anywhere to cancel (#4469)
* Double-tap to mine, tap anywhere to cancel * Make comment consistent * Remove desktop left-click mining cancel, prioritize mobile unit control over mining * Mobile: double-tap doesn't configure blocks if unit was double-tapped; control unit detected in first tap of double-tap * Add 'double-tap to mine' setting (default off) * Desktop: cancel mining when mined tile is clicked * Comment typo * Prevent redundant condition check * Cleanup Co-authored-by: Anuken <arnukren@gmail.com>
This commit is contained in:
@@ -44,6 +44,10 @@ public class DesktopInput extends InputHandler{
|
||||
public boolean deleting = false, shouldShoot = false, panning = false;
|
||||
/** Mouse pan speed. */
|
||||
public float panScale = 0.005f, panSpeed = 4.5f, panBoostSpeed = 11f;
|
||||
/** Delta time between consecutive clicks. */
|
||||
public long selectMillis = 0;
|
||||
/** Previously selected tile. */
|
||||
public Tile prevSelected;
|
||||
|
||||
boolean showHint(){
|
||||
return ui.hudfrag.shown && Core.settings.getBool("hints") && selectRequests.isEmpty() &&
|
||||
@@ -487,15 +491,19 @@ public class DesktopInput extends InputHandler{
|
||||
sreq = req;
|
||||
}else if(req != null && req.breaking){
|
||||
deleting = true;
|
||||
}else if(Core.settings.getBool("doubletapmine") && selected == prevSelected && Time.timeSinceMillis(selectMillis) < 500){
|
||||
tryBeginMine(selected);
|
||||
}else if(selected != null){
|
||||
//only begin shooting if there's no cursor event
|
||||
if(!tryTapPlayer(Core.input.mouseWorld().x, Core.input.mouseWorld().y) && !tileTapped(selected.build) && !player.unit().activelyBuilding() && !droppingItem &&
|
||||
!tryBeginMine(selected) && player.unit().mineTile == null && !Core.scene.hasKeyboard()){
|
||||
if(!tryTapPlayer(Core.input.mouseWorld().x, Core.input.mouseWorld().y) && !tileTapped(selected.build) && !player.unit().activelyBuilding() && !droppingItem
|
||||
&& (Core.settings.getBool("doubletapmine") ? !tryStopMine(selected) : !tryBeginMine(selected)) && !Core.scene.hasKeyboard()){
|
||||
player.shooting = shouldShoot;
|
||||
}
|
||||
}else if(!Core.scene.hasKeyboard()){ //if it's out of bounds, shooting is just fine
|
||||
player.shooting = shouldShoot;
|
||||
}
|
||||
selectMillis = Time.millis();
|
||||
prevSelected = selected;
|
||||
}else if(Core.input.keyTap(Binding.deselect) && isPlacing()){
|
||||
block = null;
|
||||
mode = none;
|
||||
|
||||
@@ -955,6 +955,23 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Tries to stop mining, returns true if mining was stopped. */
|
||||
boolean tryStopMine(){
|
||||
if(player.unit().mining()){
|
||||
player.unit().mineTile = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean tryStopMine(Tile tile){
|
||||
if(player.unit().mineTile == tile){
|
||||
player.unit().mineTile = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean canMine(Tile tile){
|
||||
return !Core.scene.hasMouse()
|
||||
&& tile.drop() != null
|
||||
|
||||
@@ -71,6 +71,8 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
public Teamc target;
|
||||
/** Payload target being moved to. Can be a position (for dropping), or a unit/block. */
|
||||
public Position payloadTarget;
|
||||
/** Unit last tapped, or null if last tap was not on a unit. */
|
||||
public Unit unitTapped;
|
||||
|
||||
//region utility methods
|
||||
|
||||
@@ -599,11 +601,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
//add to selection queue if it's a valid BREAK position
|
||||
selectRequests.add(new BuildPlan(linked.x, linked.y));
|
||||
}else{
|
||||
if(!canTapPlayer(worldx, worldy) && !tileTapped(linked.build)){
|
||||
tryBeginMine(cursor);
|
||||
}
|
||||
|
||||
//control units.
|
||||
//control units
|
||||
if(count == 2){
|
||||
//reset payload target
|
||||
payloadTarget = null;
|
||||
@@ -611,12 +609,20 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
if(!player.dead() && Mathf.within(worldx, worldy, player.unit().x, player.unit().y, player.unit().hitSize * 0.6f + 8f) && player.unit().type.commandLimit > 0){
|
||||
Call.unitCommand(player);
|
||||
}else{
|
||||
//control a unit/block
|
||||
Unit on = selectedUnit();
|
||||
if(on != null){
|
||||
Call.unitControl(player, on);
|
||||
//control a unit/block detected on first tap of double-tap
|
||||
if(unitTapped != null){
|
||||
Call.unitControl(player, unitTapped);
|
||||
}else if(!tryBeginMine(cursor)){
|
||||
tileTapped(linked.build);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
unitTapped = selectedUnit();
|
||||
//prevent mining if placing/breaking blocks
|
||||
if(!tryStopMine() && !canTapPlayer(worldx, worldy) && !tileTapped(linked.build) && mode == none && !Core.settings.getBool("doubletapmine")){
|
||||
tryBeginMine(cursor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -327,6 +327,8 @@ public class SettingsMenuDialog extends SettingsDialog{
|
||||
game.checkPref("buildautopause", false);
|
||||
}
|
||||
|
||||
game.checkPref("doubletapmine", false);
|
||||
|
||||
if(!ios){
|
||||
game.checkPref("modcrashdisable", true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user