Mekanism-tilera-Edition/common/mekanism/client/gui/GuiConfiguration.java

310 lines
10 KiB
Java
Raw Normal View History

2013-10-30 20:22:43 +01:00
package mekanism.client.gui;
2013-10-31 01:35:11 +01:00
import java.util.HashMap;
import java.util.Map;
import mekanism.api.EnumColor;
2013-10-30 20:22:43 +01:00
import mekanism.api.IConfigurable;
import mekanism.api.Object3D;
2013-10-31 01:35:11 +01:00
import mekanism.api.SideData;
2013-11-02 06:31:32 +01:00
import mekanism.client.render.MekanismRenderer;
2013-10-30 20:22:43 +01:00
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.block.BlockMachine.MachineType;
2013-10-31 01:35:11 +01:00
import mekanism.common.inventory.container.ContainerNull;
2013-10-30 20:22:43 +01:00
import mekanism.common.network.PacketConfigurationUpdate;
import mekanism.common.network.PacketConfigurationUpdate.ConfigurationPacket;
import mekanism.common.network.PacketSimpleGui;
2013-10-31 01:35:11 +01:00
import mekanism.common.tileentity.TileEntityContainerBlock;
2013-10-30 20:22:43 +01:00
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
2013-10-31 01:35:11 +01:00
import net.minecraft.entity.player.EntityPlayer;
2013-10-30 20:22:43 +01:00
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
2013-10-30 20:22:43 +01:00
import org.lwjgl.opengl.GL11;
2013-11-02 06:31:32 +01:00
import org.lwjgl.opengl.GL12;
2013-10-30 20:22:43 +01:00
2013-10-31 01:35:11 +01:00
public class GuiConfiguration extends GuiMekanism
2013-10-30 20:22:43 +01:00
{
public Map<Integer, GuiPos> slotPosMap = new HashMap<Integer, GuiPos>();
public Map<Integer, GuiPos> inputPosMap = new HashMap<Integer, GuiPos>();
2013-10-30 20:22:43 +01:00
public IConfigurable configurable;
2013-10-31 01:35:11 +01:00
public GuiConfiguration(EntityPlayer player, IConfigurable tile)
2013-10-30 20:22:43 +01:00
{
2013-10-31 01:35:11 +01:00
super(new ContainerNull(player, (TileEntityContainerBlock)tile));
ySize = 95;
2013-10-30 20:22:43 +01:00
configurable = tile;
2013-10-31 01:35:11 +01:00
slotPosMap.put(0, new GuiPos(126, 64));
slotPosMap.put(1, new GuiPos(126, 34));
slotPosMap.put(2, new GuiPos(126, 49));
slotPosMap.put(3, new GuiPos(111, 64));
slotPosMap.put(4, new GuiPos(111, 49));
slotPosMap.put(5, new GuiPos(141, 49));
inputPosMap.put(0, new GuiPos(36, 64));
inputPosMap.put(1, new GuiPos(36, 34));
inputPosMap.put(2, new GuiPos(36, 49));
inputPosMap.put(3, new GuiPos(21, 64));
inputPosMap.put(4, new GuiPos(21, 49));
inputPosMap.put(5, new GuiPos(51, 49));
2013-10-30 20:22:43 +01:00
}
@Override
2013-10-31 01:35:11 +01:00
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
2013-10-30 20:22:43 +01:00
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiConfiguration.png"));
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 >= 156 && xAxis <= 170 && yAxis >= 6 && yAxis <= 20)
{
drawTexturedModalRect(guiWidth + 156, guiHeight + 6, 176 + 14, 0, 14, 14);
}
else {
drawTexturedModalRect(guiWidth + 156, guiHeight + 6, 176 + 14, 14, 14, 14);
}
if(xAxis >= 156 && xAxis <= 170 && yAxis >= 21 && yAxis <= 35)
{
drawTexturedModalRect(guiWidth + 156, guiHeight + 21, 176 + 42, 0, 14, 14);
}
else {
drawTexturedModalRect(guiWidth + 156, guiHeight + 21, 176 + 42, 14, 14, 14);
}
2013-10-30 20:22:43 +01:00
if(xAxis >= 6 && xAxis <= 20 && yAxis >= 6 && yAxis <= 20)
{
drawTexturedModalRect(guiWidth + 6, guiHeight + 6, 176 + 28, 0, 14, 14);
}
else {
drawTexturedModalRect(guiWidth + 6, guiHeight + 6, 176 + 28, 14, 14, 14);
}
for(int i = 0; i < slotPosMap.size(); i++)
2013-10-31 01:35:11 +01:00
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int x = slotPosMap.get(i).xPos;
int y = slotPosMap.get(i).yPos;
2013-10-31 01:35:11 +01:00
SideData data = configurable.getSideData().get(configurable.getConfiguration()[i]);
if(data.color != EnumColor.GREY)
{
GL11.glColor4f(data.color.getColor(0), data.color.getColor(1), data.color.getColor(2), 1);
}
if(xAxis >= x && xAxis <= x+14 && yAxis >= y && yAxis <= y+14)
{
drawTexturedModalRect(guiWidth + x, guiHeight + y, 176, 0, 14, 14);
}
else {
drawTexturedModalRect(guiWidth + x, guiHeight + y, 176, 14, 14, 14);
}
}
2013-10-30 20:22:43 +01:00
for(int i = 0; i < inputPosMap.size(); i++)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int x = inputPosMap.get(i).xPos;
int y = inputPosMap.get(i).yPos;
EnumColor color = configurable.getEjector().getInputColor(ForgeDirection.getOrientation(i));
if(color != null)
{
GL11.glColor4f(color.getColor(0), color.getColor(1), color.getColor(2), 1);
}
if(xAxis >= x && xAxis <= x+14 && yAxis >= y && yAxis <= y+14)
{
drawTexturedModalRect(guiWidth + x, guiHeight + y, 176, 0, 14, 14);
}
else {
drawTexturedModalRect(guiWidth + x, guiHeight + y, 176, 14, 14, 14);
}
}
2013-10-31 01:35:11 +01:00
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
2013-10-30 20:22:43 +01:00
}
@Override
2013-10-31 01:35:11 +01:00
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
2013-10-30 20:22:43 +01:00
{
2013-10-31 01:35:11 +01:00
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
fontRenderer.drawString("Configuration", 60, 5, 0x404040);
fontRenderer.drawString("Eject: " + (configurable.getEjector().isEjecting() ? "On" : "Off"), 53, 17, 0x00CD00);
2013-10-31 01:35:11 +01:00
fontRenderer.drawString("Input (" + (configurable.getEjector().hasStrictInput() ? "On" : "Off") + ")", 18, 81, 0x787878);
fontRenderer.drawString("Output", 72, 68, 0x787878);
fontRenderer.drawString("Slots", 122, 81, 0x787878);
2013-11-02 06:31:32 +01:00
if(configurable.getEjector().getOutputColor() != null)
{
GL11.glPushMatrix();
GL11.glColor4f(1, 1, 1, 1);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
mc.getTextureManager().bindTexture(MekanismRenderer.getColorResource(configurable.getEjector().getOutputColor()));
itemRenderer.renderIcon(80, 49, MekanismRenderer.getColorIcon(configurable.getEjector().getOutputColor()), 16, 16);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
2013-11-02 06:31:32 +01:00
for(int i = 0; i < slotPosMap.size(); i++)
2013-10-31 01:35:11 +01:00
{
int x = slotPosMap.get(i).xPos;
int y = slotPosMap.get(i).yPos;
2013-10-31 01:35:11 +01:00
SideData data = configurable.getSideData().get(configurable.getConfiguration()[i]);
if(xAxis >= x && xAxis <= x+14 && yAxis >= y && yAxis <= y+14)
{
drawCreativeTabHoveringText(data.color != null ? data.color.getName() : "None", xAxis, yAxis);
}
}
2013-11-02 06:31:32 +01:00
for(int i = 0; i < inputPosMap.size(); i++)
{
int x = inputPosMap.get(i).xPos;
int y = inputPosMap.get(i).yPos;
EnumColor color = configurable.getEjector().getInputColor(ForgeDirection.getOrientation(i));
if(xAxis >= x && xAxis <= x+14 && yAxis >= y && yAxis <= y+14)
{
drawCreativeTabHoveringText(color != null ? color.getName() : "None", xAxis, yAxis);
}
}
if(xAxis >= 80 && xAxis <= 96 && yAxis >= 49 && yAxis <= 65)
2013-11-02 06:31:32 +01:00
{
if(configurable.getEjector().getOutputColor() != null)
2013-11-02 06:31:32 +01:00
{
drawCreativeTabHoveringText(configurable.getEjector().getOutputColor().getName(), xAxis, yAxis);
2013-11-02 06:31:32 +01:00
}
else {
drawCreativeTabHoveringText("None", xAxis, yAxis);
}
}
2013-11-11 00:54:30 +01:00
if(xAxis >= 156 && xAxis <= 170 && yAxis >= 6 && yAxis <= 20)
{
drawCreativeTabHoveringText("Auto-eject", xAxis, yAxis);
}
if(xAxis >= 156 && xAxis <= 170 && yAxis >= 21 && yAxis <= 35)
{
drawCreativeTabHoveringText("Strict Input", xAxis, yAxis);
}
2013-10-30 20:22:43 +01:00
}
@Override
public void updateScreen()
{
2013-10-31 01:35:11 +01:00
super.updateScreen();
2013-10-30 20:22:43 +01:00
TileEntity tile = (TileEntity)configurable;
if(tile == null || mc.theWorld.getBlockTileEntity(tile.xCoord, tile.yCoord, tile.zCoord) == null)
{
mc.displayGuiScreen(null);
}
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int button)
{
super.mouseClicked(mouseX, mouseY, button);
if(button == 0)
{
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
TileEntity tile = (TileEntity)configurable;
if(xAxis >= 6 && xAxis <= 20 && yAxis >= 6 && yAxis <= 20)
{
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
PacketHandler.sendPacket(Transmission.SERVER, new PacketSimpleGui().setParams(Object3D.get(tile), MachineType.getFromMetadata(tile.getBlockMetadata()).guiId));
}
if(xAxis >= 156 && xAxis <= 170 && yAxis >= 6 && yAxis <= 20)
{
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
PacketHandler.sendPacket(Transmission.SERVER, new PacketConfigurationUpdate().setParams(ConfigurationPacket.EJECT, Object3D.get(tile)));
}
2013-10-31 01:35:11 +01:00
if(xAxis >= 156 && xAxis <= 170 && yAxis >= 21 && yAxis <= 35)
{
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
PacketHandler.sendPacket(Transmission.SERVER, new PacketConfigurationUpdate().setParams(ConfigurationPacket.STRICT_INPUT, Object3D.get(tile)));
}
if(xAxis >= 80 && xAxis <= 96 && yAxis >= 49 && yAxis <= 65)
2013-11-02 06:31:32 +01:00
{
2013-11-11 00:54:30 +01:00
mc.sndManager.playSoundFX("mekanism:etc.Ding", 1.0F, 1.0F);
PacketHandler.sendPacket(Transmission.SERVER, new PacketConfigurationUpdate().setParams(ConfigurationPacket.EJECT_COLOR, Object3D.get(tile)));
2013-11-02 06:31:32 +01:00
}
for(int i = 0; i < slotPosMap.size(); i++)
2013-10-31 01:35:11 +01:00
{
int x = slotPosMap.get(i).xPos;
int y = slotPosMap.get(i).yPos;
2013-10-31 01:35:11 +01:00
if(xAxis >= x && xAxis <= x+14 && yAxis >= y && yAxis <= y+14)
{
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
PacketHandler.sendPacket(Transmission.SERVER, new PacketConfigurationUpdate().setParams(ConfigurationPacket.SIDE_DATA, Object3D.get(tile), i));
}
}
for(int i = 0; i < inputPosMap.size(); i++)
{
int x = inputPosMap.get(i).xPos;
int y = inputPosMap.get(i).yPos;
if(xAxis >= x && xAxis <= x+14 && yAxis >= y && yAxis <= y+14)
{
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
PacketHandler.sendPacket(Transmission.SERVER, new PacketConfigurationUpdate().setParams(ConfigurationPacket.INPUT_COLOR, Object3D.get(tile), i));
}
}
2013-10-31 01:35:11 +01:00
}
}
public static class GuiPos
{
public int xPos;
public int yPos;
public GuiPos(int x, int y)
{
xPos = x;
yPos = y;
2013-10-30 20:22:43 +01:00
}
}
}