Skip to content

Commit 6694a0d

Browse files
committed
Use custom IDrawable overlay.
Fix being able to insert items into an object holder while research is in progress.
1 parent eeddd04 commit 6694a0d

File tree

4 files changed

+54
-58
lines changed

4 files changed

+54
-58
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package gregtech.api.mui.drawable;
2+
3+
import com.cleanroommc.modularui.api.drawable.IDrawable;
4+
import com.cleanroommc.modularui.drawable.GuiDraw;
5+
import com.cleanroommc.modularui.screen.viewport.GuiContext;
6+
import com.cleanroommc.modularui.theme.WidgetTheme;
7+
8+
import java.util.function.Supplier;
9+
10+
public class DrawableColorOverlay implements IDrawable {
11+
12+
private final Supplier<Boolean> drawOverlay;
13+
private final Supplier<Integer> OVERLAY_COLOR;
14+
15+
public DrawableColorOverlay(Supplier<Boolean> drawOverlay, Supplier<Integer> color) {
16+
this.drawOverlay = drawOverlay;
17+
this.OVERLAY_COLOR = color;
18+
}
19+
20+
public DrawableColorOverlay(Supplier<Boolean> drawOverlay) {
21+
this(drawOverlay, () -> 0x80404040);
22+
}
23+
24+
@Override
25+
public void draw(GuiContext context, int x, int y, int width, int height, WidgetTheme widgetTheme) {
26+
if (drawOverlay.get()) {
27+
GuiDraw.drawRect(x, y, width, height, OVERLAY_COLOR.get());
28+
}
29+
}
30+
}

src/main/java/gregtech/api/mui/widget/BlockableSlotWidget.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityMachineHatch.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import gregtech.api.metatileentity.multiblock.MultiblockControllerBase;
1010
import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController;
1111
import gregtech.api.mui.GTGuis;
12-
import gregtech.api.mui.widget.BlockableSlotWidget;
12+
import gregtech.api.mui.drawable.DrawableColorOverlay;
1313
import gregtech.api.util.GTUtility;
1414
import gregtech.api.util.ItemStackHashStrategy;
1515
import gregtech.client.renderer.texture.Textures;
@@ -26,8 +26,10 @@
2626
import com.cleanroommc.modularui.api.drawable.IKey;
2727
import com.cleanroommc.modularui.factory.PosGuiData;
2828
import com.cleanroommc.modularui.screen.ModularPanel;
29+
import com.cleanroommc.modularui.screen.viewport.ModularGuiContext;
2930
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
3031
import com.cleanroommc.modularui.value.sync.SyncHandlers;
32+
import com.cleanroommc.modularui.widgets.ItemSlot;
3133
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
3234
import org.jetbrains.annotations.NotNull;
3335
import org.jetbrains.annotations.Nullable;
@@ -78,9 +80,17 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager)
7880
return GTGuis.createPanel(this, 176, 18 + 18 + 94)
7981
.child(IKey.lang(getMetaFullName()).asWidget().pos(5, 5))
8082
.child(SlotGroupWidget.playerInventory().left(7).bottom(7))
81-
.child(new BlockableSlotWidget()
82-
.setIsBlocked(this::isSlotBlocked)
83-
.slot(SyncHandlers.itemSlot(machineHandler, 0).slotGroup("item_inv"))
83+
.child(new ItemSlot() {
84+
85+
// Don't draw tooltip if the slot is blocked
86+
@Override
87+
public void drawForeground(ModularGuiContext context) {
88+
if (!isSlotBlocked()) super.drawForeground(context);
89+
}
90+
}
91+
.slot(SyncHandlers.itemSlot(machineHandler, 0)
92+
.slotGroup("item_inv"))
93+
.overlay(new DrawableColorOverlay(this::isSlotBlocked))
8494
.left(79).top(18));
8595
}
8696

src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityObjectHolder.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import gregtech.api.metatileentity.multiblock.MultiblockControllerBase;
1515
import gregtech.api.mui.GTGuiTextures;
1616
import gregtech.api.mui.GTGuis;
17-
import gregtech.api.mui.widget.BlockableSlotWidget;
17+
import gregtech.api.mui.drawable.DrawableColorOverlay;
1818
import gregtech.client.renderer.texture.Textures;
1919
import gregtech.client.renderer.texture.cube.SimpleOverlayRenderer;
2020

@@ -35,6 +35,7 @@
3535
import com.cleanroommc.modularui.screen.ModularPanel;
3636
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
3737
import com.cleanroommc.modularui.value.sync.SyncHandlers;
38+
import com.cleanroommc.modularui.widgets.ItemSlot;
3839
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
3940
import org.jetbrains.annotations.NotNull;
4041
import org.jetbrains.annotations.Nullable;
@@ -75,17 +76,19 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager)
7576
.child(GTGuiTextures.PROGRESS_BAR_RESEARCH_STATION_BASE.asWidget()
7677
.left(46).top(18)
7778
.size(84, 60))
78-
.child(new BlockableSlotWidget()
79-
.setIsBlocked(this::isSlotBlocked)
79+
.child(new ItemSlot()
8080
.slot(SyncHandlers.itemSlot(heldItems, 0)
81-
.slotGroup("item_inv"))
81+
.slotGroup("item_inv")
82+
.filter(itemStack -> !isSlotBlocked()))
8283
.background(GTGuiTextures.SLOT, GTGuiTextures.RESEARCH_STATION_OVERLAY)
84+
.overlay(new DrawableColorOverlay(this::isSlotBlocked))
8385
.left(79).top(39))
84-
.child(new BlockableSlotWidget()
85-
.setIsBlocked(this::isSlotBlocked)
86+
.child(new ItemSlot()
8687
.slot(SyncHandlers.itemSlot(heldItems, 1)
87-
.slotGroup("item_inv"))
88+
.slotGroup("item_inv")
89+
.filter(itemStack -> !isSlotBlocked()))
8890
.background(GTGuiTextures.SLOT, GTGuiTextures.DATA_ORB_OVERLAY)
91+
.overlay(new DrawableColorOverlay(this::isSlotBlocked))
8992
.left(15).top(39));
9093
}
9194

0 commit comments

Comments
 (0)