Commandable blocks

This commit is contained in:
Anuken
2022-02-17 16:19:07 -05:00
parent 49a39d42e7
commit 9f3af412f0
12 changed files with 177 additions and 16 deletions

View File

@@ -117,17 +117,12 @@ public class DesktopInput extends InputHandler{
if(commandMode){
//draw command overlay UI
for(Unit unit : selectedUnits){
CommandAI ai = (CommandAI)unit.controller();
CommandAI ai = unit.command();
//draw target line
if(ai.targetPos != null){
Position lineDest = ai.attackTarget != null ? ai.attackTarget : ai.targetPos;
Tmp.v1.set(lineDest).sub(unit).setLength(unit.hitSize / 2f);
Tmp.v2.set(Tmp.v1).scl(-1f).setLength(3.5f);
Drawf.line(Pal.accent, unit.x + Tmp.v1.x, unit.y + Tmp.v1.y, lineDest.getX() + Tmp.v2.x, lineDest.getY() + Tmp.v2.y);
Drawf.limitLine(unit, lineDest, unit.hitSize / 2f, 3.5f);
if(ai.attackTarget == null){
Drawf.square(lineDest.getX(), lineDest.getY(), 3.5f);
@@ -141,6 +136,16 @@ public class DesktopInput extends InputHandler{
}
}
if(commandBuild != null){
Drawf.square(commandBuild.x, commandBuild.y, commandBuild.hitSize() / 1.4f + 1f);
var cpos = commandBuild.getCommandPosition();
if(cpos != null){
Drawf.limitLine(commandBuild, cpos, commandBuild.hitSize() / 2f, 3.5f);
Drawf.square(cpos.x, cpos.y, 3.5f);
}
}
if(commandMode && !commandRect){
Unit sel = selectedCommandUnit(input.mouseWorldX(), input.mouseWorldY());
@@ -564,6 +569,7 @@ public class DesktopInput extends InputHandler{
selectedUnits.clear();
}
selectedUnits.addAll(units);
commandBuild = null;
}
commandRect = false;
}
@@ -698,6 +704,7 @@ 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);
@@ -705,16 +712,24 @@ public class DesktopInput extends InputHandler{
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;
}
}
}else if(button == KeyCode.mouseRight){
//right click: move to position
//move to location - TODO right click instead?
Vec2 target = input.mouseWorld().cpy();
if(selectedUnits.size > 0){
//move to location - TODO right click instead?
Vec2 target = input.mouseWorld().cpy();
Teamc attack = world.buildWorld(target.x, target.y);
@@ -729,6 +744,10 @@ public class DesktopInput extends InputHandler{
Call.commandUnits(player, ids, attack instanceof Building b ? b : null, attack instanceof Unit u ? u : null, target);
}
if(commandBuild != null){
Call.commandBuilding(player, commandBuild, target);
}
}
return super.tap(x, y, count, button);

View File

@@ -80,6 +80,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
//for RTS controls
public Seq<Unit> selectedUnits = new Seq<>();
public @Nullable Building commandBuild;
public boolean commandMode = false;
public boolean commandRect = false;
public boolean tappedOne = false;
@@ -228,6 +229,20 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
}
@Remote(called = Loc.server, targets = Loc.both, forward = true)
public static void commandBuilding(Player player, Building build, Vec2 target){
if(player == null || build == null || build.team != player.team() || !build.block.commandable || target == null) return;
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);
Fx.moveCommand.at(target);
}
@Remote(called = Loc.server, targets = Loc.both, forward = true)
public static void requestItem(Player player, Building build, Item item, int amount){
if(player == null || build == null || !build.interactable(player.team()) || !player.within(build, buildingRange) || player.dead()) return;
@@ -1062,12 +1077,16 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(build == null){
frag.inv.hide();
frag.config.hideConfig();
commandBuild = null;
return false;
}
boolean consumed = false, showedInventory = false;
//check if tapped block is configurable
if(build.block.configurable && build.interactable(player.team())){
//select building for commanding
if(build.block.commandable && commandMode){
//TODO handled in tap.
consumed = true;
}else if(build.block.configurable && build.interactable(player.team())){ //check if tapped block is configurable
consumed = true;
if((!frag.config.isShown() && build.shouldShowConfigure(player)) //if the config fragment is hidden, show
//alternatively, the current selected block can 'agree' to switch config tiles