Skip to content

Commit 9f26e68

Browse files
authored
Update to MUI2 RC4 (#2730)
1 parent 5f2561a commit 9f26e68

File tree

10 files changed

+79
-342
lines changed

10 files changed

+79
-342
lines changed

dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
dependencies {
4141
// Published dependencies
4242
api("codechicken:codechickenlib:3.2.3.358")
43-
api("com.cleanroommc:modularui:2.5.0-rc3") { transitive = false }
43+
api("com.cleanroommc:modularui:2.5.0-rc4") { transitive = false }
4444
api("com.cleanroommc:groovyscript:1.2.0-hotfix1") { transitive = false }
4545
api("curse.maven:inventory-bogosorter-632327:4951607-deobf-4951608-sources-4951609")
4646
api("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.700")

src/main/java/gregtech/api/mui/LocaleAccessor.java

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

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

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,35 @@
66
import gregtech.api.recipes.ingredients.IntCircuitIngredient;
77
import gregtech.client.utils.TooltipHelper;
88

9+
import net.minecraft.item.ItemStack;
910
import net.minecraft.network.PacketBuffer;
1011
import net.minecraftforge.items.IItemHandler;
1112

1213
import com.cleanroommc.modularui.api.IPanelHandler;
1314
import com.cleanroommc.modularui.api.drawable.IKey;
14-
import com.cleanroommc.modularui.api.widget.IWidget;
1515
import com.cleanroommc.modularui.api.widget.Interactable;
1616
import com.cleanroommc.modularui.drawable.ItemDrawable;
1717
import com.cleanroommc.modularui.screen.ModularScreen;
1818
import com.cleanroommc.modularui.screen.RichTooltip;
1919
import com.cleanroommc.modularui.utils.MouseData;
2020
import com.cleanroommc.modularui.value.sync.ItemSlotSH;
21+
import com.cleanroommc.modularui.value.sync.SyncHandler;
22+
import com.cleanroommc.modularui.widget.Widget;
2123
import com.cleanroommc.modularui.widgets.ButtonWidget;
2224
import com.cleanroommc.modularui.widgets.ItemSlot;
2325
import com.cleanroommc.modularui.widgets.layout.Grid;
2426
import com.cleanroommc.modularui.widgets.slot.ModularSlot;
2527
import org.jetbrains.annotations.NotNull;
28+
import org.jetbrains.annotations.Nullable;
2629

2730
import java.io.IOException;
28-
import java.util.ArrayList;
29-
import java.util.List;
3031

3132
public class GhostCircuitSlotWidget extends ItemSlot {
3233

3334
private static final int SYNC_CIRCUIT_INDEX = 10;
35+
@Nullable
36+
private IPanelHandler selectorPanel;
37+
private GhostCircuitSyncHandler syncHandler;
3438

3539
public GhostCircuitSlotWidget() {
3640
super();
@@ -41,7 +45,7 @@ public GhostCircuitSlotWidget() {
4145
public @NotNull Result onMousePressed(int mouseButton) {
4246
if (!isSelectorPanelOpen()) {
4347
if (mouseButton == 0 && TooltipHelper.isShiftDown()) {
44-
createSelectorPanel();
48+
this.getSelectorPanel().openPanel();
4549
} else {
4650
MouseData mouseData = MouseData.create(mouseButton);
4751
getSyncHandler().syncToServer(2, mouseData::writeToPacket);
@@ -58,17 +62,24 @@ public boolean onMouseScroll(ModularScreen.UpOrDown scrollDirection, int amount)
5862
return true;
5963
}
6064

65+
@Override
66+
public boolean isValidSyncHandler(SyncHandler syncHandler) {
67+
this.syncHandler = castIfTypeElseNull(syncHandler, GhostCircuitSyncHandler.class);
68+
if (this.syncHandler == null) return false;
69+
return super.isValidSyncHandler(syncHandler);
70+
}
71+
6172
@Override
6273
public ItemSlot slot(ModularSlot slot) {
63-
ItemSlotSH sh = new GhostCircuitSyncHandler(slot);
64-
isValidSyncHandler(sh);
65-
setSyncHandler(sh);
74+
this.syncHandler = new GhostCircuitSyncHandler(slot);
75+
isValidSyncHandler(this.syncHandler);
76+
setSyncHandler(this.syncHandler);
6677
return this;
6778
}
6879

6980
protected void getCircuitSlotTooltip(@NotNull RichTooltip tooltip) {
7081
String configString;
71-
int value = getSyncHandler().getGhostCircuitHandler().getCircuitValue();
82+
int value = this.syncHandler.getCircuitValue();
7283
if (value == GhostCircuitItemStackHandler.NO_CONFIG) {
7384
configString = IKey.lang("gregtech.gui.configurator_slot.no_value").get();
7485
} else {
@@ -78,11 +89,6 @@ protected void getCircuitSlotTooltip(@NotNull RichTooltip tooltip) {
7889
tooltip.addLine(IKey.lang("gregtech.gui.configurator_slot.tooltip", configString));
7990
}
8091

81-
@Override
82-
public @NotNull GhostCircuitSyncHandler getSyncHandler() {
83-
return (GhostCircuitSyncHandler) super.getSyncHandler();
84-
}
85-
8692
@Override
8793
public void onMouseDrag(int mouseButton, long timeSinceClick) {}
8894

@@ -92,44 +98,41 @@ public boolean onMouseRelease(int mouseButton) {
9298
}
9399

94100
private boolean isSelectorPanelOpen() {
95-
return getPanel().getScreen().isPanelOpen("circuit_selector");
101+
return this.getSelectorPanel().isPanelOpen();
96102
}
97103

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

135138
private static class GhostCircuitSyncHandler extends ItemSlotSH {
@@ -169,6 +172,14 @@ private void setCircuitValue(int value) {
169172
}
170173
}
171174

175+
public int getCircuitValue() {
176+
return getGhostCircuitHandler().getCircuitValue();
177+
}
178+
179+
public ItemStack getCircuitStack() {
180+
return getSlot().getStack();
181+
}
182+
172183
@Override
173184
public void readOnServer(int id, PacketBuffer buf) throws IOException {
174185
if (id == SYNC_CIRCUIT_INDEX) {

src/main/java/gregtech/mixins/minecraft/L18nMixin.java

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

src/main/java/gregtech/mixins/minecraft/LocaleMixin.java

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

src/main/java/gregtech/mixins/mui2/InputMixin.java

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

src/main/java/gregtech/mixins/mui2/LangKeyMixin.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
package gregtech.mixins.mui2;
22

3-
import gregtech.api.mui.LocaleAccessor;
4-
53
import com.cleanroommc.modularui.drawable.text.BaseKey;
64
import com.cleanroommc.modularui.drawable.text.LangKey;
75
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
86
import org.spongepowered.asm.mixin.Mixin;
97
import org.spongepowered.asm.mixin.injection.At;
10-
import org.spongepowered.asm.mixin.injection.Redirect;
118

12-
// todo remove in next mui2 version
9+
// all this mixin does is switch newlines to the expected format
1310
@Mixin(value = LangKey.class, remap = false)
1411
public abstract class LangKeyMixin extends BaseKey {
1512

16-
@Redirect(method = "getFormatted",
17-
at = @At(value = "INVOKE",
18-
target = "Lnet/minecraft/client/resources/I18n;format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;"))
19-
public String getTranslateKey(String translateKey, Object[] parameters) {
20-
return LocaleAccessor.getRawKey(translateKey)
13+
@ModifyExpressionValue(method = "getFormatted",
14+
at = @At(value = "INVOKE",
15+
target = "Lcom/cleanroommc/modularui/drawable/text/FontRenderHelper;formatArgs([Ljava/lang/Object;Lcom/cleanroommc/modularui/drawable/text/FormattingState;Ljava/lang/String;Z)Ljava/lang/String;"))
16+
public String getTranslateKey(String original) {
17+
return original
2118
.replace("\\n", "\n")
2219
.replace("/n", "\n");
2320
}

0 commit comments

Comments
 (0)