Debug hitbox toggle hotkey

This commit is contained in:
Anuken
2025-07-06 12:59:45 -04:00
parent 6ae6da35c4
commit 877bb473df
6 changed files with 29 additions and 7 deletions

View File

@@ -203,7 +203,7 @@ public class Vars implements Loadable{
* Do not change unless you know exactly what you are doing.*/
public static boolean enableDarkness = true;
/** Whether to draw debug lines for collisions. */
public static boolean drawCollisionDebug = false;
public static boolean drawDebugHitboxes = false;
/** application data directory, equivalent to {@link Settings#getDataDirectory()} */
public static Fi dataDirectory;
/** data subdirectory used for screenshots */

View File

@@ -415,7 +415,7 @@ public class Renderer implements ApplicationListener{
Groups.draw.draw(Drawc::draw);
if(drawCollisionDebug){
if(drawDebugHitboxes){
DebugCollisionRenderer.draw();
}

View File

@@ -14,6 +14,12 @@ import static arc.Core.*;
import static mindustry.Vars.*;
public class DebugCollisionRenderer{
static final float[] edges = {
1, -1,
1, 1,
-1, 1,
-1, -1,
};
public static void draw(){
Rect rect = camera.bounds(new Rect());
@@ -27,7 +33,7 @@ public class DebugCollisionRenderer{
});
//tile hitboxes for units
Lines.stroke(0.3f, Color.magenta);
Lines.stroke(0.4f, Color.magenta);
int rx = Mathf.clamp((int)(Core.camera.width / tilesize / 2) + 1, 0, world.width()/2);
int ry = Mathf.clamp((int)(Core.camera.height / tilesize / 2) + 1, 0, world.height()/2);
@@ -38,8 +44,19 @@ public class DebugCollisionRenderer{
int wy = World.toTile(Core.camera.position.y) + y;
Tile tile = world.tile(wx, wy);
if(tile != null && tile.solid()){
Draw.color(tile.legSolid() ? Color.pink : Color.magenta);
Lines.rect(wx * tilesize - tilesize/2f, wy * tilesize - tilesize/2f, tilesize, tilesize);
for(int i = 0; i < 4; i++){
Tile other = tile.nearby(i);
if(other == null || !other.solid()){
Lines.line(
wx * tilesize + edges[i*2] * tilesize/2f,
wy * tilesize + edges[i*2+1] * tilesize/2f,
wx * tilesize + edges[((i + 1) % 4)*2] * tilesize/2f,
wy * tilesize + edges[((i + 1) % 4)*2+1] * tilesize/2f
);
//Lines.rect(wx * tilesize - tilesize/2f, wy * tilesize - tilesize/2f, tilesize, tilesize);
}
}
}
}
}

View File

@@ -35,7 +35,6 @@ public class Binding{
schematicFlipY = KeyBind.add("schematic_flip_y", KeyCode.x),
schematicMenu = KeyBind.add("schematic_menu", KeyCode.t),
commandMode = KeyBind.add("command_mode", KeyCode.shiftLeft, "command"),
commandQueue = KeyBind.add("command_queue", KeyCode.mouseMiddle),
createControlGroup = KeyBind.add("create_control_group", KeyCode.controlLeft),
@@ -103,7 +102,8 @@ public class Binding{
chatHistoryNext = KeyBind.add("chat_history_next", KeyCode.down),
chatScroll = KeyBind.add("chat_scroll", new Axis(KeyCode.scroll)),
chatMode = KeyBind.add("chat_mode", KeyCode.tab),
console = KeyBind.add("console", KeyCode.f8)
console = KeyBind.add("console", KeyCode.f8),
debugHitboxes = KeyBind.add("debug_hitboxes", KeyCode.unset)
;
//dummy static class initializer

View File

@@ -234,6 +234,10 @@ public class DesktopInput extends InputHandler{
boolean detached = settings.getBool("detach-camera", false);
if(!scene.hasField() && !scene.hasDialog()){
if(input.keyTap(Binding.debugHitboxes)){
drawDebugHitboxes = !drawDebugHitboxes;
}
if(input.keyTap(Binding.detachCamera)){
settings.put("detach-camera", detached = !detached);
if(!detached){