Better unit selection visuals / Bigger unit physics collision circles
All checks were successful
Validate Gradle Wrapper / Validation (push) Successful in 32s
Tests / runPush (push) Successful in 25m10s

This commit is contained in:
Anuken 2024-11-27 12:03:42 -05:00
parent d65f226b3a
commit ec0ba9f424
11 changed files with 79 additions and 38 deletions

View File

@ -95,6 +95,8 @@ public class Vars implements Loadable{
public static final float finalWorldBounds = 250; public static final float finalWorldBounds = 250;
/** default range for building */ /** default range for building */
public static final float buildingRange = 220f; public static final float buildingRange = 220f;
/** scaling for unit circle collider radius, based on hitbox size */
public static final float unitCollisionRadiusScale = 0.6f;
/** range for moving items */ /** range for moving items */
public static final float itemTransferRange = 220f; public static final float itemTransferRange = 220f;
/** range for moving items for logic units */ /** range for moving items for logic units */

View File

@ -18,7 +18,7 @@ public class UnitGroup{
public int collisionLayer; public int collisionLayer;
public volatile float[] positions, originalPositions; public volatile float[] positions, originalPositions;
public volatile boolean valid; public volatile boolean valid;
public void calculateFormation(Vec2 dest, int collisionLayer){ public void calculateFormation(Vec2 dest, int collisionLayer){
this.collisionLayer = collisionLayer; this.collisionLayer = collisionLayer;
@ -72,7 +72,7 @@ public class UnitGroup{
positions[a * 2] = v1.x; positions[a * 2] = v1.x;
positions[a * 2 + 1] = v1.y; positions[a * 2 + 1] = v1.y;
float rad = units.get(a).hitSize/2f; float rad = units.get(a).hitSize * Vars.unitCollisionRadiusScale;
maxDst = Math.max(maxDst, v1.dst(0f, 0f) + rad); maxDst = Math.max(maxDst, v1.dst(0f, 0f) + rad);
totalArea += Mathf.PI * rad * rad; totalArea += Mathf.PI * rad * rad;

View File

@ -45,7 +45,7 @@ public class PhysicsProcess implements AsyncProcess{
body.x = entity.x; body.x = entity.x;
body.y = entity.y; body.y = entity.y;
body.mass = entity.mass(); body.mass = entity.mass();
body.radius = entity.hitSize / 2f; body.radius = entity.hitSize * Vars.unitCollisionRadiusScale;
PhysicRef ref = new PhysicRef(entity, body); PhysicRef ref = new PhysicRef(entity, body);
refs.add(ref); refs.add(ref);

View File

@ -255,7 +255,7 @@ public class UnitTypes{
reign = new UnitType("reign"){{ reign = new UnitType("reign"){{
speed = 0.4f; speed = 0.4f;
hitSize = 26f; hitSize = 30f;
rotateSpeed = 1.65f; rotateSpeed = 1.65f;
health = 24000; health = 24000;
armor = 18f; armor = 18f;
@ -1012,7 +1012,7 @@ public class UnitTypes{
accel = 0.08f; accel = 0.08f;
drag = 0.016f; drag = 0.016f;
flying = true; flying = true;
hitSize = 10f; hitSize = 11f;
targetAir = false; targetAir = false;
engineOffset = 7.8f; engineOffset = 7.8f;
range = 140f; range = 140f;

View File

@ -339,6 +339,8 @@ public class Renderer implements ApplicationListener{
Draw.draw(Layer.effect + 0.02f, bloom::render); Draw.draw(Layer.effect + 0.02f, bloom::render);
} }
control.input.drawCommanded();
Draw.draw(Layer.plans, overlays::drawBottom); Draw.draw(Layer.plans, overlays::drawBottom);
if(animateShields && Shaders.shield != null){ if(animateShields && Shaders.shield != null){

View File

@ -306,7 +306,7 @@ public class Drawf{
Draw.rect(region, x, y); Draw.rect(region, x, y);
Draw.color(); Draw.color();
} }
public static void shadow(TextureRegion region, float x, float y, float width, float height, float rotation){ public static void shadow(TextureRegion region, float x, float y, float width, float height, float rotation){
Draw.color(Pal.shadow); Draw.color(Pal.shadow);
Draw.rect(region, x, y, width, height, rotation); Draw.rect(region, x, y, width, height, rotation);
@ -361,6 +361,14 @@ public class Drawf{
Draw.reset(); Draw.reset();
} }
public static void poly(float x, float y, int sides, float radius, float rotation, Color color){
Lines.stroke(3f, Pal.gray);
Lines.poly(x, y, sides, radius + 1f, rotation);
Lines.stroke(1f, color);
Lines.poly(x, y, sides, radius + 1f, rotation);
Draw.reset();
}
public static void square(float x, float y, float radius, float rotation){ public static void square(float x, float y, float radius, float rotation){
square(x, y, radius, rotation, Pal.accent); square(x, y, radius, rotation, Pal.accent);
} }
@ -436,7 +444,7 @@ public class Drawf{
public static void construct(float x, float y, TextureRegion region, float rotation, float progress, float alpha, float time){ public static void construct(float x, float y, TextureRegion region, float rotation, float progress, float alpha, float time){
construct(x, y, region, Pal.accent, rotation, progress, alpha, time); construct(x, y, region, Pal.accent, rotation, progress, alpha, time);
} }
public static void construct(float x, float y, TextureRegion region, Color color, float rotation, float progress, float alpha, float time){ public static void construct(float x, float y, TextureRegion region, Color color, float rotation, float progress, float alpha, float time){
Shaders.build.region = region; Shaders.build.region = region;
Shaders.build.progress = progress; Shaders.build.progress = progress;
@ -458,7 +466,7 @@ public class Drawf{
public static void construct(Building t, TextureRegion region, Color color, float rotation, float progress, float alpha, float time){ public static void construct(Building t, TextureRegion region, Color color, float rotation, float progress, float alpha, float time){
construct(t, region, color, rotation, progress, alpha, time, t.block.size * tilesize - 4f); construct(t, region, color, rotation, progress, alpha, time, t.block.size * tilesize - 4f);
} }
public static void construct(Building t, TextureRegion region, Color color, float rotation, float progress, float alpha, float time, float size){ public static void construct(Building t, TextureRegion region, Color color, float rotation, float progress, float alpha, float time, float size){
Shaders.build.region = region; Shaders.build.region = region;
Shaders.build.progress = progress; Shaders.build.progress = progress;
@ -477,7 +485,7 @@ public class Drawf{
Draw.reset(); Draw.reset();
} }
/** Draws a sprite that should be light-wise correct, when rotated. Provided sprite must be symmetrical in shape. */ /** Draws a sprite that should be light-wise correct, when rotated. Provided sprite must be symmetrical in shape. */
public static void spinSprite(TextureRegion region, float x, float y, float r){ public static void spinSprite(TextureRegion region, float x, float y, float r){
float a = Draw.getColorAlpha(); float a = Draw.getColorAlpha();

View File

@ -151,6 +151,7 @@ public class OverlayRenderer{
} }
input.drawTop(); input.drawTop();
input.drawUnitSelection();
buildFade = Mathf.lerpDelta(buildFade, input.isPlacing() || input.isUsingSchematic() ? 1f : 0f, 0.06f); buildFade = Mathf.lerpDelta(buildFade, input.isPlacing() || input.isUsingSchematic() ? 1f : 0f, 0.06f);

View File

@ -132,9 +132,6 @@ public class DesktopInput extends InputHandler{
} }
} }
drawCommanded();
Draw.reset(); Draw.reset();
} }

View File

@ -1070,23 +1070,36 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
} }
public void drawCommand(Unit sel){ public void drawCommand(Unit sel){
Drawf.square(sel.x, sel.y, sel.hitSize / 1.4f + Mathf.absin(4f, 1f), selectedUnits.contains(sel) ? Pal.remove : Pal.accent); Drawf.poly(sel.x, sel.y, 6, sel.hitSize / 1.1f + Mathf.absin(4f, 1f), 0f, selectedUnits.contains(sel) ? Pal.remove : Pal.accent);
} }
public void drawCommanded(){ public void drawCommanded(){
Draw.draw(Layer.plans, () -> {
drawCommanded(true);
});
Draw.draw(Layer.groundUnit - 1, () -> {
drawCommanded(false);
});
}
public void drawCommanded(boolean flying){
float lineLimit = 6.5f;
if(commandMode){ if(commandMode){
//happens sometimes //happens sometimes
selectedUnits.removeAll(u -> !u.isCommandable()); selectedUnits.removeAll(u -> !u.isCommandable());
//draw command overlay UI //draw command overlay UI
for(Unit unit : selectedUnits){ for(Unit unit : selectedUnits){
if(unit.isFlying() != flying) continue;
CommandAI ai = unit.command(); CommandAI ai = unit.command();
Position lastPos = ai.attackTarget != null ? ai.attackTarget : ai.targetPos; Position lastPos = ai.attackTarget != null ? ai.attackTarget : ai.targetPos;
//draw target line //draw target line
if(ai.targetPos != null && ai.currentCommand().drawTarget){ if(ai.targetPos != null && ai.currentCommand().drawTarget){
Position lineDest = ai.attackTarget != null ? ai.attackTarget : ai.targetPos; Position lineDest = ai.attackTarget != null ? ai.attackTarget : ai.targetPos;
Drawf.limitLine(unit, lineDest, unit.hitSize / 2f, 3.5f); Drawf.limitLine(unit, lineDest, unit.hitSize / 1.1f + 1f, lineLimit);
if(ai.attackTarget == null){ if(ai.attackTarget == null){
Drawf.square(lineDest.getX(), lineDest.getY(), 3.5f); Drawf.square(lineDest.getX(), lineDest.getY(), 3.5f);
@ -1100,7 +1113,23 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
} }
} }
Drawf.square(unit.x, unit.y, unit.hitSize / 1.4f + 1f); float rad = unit.hitSize / 1.1f + 1f;
int sides = 6;
Fill.lightInner(unit.x, unit.y, sides,
Math.max(0f, unit.hitSize / 1.1f + 1f - 4f),
rad,
0f,
Tmp.c3.set(Pal.accent).a(0f),
Tmp.c2.set(Pal.accent).a(0.7f)
);
Lines.stroke(1f);
Draw.color(Pal.accent);
Lines.poly(unit.x, unit.y, sides, rad + 0.5f);
//Draw.color(Pal.gray);
//Lines.poly(unit.x, unit.y, sides, rad + 1.5f);
Draw.reset();
if(ai.attackTarget != null && ai.currentCommand().drawTarget){ if(ai.attackTarget != null && ai.currentCommand().drawTarget){
Drawf.target(ai.attackTarget.getX(), ai.attackTarget.getY(), 6f, Pal.remove); Drawf.target(ai.attackTarget.getX(), ai.attackTarget.getY(), 6f, Pal.remove);
@ -1113,7 +1142,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
//draw command queue //draw command queue
if(ai.currentCommand().drawTarget && ai.commandQueue.size > 0){ if(ai.currentCommand().drawTarget && ai.commandQueue.size > 0){
for(var next : ai.commandQueue){ for(var next : ai.commandQueue){
Drawf.limitLine(lastPos, next, 3.5f, 3.5f); Drawf.limitLine(lastPos, next, lineLimit, lineLimit);
lastPos = next; lastPos = next;
if(next instanceof Vec2 vec){ if(next instanceof Vec2 vec){
@ -1139,14 +1168,16 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
} }
} }
for(var commandBuild : commandBuildings){ if(flying){
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, lineLimit);
Drawf.square(cpos.x, cpos.y, 3.5f); Drawf.square(cpos.x, cpos.y, 3.5f);
}
} }
} }
} }
@ -1154,27 +1185,29 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(commandMode && !commandRect){ if(commandMode && !commandRect){
Unit sel = selectedCommandUnit(input.mouseWorldX(), input.mouseWorldY()); Unit sel = selectedCommandUnit(input.mouseWorldX(), input.mouseWorldY());
if(sel != null && !(!multiUnitSelect() && selectedUnits.size == 1 && selectedUnits.contains(sel))){ if(sel != null && sel.isFlying() == flying && !(!multiUnitSelect() && selectedUnits.size == 1 && selectedUnits.contains(sel))){
drawCommand(sel); drawCommand(sel);
} }
} }
if(commandRect){
float x2 = input.mouseWorldX(), y2 = input.mouseWorldY();
var units = selectedCommandUnits(commandRectX, commandRectY, x2 - commandRectX, y2 - commandRectY);
for(var unit : units){
drawCommand(unit);
}
Draw.color(Pal.accent, 0.3f);
Fill.crect(commandRectX, commandRectY, x2 - commandRectX, y2 - commandRectY);
}
} }
Draw.reset(); Draw.reset();
} }
public void drawUnitSelection(){
if(commandRect && commandMode){
float x2 = input.mouseWorldX(), y2 = input.mouseWorldY();
var units = selectedCommandUnits(commandRectX, commandRectY, x2 - commandRectX, y2 - commandRectY);
for(var unit : units){
drawCommand(unit);
}
Draw.color(Pal.accent, 0.3f);
Fill.crect(commandRectX, commandRectY, x2 - commandRectX, y2 - commandRectY);
}
}
public void drawBottom(){ public void drawBottom(){
} }

View File

@ -391,8 +391,6 @@ public class MobileInput extends InputHandler implements GestureListener{
}else if(mode == rebuildSelect){ }else if(mode == rebuildSelect){
drawRebuildSelection(lineStartX, lineStartY, lastLineX, lastLineY); drawRebuildSelection(lineStartX, lineStartY, lastLineX, lastLineY);
} }
drawCommanded();
} }
@Override @Override

View File

@ -26,4 +26,4 @@ org.gradle.caching=true
org.gradle.internal.http.socketTimeout=100000 org.gradle.internal.http.socketTimeout=100000
org.gradle.internal.http.connectionTimeout=100000 org.gradle.internal.http.connectionTimeout=100000
android.enableR8.fullMode=false android.enableR8.fullMode=false
archash=ed5dd285b7 archash=ae657a7db3