Further crafting lock improvements (#507)

This commit is contained in:
zeng-git
2025-03-10 15:40:11 +08:00
committed by GitHub
parent 202259ef2a
commit e833aa1e61
10 changed files with 211 additions and 14 deletions
@@ -183,6 +183,12 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
this.drawTooltip((ITooltip) c, mouseX, mouseY);
}
}
for (final Object o : this.labelList) {
if (o instanceof ITooltip) {
this.drawTooltip((ITooltip) o, mouseX, mouseY);
}
}
GlStateManager.enableDepth();
if (Platform.isModLoaded("jei")) {
bookmarkedJEIghostItem(mouseX, mouseY);
@@ -23,6 +23,7 @@ import appeng.api.config.LockCraftingMode;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiImgLabel;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.gui.widgets.GuiToggleButton;
import appeng.container.implementations.ContainerInterface;
@@ -45,12 +46,19 @@ public class GuiInterface extends GuiUpgradeable {
private GuiImgButton UnlockMode;
private GuiImgButton BlockMode;
private GuiToggleButton interfaceMode;
private GuiImgLabel lockReason;
public GuiInterface(final InventoryPlayer inventoryPlayer, final IInterfaceHost te) {
super(new ContainerInterface(inventoryPlayer, te));
this.ySize = 256;
}
@Override
public void initGui() {
super.initGui();
this.addLabel();
}
@Override
protected void addButtons() {
this.priority = new GuiTabButton(this.guiLeft + 154, this.guiTop, 2 + 4 * 16, GuiText.Priority.getLocal(), this.itemRender);
@@ -59,13 +67,21 @@ public class GuiInterface extends GuiUpgradeable {
this.BlockMode = new GuiImgButton(this.guiLeft - 18, this.guiTop + 8, Settings.BLOCK, YesNo.NO);
this.buttonList.add(this.BlockMode);
this.UnlockMode = new GuiImgButton(this.guiLeft - 18,this.guiTop + 26 ,Settings.UNLOCK, LockCraftingMode.NONE);
this.UnlockMode = new GuiImgButton(this.guiLeft - 18, this.guiTop + 26, Settings.UNLOCK, LockCraftingMode.NONE);
this.buttonList.add(this.UnlockMode);
this.interfaceMode = new GuiToggleButton(this.guiLeft - 18, this.guiTop + 44, 84, 85, GuiText.InterfaceTerminal.getLocal(), GuiText.InterfaceTerminalHint.getLocal());
this.buttonList.add(this.interfaceMode);
}
protected void addLabel() {
if (lockReason != null) {
labelList.remove(this.lockReason);
}
this.lockReason = new GuiImgLabel(this.fontRenderer, guiLeft + 40, guiTop + 12, Settings.UNLOCK, LockCraftingMode.NONE);
labelList.add(lockReason);
}
@Override
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
if (this.BlockMode != null) {
@@ -80,6 +96,10 @@ public class GuiInterface extends GuiUpgradeable {
this.interfaceMode.setState(((ContainerInterface) this.cvb).getInterfaceTerminalMode() == YesNo.YES);
}
if (this.lockReason != null) {
this.lockReason.set(((ContainerInterface) this.cvb).getCraftingLockedReason());
}
this.fontRenderer.drawString(this.getGuiDisplayName(GuiText.Interface.getLocal()), 8, 6, 4210752);
this.fontRenderer.drawString(GuiText.Config.getLocal(), 8, 6 + 11 + 7, 4210752);
@@ -345,7 +345,7 @@ public class GuiImgButton extends GuiButton implements ITooltip {
this.fillVar = fillVar;
}
private static final class EnumPair {
public static final class EnumPair {
final Enum setting;
final Enum value;
@@ -0,0 +1,142 @@
package appeng.client.gui.widgets;
import appeng.api.config.LockCraftingMode;
import appeng.api.config.Settings;
import appeng.core.localization.GuiText;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiLabel;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import java.util.HashMap;
import java.util.Map;
public class GuiImgLabel extends GuiLabel implements ITooltip {
public GuiImgLabel(FontRenderer fontRendererObj, final int x, final int y, final Enum idx, final Enum val) {
super(fontRendererObj, 0, x, y, 16, 16, 0);
this.currentValue = val;
this.labelSetting = idx;
this.fontRenderer = fontRendererObj;
if (appearances == null) {
appearances = new HashMap<>();
registerApp(10, Settings.UNLOCK, LockCraftingMode.NONE, GuiText.NoneLock, null, 0x00FF00);
registerApp(9, Settings.UNLOCK, LockCraftingMode.LOCK_WHILE_LOW, GuiText.CraftingLock, GuiText.LowRedstoneLock, 0xFF0000);
registerApp(9, Settings.UNLOCK, LockCraftingMode.LOCK_WHILE_HIGH, GuiText.CraftingLock, GuiText.HighRedstoneLock, 0xFF0000);
registerApp(9, Settings.UNLOCK, LockCraftingMode.LOCK_UNTIL_PULSE, GuiText.CraftingLock, GuiText.UntilPulseUnlock, 0xFF0000);
registerApp(9, Settings.UNLOCK, LockCraftingMode.LOCK_UNTIL_RESULT, GuiText.CraftingLock, GuiText.ResultLock, 0xFF0000);
}
}
private final Enum labelSetting;
private Enum currentValue;
private static Map<GuiImgButton.EnumPair, LabelAppearance> appearances;
private final FontRenderer fontRenderer;
public void setVisibility(final boolean vis) {
this.visible = vis;
}
@Override
public void drawLabel(Minecraft mc, int mouseX, int mouseY) {
if (this.visible) {
final int iconIndex = this.getIconIndex();
if (iconIndex == -1) {
return;
}
mc.renderEngine.bindTexture(new ResourceLocation("appliedenergistics2", "textures/guis/states.png"));
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
final int uv_y = (int) Math.floor(iconIndex / 16);
final int uv_x = iconIndex - uv_y * 16;
this.drawTexturedModalRect(this.x, this.y, uv_x * 16, uv_y * 16, 16, 16);
if (labelSetting != null && currentValue != null) {
LabelAppearance labelAppearance = appearances.get(new GuiImgButton.EnumPair(this.labelSetting, this.currentValue));
String translated = I18n.translateToLocal(labelAppearance.displayLabel);
fontRenderer.drawString(translated, x + 16, y + 5, labelAppearance.color);
width = 16 + fontRenderer.getStringWidth(translated);
}
}
}
private int getIconIndex() {
if (this.labelSetting != null && this.currentValue != null) {
final LabelAppearance app = appearances.get(new GuiImgButton.EnumPair(this.labelSetting, this.currentValue));
if (app == null) {
return -1;
}
return app.index;
}
return -1;
}
private void registerApp(final int iconIndex, final Settings setting, final Enum val, final GuiText label, final Object hint, int color) {
final LabelAppearance a = new LabelAppearance();
if (hint != null) {
a.hiddenValue = (String) (hint instanceof String ? hint : ((GuiText) hint).getUnlocalized());
} else {
a.hiddenValue = null;
}
a.index = iconIndex;
a.displayLabel = label.getUnlocalized();
a.color = color;
appearances.put(new GuiImgButton.EnumPair(setting, val), a);
}
@Override
public String getMessage() {
if (labelSetting != null && this.currentValue != null) {
LabelAppearance labelAppearance = appearances.get(new GuiImgButton.EnumPair(this.labelSetting, this.currentValue));
if (labelAppearance == null) {
return "No Such Message";
}
if (labelAppearance.hiddenValue != null) {
return I18n.translateToLocal(labelAppearance.hiddenValue);
}
}
return null;
}
public void set(final Enum e) {
if (this.currentValue != e) {
this.currentValue = e;
}
}
@Override
public int xPos() {
return x;
}
@Override
public int yPos() {
return y;
}
@Override
public int getWidth() {
return width;
}
@Override
public int getHeight() {
return height;
}
@Override
public boolean isVisible() {
return visible;
}
private static class LabelAppearance {
public int index;
public String displayLabel;
public String hiddenValue;
public int color;
}
}