2013-08-27 00:49:32 +02:00
|
|
|
package mekanism.client.gui;
|
2013-04-13 02:25:21 +02:00
|
|
|
|
2013-12-01 06:03:40 +01:00
|
|
|
import mekanism.api.EnumColor;
|
2013-12-20 22:09:09 +01:00
|
|
|
import mekanism.api.Coord4D;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.api.energy.IEnergizedItem;
|
2013-04-13 02:25:21 +02:00
|
|
|
import mekanism.common.IElectricChest;
|
|
|
|
import mekanism.common.PacketHandler;
|
2013-06-13 23:37:30 +02:00
|
|
|
import mekanism.common.PacketHandler.Transmission;
|
|
|
|
import mekanism.common.network.PacketElectricChest;
|
|
|
|
import mekanism.common.network.PacketElectricChest.ElectricChestPacketType;
|
2014-01-08 02:55:50 +01:00
|
|
|
import mekanism.common.tile.TileEntityElectricChest;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.common.util.MekanismUtils;
|
|
|
|
import mekanism.common.util.MekanismUtils.ResourceType;
|
2013-04-13 02:25:21 +02:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
|
|
|
import net.minecraft.client.gui.GuiTextField;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-08-27 00:49:32 +02:00
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
import org.lwjgl.input.Keyboard;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2013-04-13 16:33:37 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-04-13 02:25:21 +02:00
|
|
|
public class GuiPasswordEnter extends GuiScreen
|
|
|
|
{
|
|
|
|
public int xSize = 176;
|
|
|
|
public int ySize = 95;
|
|
|
|
|
|
|
|
public TileEntityElectricChest tileEntity;
|
|
|
|
|
|
|
|
public ItemStack itemStack;
|
|
|
|
|
|
|
|
public boolean isBlock;
|
|
|
|
|
|
|
|
public GuiTextField passwordField;
|
|
|
|
|
2013-11-30 06:28:02 +01:00
|
|
|
public String displayText = EnumColor.BRIGHT_GREEN + MekanismUtils.localize("gui.password.enterPassword");
|
2013-04-13 02:25:21 +02:00
|
|
|
|
|
|
|
public int ticker = 0;
|
|
|
|
|
|
|
|
public GuiPasswordEnter(TileEntityElectricChest tileentity)
|
|
|
|
{
|
|
|
|
isBlock = true;
|
|
|
|
tileEntity = tileentity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiPasswordEnter(ItemStack itemstack)
|
|
|
|
{
|
|
|
|
isBlock = false;
|
|
|
|
itemStack = itemstack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void mouseClicked(int mouseX, int mouseY, int button)
|
|
|
|
{
|
|
|
|
super.mouseClicked(mouseX, mouseY, button);
|
|
|
|
passwordField.mouseClicked(mouseX, mouseY, button);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initGui()
|
|
|
|
{
|
|
|
|
super.initGui();
|
|
|
|
|
|
|
|
int guiWidth = (width - xSize) / 2;
|
|
|
|
int guiHeight = (height - ySize) / 2;
|
|
|
|
|
|
|
|
buttonList.clear();
|
2013-11-30 06:28:02 +01:00
|
|
|
buttonList.add(new GuiButton(0, guiWidth + 55, guiHeight + 68, 60, 20, MekanismUtils.localize("gui.open")));
|
2013-04-13 02:25:21 +02:00
|
|
|
|
|
|
|
passwordField = new GuiTextField(fontRenderer, guiWidth + 45, guiHeight + 50, 80, 12);
|
|
|
|
passwordField.setMaxStringLength(12);
|
|
|
|
passwordField.setFocused(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void keyTyped(char c, int i)
|
|
|
|
{
|
|
|
|
super.keyTyped(c, i);
|
|
|
|
|
|
|
|
if(i == Keyboard.KEY_RETURN)
|
|
|
|
{
|
|
|
|
tryOpen();
|
|
|
|
}
|
|
|
|
|
|
|
|
passwordField.textboxKeyTyped(c, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean doesGuiPauseGame()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateScreen()
|
|
|
|
{
|
|
|
|
passwordField.updateCursorCounter();
|
|
|
|
|
|
|
|
if(ticker > 0)
|
|
|
|
{
|
|
|
|
ticker--;
|
|
|
|
}
|
|
|
|
else {
|
2013-11-30 06:28:02 +01:00
|
|
|
displayText = EnumColor.BRIGHT_GREEN + MekanismUtils.localize("gui.password.enterPassword");
|
2013-04-13 02:25:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void actionPerformed(GuiButton guibutton)
|
|
|
|
{
|
|
|
|
if(guibutton.id == 0)
|
|
|
|
{
|
|
|
|
tryOpen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void tryOpen()
|
|
|
|
{
|
|
|
|
if(passwordField.getText() == null || passwordField.getText() == "")
|
|
|
|
{
|
2013-11-30 06:28:02 +01:00
|
|
|
displayText = EnumColor.DARK_RED + MekanismUtils.localize("gui.password.fieldsEmpty");
|
2013-11-05 03:11:09 +01:00
|
|
|
mc.sndManager.playSoundFX("mekanism:etc.Error", 1.0F, 1.0F);
|
2013-04-13 02:25:21 +02:00
|
|
|
ticker = 30;
|
|
|
|
}
|
|
|
|
else if(!getPassword().equals(passwordField.getText()))
|
|
|
|
{
|
2013-11-30 06:28:02 +01:00
|
|
|
displayText = EnumColor.DARK_RED + MekanismUtils.localize("gui.password.invalid");
|
2013-04-13 02:25:21 +02:00
|
|
|
passwordField.setText("");
|
2013-11-05 03:11:09 +01:00
|
|
|
mc.sndManager.playSoundFX("mekanism:etc.Error", 1.0F, 1.0F);
|
2013-04-13 02:25:21 +02:00
|
|
|
ticker = 30;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(isBlock)
|
|
|
|
{
|
2013-04-23 21:36:43 +02:00
|
|
|
tileEntity.setEnergy(tileEntity.getEnergy() - 100);
|
2013-12-20 22:09:09 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketElectricChest().setParams(ElectricChestPacketType.SERVER_OPEN, true, true, Coord4D.get(tileEntity)));
|
2013-04-13 02:25:21 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-04-23 21:36:43 +02:00
|
|
|
((IEnergizedItem)itemStack.getItem()).setEnergy(itemStack, ((IEnergizedItem)itemStack.getItem()).getEnergy(itemStack) - 100);
|
2013-06-15 00:25:09 +02:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketElectricChest().setParams(ElectricChestPacketType.SERVER_OPEN, true, false));
|
2013-04-13 02:25:21 +02:00
|
|
|
}
|
2013-11-05 03:11:09 +01:00
|
|
|
|
|
|
|
mc.sndManager.playSoundFX("mekanism:etc.Success", 1.0F, 1.0F);
|
2013-04-13 02:25:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPassword()
|
|
|
|
{
|
|
|
|
if(isBlock)
|
|
|
|
{
|
|
|
|
return tileEntity.password;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ((IElectricChest)itemStack.getItem()).getPassword(itemStack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-11-27 02:11:26 +01:00
|
|
|
public void drawScreen(int mouseX, int mouseY, float partialTick)
|
2013-04-13 02:25:21 +02:00
|
|
|
{
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
2013-09-28 03:59:47 +02:00
|
|
|
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiPasswordEnter.png"));
|
2013-04-13 02:25:21 +02:00
|
|
|
|
|
|
|
int guiWidth = (width - xSize) / 2;
|
|
|
|
int guiHeight = (height - ySize) / 2;
|
|
|
|
|
|
|
|
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
|
|
|
|
passwordField.drawTextBox();
|
2013-10-30 20:22:43 +01:00
|
|
|
|
2013-11-27 02:11:26 +01:00
|
|
|
super.drawScreen(mouseX, mouseY, partialTick);
|
2013-10-30 20:22:43 +01:00
|
|
|
|
2013-11-30 06:28:02 +01:00
|
|
|
fontRenderer.drawString(MekanismUtils.localize("gui.password"), guiWidth + 64, guiHeight + 5, 0x404040);
|
2013-04-13 02:25:21 +02:00
|
|
|
fontRenderer.drawString("Enter:", guiWidth + 45, guiHeight + 40, 0x404040);
|
|
|
|
fontRenderer.drawString(displayText, guiWidth + 37, guiHeight + 19, 0x404040);
|
2013-10-30 20:22:43 +01:00
|
|
|
|
2013-04-13 02:25:21 +02:00
|
|
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
GL11.glEnable(GL11.GL_CULL_FACE);
|
|
|
|
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
|
|
|
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
|
|
|
}
|
|
|
|
}
|