diff --git a/src/main/java/com/cleanroommc/modularui/drawable/GuiDraw.java b/src/main/java/com/cleanroommc/modularui/drawable/GuiDraw.java index 8db63da7..22f2ea50 100644 --- a/src/main/java/com/cleanroommc/modularui/drawable/GuiDraw.java +++ b/src/main/java/com/cleanroommc/modularui/drawable/GuiDraw.java @@ -559,12 +559,12 @@ public static void drawText(String text, float x, float y, float scale, int colo GlStateManager.enableBlend(); } - public static void drawTooltipBackground(List lines, int x, int y, int textWidth, int height) { + public static void drawTooltipBackground(ItemStack stack, List lines, int x, int y, int textWidth, int height) { // TODO theme color int backgroundColor = 0xF0100010; int borderColorStart = 0x505000FF; int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000; - RenderTooltipEvent.Color colorEvent = new RenderTooltipEvent.Color(ItemStack.EMPTY, lines, x, y, TextRenderer.getFontRenderer(), backgroundColor, borderColorStart, borderColorEnd); + RenderTooltipEvent.Color colorEvent = new RenderTooltipEvent.Color(stack, lines, x, y, TextRenderer.getFontRenderer(), backgroundColor, borderColorStart, borderColorEnd); MinecraftForge.EVENT_BUS.post(colorEvent); backgroundColor = colorEvent.getBackground(); borderColorStart = colorEvent.getBorderStart(); diff --git a/src/main/java/com/cleanroommc/modularui/screen/Tooltip.java b/src/main/java/com/cleanroommc/modularui/screen/Tooltip.java index d6d492c4..135c1155 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/Tooltip.java +++ b/src/main/java/com/cleanroommc/modularui/screen/Tooltip.java @@ -23,9 +23,9 @@ import java.awt.*; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.function.Consumer; +import java.util.stream.Collectors; public class Tooltip { @@ -64,6 +64,10 @@ public void buildTooltip() { } public void draw(GuiContext context) { + draw(context, ItemStack.EMPTY); + } + + public void draw(GuiContext context, @Nullable ItemStack stack) { if (updateTooltipEveryTick) { markDirty(); } @@ -72,12 +76,14 @@ public void draw(GuiContext context) { if (maxWidth <= 0) { maxWidth = Integer.MAX_VALUE; } + if (stack == null) stack = ItemStack.EMPTY; Area screen = context.screen.getScreenArea(); int mouseX = context.getAbsMouseX(), mouseY = context.getAbsMouseY(); IconRenderer renderer = IconRenderer.SHARED; //List icons = renderer.measureLines(this.lines); - List textLines = Collections.emptyList();//icons.stream().filter(iIcon -> iIcon instanceof TextIcon).map(icon -> ((TextIcon) icon).getText()).collect(Collectors.toList()); - RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(ItemStack.EMPTY, Collections.emptyList(), mouseX, mouseY, screen.width, screen.height, maxWidth, TextRenderer.getFontRenderer()); + List textLines = lines.stream().filter(drawable -> drawable instanceof IKey).map(key -> ((IKey) key).get()).collect(Collectors.toList()); + //icons.stream().filter(iIcon -> iIcon instanceof TextIcon).map(icon -> ((TextIcon) icon).getText()).collect(Collectors.toList()); + RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(stack, textLines, mouseX, mouseY, screen.width, screen.height, maxWidth, TextRenderer.getFontRenderer()); if (MinecraftForge.EVENT_BUS.post(event)) { return; } @@ -106,9 +112,9 @@ public void draw(GuiContext context) { GlStateManager.disableDepth(); GlStateManager.disableBlend(); - GuiDraw.drawTooltipBackground(textLines, area.x, area.y, area.width, area.height); + GuiDraw.drawTooltipBackground(stack, textLines, area.x, area.y, area.width, area.height); - MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostBackground(ItemStack.EMPTY, textLines, area.x, area.y, TextRenderer.getFontRenderer(), area.width, area.height)); + MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostBackground(stack, textLines, area.x, area.y, TextRenderer.getFontRenderer(), area.width, area.height)); GlStateManager.color(1f, 1f, 1f, 1f); @@ -117,7 +123,7 @@ public void draw(GuiContext context) { renderer.setPos(area.x, area.y); renderer.draw(context, this.lines); - MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(ItemStack.EMPTY, textLines, area.x, area.y, TextRenderer.getFontRenderer(), area.width, area.height)); + MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(stack, textLines, area.x, area.y, TextRenderer.getFontRenderer(), area.width, area.height)); } public Rectangle determineTooltipArea(GuiContext context, List lines, IconRenderer renderer, int screenWidth, int screenHeight, int mouseX, int mouseY) { diff --git a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java index dde69a16..4e438d84 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java @@ -9,6 +9,7 @@ import com.cleanroommc.modularui.drawable.TextRenderer; import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot; import com.cleanroommc.modularui.integration.jei.JeiIngredientProvider; +import com.cleanroommc.modularui.screen.Tooltip; import com.cleanroommc.modularui.screen.viewport.GuiContext; import com.cleanroommc.modularui.screen.GuiScreenWrapper; import com.cleanroommc.modularui.screen.ModularScreen; @@ -146,6 +147,14 @@ protected List getItemTooltip(ItemStack stack) { return getScreen().getScreenWrapper().getItemToolTip(stack); } + @Override + public void drawForeground(GuiContext context) { + Tooltip tooltip = getTooltip(); + if (tooltip != null && isHoveringFor(tooltip.getShowUpTimer())) { + tooltip.draw(getContext(), getSlot().getStack()); + } + } + @SideOnly(Side.CLIENT) private void drawSlot(Slot slotIn) { GuiScreenWrapper guiScreen = getScreen().getScreenWrapper();