2013-04-13 02:25:21 +02:00
|
|
|
package mekanism.client;
|
|
|
|
|
|
|
|
import mekanism.api.EnumColor;
|
2013-04-23 21:36:43 +02:00
|
|
|
import mekanism.api.IEnergizedItem;
|
2013-06-13 23:37:30 +02:00
|
|
|
import mekanism.api.Object3D;
|
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;
|
2013-04-13 02:25:21 +02:00
|
|
|
import mekanism.common.TileEntityElectricChest;
|
2013-06-13 23:37:30 +02:00
|
|
|
import mekanism.common.network.PacketElectricChest;
|
|
|
|
import mekanism.common.network.PacketElectricChest.ElectricChestPacketType;
|
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-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;
|
|
|
|
|
|
|
|
public String displayText = EnumColor.BRIGHT_GREEN + "Enter password";
|
|
|
|
|
|
|
|
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();
|
|
|
|
buttonList.add(new GuiButton(0, guiWidth + 55, guiHeight + 68, 60, 20, "Open"));
|
|
|
|
|
|
|
|
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 {
|
|
|
|
displayText = EnumColor.BRIGHT_GREEN + "Enter password";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void actionPerformed(GuiButton guibutton)
|
|
|
|
{
|
|
|
|
if(guibutton.id == 0)
|
|
|
|
{
|
|
|
|
tryOpen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void tryOpen()
|
|
|
|
{
|
|
|
|
if(passwordField.getText() == null || passwordField.getText() == "")
|
|
|
|
{
|
|
|
|
displayText = EnumColor.DARK_RED + "Field empty";
|
|
|
|
ticker = 30;
|
|
|
|
}
|
|
|
|
else if(!getPassword().equals(passwordField.getText()))
|
|
|
|
{
|
|
|
|
displayText = EnumColor.DARK_RED + "Invalid";
|
|
|
|
passwordField.setText("");
|
|
|
|
ticker = 30;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(isBlock)
|
|
|
|
{
|
2013-04-23 21:36:43 +02:00
|
|
|
tileEntity.setEnergy(tileEntity.getEnergy() - 100);
|
2013-06-15 00:25:09 +02:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketElectricChest().setParams(ElectricChestPacketType.SERVER_OPEN, true, true, Object3D.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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPassword()
|
|
|
|
{
|
|
|
|
if(isBlock)
|
|
|
|
{
|
|
|
|
return tileEntity.password;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ((IElectricChest)itemStack.getItem()).getPassword(itemStack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawScreen(int i, int j, float f)
|
|
|
|
{
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
mc.renderEngine.bindTexture("/mods/mekanism/gui/GuiPasswordEnter.png");
|
|
|
|
|
|
|
|
int guiWidth = (width - xSize) / 2;
|
|
|
|
int guiHeight = (height - ySize) / 2;
|
|
|
|
|
|
|
|
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
|
|
|
|
passwordField.drawTextBox();
|
|
|
|
super.drawScreen(i, j, f);
|
|
|
|
fontRenderer.drawString("Password", guiWidth + 64, guiHeight + 5, 0x404040);
|
|
|
|
fontRenderer.drawString("Enter:", guiWidth + 45, guiHeight + 40, 0x404040);
|
|
|
|
fontRenderer.drawString(displayText, guiWidth + 37, guiHeight + 19, 0x404040);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|