2013-08-27 00:49:32 +02:00
|
|
|
package mekanism.client.gui;
|
2013-05-20 00:43:01 +02:00
|
|
|
|
|
|
|
import mekanism.common.EntityRobit;
|
|
|
|
import mekanism.common.Mekanism;
|
|
|
|
import mekanism.common.PacketHandler;
|
2013-06-07 17:16:47 +02:00
|
|
|
import mekanism.common.PacketHandler.Transmission;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.common.inventory.container.ContainerRobitMain;
|
2013-06-13 23:37:30 +02:00
|
|
|
import mekanism.common.network.PacketRobit;
|
|
|
|
import mekanism.common.network.PacketRobit.RobitPacketType;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.common.util.MekanismUtils;
|
|
|
|
import mekanism.common.util.MekanismUtils.ResourceType;
|
2013-05-20 00:43:01 +02:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
2013-05-29 17:35:30 +02:00
|
|
|
import net.minecraft.client.gui.GuiTextField;
|
2013-05-20 00:43:01 +02:00
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
2013-08-27 00:49:32 +02:00
|
|
|
|
2013-05-29 17:35:30 +02:00
|
|
|
import org.lwjgl.input.Keyboard;
|
2013-05-20 00:43:01 +02:00
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import universalelectricity.core.electricity.ElectricityDisplay;
|
|
|
|
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
|
2013-05-30 03:51:48 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2013-05-20 00:43:01 +02:00
|
|
|
|
2013-05-29 17:35:30 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-05-20 00:43:01 +02:00
|
|
|
public class GuiRobitMain extends GuiContainer
|
|
|
|
{
|
|
|
|
public EntityRobit robit;
|
2013-05-29 17:35:30 +02:00
|
|
|
|
|
|
|
public boolean displayNameChange;
|
|
|
|
|
|
|
|
private GuiTextField nameChangeField;
|
|
|
|
private GuiButton confirmName;
|
2013-05-20 00:43:01 +02:00
|
|
|
|
|
|
|
public GuiRobitMain(InventoryPlayer inventory, EntityRobit entity)
|
|
|
|
{
|
|
|
|
super(new ContainerRobitMain(inventory, entity));
|
|
|
|
xSize += 25;
|
|
|
|
robit = entity;
|
|
|
|
}
|
2013-05-29 17:35:30 +02:00
|
|
|
|
|
|
|
private void toggleNameChange()
|
|
|
|
{
|
|
|
|
displayNameChange = !displayNameChange;
|
|
|
|
confirmName.drawButton = displayNameChange;
|
|
|
|
nameChangeField.setFocused(displayNameChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void changeName()
|
|
|
|
{
|
|
|
|
if(nameChangeField.getText() != null && !nameChangeField.getText().isEmpty())
|
|
|
|
{
|
2013-06-15 00:25:09 +02:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketRobit().setParams(RobitPacketType.NAME, nameChangeField.getText(), robit.entityId));
|
2013-05-29 17:35:30 +02:00
|
|
|
toggleNameChange();
|
|
|
|
nameChangeField.setText("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void actionPerformed(GuiButton guibutton)
|
|
|
|
{
|
|
|
|
if(guibutton.id == 0)
|
|
|
|
{
|
|
|
|
changeName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initGui()
|
|
|
|
{
|
|
|
|
super.initGui();
|
|
|
|
|
|
|
|
int guiWidth = (width - xSize) / 2;
|
|
|
|
int guiHeight = (height - ySize) / 2;
|
|
|
|
|
|
|
|
buttonList.clear();
|
|
|
|
buttonList.add(confirmName = new GuiButton(0, guiWidth + 58, guiHeight + 47, 60, 20, "Confirm"));
|
|
|
|
confirmName.drawButton = displayNameChange;
|
|
|
|
|
|
|
|
nameChangeField = new GuiTextField(fontRenderer, guiWidth + 48, guiHeight + 21, 80, 12);
|
|
|
|
nameChangeField.setMaxStringLength(12);
|
|
|
|
nameChangeField.setFocused(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void keyTyped(char c, int i)
|
|
|
|
{
|
|
|
|
if(!displayNameChange)
|
|
|
|
{
|
|
|
|
super.keyTyped(c, i);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(i == Keyboard.KEY_RETURN)
|
|
|
|
{
|
|
|
|
changeName();
|
|
|
|
}
|
|
|
|
else if(i == Keyboard.KEY_ESCAPE)
|
|
|
|
{
|
|
|
|
mc.thePlayer.closeScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
nameChangeField.textboxKeyTyped(c, i);
|
|
|
|
}
|
|
|
|
}
|
2013-05-20 00:43:01 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
|
|
|
|
{
|
|
|
|
fontRenderer.drawString("Robit", 76, 6, 0x404040);
|
2013-05-29 17:35:30 +02:00
|
|
|
|
|
|
|
if(!displayNameChange)
|
|
|
|
{
|
|
|
|
fontRenderer.drawString("Hi, I'm " + robit.getTranslatedEntityName() + "!", 29, 18, 0x00CD00);
|
2013-07-31 22:44:53 +02:00
|
|
|
fontRenderer.drawString("Energy: " + ElectricityDisplay.getDisplayShort((float)(robit.getEnergy()*Mekanism.TO_UE), ElectricUnit.JOULES), 29, 36-4, 0x00CD00);
|
2013-06-01 18:37:43 +02:00
|
|
|
fontRenderer.drawString("Following: " + robit.getFollowing(), 29, 45-4, 0x00CD00);
|
|
|
|
fontRenderer.drawString("Drop pickup: " + robit.getDropPickup(), 29, 54-4, 0x00CD00);
|
|
|
|
fontRenderer.drawString("Owner: " + robit.getOwnerName(), 29, 63-4, 0x00CD00);
|
2013-05-29 17:35:30 +02:00
|
|
|
}
|
2013-05-20 00:43:01 +02:00
|
|
|
|
|
|
|
int xAxis = (mouseX - (width - xSize) / 2);
|
|
|
|
int yAxis = (mouseY - (height - ySize) / 2);
|
|
|
|
|
2013-06-01 18:37:43 +02:00
|
|
|
if(xAxis >= 28 && xAxis <= 148 && yAxis >= 75 && yAxis <= 79)
|
2013-05-20 00:43:01 +02:00
|
|
|
{
|
2013-07-31 22:44:53 +02:00
|
|
|
drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)(robit.getEnergy()*Mekanism.TO_UE), ElectricUnit.JOULES), xAxis, yAxis);
|
2013-05-20 00:43:01 +02:00
|
|
|
}
|
2013-06-01 18:37:43 +02:00
|
|
|
else if(xAxis >= 152 && xAxis <= 170 && yAxis >= 54 && yAxis <= 72)
|
2013-05-20 00:43:01 +02:00
|
|
|
{
|
|
|
|
drawCreativeTabHoveringText("Toggle 'follow' mode", xAxis, yAxis);
|
|
|
|
}
|
2013-06-01 18:37:43 +02:00
|
|
|
else if(xAxis >= 6 && xAxis <= 24 && yAxis >= 54 && yAxis <= 72)
|
2013-05-29 17:35:30 +02:00
|
|
|
{
|
|
|
|
drawCreativeTabHoveringText("Rename this Robit", xAxis, yAxis);
|
|
|
|
}
|
2013-05-30 03:51:48 +02:00
|
|
|
else if(xAxis >= 6 && xAxis <= 24 && yAxis >= 16 && yAxis <= 34)
|
|
|
|
{
|
|
|
|
drawCreativeTabHoveringText("Teleport back home", xAxis, yAxis);
|
|
|
|
}
|
2013-06-01 18:37:43 +02:00
|
|
|
else if(xAxis >= 6 && xAxis <= 24 && yAxis >= 35 && yAxis <= 53)
|
|
|
|
{
|
|
|
|
drawCreativeTabHoveringText("Toggle 'drop pickup' mode", xAxis, yAxis);
|
|
|
|
}
|
2013-05-20 00:43:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void drawGuiContainerBackgroundLayer(float par1, int mouseX, int mouseY)
|
|
|
|
{
|
2013-07-20 18:10:14 +02:00
|
|
|
mc.renderEngine.func_110577_a(MekanismUtils.getResource(ResourceType.GUI, "GuiRobitMain.png"));
|
2013-05-20 00:43:01 +02:00
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
int guiWidth = (width - xSize) / 2;
|
|
|
|
int guiHeight = (height - ySize) / 2;
|
|
|
|
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
|
|
|
|
|
|
|
|
int xAxis = (mouseX - (width - xSize) / 2);
|
|
|
|
int yAxis = (mouseY - (height - ySize) / 2);
|
|
|
|
|
|
|
|
if(xAxis >= 179 && xAxis <= 197 && yAxis >= 10 && yAxis <= 28)
|
|
|
|
{
|
|
|
|
drawTexturedModalRect(guiWidth + 179, guiHeight + 10, 176 + 25, 0, 18, 18);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
drawTexturedModalRect(guiWidth + 179, guiHeight + 10, 176 + 25, 18, 18, 18);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(xAxis >= 179 && xAxis <= 197 && yAxis >= 30 && yAxis <= 48)
|
|
|
|
{
|
|
|
|
drawTexturedModalRect(guiWidth + 179, guiHeight + 30, 176 + 25, 36, 18, 18);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
drawTexturedModalRect(guiWidth + 179, guiHeight + 30, 176 + 25, 54, 18, 18);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(xAxis >= 179 && xAxis <= 197 && yAxis >= 50 && yAxis <= 68)
|
|
|
|
{
|
|
|
|
drawTexturedModalRect(guiWidth + 179, guiHeight + 50, 176 + 25, 72, 18, 18);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
drawTexturedModalRect(guiWidth + 179, guiHeight + 50, 176 + 25, 90, 18, 18);
|
|
|
|
}
|
|
|
|
|
2013-05-20 19:51:18 +02:00
|
|
|
if(xAxis >= 179 && xAxis <= 197 && yAxis >= 70 && yAxis <= 88)
|
|
|
|
{
|
|
|
|
drawTexturedModalRect(guiWidth + 179, guiHeight + 70, 176 + 25, 108, 18, 18);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
drawTexturedModalRect(guiWidth + 179, guiHeight + 70, 176 + 25, 126, 18, 18);
|
|
|
|
}
|
|
|
|
|
2013-05-20 21:06:10 +02:00
|
|
|
if(xAxis >= 179 && xAxis <= 197 && yAxis >= 90 && yAxis <= 108)
|
|
|
|
{
|
|
|
|
drawTexturedModalRect(guiWidth + 179, guiHeight + 90, 176 + 25, 144, 18, 18);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
drawTexturedModalRect(guiWidth + 179, guiHeight + 90, 176 + 25, 162, 18, 18);
|
|
|
|
}
|
|
|
|
|
2013-06-01 18:37:43 +02:00
|
|
|
if(xAxis >= 152 && xAxis <= 170 && yAxis >= 54 && yAxis <= 72)
|
2013-05-20 00:43:01 +02:00
|
|
|
{
|
2013-06-01 18:37:43 +02:00
|
|
|
drawTexturedModalRect(guiWidth + 152, guiHeight + 54, 176 + 25, 180, 18, 18);
|
2013-05-20 00:43:01 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-06-01 18:37:43 +02:00
|
|
|
drawTexturedModalRect(guiWidth + 152, guiHeight + 54, 176 + 25, 198, 18, 18);
|
2013-05-20 00:43:01 +02:00
|
|
|
}
|
|
|
|
|
2013-06-01 18:37:43 +02:00
|
|
|
if(xAxis >= 6 && xAxis <= 24 && yAxis >= 54 && yAxis <= 72)
|
2013-05-29 17:35:30 +02:00
|
|
|
{
|
2013-06-01 18:37:43 +02:00
|
|
|
drawTexturedModalRect(guiWidth + 6, guiHeight + 54, 176 + 25, 216, 18, 18);
|
2013-05-29 17:35:30 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-06-01 18:37:43 +02:00
|
|
|
drawTexturedModalRect(guiWidth + 6, guiHeight + 54, 176 + 25, 234, 18, 18);
|
2013-05-29 17:35:30 +02:00
|
|
|
}
|
|
|
|
|
2013-05-30 03:51:48 +02:00
|
|
|
if(xAxis >= 6 && xAxis <= 24 && yAxis >= 16 && yAxis <= 34)
|
|
|
|
{
|
|
|
|
drawTexturedModalRect(guiWidth + 6, guiHeight + 16, 176 + 25 + 18, 36, 18, 18);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
drawTexturedModalRect(guiWidth + 6, guiHeight + 16, 176 + 25 + 18, 54, 18, 18);
|
|
|
|
}
|
|
|
|
|
2013-06-01 18:37:43 +02:00
|
|
|
if(xAxis >= 6 && xAxis <= 24 && yAxis >= 35 && yAxis <= 53)
|
|
|
|
{
|
|
|
|
drawTexturedModalRect(guiWidth + 6, guiHeight + 35, 176 + 25 + 18, 72, 18, 18);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
drawTexturedModalRect(guiWidth + 6, guiHeight + 35, 176 + 25 + 18, 90, 18, 18);
|
|
|
|
}
|
|
|
|
|
2013-05-20 00:43:01 +02:00
|
|
|
int displayInt;
|
|
|
|
|
2013-05-29 17:35:30 +02:00
|
|
|
displayInt = getScaledEnergyLevel(120);
|
2013-06-01 18:37:43 +02:00
|
|
|
drawTexturedModalRect(guiWidth + 28, guiHeight + 75, 0, 166, displayInt, 4);
|
2013-05-29 17:35:30 +02:00
|
|
|
|
|
|
|
if(displayNameChange)
|
|
|
|
{
|
2013-06-01 18:37:43 +02:00
|
|
|
drawTexturedModalRect(guiWidth + 28, guiHeight + 17, 0, 166 + 4, 120, 54);
|
2013-05-29 17:35:30 +02:00
|
|
|
nameChangeField.drawTextBox();
|
|
|
|
}
|
2013-05-20 00:43:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private int getScaledEnergyLevel(int i)
|
|
|
|
{
|
|
|
|
return (int)(robit.getEnergy()*i / robit.MAX_ELECTRICITY);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void mouseClicked(int mouseX, int mouseY, int button)
|
|
|
|
{
|
|
|
|
super.mouseClicked(mouseX, mouseY, button);
|
|
|
|
|
2013-05-29 17:35:30 +02:00
|
|
|
nameChangeField.mouseClicked(mouseX, mouseY, button);
|
|
|
|
|
2013-05-20 00:43:01 +02:00
|
|
|
if(button == 0)
|
|
|
|
{
|
|
|
|
int xAxis = (mouseX - (width - xSize) / 2);
|
|
|
|
int yAxis = (mouseY - (height - ySize) / 2);
|
|
|
|
|
|
|
|
if(xAxis >= 179 && xAxis <= 197 && yAxis >= 10 && yAxis <= 28)
|
|
|
|
{
|
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
|
|
|
}
|
|
|
|
else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 30 && yAxis <= 48)
|
|
|
|
{
|
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
2013-06-15 00:25:09 +02:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketRobit().setParams(RobitPacketType.GUI, 1, robit.entityId));
|
2013-05-20 00:43:01 +02:00
|
|
|
mc.thePlayer.openGui(Mekanism.instance, 22, mc.theWorld, robit.entityId, 0, 0);
|
|
|
|
}
|
|
|
|
else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 50 && yAxis <= 68)
|
|
|
|
{
|
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
2013-06-15 00:25:09 +02:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketRobit().setParams(RobitPacketType.GUI, 2, robit.entityId));
|
2013-05-20 00:43:01 +02:00
|
|
|
mc.thePlayer.openGui(Mekanism.instance, 23, mc.theWorld, robit.entityId, 0, 0);
|
|
|
|
}
|
2013-05-20 19:51:18 +02:00
|
|
|
else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 70 && yAxis <= 88)
|
|
|
|
{
|
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
2013-06-15 00:25:09 +02:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketRobit().setParams(RobitPacketType.GUI, 3, robit.entityId));
|
2013-05-20 19:51:18 +02:00
|
|
|
mc.thePlayer.openGui(Mekanism.instance, 24, mc.theWorld, robit.entityId, 0, 0);
|
|
|
|
}
|
2013-05-20 21:06:10 +02:00
|
|
|
else if(xAxis >= 179 && xAxis <= 197 && yAxis >= 90 && yAxis <= 108)
|
|
|
|
{
|
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
2013-06-15 00:25:09 +02:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketRobit().setParams(RobitPacketType.GUI, 4, robit.entityId));
|
2013-05-20 21:06:10 +02:00
|
|
|
mc.thePlayer.openGui(Mekanism.instance, 25, mc.theWorld, robit.entityId, 0, 0);
|
|
|
|
}
|
2013-06-01 18:37:43 +02:00
|
|
|
else if(xAxis >= 152 && xAxis <= 170 && yAxis >= 54 && yAxis <= 72)
|
2013-05-20 00:43:01 +02:00
|
|
|
{
|
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
2013-06-15 00:25:09 +02:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketRobit().setParams(RobitPacketType.FOLLOW, robit.entityId));
|
2013-05-20 00:43:01 +02:00
|
|
|
}
|
2013-06-01 18:37:43 +02:00
|
|
|
else if(xAxis >= 6 && xAxis <= 24 && yAxis >= 54 && yAxis <= 72)
|
2013-05-29 17:35:30 +02:00
|
|
|
{
|
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
|
|
|
toggleNameChange();
|
|
|
|
}
|
2013-05-30 03:51:48 +02:00
|
|
|
else if(xAxis >= 6 && xAxis <= 24 && yAxis >= 16 && yAxis <= 34)
|
|
|
|
{
|
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
2013-06-15 00:25:09 +02:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketRobit().setParams(RobitPacketType.GO_HOME, robit.entityId));
|
2013-06-19 20:11:29 +02:00
|
|
|
mc.displayGuiScreen(null);
|
2013-05-30 03:51:48 +02:00
|
|
|
}
|
2013-06-01 18:37:43 +02:00
|
|
|
else if(xAxis >= 6 && xAxis <= 24 && yAxis >= 35 && yAxis <= 53)
|
|
|
|
{
|
|
|
|
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
|
2013-06-15 00:25:09 +02:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketRobit().setParams(RobitPacketType.DROP_PICKUP, robit.entityId));
|
2013-06-01 18:37:43 +02:00
|
|
|
}
|
2013-05-20 00:43:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|