RTS unit control improvements/fixes

This commit is contained in:
Anuken
2022-05-08 12:45:48 -04:00
parent 61b01892e7
commit d28a839f55
7 changed files with 61 additions and 22 deletions

View File

@@ -374,6 +374,10 @@ public class ErekirTechTree{
});
nodeProduce(Liquids.arkycite, () -> {
});
nodeProduce(Items.thorium, () -> {
nodeProduce(Items.carbide, () -> {
nodeProduce(Items.surgeAlloy, () -> {

View File

@@ -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);

View File

@@ -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();

View File

@@ -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){

View File

@@ -58,7 +58,7 @@ public class CrashSender{
}catch(Throwable ignored){}
//don't create crash logs for custom builds, as it's expected
if(Version.build == -1 || (OS.username.equals("anuke") && !"steam".equals(Version.modifier))){
if(OS.username.equals("anuke") && !"steam".equals(Version.modifier)){
ret();
}

View File

@@ -315,6 +315,7 @@ public class SettingsMenuDialog extends BaseDialog{
}
game.checkPref("doubletapmine", false);
game.checkPref("commandmodehold", false);
if(!ios){
game.checkPref("modcrashdisable", true);