|
1 | 1 | package gregtech.client.utils; |
2 | 2 |
|
3 | 3 | import gregtech.api.gui.resources.TextureArea; |
4 | | -import gregtech.api.util.Mods; |
| 4 | +import gregtech.api.util.JEIUtil; |
5 | 5 |
|
6 | 6 | import net.minecraft.client.Minecraft; |
7 | 7 | import net.minecraft.client.gui.FontRenderer; |
|
31 | 31 | import com.cleanroommc.modularui.api.widget.IWidget; |
32 | 32 | import com.cleanroommc.modularui.drawable.GuiDraw; |
33 | 33 | import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot; |
34 | | -import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin; |
35 | 34 | import com.cleanroommc.modularui.theme.WidgetSlotTheme; |
36 | 35 | import com.cleanroommc.modularui.theme.WidgetTheme; |
37 | 36 | import com.cleanroommc.modularui.utils.Color; |
|
47 | 46 | public class RenderUtil { |
48 | 47 |
|
49 | 48 | private static final Deque<int[]> scissorFrameStack = new ArrayDeque<>(); |
| 49 | + public static final int defaultSlotHoverColor = Color.withAlpha(Color.WHITE.main, 0x60); |
50 | 50 |
|
51 | 51 | public static void useScissor(int x, int y, int width, int height, Runnable codeBlock) { |
52 | 52 | pushScissorFrame(x, y, width, height); |
@@ -720,51 +720,39 @@ public void put(int element, float @NotNull... data) { |
720 | 720 | return getTextureMap().getMissingSprite(); |
721 | 721 | } |
722 | 722 |
|
723 | | - /** |
724 | | - * Draws the green overlay when a valid ingredient for the slot is hovered over in JEI |
725 | | - * |
726 | | - * @param slot the slot to draw the overlay on |
727 | | - * @return true if the overlay was drawn, false if not |
728 | | - */ |
729 | | - @SuppressWarnings("BooleanMethodIsAlwaysInverted") |
730 | | - public static boolean handleJeiGhostOverlay(@NotNull IWidget slot) { |
731 | | - if (!Mods.JustEnoughItems.isModLoaded()) return false; |
732 | | - if (!(slot instanceof JeiGhostIngredientSlot<?>ingredientSlot)) return false; |
733 | | - |
734 | | - if (ModularUIJeiPlugin.hoveringOverIngredient(ingredientSlot)) { |
735 | | - GlStateManager.colorMask(true, true, true, false); |
736 | | - ingredientSlot.drawHighlight(slot.getArea(), slot.isHovering()); |
737 | | - GlStateManager.colorMask(true, true, true, true); |
738 | | - return true; |
739 | | - } |
740 | | - |
741 | | - return false; |
742 | | - } |
743 | | - |
744 | | - /** |
745 | | - * Draws a gray-ish overlay over the slot 1px inwards from each side. Intended for item slots. |
746 | | - * |
747 | | - * @param slot the slot to draw the overlay above |
748 | | - */ |
749 | 723 | public static void drawSlotOverlay(@NotNull IWidget slot, int overlayColor) { |
750 | 724 | GlStateManager.colorMask(true, true, true, false); |
751 | 725 | GuiDraw.drawRect(1, 1, slot.getArea().w() - 2, slot.getArea().h() - 2, overlayColor); |
752 | 726 | GlStateManager.colorMask(true, true, true, true); |
753 | 727 | } |
754 | 728 |
|
755 | | - private static final int defaultSlotHoverColor = Color.withAlpha(Color.WHITE.main, 0x60); |
| 729 | + public static void drawSlotOverlay(@NotNull IWidget slot, WidgetTheme widgetTheme) { |
| 730 | + drawSlotOverlay(slot, widgetTheme instanceof WidgetSlotTheme slotTheme ? slotTheme.getSlotHoverColor() : |
| 731 | + defaultSlotHoverColor); |
| 732 | + } |
756 | 733 |
|
757 | | - /** |
758 | | - * Handles drawing the green JEI overlay when dragging an item, and if no item is being dragged, the overlay when |
759 | | - * mousing over the slot. |
760 | | - * |
761 | | - * @param slot the slot to draw the overlay above |
762 | | - * @param widgetTheme the theme to attempt to get the slot overlay color from |
763 | | - */ |
764 | 734 | public static void handleSlotOverlay(@NotNull IWidget slot, @NotNull WidgetTheme widgetTheme) { |
765 | | - if (!handleJeiGhostOverlay(slot) && slot.isHovering()) { |
766 | | - drawSlotOverlay(slot, widgetTheme instanceof WidgetSlotTheme slotTheme ? slotTheme.getSlotHoverColor() : |
767 | | - defaultSlotHoverColor); |
| 735 | + if (slot.isHovering()) { |
| 736 | + drawSlotOverlay(slot, widgetTheme); |
768 | 737 | } |
769 | 738 | } |
| 739 | + |
| 740 | + public static < |
| 741 | + T extends IWidget & JeiGhostIngredientSlot<?>> void drawJEIGhostSlotOverlay(@NotNull T jeiGhostIngredientSlot) { |
| 742 | + GlStateManager.colorMask(true, true, true, false); |
| 743 | + jeiGhostIngredientSlot.drawHighlight(jeiGhostIngredientSlot.getArea(), jeiGhostIngredientSlot.isHovering()); |
| 744 | + GlStateManager.colorMask(true, true, true, true); |
| 745 | + } |
| 746 | + |
| 747 | + public static < |
| 748 | + T extends IWidget & JeiGhostIngredientSlot<?>> boolean handleJEIGhostSlotOverlay(@NotNull T jeiGhostIngredientSlot, |
| 749 | + @NotNull WidgetTheme widgetTheme) { |
| 750 | + if (JEIUtil.hoveringOverIngredient(jeiGhostIngredientSlot)) { |
| 751 | + drawJEIGhostSlotOverlay(jeiGhostIngredientSlot); |
| 752 | + return true; |
| 753 | + } |
| 754 | + |
| 755 | + handleSlotOverlay(jeiGhostIngredientSlot, widgetTheme); |
| 756 | + return false; |
| 757 | + } |
770 | 758 | } |
0 commit comments