From c9be2d57a07c03f5e7ce2784ce40eb7eca842bbf Mon Sep 17 00:00:00 2001 From: Lucy Poulton Date: Thu, 21 Dec 2023 17:17:49 +0000 Subject: [PATCH] Add some debug stuff to track down the alt-tab focus issue --- .../com/noxcrew/sheeplib/mixin/GuiMixin.java | 35 ++++++++++++++++++- build.gradle.kts | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/com/noxcrew/sheeplib/mixin/GuiMixin.java b/api/src/main/java/com/noxcrew/sheeplib/mixin/GuiMixin.java index 70aeeb6..64ffdd4 100644 --- a/api/src/main/java/com/noxcrew/sheeplib/mixin/GuiMixin.java +++ b/api/src/main/java/com/noxcrew/sheeplib/mixin/GuiMixin.java @@ -2,10 +2,16 @@ import com.mojang.blaze3d.platform.Window; import com.noxcrew.sheeplib.DialogContainer; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ComponentPath; +import net.minecraft.client.gui.Font; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.util.CommonColors; import net.minecraft.world.scores.Scoreboard; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -15,7 +21,24 @@ * Renders the [DialogContainerScreen]. */ @Mixin(Gui.class) -public class GuiMixin { +public abstract class GuiMixin { + + @Shadow public abstract Font getFont(); + + @Unique + private int drawContainerFocus(ComponentPath componentPath, GuiGraphics guiGraphics, int y) { + final var font = Minecraft.getInstance().font; + int i = y; + for ( + var el = componentPath; + el != null; + el = (el instanceof ComponentPath.Path path) ? path.childPath() : null, i += font.lineHeight + ) { + guiGraphics.drawString(font, el.component().toString(), 5, i, CommonColors.WHITE); + } + return i; + } + @SuppressWarnings("InvalidInjectorMethodSignature") @Inject( method = "render", @@ -26,5 +49,15 @@ public class GuiMixin { locals = LocalCapture.CAPTURE_FAILHARD) public void render(GuiGraphics guiGraphics, float f, CallbackInfo ci, Window window, Scoreboard scoreboard, int o, int q) { DialogContainer.INSTANCE.render(guiGraphics, o, q, 0); + + int y = 5; + + // Debug - draw focus path on screen + final var screen = Minecraft.getInstance().screen; + if (screen != null) { + y = drawContainerFocus(screen.getCurrentFocusPath(), guiGraphics, y); + } + + drawContainerFocus(DialogContainer.INSTANCE.getCurrentFocusPath(), guiGraphics, y + getFont().lineHeight); } } diff --git a/build.gradle.kts b/build.gradle.kts index eda6873..ca2bac8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,4 @@ allprojects { group = "com.noxcrew.sheeplib" - version = "1.1.0" + version = "1.1.1-SNAPSHOT" }