RTS unit control improvements/fixes
This commit is contained in:
@@ -242,7 +242,11 @@ public class DesktopInput extends InputHandler{
|
||||
if(!locked && block == null && !scene.hasField() &&
|
||||
//disable command mode when player unit can boost and command mode binding is the same
|
||||
!(!player.dead() && player.unit().type.canBoost && keybinds.get(Binding.command_mode).key == keybinds.get(Binding.boost).key)){
|
||||
commandMode = input.keyDown(Binding.command_mode);
|
||||
if(settings.getBool("commandmodehold")){
|
||||
commandMode = input.keyDown(Binding.command_mode);
|
||||
}else if(input.keyTap(Binding.command_mode)){
|
||||
commandMode = !commandMode;
|
||||
}
|
||||
}else{
|
||||
commandMode = false;
|
||||
}
|
||||
@@ -652,26 +656,12 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
//click: select a single unit
|
||||
if(button == KeyCode.mouseLeft){
|
||||
Unit unit = selectedCommandUnit(input.mouseWorldX(), input.mouseWorldY());
|
||||
Building build = world.buildWorld(input.mouseWorldX(), input.mouseWorldY());
|
||||
if(unit != null){
|
||||
if(selectedUnits.contains(unit)){
|
||||
selectedUnits.remove(unit);
|
||||
}else{
|
||||
selectedUnits.clear();
|
||||
selectedUnits.add(unit);
|
||||
}
|
||||
commandBuild = null;
|
||||
if(count >= 2){
|
||||
selectTypedUnits();
|
||||
}else{
|
||||
//deselect
|
||||
selectedUnits.clear();
|
||||
|
||||
if(build != null && build.team == player.team() && build.block.commandable){
|
||||
commandBuild = (commandBuild == build ? null : build);
|
||||
}else{
|
||||
commandBuild = null;
|
||||
}
|
||||
tapCommandUnit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return super.tap(x, y, count, button);
|
||||
|
||||
@@ -725,6 +725,43 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
}
|
||||
}
|
||||
|
||||
public void selectTypedUnits(){
|
||||
if(commandMode){
|
||||
Unit unit = selectedCommandUnit(input.mouseWorldX(), input.mouseWorldY());
|
||||
if(unit != null){
|
||||
selectedUnits.clear();
|
||||
camera.bounds(Tmp.r1);
|
||||
selectedUnits.addAll(selectedCommandUnits(Tmp.r1.x, Tmp.r1.y, Tmp.r1.width, Tmp.r1.height, u -> u.type == unit.type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void tapCommandUnit(){
|
||||
if(commandMode){
|
||||
|
||||
Unit unit = selectedCommandUnit(input.mouseWorldX(), input.mouseWorldY());
|
||||
Building build = world.buildWorld(input.mouseWorldX(), input.mouseWorldY());
|
||||
if(unit != null){
|
||||
if(selectedUnits.contains(unit)){
|
||||
selectedUnits.remove(unit);
|
||||
}else{
|
||||
selectedUnits.clear();
|
||||
selectedUnits.add(unit);
|
||||
}
|
||||
commandBuild = null;
|
||||
}else{
|
||||
//deselect
|
||||
selectedUnits.clear();
|
||||
|
||||
if(build != null && build.team == player.team() && build.block.commandable){
|
||||
commandBuild = (commandBuild == build ? null : build);
|
||||
}else{
|
||||
commandBuild = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void commandTap(float screenX, float screenY){
|
||||
if(commandMode){
|
||||
//right click: move to position
|
||||
@@ -1434,15 +1471,19 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
return tmpUnits.min(u -> !u.inFogTo(player.team()), u -> u.dst(x, y) - u.hitSize/2f);
|
||||
}
|
||||
|
||||
public Seq<Unit> selectedCommandUnits(float x, float y, float w, float h){
|
||||
public Seq<Unit> selectedCommandUnits(float x, float y, float w, float h, Boolf<Unit> predicate){
|
||||
var tree = player.team().data().tree();
|
||||
tmpUnits.clear();
|
||||
float rad = 4f;
|
||||
tree.intersect(Tmp.r1.set(x - rad/2f, y - rad/2f, rad*2f + w, rad*2f + h).normalize(), tmpUnits);
|
||||
tmpUnits.removeAll(u -> !u.isCommandable());
|
||||
tmpUnits.removeAll(u -> !u.isCommandable() || !predicate.get(u));
|
||||
return tmpUnits;
|
||||
}
|
||||
|
||||
public Seq<Unit> selectedCommandUnits(float x, float y, float w, float h){
|
||||
return selectedCommandUnits(x, y, w, h, u -> true);
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
Core.input.removeProcessor(this);
|
||||
group.remove();
|
||||
|
||||
@@ -649,6 +649,8 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}else if(commandMode && selectedUnits.size > 0){
|
||||
//handle selecting units with command mode
|
||||
commandTap(x, y);
|
||||
}else if(commandMode){
|
||||
tapCommandUnit();
|
||||
}else{
|
||||
//control units
|
||||
if(count == 2){
|
||||
|
||||
Reference in New Issue
Block a user