Multi-building command selection

This commit is contained in:
Anuken
2025-07-27 00:50:10 -04:00
parent 57ae1b3ec1
commit 0aa1bd7df9
3 changed files with 32 additions and 4 deletions

View File

@@ -62,6 +62,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
final static int maxLength = 100;
final static Rect r1 = new Rect(), r2 = new Rect();
final static Seq<Unit> tmpUnits = new Seq<>(false);
final static Seq<Building> tmpBuildings = new Seq<>(false);
final static KeyBind[] controlGroupBindings = {
Binding.blockSelect01,
Binding.blockSelect02,
@@ -995,9 +996,13 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
//nothing selected, clear units
selectedUnits.clear();
}
selectedUnits.addAll(units);
Events.fire(Trigger.unitCommandChange);
commandBuildings.clear();
selectedUnits.addAll(units);
if(selectedUnits.isEmpty()){
commandBuildings.addAll(selectedCommandBuildings(commandRectX, commandRectY, input.mouseWorldX() - commandRectX, input.mouseWorldY() - commandRectY));
}
Events.fire(Trigger.unitCommandChange);
}
commandRect = false;
}
@@ -1098,6 +1103,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
Drawf.poly(sel.x, sel.y, 6, sel.hitSize / unitSelectRadScl + Mathf.absin(4f, 1f), 0f, selectedUnits.contains(sel) ? Pal.remove : Pal.accent);
}
public void drawCommand(Building build){
Drawf.poly(build.x, build.y, 4, build.hitSize() / 1.4f + + 0.5f + Mathf.absin(4f, 1f), 0f, commandBuildings.contains(build) ? Pal.remove : Pal.accent);
}
public void drawCommanded(){
Draw.draw(Layer.plans, () -> {
drawCommanded(true);
@@ -1234,6 +1243,12 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
for(var unit : units){
drawCommand(unit);
}
if(units.isEmpty()){
var buildings = selectedCommandBuildings(commandRectX, commandRectY, x2 - commandRectX, y2 - commandRectY);
for(var build : buildings){
drawCommand(build);
}
}
Draw.color(Pal.accent, 0.3f);
Fill.crect(commandRectX, commandRectY, x2 - commandRectX, y2 - commandRectY);
@@ -1967,6 +1982,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<Building> selectedCommandBuildings(float x, float y, float w, float h){
var tree = player.team().data().buildingTree;
tmpBuildings.clear();
if(tree == null) return tmpBuildings;
float rad = 4f;
tree.intersect(Tmp.r1.set(x - rad/2f, y - rad/2f, rad*2f + w, rad*2f + h).normalize(), b -> {
if(b.isCommandable()){
tmpBuildings.add(b);
}
});
return tmpBuildings;
}
public Seq<Unit> selectedCommandUnits(float x, float y, float w, float h, Boolf<Unit> predicate){
var tree = player.team().data().tree();
tmpUnits.clear();

View File

@@ -190,7 +190,7 @@ public class ColoredFloor extends Floor{
@Override
public boolean checkAutotileSame(Tile tile, @Nullable Tile other){
return other != null && other.floor().blendGroup == blendGroup && ((tile.extraData & 0xff) == flagIgnoreDifferentColor || tile.extraData == other.extraData);
return other != null && (this == tile.floor() ? other.floor() : other.overlay()).blendGroup == blendGroup && ((tile.extraData & 0xff) == flagIgnoreDifferentColor || tile.extraData == other.extraData);
}
@Override

View File

@@ -265,7 +265,7 @@ public class Floor extends Block{
}
public boolean checkAutotileSame(Tile tile, @Nullable Tile other){
return other != null && other.floor().blendGroup == blendGroup;
return other != null && (this == tile.floor() ? other.floor() : other.overlay()).blendGroup == blendGroup;
}
public int variant(int x, int y){