Skip to content

Commit

Permalink
Update to MUI2 RC4 (GregTechCEu#2730)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude authored Feb 27, 2025
1 parent 5f2561a commit 9f26e68
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 342 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
dependencies {
// Published dependencies
api("codechicken:codechickenlib:3.2.3.358")
api("com.cleanroommc:modularui:2.5.0-rc3") { transitive = false }
api("com.cleanroommc:modularui:2.5.0-rc4") { transitive = false }
api("com.cleanroommc:groovyscript:1.2.0-hotfix1") { transitive = false }
api("curse.maven:inventory-bogosorter-632327:4951607-deobf-4951608-sources-4951609")
api("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.700")
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/gregtech/api/mui/LocaleAccessor.java

This file was deleted.

109 changes: 60 additions & 49 deletions src/main/java/gregtech/api/mui/widget/GhostCircuitSlotWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,35 @@
import gregtech.api.recipes.ingredients.IntCircuitIngredient;
import gregtech.client.utils.TooltipHelper;

import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.items.IItemHandler;

import com.cleanroommc.modularui.api.IPanelHandler;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.api.widget.IWidget;
import com.cleanroommc.modularui.api.widget.Interactable;
import com.cleanroommc.modularui.drawable.ItemDrawable;
import com.cleanroommc.modularui.screen.ModularScreen;
import com.cleanroommc.modularui.screen.RichTooltip;
import com.cleanroommc.modularui.utils.MouseData;
import com.cleanroommc.modularui.value.sync.ItemSlotSH;
import com.cleanroommc.modularui.value.sync.SyncHandler;
import com.cleanroommc.modularui.widget.Widget;
import com.cleanroommc.modularui.widgets.ButtonWidget;
import com.cleanroommc.modularui.widgets.ItemSlot;
import com.cleanroommc.modularui.widgets.layout.Grid;
import com.cleanroommc.modularui.widgets.slot.ModularSlot;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class GhostCircuitSlotWidget extends ItemSlot {

private static final int SYNC_CIRCUIT_INDEX = 10;
@Nullable
private IPanelHandler selectorPanel;
private GhostCircuitSyncHandler syncHandler;

public GhostCircuitSlotWidget() {
super();
Expand All @@ -41,7 +45,7 @@ public GhostCircuitSlotWidget() {
public @NotNull Result onMousePressed(int mouseButton) {
if (!isSelectorPanelOpen()) {
if (mouseButton == 0 && TooltipHelper.isShiftDown()) {
createSelectorPanel();
this.getSelectorPanel().openPanel();
} else {
MouseData mouseData = MouseData.create(mouseButton);
getSyncHandler().syncToServer(2, mouseData::writeToPacket);
Expand All @@ -58,17 +62,24 @@ public boolean onMouseScroll(ModularScreen.UpOrDown scrollDirection, int amount)
return true;
}

@Override
public boolean isValidSyncHandler(SyncHandler syncHandler) {
this.syncHandler = castIfTypeElseNull(syncHandler, GhostCircuitSyncHandler.class);
if (this.syncHandler == null) return false;
return super.isValidSyncHandler(syncHandler);
}

@Override
public ItemSlot slot(ModularSlot slot) {
ItemSlotSH sh = new GhostCircuitSyncHandler(slot);
isValidSyncHandler(sh);
setSyncHandler(sh);
this.syncHandler = new GhostCircuitSyncHandler(slot);
isValidSyncHandler(this.syncHandler);
setSyncHandler(this.syncHandler);
return this;
}

protected void getCircuitSlotTooltip(@NotNull RichTooltip tooltip) {
String configString;
int value = getSyncHandler().getGhostCircuitHandler().getCircuitValue();
int value = this.syncHandler.getCircuitValue();
if (value == GhostCircuitItemStackHandler.NO_CONFIG) {
configString = IKey.lang("gregtech.gui.configurator_slot.no_value").get();
} else {
Expand All @@ -78,11 +89,6 @@ protected void getCircuitSlotTooltip(@NotNull RichTooltip tooltip) {
tooltip.addLine(IKey.lang("gregtech.gui.configurator_slot.tooltip", configString));
}

@Override
public @NotNull GhostCircuitSyncHandler getSyncHandler() {
return (GhostCircuitSyncHandler) super.getSyncHandler();
}

@Override
public void onMouseDrag(int mouseButton, long timeSinceClick) {}

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

private boolean isSelectorPanelOpen() {
return getPanel().getScreen().isPanelOpen("circuit_selector");
return this.getSelectorPanel().isPanelOpen();
}

private void createSelectorPanel() {
ItemDrawable circuitPreview = new ItemDrawable(getSyncHandler().getSlot().getStack());

IPanelHandler.simple(getPanel(), (mainPanel, player) -> {
var panel = GTGuis.createPopupPanel("circuit_selector", 176, 120);
List<List<IWidget>> options = new ArrayList<>();
for (int i = 0; i < 4; i++) {
options.add(new ArrayList<>());
for (int j = 0; j < 9; j++) {
int index = i * 9 + j;
if (index > 32) break;
options.get(i).add(new ButtonWidget<>()
.size(18)
.background(GTGuiTextures.SLOT, new ItemDrawable(
IntCircuitIngredient.getIntegratedCircuit(index)).asIcon())
.disableHoverBackground()
.onMousePressed(mouseButton -> {
getSyncHandler().syncToServer(SYNC_CIRCUIT_INDEX, buf -> buf.writeShort(index));
circuitPreview.setItem(IntCircuitIngredient.getIntegratedCircuit(index));
if (Interactable.hasShiftDown()) panel.animateClose();
return true;
}));
}
}
return panel.child(IKey.lang("metaitem.circuit.integrated.gui").asWidget().pos(5, 5))
.child(circuitPreview.asIcon().size(16).asWidget()
.size(18)
.top(19).alignX(0.5f)
.background(GTGuiTextures.SLOT, GTGuiTextures.INT_CIRCUIT_OVERLAY))
.child(new Grid()
.left(7).right(7).top(41).height(4 * 18)
.matrix(options)
.minColWidth(18).minRowHeight(18)
.minElementMargin(0, 0));
}, true).openPanel();
@NotNull
private IPanelHandler getSelectorPanel() {
if (this.selectorPanel == null) {
this.selectorPanel = IPanelHandler.simple(getPanel(), (mainPanel, player) -> {
ItemDrawable circuitPreview = new ItemDrawable(this.syncHandler.getCircuitStack());

return GTGuis.createPopupPanel("circuit_selector", 176, 120)
.child(IKey.lang("metaitem.circuit.integrated.gui").asWidget().pos(5, 5))
.child(new Widget<>()
.size(18)
.top(19).alignX(0.5f)
.overlay(circuitPreview.asIcon().margin(1))
.background(GTGuiTextures.SLOT, GTGuiTextures.INT_CIRCUIT_OVERLAY))
.child(new Grid()
.left(7).right(7).top(41).height(4 * 18)
.mapTo(9, 33, value -> new ButtonWidget<>()
.size(18)
.background(GTGuiTextures.SLOT, new ItemDrawable(
IntCircuitIngredient.getIntegratedCircuit(value)).asIcon())
.disableHoverBackground()
.onMousePressed(mouseButton -> {
getSyncHandler().syncToServer(SYNC_CIRCUIT_INDEX,
buf -> buf.writeShort(value));
circuitPreview.setItem(IntCircuitIngredient.getIntegratedCircuit(value));
if (Interactable.hasShiftDown()) this.selectorPanel.closePanel();
return true;
}))
.minColWidth(18).minRowHeight(18)
.minElementMargin(0, 0));
}, true);
}
return this.selectorPanel;
}

private static class GhostCircuitSyncHandler extends ItemSlotSH {
Expand Down Expand Up @@ -169,6 +172,14 @@ private void setCircuitValue(int value) {
}
}

public int getCircuitValue() {
return getGhostCircuitHandler().getCircuitValue();
}

public ItemStack getCircuitStack() {
return getSlot().getStack();
}

@Override
public void readOnServer(int id, PacketBuffer buf) throws IOException {
if (id == SYNC_CIRCUIT_INDEX) {
Expand Down
21 changes: 0 additions & 21 deletions src/main/java/gregtech/mixins/minecraft/L18nMixin.java

This file was deleted.

23 changes: 0 additions & 23 deletions src/main/java/gregtech/mixins/minecraft/LocaleMixin.java

This file was deleted.

64 changes: 0 additions & 64 deletions src/main/java/gregtech/mixins/mui2/InputMixin.java

This file was deleted.

15 changes: 6 additions & 9 deletions src/main/java/gregtech/mixins/mui2/LangKeyMixin.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package gregtech.mixins.mui2;

import gregtech.api.mui.LocaleAccessor;

import com.cleanroommc.modularui.drawable.text.BaseKey;
import com.cleanroommc.modularui.drawable.text.LangKey;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

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

@Redirect(method = "getFormatted",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/resources/I18n;format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;"))
public String getTranslateKey(String translateKey, Object[] parameters) {
return LocaleAccessor.getRawKey(translateKey)
@ModifyExpressionValue(method = "getFormatted",
at = @At(value = "INVOKE",
target = "Lcom/cleanroommc/modularui/drawable/text/FontRenderHelper;formatArgs([Ljava/lang/Object;Lcom/cleanroommc/modularui/drawable/text/FormattingState;Ljava/lang/String;Z)Ljava/lang/String;"))
public String getTranslateKey(String original) {
return original
.replace("\\n", "\n")
.replace("/n", "\n");
}
Expand Down
Loading

0 comments on commit 9f26e68

Please sign in to comment.