diff --git a/src/main/java/com/cleanroommc/modularui/ClientProxy.java b/src/main/java/com/cleanroommc/modularui/ClientProxy.java index e211f19d4..acaf73431 100644 --- a/src/main/java/com/cleanroommc/modularui/ClientProxy.java +++ b/src/main/java/com/cleanroommc/modularui/ClientProxy.java @@ -9,6 +9,7 @@ import com.cleanroommc.modularui.holoui.HoloScreenEntity; import com.cleanroommc.modularui.holoui.ScreenEntityRender; import com.cleanroommc.modularui.network.ModularNetwork; +import com.cleanroommc.modularui.overlay.OverlayInputHandler; import com.cleanroommc.modularui.screen.ClientScreenHandler; import com.cleanroommc.modularui.test.TestItem; import com.cleanroommc.modularui.theme.ThemeManager; @@ -66,6 +67,9 @@ void preInit(FMLPreInitializationEvent event) { // registered to both buses since handled events are not bound to a single bus FMLCommonHandler.instance().bus().register(clientScreenHandler); MinecraftForge.EVENT_BUS.register(clientScreenHandler); + if (ModularUI.Mods.LWJGL3IFY.isLoaded()) { + OverlayInputHandler.register(); + } AnimatorManager.init(); if (ModularUIConfig.enableTestGuis) { diff --git a/src/main/java/com/cleanroommc/modularui/overlay/OverlayInputHandler.java b/src/main/java/com/cleanroommc/modularui/overlay/OverlayInputHandler.java new file mode 100644 index 000000000..da539fee8 --- /dev/null +++ b/src/main/java/com/cleanroommc/modularui/overlay/OverlayInputHandler.java @@ -0,0 +1,32 @@ +package com.cleanroommc.modularui.overlay; + +import com.cleanroommc.modularui.ModularUI; + +import cpw.mods.fml.common.Optional; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import me.eigenraven.lwjgl3ify.api.InputEvents; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +@SideOnly(Side.CLIENT) +@Optional.Interface(modid = ModularUI.ModIds.LWJGL3IFY, iface = "me.eigenraven.lwjgl3ify.api.InputEvents$KeyboardListener") +public class OverlayInputHandler implements InputEvents.KeyboardListener { + + @Optional.Method(modid = ModularUI.ModIds.LWJGL3IFY) + public static void register() { + InputEvents.addKeyboardListener(new OverlayInputHandler()); + } + + @Override + @Optional.Method(modid = ModularUI.ModIds.LWJGL3IFY) + public void onTextEvent(InputEvents.TextEvent event) { + OverlayStack.interact(screen -> { + if (screen.getContext().getFocusedWidget() == null) { + return false; + } + screen.onTextEvent(event); + return true; + }, true); + } +} diff --git a/src/main/java/com/cleanroommc/modularui/overlay/OverlayStack.java b/src/main/java/com/cleanroommc/modularui/overlay/OverlayStack.java index 01a485c77..43f797c30 100644 --- a/src/main/java/com/cleanroommc/modularui/overlay/OverlayStack.java +++ b/src/main/java/com/cleanroommc/modularui/overlay/OverlayStack.java @@ -9,6 +9,7 @@ import com.cleanroommc.modularui.utils.GlStateManager; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.RenderHelper; import net.minecraftforge.common.MinecraftForge; import org.jetbrains.annotations.ApiStatus; @@ -71,6 +72,24 @@ public static void draw(int mouseX, int mouseY, float partialTicks) { fallback = screen; } ClientScreenHandler.drawDebugScreen(hovered, fallback); + drawTooltips(); + } + + private static void drawTooltips() { + GlStateManager.disableRescaleNormal(); + RenderHelper.disableStandardItemLighting(); + GlStateManager.disableLighting(); + GlStateManager.disableDepth(); + GlStateManager.disableAlpha(); + + for (ModularScreen screen : overlay) { + screen.getContext().drawQueuedForeground(); + } + + GlStateManager.enableRescaleNormal(); + GlStateManager.enableLighting(); + RenderHelper.enableStandardItemLighting(); + GlStateManager.enableAlpha(); } public static void open(ModularScreen screen) { diff --git a/src/main/java/com/cleanroommc/modularui/screen/ModularScreen.java b/src/main/java/com/cleanroommc/modularui/screen/ModularScreen.java index b8dc16b38..81140b272 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/ModularScreen.java +++ b/src/main/java/com/cleanroommc/modularui/screen/ModularScreen.java @@ -344,6 +344,9 @@ public void drawForeground() { } this.context.drawDraggable(); this.context.popViewport(null); + if (!isOverlay()) { + this.context.drawQueuedForeground(); + } GlStateManager.enableRescaleNormal(); GlStateManager.enableLighting(); diff --git a/src/main/java/com/cleanroommc/modularui/screen/viewport/DeferredRenderQueue.java b/src/main/java/com/cleanroommc/modularui/screen/viewport/DeferredRenderQueue.java new file mode 100644 index 000000000..c2a2e2abc --- /dev/null +++ b/src/main/java/com/cleanroommc/modularui/screen/viewport/DeferredRenderQueue.java @@ -0,0 +1,21 @@ +package com.cleanroommc.modularui.screen.viewport; + +import java.util.ArrayList; +import java.util.List; + +final class DeferredRenderQueue { + + private final List renderCalls = new ArrayList<>(); + + void queue(Runnable renderCall) { + this.renderCalls.add(renderCall); + } + + void drawQueued() { + try { + this.renderCalls.forEach(Runnable::run); + } finally { + this.renderCalls.clear(); + } + } +} diff --git a/src/main/java/com/cleanroommc/modularui/screen/viewport/ModularGuiContext.java b/src/main/java/com/cleanroommc/modularui/screen/viewport/ModularGuiContext.java index 073cbd47d..640a6fca2 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/viewport/ModularGuiContext.java +++ b/src/main/java/com/cleanroommc/modularui/screen/viewport/ModularGuiContext.java @@ -55,6 +55,7 @@ public class ModularGuiContext extends GuiContext { private int lastDragX, lastDragY; public List> postRenderCallbacks = new ArrayList<>(); + private final DeferredRenderQueue foregroundRenderQueue = new DeferredRenderQueue(); private UISettings settings; @@ -81,6 +82,16 @@ public ModularScreen getScreen() { return screen; } + @ApiStatus.Internal + public void queueForegroundRender(Runnable renderCall) { + this.foregroundRenderQueue.queue(renderCall); + } + + @ApiStatus.Internal + public void drawQueuedForeground() { + this.foregroundRenderQueue.drawQueued(); + } + /** * @return the screen that was open before when this screen was opened or null of none was open */ diff --git a/src/main/java/com/cleanroommc/modularui/widget/Widget.java b/src/main/java/com/cleanroommc/modularui/widget/Widget.java index fb5e48608..b6ae04f97 100644 --- a/src/main/java/com/cleanroommc/modularui/widget/Widget.java +++ b/src/main/java/com/cleanroommc/modularui/widget/Widget.java @@ -203,7 +203,7 @@ public void drawOverlay(ModularGuiContext context, WidgetThemeEntry widgetThe public void drawForeground(ModularGuiContext context) { RichTooltip tooltip = getTooltip(); if (tooltip != null && isHoveringFor(tooltip.getShowUpTimer()) && !context.hasDraggable()) { - tooltip.draw(context); + context.queueForegroundRender(() -> tooltip.draw(context)); } } diff --git a/src/main/java/com/cleanroommc/modularui/widgets/RichTextWidget.java b/src/main/java/com/cleanroommc/modularui/widgets/RichTextWidget.java index bbabc227a..3bd3050dc 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/RichTextWidget.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/RichTextWidget.java @@ -46,7 +46,7 @@ public void drawForeground(ModularGuiContext context) { hoverable.onHover(); RichTooltip tooltip = hoverable.getTooltip(); if (tooltip != null) { - tooltip.draw(context); + context.queueForegroundRender(() -> tooltip.draw(context)); } } } diff --git a/src/main/java/com/cleanroommc/modularui/widgets/slot/ItemSlot.java b/src/main/java/com/cleanroommc/modularui/widgets/slot/ItemSlot.java index b071d10e9..a88db90ca 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/slot/ItemSlot.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/slot/ItemSlot.java @@ -111,7 +111,7 @@ protected void drawOverlay() { public void drawForeground(ModularGuiContext context) { RichTooltip tooltip = getTooltip(); if (tooltip != null && isHoveringFor(tooltip.getShowUpTimer()) && !context.hasDraggable()) { - tooltip.draw(getContext(), getSlot().getStack()); + context.queueForegroundRender(() -> tooltip.draw(context, getSlot().getStack())); } }