Support for selecting multiple buildings to command
This commit is contained in:
@@ -82,7 +82,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
|
|
||||||
//for RTS controls
|
//for RTS controls
|
||||||
public Seq<Unit> selectedUnits = new Seq<>();
|
public Seq<Unit> selectedUnits = new Seq<>();
|
||||||
public @Nullable Building commandBuild;
|
public Seq<Building> commandBuildings = new Seq<>(false);
|
||||||
public boolean commandMode = false;
|
public boolean commandMode = false;
|
||||||
public boolean commandRect = false;
|
public boolean commandRect = false;
|
||||||
public boolean tappedOne = false;
|
public boolean tappedOne = false;
|
||||||
@@ -279,21 +279,28 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Remote(called = Loc.server, targets = Loc.both, forward = true)
|
@Remote(called = Loc.server, targets = Loc.both, forward = true)
|
||||||
public static void commandBuilding(Player player, Building build, Vec2 target){
|
public static void commandBuilding(Player player, int[] buildings, Vec2 target){
|
||||||
if(player == null || build == null || build.team != player.team() || !build.block.commandable || target == null) return;
|
if(player == null || target == null) return;
|
||||||
|
|
||||||
if(net.server() && !netServer.admins.allowAction(player, ActionType.commandBuilding, event -> {
|
for(int pos : buildings){
|
||||||
event.tile = build.tile;
|
var build = world.build(pos);
|
||||||
})){
|
|
||||||
throw new ValidateException(player, "Player cannot command building.");
|
if(build == null || build.team() != player.team() || !build.block.commandable) continue;
|
||||||
|
|
||||||
|
if(net.server() && !netServer.admins.allowAction(player, ActionType.commandBuilding, event -> {
|
||||||
|
event.tile = build.tile;
|
||||||
|
})){
|
||||||
|
throw new ValidateException(player, "Player cannot command building.");
|
||||||
|
}
|
||||||
|
|
||||||
|
build.onCommand(target);
|
||||||
|
if(!state.isPaused() && player == Vars.player){
|
||||||
|
Fx.moveCommand.at(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
Events.fire(new BuildingCommandEvent(player, build, target));
|
||||||
}
|
}
|
||||||
|
|
||||||
build.onCommand(target);
|
|
||||||
if(!state.isPaused() && player == Vars.player){
|
|
||||||
Fx.moveCommand.at(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
Events.fire(new BuildingCommandEvent(player, build, target));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(called = Loc.server, targets = Loc.both, forward = true)
|
@Remote(called = Loc.server, targets = Loc.both, forward = true)
|
||||||
@@ -633,9 +640,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
logicCutsceneZoom = -1f;
|
logicCutsceneZoom = -1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(commandBuild != null && !commandBuild.isValid()){
|
commandBuildings.removeAll(b -> !b.isValid());
|
||||||
commandBuild = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!commandMode){
|
if(!commandMode){
|
||||||
commandRect = false;
|
commandRect = false;
|
||||||
@@ -768,7 +773,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
selectedUnits.addAll(units);
|
selectedUnits.addAll(units);
|
||||||
Events.fire(Trigger.unitCommandChange);
|
Events.fire(Trigger.unitCommandChange);
|
||||||
commandBuild = null;
|
commandBuildings.clear();
|
||||||
}
|
}
|
||||||
commandRect = false;
|
commandRect = false;
|
||||||
}
|
}
|
||||||
@@ -797,15 +802,20 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}else{
|
}else{
|
||||||
selectedUnits.remove(unit);
|
selectedUnits.remove(unit);
|
||||||
}
|
}
|
||||||
commandBuild = null;
|
commandBuildings.clear();
|
||||||
}else{
|
}else{
|
||||||
//deselect
|
//deselect
|
||||||
selectedUnits.clear();
|
selectedUnits.clear();
|
||||||
|
|
||||||
if(build != null && build.team == player.team() && build.block.commandable){
|
if(build != null && build.team == player.team() && build.block.commandable){
|
||||||
commandBuild = (commandBuild == build ? null : build);
|
if(commandBuildings.contains(build)){
|
||||||
|
commandBuildings.remove(build);
|
||||||
|
}else{
|
||||||
|
commandBuildings.add(build);
|
||||||
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
commandBuild = null;
|
commandBuildings.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Events.fire(Trigger.unitCommandChange);
|
Events.fire(Trigger.unitCommandChange);
|
||||||
@@ -839,8 +849,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
Call.commandUnits(player, ids, attack instanceof Building b ? b : null, attack instanceof Unit u ? u : null, target);
|
Call.commandUnits(player, ids, attack instanceof Building b ? b : null, attack instanceof Unit u ? u : null, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(commandBuild != null){
|
if(commandBuildings.size > 0){
|
||||||
Call.commandBuilding(player, commandBuild, target);
|
Call.commandBuilding(player, commandBuildings.mapInt(b -> b.pos()).toArray(), target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -875,13 +885,15 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(commandBuild != null){
|
for(var commandBuild : commandBuildings){
|
||||||
Drawf.square(commandBuild.x, commandBuild.y, commandBuild.hitSize() / 1.4f + 1f);
|
if(commandBuild != null){
|
||||||
var cpos = commandBuild.getCommandPosition();
|
Drawf.square(commandBuild.x, commandBuild.y, commandBuild.hitSize() / 1.4f + 1f);
|
||||||
|
var cpos = commandBuild.getCommandPosition();
|
||||||
|
|
||||||
if(cpos != null){
|
if(cpos != null){
|
||||||
Drawf.limitLine(commandBuild, cpos, commandBuild.hitSize() / 2f, 3.5f);
|
Drawf.limitLine(commandBuild, cpos, commandBuild.hitSize() / 2f, 3.5f);
|
||||||
Drawf.square(cpos.x, cpos.y, 3.5f);
|
Drawf.square(cpos.x, cpos.y, 3.5f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1334,7 +1346,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
if(build == null){
|
if(build == null){
|
||||||
inv.hide();
|
inv.hide();
|
||||||
config.hideConfig();
|
config.hideConfig();
|
||||||
commandBuild = null;
|
commandBuildings.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean consumed = false, showedInventory = false;
|
boolean consumed = false, showedInventory = false;
|
||||||
|
|||||||
@@ -646,7 +646,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||||||
}else if(mode == breaking && validBreak(linked.x,linked.y) && !hasPlan(linked)){
|
}else if(mode == breaking && validBreak(linked.x,linked.y) && !hasPlan(linked)){
|
||||||
//add to selection queue if it's a valid BREAK position
|
//add to selection queue if it's a valid BREAK position
|
||||||
selectPlans.add(new BuildPlan(linked.x, linked.y));
|
selectPlans.add(new BuildPlan(linked.x, linked.y));
|
||||||
}else if((commandMode && selectedUnits.size > 0) || commandBuild != null){
|
}else if((commandMode && selectedUnits.size > 0) || commandBuildings.size > 0){
|
||||||
//handle selecting units with command mode
|
//handle selecting units with command mode
|
||||||
commandTap(x, y);
|
commandTap(x, y);
|
||||||
}else if(commandMode){
|
}else if(commandMode){
|
||||||
@@ -715,7 +715,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||||||
selectedUnits.removeAll(u -> !u.isCommandable() || !u.isValid());
|
selectedUnits.removeAll(u -> !u.isCommandable() || !u.isValid());
|
||||||
|
|
||||||
if(!commandMode){
|
if(!commandMode){
|
||||||
commandBuild = null;
|
commandBuildings.clear();
|
||||||
selectedUnits.clear();
|
selectedUnits.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user