package com.example.examplemod.block;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
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 org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.common.Mod;
import buildcraft.BuildCraftBuilders;
import buildcraft.core.network.RPCHandler;
import buildcraft.core.utils.StringUtils;
public class GUIOrangeBlock extends GuiScreen{
private GuiTextField tFX;
private GuiTextField tFY;
private GuiTextField tFZ;
private GuiTextField tFName;
private int MAX_NAME_SIZE=120;
private int MAX_COORD_SIZE=3;
private static final int TEXT_X = 130;
private static final int TEXT_Y = 62;
private static final int TEXT_WIDTH = 156;
private static final int NUM_WIDTH = 30;
private static final int NUM_X = TEXT_X+TEXT_WIDTH-NUM_WIDTH;
private static final int TEXT_HEIGHT = 12;
private static final int guiLeft=85;
private static final int guiTop=37;
private EntityPlayer lplayer;
private OrangeBlock lblock;
private int X,Y,Z,MRub;
private String zoneName;
public GUIOrangeBlock(EntityPlayer player, Block block)
{
super();
this.lplayer=player;
this.lblock=(OrangeBlock)block;
}
@Override
public void initGui() {
super.initGui();
Keyboard.enableRepeatEvents(true);
// int posX = (this.width - 120) / 2;
// int posY = (this.height - 80) / 2;
int btwn =TEXT_HEIGHT+3;
buttonList.add(new GuiButton(0, TEXT_X, TEXT_Y+btwn * 5, TEXT_WIDTH/2-3, 20, "Sale Castle"));
buttonList.add(new GuiButton(1, TEXT_X + TEXT_WIDTH/2+3, TEXT_Y+btwn * 5, TEXT_WIDTH/2-3, 20, "Pay Castle"));
tFX = new GuiTextField(this.fontRendererObj, NUM_X, TEXT_Y, NUM_WIDTH, TEXT_HEIGHT);
tFY = new GuiTextField(this.fontRendererObj, NUM_X, TEXT_Y+btwn, NUM_WIDTH, TEXT_HEIGHT);
tFZ = new GuiTextField(this.fontRendererObj, NUM_X, TEXT_Y+btwn*2, NUM_WIDTH, TEXT_HEIGHT);
tFName = new GuiTextField(this.fontRendererObj, TEXT_X, TEXT_Y+btwn*4, TEXT_WIDTH, TEXT_HEIGHT);
tFX.setMaxStringLength(MAX_COORD_SIZE);
tFY.setMaxStringLength(MAX_COORD_SIZE);
tFZ.setMaxStringLength(MAX_COORD_SIZE);
tFName.setMaxStringLength(MAX_NAME_SIZE);
tFName.setText("MySuperCastle");
tFX.setText("16");
tFY.setText("16");
tFZ.setText("16");
tFX.setFocused(true);
}
@Override
public void drawScreen(int x, int y, float f)
{
this.drawDefaultBackground();
String title = StringUtils.localize("tile.architectBlock.name");
fontRendererObj.drawString(title, 50, 6, 0x404040);
tFX.drawTextBox();
tFY.drawTextBox();
tFZ.drawTextBox();
tFName.drawTextBox();
super.drawScreen(x, y, f);
}
@Override
protected void mouseClicked(int x, int y, int btn) {
tFX.mouseClicked(x , y , btn);
tFY.mouseClicked(x , y , btn);
tFZ.mouseClicked(x , y , btn);
tFName.mouseClicked(x , y , btn);
super.mouseClicked(x, y, btn);
}
@Override
public void actionPerformed(GuiButton button)
{
switch(button.id)
{
case 0:
lblock.dump(tFX.getText(),
tFY.getText(),
tFZ.getText(),
tFName.getText());
break;
case 1:
try{
lblock.reupdump(tFName.getText());
}catch (Exception e) {
// TODO: handle exception
}
break;
default:
}
}
@Override
protected void keyTyped(char c, int i) {
if(i==1){
Minecraft.getMinecraft().displayGuiScreen(null);
return;
}
if (tFX.isFocused()) {
if (c == 13 || c == 27) {
tFX.setFocused(false);
} else{
super.keyTyped(c, i);
tFX.textboxKeyTyped(c, i);
//RPCHandler.rpcServer(architect, "handleClientSetName", tF.getText());
}
} else if (tFY.isFocused()) {
if (c == 13 || c == 27) {
tFY.setFocused(false);
} else{
super.keyTyped(c, i);
tFY.textboxKeyTyped(c, i);
//RPCHandler.rpcServer(architect, "handleClientSetName", tF.getText());
}
} else if (tFZ.isFocused()) {
if (c == 13 || c == 27) {
tFZ.setFocused(false);
} else{
super.keyTyped(c, i);
tFZ.textboxKeyTyped(c, i);
//RPCHandler.rpcServer(architect, "handleClientSetName", tF.getText());
}
} else if (tFName.isFocused()) {
if (c == 13 || c == 27) {
tFName.setFocused(false);
} else{
super.keyTyped(c, i);
tFName.textboxKeyTyped(c, i);
//RPCHandler.rpcServer(architect, "handleClientSetName", tF.getText());
}
}
// else {
// if (i == 1 || i == this.mc.gameSettings.keyBindInventory.getKeyCode())
// {
// //this.mc.thePlayer.closeScreen();
// Minecraft.getMinecraft().displayGuiScreen(null);
// }
// }
super.keyTyped(c, i);
}
@Override
public void updateScreen()
{
super.updateScreen();
tFX.updateCursorCounter();
tFY.updateCursorCounter();
tFZ.updateCursorCounter();
tFName.updateCursorCounter();
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
}