Skip to content

Commit 3cf345f

Browse files
committed
add shift click to set and close panel
1 parent d4d70ac commit 3cf345f

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

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

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package gregtech.api.mui.widget;
22

3+
import com.cleanroommc.modularui.api.widget.Interactable;
4+
35
import gregtech.api.capability.impl.GhostCircuitItemStackHandler;
46
import gregtech.api.mui.GTGuiTextures;
57
import gregtech.api.mui.GTGuis;
@@ -97,38 +99,38 @@ private boolean isSelectorPanelOpen() {
9799
private void createSelectorPanel() {
98100
ItemDrawable circuitPreview = new ItemDrawable(getSyncHandler().getSlot().getStack());
99101

100-
List<List<IWidget>> options = new ArrayList<>();
101-
for (int i = 0; i < 4; i++) {
102-
options.add(new ArrayList<>());
103-
for (int j = 0; j < 9; j++) {
104-
int index = i * 9 + j;
105-
if (index > 32) break;
106-
options.get(i).add(new ButtonWidget<>()
107-
.size(18)
108-
.background(GTGuiTextures.SLOT, new ItemDrawable(
109-
IntCircuitIngredient.getIntegratedCircuit(index)).asIcon())
110-
.disableHoverBackground()
111-
.onMousePressed(mouseButton -> {
112-
getSyncHandler().syncToServer(SYNC_CIRCUIT_INDEX, buf -> buf.writeShort(index));
113-
circuitPreview.setItem(IntCircuitIngredient.getIntegratedCircuit(index));
114-
return true;
115-
}));
102+
IPanelHandler.simple(getPanel(), (mainPanel, player) -> {
103+
var panel = GTGuis.createPopupPanel("circuit_selector", 176, 120);
104+
List<List<IWidget>> options = new ArrayList<>();
105+
for (int i = 0; i < 4; i++) {
106+
options.add(new ArrayList<>());
107+
for (int j = 0; j < 9; j++) {
108+
int index = i * 9 + j;
109+
if (index > 32) break;
110+
options.get(i).add(new ButtonWidget<>()
111+
.size(18)
112+
.background(GTGuiTextures.SLOT, new ItemDrawable(
113+
IntCircuitIngredient.getIntegratedCircuit(index)).asIcon())
114+
.disableHoverBackground()
115+
.onMousePressed(mouseButton -> {
116+
getSyncHandler().syncToServer(SYNC_CIRCUIT_INDEX, buf -> buf.writeShort(index));
117+
circuitPreview.setItem(IntCircuitIngredient.getIntegratedCircuit(index));
118+
if (Interactable.hasShiftDown()) panel.animateClose();
119+
return true;
120+
}));
121+
}
116122
}
117-
}
118-
119-
IPanelHandler.simple(getPanel(), (mainPanel, player) -> GTGuis.createPopupPanel("circuit_selector", 176, 120)
120-
.child(IKey.lang("metaitem.circuit.integrated.gui").asWidget().pos(5, 5))
121-
.child(circuitPreview.asIcon().size(16).asWidget()
122-
.size(18)
123-
.top(19).alignX(0.5f)
124-
.background(GTGuiTextures.SLOT, GTGuiTextures.INT_CIRCUIT_OVERLAY))
125-
.child(new Grid()
126-
.left(7).right(7).top(41).height(4 * 18)
127-
.matrix(options)
128-
.minColWidth(18).minRowHeight(18)
129-
.minElementMargin(0, 0)),
130-
true)
131-
.openPanel();
123+
return panel.child(IKey.lang("metaitem.circuit.integrated.gui").asWidget().pos(5, 5))
124+
.child(circuitPreview.asIcon().size(16).asWidget()
125+
.size(18)
126+
.top(19).alignX(0.5f)
127+
.background(GTGuiTextures.SLOT, GTGuiTextures.INT_CIRCUIT_OVERLAY))
128+
.child(new Grid()
129+
.left(7).right(7).top(41).height(4 * 18)
130+
.matrix(options)
131+
.minColWidth(18).minRowHeight(18)
132+
.minElementMargin(0, 0));
133+
}, true).openPanel();
132134
}
133135

134136
private static class GhostCircuitSyncHandler extends ItemSlotSH {

src/main/java/gregtech/common/items/behaviors/IntCircuitBehaviour.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package gregtech.common.items.behaviors;
22

3+
import com.cleanroommc.modularui.api.widget.Interactable;
4+
35
import gregtech.api.capability.IGhostSlotConfigurable;
46
import gregtech.api.items.gui.ItemUIFactory;
57
import gregtech.api.items.metaitem.stats.IItemBehaviour;
@@ -65,6 +67,7 @@ public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player
6567

6668
@Override
6769
public ModularPanel buildUI(HandGuiData guiData, PanelSyncManager guiSyncManager) {
70+
var panel = GTGuis.createPanel(guiData.getUsedItemStack(), 176, 120);
6871
ItemDrawable circuitPreview = new ItemDrawable(guiData.getUsedItemStack());
6972
for (int i = 0; i <= 32; i++) {
7073
int finalI = i;
@@ -73,6 +76,7 @@ public ModularPanel buildUI(HandGuiData guiData, PanelSyncManager guiSyncManager
7376
ItemStack item = IntCircuitIngredient.getIntegratedCircuit(finalI);
7477
item.setCount(guiData.getUsedItemStack().getCount());
7578
circuitPreview.setItem(item);
79+
if (Interactable.hasShiftDown()) panel.animateClose();
7680
guiData.getPlayer().setHeldItem(guiData.getHand(), item);
7781
}));
7882
}
@@ -91,8 +95,7 @@ public ModularPanel buildUI(HandGuiData guiData, PanelSyncManager guiSyncManager
9195
.syncHandler("config", index));
9296
}
9397
}
94-
return GTGuis.createPanel(guiData.getUsedItemStack(), 176, 120)
95-
.child(IKey.lang("metaitem.circuit.integrated.gui").asWidget().pos(5, 5))
98+
return panel.child(IKey.lang("metaitem.circuit.integrated.gui").asWidget().pos(5, 5))
9699
.child(circuitPreview.asIcon().size(16).asWidget()
97100
.size(18)
98101
.top(19).alignX(0.5f)

0 commit comments

Comments
 (0)