Misc fixes and unit selection tweaks
Some checks failed
Validate Gradle Wrapper / Validation (push) Successful in 29s
Tests / runPush (push) Failing after 2m8s

This commit is contained in:
Anuken 2024-11-27 21:51:13 -05:00
parent ec0ba9f424
commit 0f492e0c7a
4 changed files with 47 additions and 32 deletions

View File

@ -141,11 +141,18 @@ public class Drawf{
Draw.z(pz);
}
public static void limitLine(Position start, Position dest, float len1, float len2){
public static void limitLine(Position start, Position dest, float len1, float len2, Color color){
if(start.within(dest, len1 + len2)){
return;
}
Tmp.v1.set(dest).sub(start).setLength(len1);
Tmp.v2.set(Tmp.v1).scl(-1f).setLength(len2);
Drawf.line(Pal.accent, start.getX() + Tmp.v1.x, start.getY() + Tmp.v1.y, dest.getX() + Tmp.v2.x, dest.getY() + Tmp.v2.y);
Drawf.line(color, start.getX() + Tmp.v1.x, start.getY() + Tmp.v1.y, dest.getX() + Tmp.v2.x, dest.getY() + Tmp.v2.y);
}
public static void limitLine(Position start, Position dest, float len1, float len2){
limitLine(start, dest, len1, len2, Pal.accent);
}
public static void dashLineDst(Color color, float x, float y, float x2, float y2){
@ -354,7 +361,7 @@ public class Drawf{
}
public static void square(float x, float y, float radius, float rotation, Color color){
Lines.stroke(3f, Pal.gray);
Lines.stroke(3f, Pal.gray.write(Tmp.c3).a(color.a));
Lines.square(x, y, radius + 1f, rotation);
Lines.stroke(1f, color);
Lines.square(x, y, radius + 1f, rotation);

View File

@ -53,6 +53,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
/** Used for dropping items. */
final static float playerSelectRange = mobile ? 17f : 11f;
final static float unitSelectRadScl = 1f;
final static IntSeq removed = new IntSeq();
final static IntSet intSet = new IntSet();
/** Maximum line length. */
@ -1070,7 +1071,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
public void drawCommand(Unit sel){
Drawf.poly(sel.x, sel.y, 6, sel.hitSize / 1.1f + 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 drawCommanded(){
@ -1085,6 +1086,9 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public void drawCommanded(boolean flying){
float lineLimit = 6.5f;
Color color = Pal.accent;
int sides = 6;
float alpha = 0.5f;
if(commandMode){
//happens sometimes
@ -1099,34 +1103,34 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
//draw target line
if(ai.targetPos != null && ai.currentCommand().drawTarget){
Position lineDest = ai.attackTarget != null ? ai.attackTarget : ai.targetPos;
Drawf.limitLine(unit, lineDest, unit.hitSize / 1.1f + 1f, lineLimit);
Drawf.limitLine(unit, lineDest, unit.hitSize / unitSelectRadScl + 1f, lineLimit, color.write(Tmp.c1).a(alpha));
if(ai.attackTarget == null){
Drawf.square(lineDest.getX(), lineDest.getY(), 3.5f);
Drawf.square(lineDest.getX(), lineDest.getY(), 3.5f, color.write(Tmp.c1).a(alpha));
if(ai.currentCommand() == UnitCommand.enterPayloadCommand){
var build = world.buildWorld(lineDest.getX(), lineDest.getY());
if(build != null && build.block.acceptsUnitPayloads && build.team == unit.team){
Drawf.selected(build, Pal.accent);
Drawf.selected(build, color);
}
}
}
}
float rad = unit.hitSize / 1.1f + 1f;
int sides = 6;
float rad = unit.hitSize / unitSelectRadScl + 1f;
Fill.lightInner(unit.x, unit.y, sides,
Math.max(0f, unit.hitSize / 1.1f + 1f - 4f),
Math.max(0f, rad * 0.8f),
rad,
0f,
Tmp.c3.set(Pal.accent).a(0f),
Tmp.c2.set(Pal.accent).a(0.7f)
Tmp.c3.set(color).a(0f),
Tmp.c2.set(color).a(0.7f)
);
Lines.stroke(1f);
Draw.color(Pal.accent);
Draw.color(color);
Lines.poly(unit.x, unit.y, sides, rad + 0.5f);
//uncomment for a dark border
//Draw.color(Pal.gray);
//Lines.poly(unit.x, unit.y, sides, rad + 1.5f);
Draw.reset();
@ -1142,11 +1146,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
//draw command queue
if(ai.currentCommand().drawTarget && ai.commandQueue.size > 0){
for(var next : ai.commandQueue){
Drawf.limitLine(lastPos, next, lineLimit, lineLimit);
Drawf.limitLine(lastPos, next, lineLimit, lineLimit, color.write(Tmp.c1).a(alpha));
lastPos = next;
if(next instanceof Vec2 vec){
Drawf.square(vec.x, vec.y, 3.5f);
Drawf.square(vec.x, vec.y, 3.5f, color.write(Tmp.c1).a(alpha));
}else{
Drawf.target(next.getX(), next.getY(), 6f, Pal.remove);
}
@ -1154,7 +1158,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
}
if(ai.targetPos != null && ai.currentCommand() == UnitCommand.loopPayloadCommand && unit instanceof Payloadc pay){
Draw.color(Pal.accent, 0.4f + Mathf.absin(5f, 0.5f));
Draw.color(color, 0.4f + Mathf.absin(5f, 0.5f));
TextureRegion region = pay.hasPayload() ? Icon.download.getRegion() : Icon.upload.getRegion();
float offset = 11f;
float size = 8f;
@ -1175,20 +1179,12 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
var cpos = commandBuild.getCommandPosition();
if(cpos != null){
Drawf.limitLine(commandBuild, cpos, commandBuild.hitSize() / 2f, lineLimit);
Drawf.square(cpos.x, cpos.y, 3.5f);
Drawf.limitLine(commandBuild, cpos, commandBuild.hitSize() / 2f, lineLimit, color.write(Tmp.c1).a(alpha));
Drawf.square(cpos.x, cpos.y, 3.5f, color.write(Tmp.c1).a(alpha));
}
}
}
}
if(commandMode && !commandRect){
Unit sel = selectedCommandUnit(input.mouseWorldX(), input.mouseWorldY());
if(sel != null && sel.isFlying() == flying && !(!multiUnitSelect() && selectedUnits.size == 1 && selectedUnits.contains(sel))){
drawCommand(sel);
}
}
}
Draw.reset();
@ -1206,6 +1202,14 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
Draw.color(Pal.accent, 0.3f);
Fill.crect(commandRectX, commandRectY, x2 - commandRectX, y2 - commandRectY);
}
if(commandMode && !commandRect){
Unit sel = selectedCommandUnit(input.mouseWorldX(), input.mouseWorldY());
if(sel != null && !(!multiUnitSelect() && selectedUnits.size == 1 && selectedUnits.contains(sel))){
drawCommand(sel);
}
}
}
public void drawBottom(){

View File

@ -35,10 +35,12 @@ public abstract class GenerateFilter implements Cloneable{
Tile tile = tiles.geti(i);
long b = buffer[i];
Block block = Vars.content.block(PackTile.block(b)), floor = Vars.content.block(PackTile.floor(b)), overlay = Vars.content.block(PackTile.overlay(b));
Block block = Vars.content.block(PackTile.block(b)), floorb = Vars.content.block(PackTile.floor(b)), overlay = Vars.content.block(PackTile.overlay(b));
tile.setFloor(floor.asFloor());
tile.setOverlay(!floor.asFloor().hasSurface() && overlay.asFloor().needsSurface && overlay instanceof OreBlock ? Blocks.air : overlay);
if(floorb instanceof Floor floor){
tile.setFloor(floor);
tile.setOverlay(!floor.hasSurface() && overlay.asFloor().needsSurface && overlay instanceof OreBlock ? Blocks.air : overlay);
}
if(!tile.block().synthetic() && !block.synthetic()){
tile.setBlock(block);
@ -49,8 +51,10 @@ public abstract class GenerateFilter implements Cloneable{
in.set(tile.x, tile.y, tile.block(), tile.floor(), tile.overlay());
apply(in);
tile.setFloor(in.floor.asFloor());
tile.setOverlay(!in.floor.asFloor().hasSurface() && in.overlay.asFloor().needsSurface && in.overlay instanceof OreBlock ? Blocks.air : in.overlay);
if(in.floor instanceof Floor floor){
tile.setFloor(floor);
tile.setOverlay(!floor.hasSurface() && in.overlay.asFloor().needsSurface && in.overlay instanceof OreBlock ? Blocks.air : in.overlay);
}
if(!tile.block().synthetic() && !in.block.synthetic()){
tile.setBlock(in.block);

View File

@ -462,7 +462,7 @@ public class UnitType extends UnlockableContent implements Senseable{
Unit unit = constructor.get();
unit.team = team;
unit.setType(this);
if(controller instanceof CommandAI command && defaultCommand != null){
if(unit.controller() instanceof CommandAI command && defaultCommand != null){
command.command = defaultCommand;
}
unit.ammo = ammoCapacity; //fill up on ammo upon creation