Skip to content

Commit

Permalink
Misc fixes and unit selection tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed Nov 28, 2024
1 parent ec0ba9f commit 0f492e0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 32 deletions.
13 changes: 10 additions & 3 deletions core/src/mindustry/graphics/Drawf.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,18 @@ public static void additive(TextureRegion region, Color color, float alpha, floa
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){
Expand Down Expand Up @@ -354,7 +361,7 @@ public static void select(float x, float y, float radius, Color color){
}

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);
Expand Down
50 changes: 27 additions & 23 deletions core/src/mindustry/input/InputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -1070,7 +1071,7 @@ public void commandTap(float screenX, float screenY, boolean queue){
}

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(){
Expand All @@ -1085,6 +1086,9 @@ public void drawCommanded(){

public void drawCommanded(boolean flying){
float lineLimit = 6.5f;
Color color = Pal.accent;
int sides = 6;
float alpha = 0.5f;

if(commandMode){
//happens sometimes
Expand All @@ -1099,34 +1103,34 @@ public void drawCommanded(boolean flying){
//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();
Expand All @@ -1142,19 +1146,19 @@ public void drawCommanded(boolean flying){
//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);
}
}
}

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;
Expand All @@ -1175,20 +1179,12 @@ public void drawCommanded(boolean flying){
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();
Expand All @@ -1206,6 +1202,14 @@ public void drawUnitSelection(){
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(){
Expand Down
14 changes: 9 additions & 5 deletions core/src/mindustry/maps/filters/GenerateFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public void apply(Tiles tiles, GenerateInput in){
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);
Expand All @@ -49,8 +51,10 @@ public void apply(Tiles tiles, GenerateInput in){
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);
Expand Down
2 changes: 1 addition & 1 deletion core/src/mindustry/type/UnitType.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public Unit create(Team team){
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
Expand Down

0 comments on commit 0f492e0

Please sign in to comment.