Multi-building command selection
This commit is contained in:
@@ -62,6 +62,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
final static int maxLength = 100;
|
final static int maxLength = 100;
|
||||||
final static Rect r1 = new Rect(), r2 = new Rect();
|
final static Rect r1 = new Rect(), r2 = new Rect();
|
||||||
final static Seq<Unit> tmpUnits = new Seq<>(false);
|
final static Seq<Unit> tmpUnits = new Seq<>(false);
|
||||||
|
final static Seq<Building> tmpBuildings = new Seq<>(false);
|
||||||
final static KeyBind[] controlGroupBindings = {
|
final static KeyBind[] controlGroupBindings = {
|
||||||
Binding.blockSelect01,
|
Binding.blockSelect01,
|
||||||
Binding.blockSelect02,
|
Binding.blockSelect02,
|
||||||
@@ -995,9 +996,13 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
//nothing selected, clear units
|
//nothing selected, clear units
|
||||||
selectedUnits.clear();
|
selectedUnits.clear();
|
||||||
}
|
}
|
||||||
selectedUnits.addAll(units);
|
|
||||||
Events.fire(Trigger.unitCommandChange);
|
|
||||||
commandBuildings.clear();
|
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;
|
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);
|
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(){
|
public void drawCommanded(){
|
||||||
Draw.draw(Layer.plans, () -> {
|
Draw.draw(Layer.plans, () -> {
|
||||||
drawCommanded(true);
|
drawCommanded(true);
|
||||||
@@ -1234,6 +1243,12 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
for(var unit : units){
|
for(var unit : units){
|
||||||
drawCommand(unit);
|
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);
|
Draw.color(Pal.accent, 0.3f);
|
||||||
Fill.crect(commandRectX, commandRectY, x2 - commandRectX, y2 - commandRectY);
|
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);
|
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){
|
public Seq<Unit> selectedCommandUnits(float x, float y, float w, float h, Boolf<Unit> predicate){
|
||||||
var tree = player.team().data().tree();
|
var tree = player.team().data().tree();
|
||||||
tmpUnits.clear();
|
tmpUnits.clear();
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ public class ColoredFloor extends Floor{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkAutotileSame(Tile tile, @Nullable Tile other){
|
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
|
@Override
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ public class Floor extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkAutotileSame(Tile tile, @Nullable Tile other){
|
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){
|
public int variant(int x, int y){
|
||||||
|
|||||||
Reference in New Issue
Block a user