2012-11-05 20:29:04 +01:00
|
|
|
package mekanism.client;
|
2012-11-05 16:46:50 +01:00
|
|
|
|
2013-03-11 18:49:01 +01:00
|
|
|
import mekanism.api.EnumColor;
|
2012-11-05 20:29:04 +01:00
|
|
|
import mekanism.api.IAccessibleGui;
|
2012-11-21 16:14:35 +01:00
|
|
|
import mekanism.common.PacketHandler;
|
|
|
|
import mekanism.common.TileEntityControlPanel;
|
2012-12-20 22:53:39 +01:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
|
|
|
import net.minecraft.client.gui.GuiTextField;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
2012-11-05 16:46:50 +01:00
|
|
|
|
2013-04-13 16:33:37 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2012-11-05 16:46:50 +01:00
|
|
|
public class GuiControlPanel extends GuiScreen
|
|
|
|
{
|
2012-11-21 16:14:35 +01:00
|
|
|
public TileEntityControlPanel tileEntity;
|
2012-11-05 16:46:50 +01:00
|
|
|
public EntityPlayer usingPlayer;
|
|
|
|
public World worldObj;
|
2012-11-05 16:52:56 +01:00
|
|
|
public String displayText = "";
|
2012-11-05 16:46:50 +01:00
|
|
|
public int ticker = 0;
|
|
|
|
|
|
|
|
private GuiTextField xField;
|
|
|
|
private GuiTextField yField;
|
|
|
|
private GuiTextField zField;
|
|
|
|
|
2012-11-21 16:14:35 +01:00
|
|
|
public GuiControlPanel(TileEntityControlPanel tentity, EntityPlayer player, World world)
|
2012-11-05 16:46:50 +01:00
|
|
|
{
|
2012-11-21 16:14:35 +01:00
|
|
|
tileEntity = tentity;
|
2012-11-05 16:46:50 +01:00
|
|
|
usingPlayer = player;
|
|
|
|
worldObj = world;
|
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-11-05 16:46:50 +01:00
|
|
|
public void initGui()
|
|
|
|
{
|
|
|
|
super.initGui();
|
2013-03-18 17:23:57 +01:00
|
|
|
buttonList.clear();
|
|
|
|
buttonList.add(new GuiButton(0, width / 2 - 80, height / 4 + 72 + 12, 60, 20, "Access"));
|
2012-11-05 16:46:50 +01:00
|
|
|
|
2012-11-05 16:52:56 +01:00
|
|
|
xField = new GuiTextField(fontRenderer, width / 2 - 80, 53, 35, 12);
|
2012-11-05 16:46:50 +01:00
|
|
|
xField.setMaxStringLength(4);
|
2012-11-21 16:14:35 +01:00
|
|
|
xField.setText(Integer.toString(tileEntity.xCached));
|
2012-11-05 16:46:50 +01:00
|
|
|
xField.setFocused(true);
|
|
|
|
|
2012-11-05 16:52:56 +01:00
|
|
|
yField = new GuiTextField(fontRenderer, width / 2 - 80, 70, 35, 12);
|
2012-11-05 16:46:50 +01:00
|
|
|
yField.setMaxStringLength(4);
|
2012-11-21 16:14:35 +01:00
|
|
|
yField.setText(Integer.toString(tileEntity.yCached));
|
2012-11-05 16:46:50 +01:00
|
|
|
|
2012-11-05 16:52:56 +01:00
|
|
|
zField = new GuiTextField(fontRenderer, width / 2 - 80, 87, 35, 12);
|
2012-11-05 16:46:50 +01:00
|
|
|
zField.setMaxStringLength(4);
|
2012-11-21 16:14:35 +01:00
|
|
|
zField.setText(Integer.toString(tileEntity.zCached));
|
2012-11-05 16:46:50 +01:00
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-11-05 16:46:50 +01:00
|
|
|
public void drawScreen(int i, int j, float f)
|
|
|
|
{
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
2013-03-25 17:00:45 +01:00
|
|
|
mc.renderEngine.bindTexture("/mods/mekanism/gui/GuiControlPanel.png");
|
2012-11-05 16:46:50 +01:00
|
|
|
drawTexturedModalRect(width / 2 - 100, height / 2 - 100, 0, 0, 176, 166);
|
2012-11-05 16:52:56 +01:00
|
|
|
xField.drawTextBox();
|
|
|
|
yField.drawTextBox();
|
|
|
|
zField.drawTextBox();
|
2012-11-05 16:46:50 +01:00
|
|
|
super.drawScreen(i, j, f);
|
2012-11-05 16:52:56 +01:00
|
|
|
fontRenderer.drawString("Control Panel", 165, 40, 0x404040);
|
|
|
|
fontRenderer.drawString(displayText, 133, 120, 0x404040);
|
2012-11-05 16:46:50 +01: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);
|
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-11-05 16:46:50 +01:00
|
|
|
public void keyTyped(char c, int i)
|
|
|
|
{
|
|
|
|
super.keyTyped(c, i);
|
|
|
|
|
2012-11-05 16:52:56 +01:00
|
|
|
xField.textboxKeyTyped(c, i);
|
|
|
|
yField.textboxKeyTyped(c, i);
|
|
|
|
zField.textboxKeyTyped(c, i);
|
2012-11-21 16:14:35 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
tileEntity.xCached = Integer.parseInt(xField.getText());
|
|
|
|
} catch(NumberFormatException e) { tileEntity.xCached = 0; }
|
|
|
|
try {
|
|
|
|
tileEntity.yCached = Integer.parseInt(yField.getText());
|
|
|
|
} catch(NumberFormatException e) { tileEntity.yCached = 0; }
|
|
|
|
try {
|
|
|
|
tileEntity.zCached = Integer.parseInt(zField.getText());
|
|
|
|
} catch(NumberFormatException e) { tileEntity.zCached = 0; }
|
2012-11-05 16:52:56 +01:00
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-11-05 16:52:56 +01:00
|
|
|
public boolean doesGuiPauseGame()
|
|
|
|
{
|
|
|
|
return false;
|
2012-11-05 16:46:50 +01:00
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-11-05 16:46:50 +01:00
|
|
|
public void updateScreen()
|
|
|
|
{
|
|
|
|
xField.updateCursorCounter();
|
|
|
|
yField.updateCursorCounter();
|
|
|
|
zField.updateCursorCounter();
|
|
|
|
|
2012-11-05 16:52:56 +01:00
|
|
|
if(ticker > 0)
|
2012-11-05 16:46:50 +01:00
|
|
|
{
|
2012-11-05 16:52:56 +01:00
|
|
|
ticker--;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
displayText = "";
|
2012-11-05 16:46:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-11-05 16:46:50 +01:00
|
|
|
public void mouseClicked(int x, int y, int z)
|
|
|
|
{
|
|
|
|
super.mouseClicked(x, y, z);
|
|
|
|
xField.mouseClicked(x, y, z);
|
|
|
|
yField.mouseClicked(x, y, z);
|
|
|
|
zField.mouseClicked(x, y, z);
|
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-11-05 16:46:50 +01:00
|
|
|
public void actionPerformed(GuiButton guibutton)
|
|
|
|
{
|
|
|
|
if(!guibutton.enabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(guibutton.id == 0)
|
|
|
|
{
|
2012-11-05 16:52:56 +01:00
|
|
|
try {
|
|
|
|
if(worldObj.getBlockTileEntity(Integer.parseInt(xField.getText()), Integer.parseInt(yField.getText()), Integer.parseInt(zField.getText())) != null)
|
2012-11-05 16:46:50 +01:00
|
|
|
{
|
2012-11-05 16:52:56 +01:00
|
|
|
if(worldObj.getBlockTileEntity(Integer.parseInt(xField.getText()), Integer.parseInt(yField.getText()), Integer.parseInt(zField.getText())) instanceof IAccessibleGui)
|
|
|
|
{
|
|
|
|
IAccessibleGui gui = (IAccessibleGui)worldObj.getBlockTileEntity(Integer.parseInt(xField.getText()), Integer.parseInt(yField.getText()), Integer.parseInt(zField.getText()));
|
2012-11-21 16:14:35 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
Class mod = Class.forName(gui.getClassPath());
|
|
|
|
|
|
|
|
if(mod == null)
|
|
|
|
{
|
|
|
|
System.err.println("[Mekanism] Incorrectly implemented IAccessibleGui -- ignoring handler packet.");
|
|
|
|
System.err.println(" ~ Unable to locate class '" + gui.getClassPath() + ".'");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object instance = mod.getField(gui.getInstanceName()).get(null);
|
|
|
|
|
|
|
|
if(instance == null)
|
|
|
|
{
|
|
|
|
System.err.println("[Mekanism] Incorrectly implemented IAccessibleGui -- ignoring handler packet.");
|
|
|
|
System.err.println(" ~ Unable to locate instance object '" + gui.getInstanceName() + ".'");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PacketHandler.sendGuiRequest(gui.getClassPath(), gui.getInstanceName(), Integer.parseInt(xField.getText()), Integer.parseInt(yField.getText()), Integer.parseInt(zField.getText()), gui.getGuiID());
|
|
|
|
usingPlayer.openGui(instance, gui.getGuiID(), worldObj, Integer.parseInt(xField.getText()), Integer.parseInt(yField.getText()), Integer.parseInt(zField.getText()));
|
|
|
|
} catch(Exception e) {
|
|
|
|
System.err.println("[Mekanism] Error while handling Control Panel GUI request.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2012-11-05 16:52:56 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
displayText = EnumColor.DARK_RED + "Tile entity isn't available.";
|
|
|
|
ticker = 40;
|
|
|
|
}
|
2012-11-05 16:46:50 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-11-05 16:52:56 +01:00
|
|
|
displayText = EnumColor.DARK_RED + "Tile entity doesn't exist.";
|
|
|
|
ticker = 40;
|
2012-11-05 16:46:50 +01:00
|
|
|
}
|
2012-11-05 16:52:56 +01:00
|
|
|
} catch(NumberFormatException e) {
|
|
|
|
displayText = EnumColor.DARK_RED + "Invalid characters.";
|
|
|
|
ticker = 40;
|
2012-11-05 16:46:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|