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

Regulator card #613

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/main/java/appeng/api/config/ActionItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public enum ActionItems {
SUBSTITUTION,
SLOT_CONFIG,
ORE_FILTER,
REGULATOR_CARD,
REGULATOR_CARD_STOCK,
DOUBLE,
MULTIPLY,
DIVIDE,
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/appeng/api/config/Upgrades.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public enum Upgrades {
PATTERN_CAPACITY(1),
ORE_FILTER(1),
ADVANCED_BLOCKING(1),
LOCK_CRAFTING(1);
LOCK_CRAFTING(1),
REGULATOR(1);

/**
* @deprecated use {@link Upgrades#getTier()}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/appeng/api/definitions/IMaterials.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@ public interface IMaterials {
IItemDefinition cardAdvancedBlocking();

IItemDefinition cardLockCrafting();

IItemDefinition cardRegulator();
}
2 changes: 2 additions & 0 deletions src/main/java/appeng/api/definitions/Materials.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public class Materials {

public AEItemDefinition materialCardSticky;

public AEItemDefinition materialCardRegulator;

public AEItemDefinition materialEnderDust;

public AEItemDefinition materialFlour;
Expand Down
178 changes: 178 additions & 0 deletions src/main/java/appeng/client/gui/implementations/GuiRegulatorCard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
package appeng.client.gui.implementations;

import java.io.IOException;

import net.minecraft.entity.player.InventoryPlayer;

import org.lwjgl.input.Keyboard;

import appeng.api.config.ActionItems;
import appeng.api.config.Settings;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.MEGuiTextField;
import appeng.container.AEBaseContainer;
import appeng.container.implementations.ContainerRegulatorCard;
import appeng.core.AELog;
import appeng.core.localization.GuiColors;
import appeng.core.localization.GuiText;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.IRegulatorCard;
import appeng.parts.automation.PartSharedItemBus;
import appeng.parts.misc.PartStorageBus;

public class GuiRegulatorCard extends AEBaseGui {

private MEGuiTextField amountField;
private MEGuiTextField ticksField;
private MEGuiTextField stockModeLabel;
private GuiImgButton stockModeButtonActive;
private boolean stockMode;

public GuiRegulatorCard(InventoryPlayer ip, IRegulatorCard obj) {
super(new ContainerRegulatorCard(ip, obj));
this.xSize = 256;

this.amountField = new MEGuiTextField(75, 12);
this.ticksField = new MEGuiTextField(40, 12);
this.stockModeLabel = new MEGuiTextField(70, 12) {

@Override
public void onTextChange(final String oldText) {
final String text = getText();
if (text == "Active") {
stockMode = true;
} else if (text == "Not Active") {
stockMode = false;
}
}
};
this.stockModeButtonActive = new GuiImgButton(
this.guiLeft,
this.guiTop,
Settings.ACTIONS,
ActionItems.REGULATOR_CARD_STOCK);

}

@Override
public void initGui() {
super.initGui();

this.amountField.x = this.guiLeft + 64;
this.amountField.y = this.guiTop + 32;

this.ticksField.x = this.guiLeft + 152;
this.ticksField.y = this.guiTop + 32;

this.stockModeLabel.x = this.guiLeft + 84;
this.stockModeLabel.y = this.guiTop + 48;

this.stockModeButtonActive.xPosition = this.guiLeft + 64;
this.stockModeButtonActive.yPosition = this.guiTop + 46;

this.buttonList.add(this.stockModeButtonActive);
((ContainerRegulatorCard) this.inventorySlots).setAmountField(this.amountField);
((ContainerRegulatorCard) this.inventorySlots).setTicksField(this.ticksField);
((ContainerRegulatorCard) this.inventorySlots).setStockModeField(this.stockModeLabel);
}

@Override
public void onGuiClosed() {
super.onGuiClosed();
}

public String filterRegulatorSettings(final String amount, final String ticks) {
String s = "1000:20";
if (amount != "" && ticks != "") {
try {
if (Integer.parseInt(amount) == 0) {
s = "1:";
} else {
s = amount + ":";
}
} catch (Exception ignored) {
s = Integer.MAX_VALUE + ":";
}
try {
final int m = Integer.parseInt(ticks);
if (m > 72000) {
s += "72000";
} else if (m == 0) {
s += "1";
} else {
s += ticks;
}
} catch (Exception ignored) {
s += "72000";
}
} else if (amount == "" && ticks != "") {
s = "1000:" + ticks;
} else if (ticks == "") {
s = amount + ":20";
}
return s;
}

@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.fontRendererObj
.drawString(GuiText.RegulatorCardLabel.getLocal(), 58, 6, GuiColors.RegulatorCardLabel.getColor());
this.fontRendererObj
.drawString(GuiText.RegulatorCardAmount.getLocal(), 64, 23, GuiColors.RegulatorCardAmount.getColor());
this.fontRendererObj
.drawString(GuiText.RegulatorCardTicks.getLocal(), 152, 23, GuiColors.RegulatorCardTicks.getColor());
}

@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.bindTexture("guis/regulator.png");
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize);
this.amountField.drawTextBox();
this.ticksField.drawTextBox();
this.stockModeLabel.drawTextBox();
}

@Override
protected void mouseClicked(final int xCoord, final int yCoord, final int btn) {
this.amountField.mouseClicked(xCoord, yCoord, btn);
this.ticksField.mouseClicked(xCoord, yCoord, btn);
if (this.stockModeButtonActive.mousePressed(mc, xCoord, yCoord)) {
if (!stockMode) {
this.stockModeLabel.setText("Active");
} else {
this.stockModeLabel.setText("Not Active");
}
}
super.mouseClicked(xCoord, yCoord, btn);
}

@Override
protected void keyTyped(final char character, final int key) {
if (key == Keyboard.KEY_RETURN || key == Keyboard.KEY_NUMPADENTER) {
try {
NetworkHandler.instance.sendToServer(
new PacketValueConfig(
"RegulatorSettings",
filterRegulatorSettings(this.amountField.getText(), this.ticksField.getText()) + ":"
+ stockMode));
} catch (IOException e) {
AELog.debug(e);
}
final Object target = ((AEBaseContainer) this.inventorySlots).getTarget();
GuiBridge OriginalGui = null;
if (target instanceof PartStorageBus) OriginalGui = GuiBridge.GUI_STORAGEBUS;
else if (target instanceof PartSharedItemBus) OriginalGui = GuiBridge.GUI_BUS;

if (OriginalGui != null) NetworkHandler.instance.sendToServer(new PacketSwitchGuis(OriginalGui));
else this.mc.thePlayer.closeScreen();

} else if (!(this.amountField.textboxKeyTyped(character, key)
|| this.ticksField.textboxKeyTyped(character, key))) {
super.keyTyped(character, key);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class GuiUpgradeable extends AEBaseGui implements INEIGuiHandler {
protected GuiImgButton craftMode;
protected GuiImgButton schedulingMode;
protected GuiImgButton oreFilter;
protected GuiImgButton regulatorCard;

public GuiUpgradeable(final InventoryPlayer inventoryPlayer, final IUpgradeableHost te) {
this(new ContainerUpgradeable(inventoryPlayer, te));
Expand Down Expand Up @@ -119,12 +120,18 @@ protected void addButtons() {
this.guiTop + 28,
Settings.ACTIONS,
ActionItems.ORE_FILTER);
this.regulatorCard = new GuiImgButton(
this.guiLeft - 18,
this.guiTop + 46,
Settings.ACTIONS,
ActionItems.REGULATOR_CARD);

this.buttonList.add(this.craftMode);
this.buttonList.add(this.redstoneMode);
this.buttonList.add(this.fuzzyMode);
this.buttonList.add(this.schedulingMode);
this.buttonList.add(this.oreFilter);
this.buttonList.add(this.regulatorCard);
}

@Override
Expand Down Expand Up @@ -202,6 +209,9 @@ protected void handleButtonVisibility() {
if (this.oreFilter != null) {
this.oreFilter.setVisibility(this.bc.getInstalledUpgrades(Upgrades.ORE_FILTER) > 0);
}
if (this.regulatorCard != null) {
this.regulatorCard.setVisibility(this.bc.getInstalledUpgrades(Upgrades.REGULATOR) > 0);
}
}

protected String getBackground() {
Expand Down Expand Up @@ -245,6 +255,10 @@ protected void actionPerformed(final GuiButton btn) {
if (btn == this.oreFilter) {
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(GuiBridge.GUI_ORE_FILTER));
}

if (btn == this.regulatorCard) {
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(GuiBridge.GUI_REGULATOR_CARD));
}
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/appeng/client/gui/widgets/GuiImgButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,18 @@ public GuiImgButton(final int x, final int y, final Enum idx, final Enum val) {
StringOrder.ALPHANUM,
ButtonToolTips.StringOrder,
ButtonToolTips.StringOrderAlphanum);
this.registerApp(
16 * 15 + 3,
Settings.ACTIONS,
ActionItems.REGULATOR_CARD,
ButtonToolTips.RegulatorCardLabel,
ButtonToolTips.RegulatorCardHint);
this.registerApp(
16 * 15 + 4,
Settings.ACTIONS,
ActionItems.REGULATOR_CARD_STOCK,
ButtonToolTips.RegulatorCardStockLabel,
ButtonToolTips.RegulatorCardStockHint);

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package appeng.container.implementations;

import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.tileentity.TileEntity;

import appeng.api.parts.IPart;
import appeng.client.gui.widgets.MEGuiTextField;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.helpers.IRegulatorCard;
import appeng.util.Platform;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ContainerRegulatorCard extends AEBaseContainer {

private final IRegulatorCard filterHost;

@SideOnly(Side.CLIENT)
private MEGuiTextField amountField;

@SideOnly(Side.CLIENT)
private MEGuiTextField ticksField;

@SideOnly(Side.CLIENT)
private MEGuiTextField stockModeField;

@GuiSync(69)
public String regulatorSettings;

public ContainerRegulatorCard(final InventoryPlayer ip, final IRegulatorCard te) {
super(ip, (TileEntity) (te instanceof TileEntity ? te : null), (IPart) (te instanceof IPart ? te : null));
this.filterHost = te;
}

@SideOnly(Side.CLIENT)
public void setAmountField(final MEGuiTextField f) {
this.amountField = f;
}

@SideOnly(Side.CLIENT)
public void setTicksField(final MEGuiTextField f) {
this.ticksField = f;
}

@SideOnly(Side.CLIENT)
public void setStockModeField(final MEGuiTextField f) {
this.stockModeField = f;
}

public void setRegulatorSettings(final String newValue) {
this.filterHost.setRegulatorSettings(newValue);
this.regulatorSettings = newValue;
}

@Override
public void detectAndSendChanges() {
if (Platform.isServer()) this.regulatorSettings = this.filterHost.getRegulatorSettings();
super.detectAndSendChanges();
}

@Override
public void onUpdate(final String field, final Object oldValue, final Object newValue) {
if (field.equals("regulatorSettings") && (this.amountField != null && this.ticksField != null)) {
String[] rs = regulatorSettings.split(":");
this.amountField.setText(rs[0]);
this.ticksField.setText(rs[1]);
if (Boolean.parseBoolean(rs[2])) {
this.stockModeField.setText("Active");
} else {
this.stockModeField.setText("Not Active");
}
}
super.onUpdate(field, oldValue, newValue);
}
}
3 changes: 3 additions & 0 deletions src/main/java/appeng/core/Registration.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ private void assignMaterials(final Materials target, final IMaterials source) {
target.materialCardInverter = this.converter.of(source.cardInverter());
target.materialCardCrafting = this.converter.of(source.cardCrafting());
target.materialCardSticky = this.converter.of(source.cardSticky());
target.materialCardRegulator = this.converter.of(source.cardRegulator());

target.materialEnderDust = this.converter.of(source.enderDust());
target.materialFlour = this.converter.of(source.flour());
Expand Down Expand Up @@ -629,6 +630,7 @@ void postInit(final FMLPostInitializationEvent event) {
Upgrades.CAPACITY.registerItem(parts.importBus(), 2);
Upgrades.SPEED.registerItem(parts.importBus(), 4);
Upgrades.ORE_FILTER.registerItem(parts.importBus(), 1);
Upgrades.REGULATOR.registerItem(parts.importBus(), 1);

// Export Bus
Upgrades.FUZZY.registerItem(parts.exportBus(), 1);
Expand All @@ -637,6 +639,7 @@ void postInit(final FMLPostInitializationEvent event) {
Upgrades.SPEED.registerItem(parts.exportBus(), 4);
Upgrades.CRAFTING.registerItem(parts.exportBus(), 1);
Upgrades.ORE_FILTER.registerItem(parts.exportBus(), 1);
Upgrades.REGULATOR.registerItem(parts.exportBus(), 1);

// Storage Cells
Upgrades.FUZZY.registerItem(items.cell1k(), 1);
Expand Down
Loading