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:
@@ -800,6 +800,7 @@ setting.logichints.name = Logic Hints
|
|||||||
setting.flow.name = Display Resource Flow Rate
|
setting.flow.name = Display Resource Flow Rate
|
||||||
setting.backgroundpause.name = Pause In Background
|
setting.backgroundpause.name = Pause In Background
|
||||||
setting.buildautopause.name = Auto-Pause Building
|
setting.buildautopause.name = Auto-Pause Building
|
||||||
|
setting.doubletapmine.name = Double-Tap to Mine
|
||||||
setting.modcrashdisable.name = Disable Mods On Startup Crash
|
setting.modcrashdisable.name = Disable Mods On Startup Crash
|
||||||
setting.animatedwater.name = Animated Surfaces
|
setting.animatedwater.name = Animated Surfaces
|
||||||
setting.animatedshields.name = Animated Shields
|
setting.animatedshields.name = Animated Shields
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ public class DesktopInput extends InputHandler{
|
|||||||
public boolean deleting = false, shouldShoot = false, panning = false;
|
public boolean deleting = false, shouldShoot = false, panning = false;
|
||||||
/** Mouse pan speed. */
|
/** Mouse pan speed. */
|
||||||
public float panScale = 0.005f, panSpeed = 4.5f, panBoostSpeed = 11f;
|
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(){
|
boolean showHint(){
|
||||||
return ui.hudfrag.shown && Core.settings.getBool("hints") && selectRequests.isEmpty() &&
|
return ui.hudfrag.shown && Core.settings.getBool("hints") && selectRequests.isEmpty() &&
|
||||||
@@ -487,15 +491,19 @@ public class DesktopInput extends InputHandler{
|
|||||||
sreq = req;
|
sreq = req;
|
||||||
}else if(req != null && req.breaking){
|
}else if(req != null && req.breaking){
|
||||||
deleting = true;
|
deleting = true;
|
||||||
|
}else if(Core.settings.getBool("doubletapmine") && selected == prevSelected && Time.timeSinceMillis(selectMillis) < 500){
|
||||||
|
tryBeginMine(selected);
|
||||||
}else if(selected != null){
|
}else if(selected != null){
|
||||||
//only begin shooting if there's no cursor event
|
//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 &&
|
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()){
|
&& (Core.settings.getBool("doubletapmine") ? !tryStopMine(selected) : !tryBeginMine(selected)) && !Core.scene.hasKeyboard()){
|
||||||
player.shooting = shouldShoot;
|
player.shooting = shouldShoot;
|
||||||
}
|
}
|
||||||
}else if(!Core.scene.hasKeyboard()){ //if it's out of bounds, shooting is just fine
|
}else if(!Core.scene.hasKeyboard()){ //if it's out of bounds, shooting is just fine
|
||||||
player.shooting = shouldShoot;
|
player.shooting = shouldShoot;
|
||||||
}
|
}
|
||||||
|
selectMillis = Time.millis();
|
||||||
|
prevSelected = selected;
|
||||||
}else if(Core.input.keyTap(Binding.deselect) && isPlacing()){
|
}else if(Core.input.keyTap(Binding.deselect) && isPlacing()){
|
||||||
block = null;
|
block = null;
|
||||||
mode = none;
|
mode = none;
|
||||||
|
|||||||
@@ -955,6 +955,23 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
return false;
|
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){
|
boolean canMine(Tile tile){
|
||||||
return !Core.scene.hasMouse()
|
return !Core.scene.hasMouse()
|
||||||
&& tile.drop() != null
|
&& tile.drop() != null
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||||||
public Teamc target;
|
public Teamc target;
|
||||||
/** Payload target being moved to. Can be a position (for dropping), or a unit/block. */
|
/** Payload target being moved to. Can be a position (for dropping), or a unit/block. */
|
||||||
public Position payloadTarget;
|
public Position payloadTarget;
|
||||||
|
/** Unit last tapped, or null if last tap was not on a unit. */
|
||||||
|
public Unit unitTapped;
|
||||||
|
|
||||||
//region utility methods
|
//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
|
//add to selection queue if it's a valid BREAK position
|
||||||
selectRequests.add(new BuildPlan(linked.x, linked.y));
|
selectRequests.add(new BuildPlan(linked.x, linked.y));
|
||||||
}else{
|
}else{
|
||||||
if(!canTapPlayer(worldx, worldy) && !tileTapped(linked.build)){
|
//control units
|
||||||
tryBeginMine(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
//control units.
|
|
||||||
if(count == 2){
|
if(count == 2){
|
||||||
//reset payload target
|
//reset payload target
|
||||||
payloadTarget = null;
|
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){
|
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);
|
Call.unitCommand(player);
|
||||||
}else{
|
}else{
|
||||||
//control a unit/block
|
//control a unit/block detected on first tap of double-tap
|
||||||
Unit on = selectedUnit();
|
if(unitTapped != null){
|
||||||
if(on != null){
|
Call.unitControl(player, unitTapped);
|
||||||
Call.unitControl(player, on);
|
}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("buildautopause", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
game.checkPref("doubletapmine", false);
|
||||||
|
|
||||||
if(!ios){
|
if(!ios){
|
||||||
game.checkPref("modcrashdisable", true);
|
game.checkPref("modcrashdisable", true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user