From 0f492e0c7ac1a3969c5404de0b5aa3242a885821 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 27 Nov 2024 21:51:13 -0500 Subject: [PATCH] Misc fixes and unit selection tweaks --- core/src/mindustry/graphics/Drawf.java | 13 +++-- core/src/mindustry/input/InputHandler.java | 50 ++++++++++--------- .../maps/filters/GenerateFilter.java | 14 ++++-- core/src/mindustry/type/UnitType.java | 2 +- 4 files changed, 47 insertions(+), 32 deletions(-) diff --git a/core/src/mindustry/graphics/Drawf.java b/core/src/mindustry/graphics/Drawf.java index e9d371fbf9a1..497736e6c968 100644 --- a/core/src/mindustry/graphics/Drawf.java +++ b/core/src/mindustry/graphics/Drawf.java @@ -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){ @@ -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); diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index c61430977894..55961ae9661c 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -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 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(){ @@ -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 @@ -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(); @@ -1142,11 +1146,11 @@ 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); } @@ -1154,7 +1158,7 @@ public void drawCommanded(boolean flying){ } 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 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(); @@ -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(){ diff --git a/core/src/mindustry/maps/filters/GenerateFilter.java b/core/src/mindustry/maps/filters/GenerateFilter.java index a412a5197886..9ce29045f6fb 100644 --- a/core/src/mindustry/maps/filters/GenerateFilter.java +++ b/core/src/mindustry/maps/filters/GenerateFilter.java @@ -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); @@ -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); diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index 3bce5fc53087..c12e1309e20c 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -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