Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport Lock Reason Display for Interface #507

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/api/java/appeng/api/config/LockCraftingMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ public enum LockCraftingMode {
*/
NONE,
/**
* After pushing a pattern to an adjacent machine, the pattern provider will not accept further crafts until a
* After pushing a pattern to an adjacent machine, the interface will not accept further crafts until a
* redstone pulse is received.
*/
LOCK_UNTIL_PULSE,
/**
* Crafting is locked while the pattern provider is receiving a redstone signal.
* Crafting is locked while the interface is receiving a redstone signal.
*/
LOCK_WHILE_HIGH,
/**
* Crafting is locked while the pattern provider is not receiving a redstone signal.
* Crafting is locked while the interface is not receiving a redstone signal.
*/
LOCK_WHILE_LOW,
/**
* After pushing a pattern to an adjacent machine, the pattern provider will not accept further crafts until the
* primary pattern result is returned to the network through the pattern provider.
* After pushing a pattern to an adjacent machine, the interface will not accept further crafts until the
* primary pattern result is returned to the network through the interface.
*/
LOCK_UNTIL_RESULT
}
6 changes: 6 additions & 0 deletions src/main/java/appeng/client/gui/AEBaseGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ public void drawScreen(final int mouseX, final int mouseY, final float partialTi
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand All @@ -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);
Expand All @@ -59,13 +67,18 @@ protected void addButtons() {
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() {
this.lockReason = new GuiImgLabel(this.fontRenderer, guiLeft + 40, guiTop + 12, Settings.UNLOCK, LockCraftingMode.NONE);
zeng-github01 marked this conversation as resolved.
Show resolved Hide resolved
labelList.add(lockReason);
}

@Override
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
if (this.BlockMode != null) {
Expand All @@ -80,6 +93,10 @@ public void drawFG(final int offsetX, final int offsetY, final int mouseX, final
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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/client/gui/widgets/GuiImgButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public void setFillVar(final String fillVar) {
this.fillVar = fillVar;
}

private static final class EnumPair {
public static final class EnumPair {

final Enum setting;
final Enum value;
Expand Down
142 changes: 142 additions & 0 deletions src/main/java/appeng/client/gui/widgets/GuiImgLabel.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class ContainerInterface extends ContainerUpgradeable implements IOptiona
@GuiSync(8)
public YesNo iTermMode = YesNo.YES;

@GuiSync(9)
public LockCraftingMode lockReason = LockCraftingMode.NONE;

public ContainerInterface(final InventoryPlayer ip, final IInterfaceHost te) {
super(ip, te.getInterfaceDuality().getHost());

Expand Down Expand Up @@ -94,6 +97,10 @@ public void detectAndSendChanges() {
patternExpansions = getPatternUpgrades();
this.myDuality.dropExcessPatterns();
}

if (Platform.isServer()){
lockReason = myDuality.getCraftingLockedReason();
}
super.detectAndSendChanges();
}

Expand Down Expand Up @@ -134,4 +141,8 @@ private void setInterfaceTerminalMode(final YesNo iTermMode) {
public int getPatternUpgrades() {
return this.myDuality.getInstalledUpgrades(Upgrades.PATTERN_EXPANSION);
}

public LockCraftingMode getCraftingLockedReason() {
return lockReason;
}
}
9 changes: 9 additions & 0 deletions src/main/java/appeng/core/localization/GuiText.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ public enum GuiText {
CraftingToastDone,
CraftingToastCancelled,

//Used in Lock Crafting,
CraftingLock,
NoneLock,
LowRedstoneLock,
HighRedstoneLock,
ResultLock,
UntilPulseUnlock,

// Used in Annihilation Planes
CanBeEnchanted,
IncreasedEnergyUseFromEnchants,
Deprecated;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/appeng/helpers/DualityInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ private void onPushPatternSuccess(ICraftingPatternDetails pattern) {
/**
* Gets if the crafting lock is in effect and why.
*
* @return null if the lock isn't in effect
* @return {@link LockCraftingMode#NONE} if the lock isn't in effect
*/
public LockCraftingMode getCraftingLockedReason() {
var lockMode = cm.getSetting(Settings.UNLOCK);
Expand Down Expand Up @@ -1520,7 +1520,7 @@ public void updateRedstoneState() {
/**
* @return Null if {@linkplain #getCraftingLockedReason()} is not {@link LockCraftingMode#LOCK_UNTIL_RESULT}.
*/
@org.jetbrains.annotations.Nullable
@Nullable
public IAEItemStack getUnlockStack() {
return unlockStack;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/appliedenergistics2/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ gui.appliedenergistics2.CraftingToastDone=Crafting Done!
gui.appliedenergistics2.CraftingToastCancelled=Crafting Cancelled!
gui.appliedenergistics2.Sticky=Sticky
gui.appliedenergistics2.FluidTerminal=Fluid Terminal
gui.appliedenergistics2.CraftingLock=Crafting is locked
gui.appliedenergistics2.NoneLock=Crafting is unlocked
gui.appliedenergistics2.HighRedstoneLock=Locked by redstone signal
gui.appliedenergistics2.LowRedstoneLock=Locked by lack of redstone signal
gui.appliedenergistics2.ResultLock=Waiting for pattern output to unlock
gui.appliedenergistics2.UntilPulseUnlock=Waiting for redstone pulse to unlock
gui.appliedenergistics2.CanBeEnchanted=Can be enchanted
gui.appliedenergistics2.IncreasedEnergyUseFromEnchants=Enchants increase energy use
gui.appliedenergistics2.Deprecated=Deprecated
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/appliedenergistics2/lang/zh_cn.lang
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ gui.appliedenergistics2.CraftingToastDone=合成已完成!
gui.appliedenergistics2.CraftingToastCancelled=合成已取消!
gui.appliedenergistics2.Sticky=粘滞
gui.appliedenergistics2.FluidTerminal=流体终端
gui.appliedenergistics2.NoneLock=合成已解锁
gui.appliedenergistics2.CraftingLock=合成已锁定
gui.appliedenergistics2.LowRedstoneLock=由于缺少红石信号而锁定
gui.appliedenergistics2.HighRedstoneLock=由于红石信号而锁定
gui.appliedenergistics2.ResultLock=等待样板输出解锁
gui.appliedenergistics2.UntilPulseUnlock=等待红石脉冲解锁
gui.appliedenergistics2.CanBeEnchanted=可被附魔
gui.appliedenergistics2.IncreasedEnergyUseFromEnchants=附魔会增加能耗
gui.appliedenergistics2.Deprecated=已弃用
Expand Down