From f5d46dea812f0019ce06e1512dff697bb811f739 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Sun, 26 Nov 2023 17:04:41 +0200 Subject: Fix title being hidden below screen Fixes #227. Introduces a minor new API, CottonInventoryScreen.paintDescription, for use in a mixin. --- .../cotton/gui/client/CottonClientScreen.java | 8 +------ .../cotton/gui/client/CottonInventoryScreen.java | 23 +++++++++++------- .../gui/impl/client/CottonInventoryScreenImpl.java | 7 ++++++ .../gui/impl/mixin/client/HandledScreenMixin.java | 28 ++++++++++++++++++++++ src/main/resources/mixins.libgui.json | 1 + 5 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/client/CottonInventoryScreenImpl.java create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/mixin/client/HandledScreenMixin.java diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java index 9e47c40..ac34d4e 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java @@ -125,9 +125,6 @@ public class CottonClientScreen extends Screen implements CottonScreenImpl { private void paint(DrawContext context, int mouseX, int mouseY, float delta) { if (description!=null) { - context.getMatrices().push(); - context.getMatrices().translate(0f, 0f, 0.01f); - WPanel root = description.getRootPanel(); if (root!=null) { GL11.glEnable(GL11.GL_SCISSOR_TEST); @@ -141,16 +138,13 @@ public class CottonClientScreen extends Screen implements CottonScreenImpl { int width = description.getRootPanel().getWidth(); ScreenDrawing.drawString(context, getTitle().asOrderedText(), description.getTitleAlignment(), left + titleX, top + titleY, width - 2 * titleX, description.getTitleColor()); } - - context.getMatrices().pop(); } } @Override public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - paint(context, mouseX, mouseY, partialTicks); - super.render(context, mouseX, mouseY, partialTicks); + paint(context, mouseX, mouseY, partialTicks); if (description!=null) { WPanel root = description.getRootPanel(); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java index 701380d..071d0ca 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java @@ -13,7 +13,7 @@ import net.minecraft.text.Text; import io.github.cottonmc.cotton.gui.GuiDescription; import io.github.cottonmc.cotton.gui.SyncedGuiDescription; import io.github.cottonmc.cotton.gui.impl.VisualLogger; -import io.github.cottonmc.cotton.gui.impl.client.CottonScreenImpl; +import io.github.cottonmc.cotton.gui.impl.client.CottonInventoryScreenImpl; import io.github.cottonmc.cotton.gui.impl.client.FocusElements; import io.github.cottonmc.cotton.gui.impl.client.MouseInputHandler; import io.github.cottonmc.cotton.gui.impl.client.NarrationHelper; @@ -30,7 +30,7 @@ import org.lwjgl.opengl.GL11; * * @param the description type */ -public class CottonInventoryScreen extends HandledScreen implements CottonScreenImpl { +public class CottonInventoryScreen extends HandledScreen implements CottonInventoryScreenImpl { private static final VisualLogger LOGGER = new VisualLogger(CottonInventoryScreen.class); protected SyncedGuiDescription description; @Nullable protected WWidget lastResponder = null; @@ -274,27 +274,32 @@ public class CottonInventoryScreen extends Handl @Override protected void drawBackground(DrawContext context, float partialTicks, int mouseX, int mouseY) {} //This is just an AbstractContainerScreen thing; most Screens don't work this way. - - private void paint(DrawContext context, int mouseX, int mouseY, float delta) { + + /** + * Paints the GUI description of this screen. + * + * @param context the draw context + * @param mouseX the absolute X coordinate of the mouse cursor + * @param mouseY the absolute Y coordinate of the mouse cursor + * @param delta the tick delta + * @since 9.2.0 + */ + @Override + public void paintDescription(DrawContext context, int mouseX, int mouseY, float delta) { if (description!=null) { WPanel root = description.getRootPanel(); if (root!=null) { - context.getMatrices().push(); - context.getMatrices().translate(0f, 0f, 0.01f); GL11.glEnable(GL11.GL_SCISSOR_TEST); Scissors.refreshScissors(); root.paint(context, x, y, mouseX-x, mouseY-y); GL11.glDisable(GL11.GL_SCISSOR_TEST); Scissors.checkStackIsEmpty(); - context.getMatrices().pop(); } } } @Override public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - paint(context, mouseX, mouseY, partialTicks); - super.render(context, mouseX, mouseY, partialTicks); DiffuseLighting.disableGuiDepthLighting(); //Needed because super.render leaves dirty state diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/CottonInventoryScreenImpl.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/CottonInventoryScreenImpl.java new file mode 100644 index 0000000..877c92a --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/CottonInventoryScreenImpl.java @@ -0,0 +1,7 @@ +package io.github.cottonmc.cotton.gui.impl.client; + +import net.minecraft.client.gui.DrawContext; + +public interface CottonInventoryScreenImpl extends CottonScreenImpl { + void paintDescription(DrawContext context, int mouseX, int mouseY, float delta); +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/mixin/client/HandledScreenMixin.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/mixin/client/HandledScreenMixin.java new file mode 100644 index 0000000..1697ab6 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/mixin/client/HandledScreenMixin.java @@ -0,0 +1,28 @@ +package io.github.cottonmc.cotton.gui.impl.mixin.client; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.ingame.HandledScreen; + +import io.github.cottonmc.cotton.gui.impl.client.CottonInventoryScreenImpl; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(HandledScreen.class) +abstract class HandledScreenMixin { + @Inject( + method = "render", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/screen/Screen;render(Lnet/minecraft/client/gui/DrawContext;IIF)V", + shift = At.Shift.AFTER + ), + allow = 1 + ) + private void onSuperRender(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo info) { + if (this instanceof CottonInventoryScreenImpl cottonInventoryScreen) { + cottonInventoryScreen.paintDescription(context, mouseX, mouseY, delta); + } + } +} diff --git a/src/main/resources/mixins.libgui.json b/src/main/resources/mixins.libgui.json index d72e129..226bd52 100644 --- a/src/main/resources/mixins.libgui.json +++ b/src/main/resources/mixins.libgui.json @@ -6,6 +6,7 @@ "plugin": "io.github.cottonmc.cotton.gui.impl.LibGuiMixinPlugin", "client": [ + "client.HandledScreenMixin", "client.MinecraftClientMixin", "client.PressableWidgetAccessor", "client.ScreenAccessor", -- cgit