Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/com/cleanroommc/modularui/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/cleanroommc/modularui/overlay/OverlayStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ public void drawForeground() {
}
this.context.drawDraggable();
this.context.popViewport(null);
if (!isOverlay()) {
this.context.drawQueuedForeground();
}

GlStateManager.enableRescaleNormal();
GlStateManager.enableLighting();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.cleanroommc.modularui.screen.viewport;

import java.util.ArrayList;
import java.util.List;

final class DeferredRenderQueue {

private final List<Runnable> renderCalls = new ArrayList<>();

void queue(Runnable renderCall) {
this.renderCalls.add(renderCall);
}

void drawQueued() {
try {
this.renderCalls.forEach(Runnable::run);
} finally {
this.renderCalls.clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class ModularGuiContext extends GuiContext {
private int lastDragX, lastDragY;

public List<Consumer<ModularGuiContext>> postRenderCallbacks = new ArrayList<>();
private final DeferredRenderQueue foregroundRenderQueue = new DeferredRenderQueue();

private UISettings settings;

Expand All @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cleanroommc/modularui/widget/Widget.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

Expand Down