2013-08-27 00:49:32 +02:00
|
|
|
package mekanism.client.gui;
|
2013-08-27 00:28:55 +02:00
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2013-11-30 18:29:49 +01:00
|
|
|
import mekanism.common.IInvConfiguration;
|
2013-11-30 06:28:02 +01:00
|
|
|
import mekanism.common.SideData;
|
2013-11-30 01:11:07 +01:00
|
|
|
import mekanism.common.item.ItemConfigurator;
|
|
|
|
import mekanism.common.tileentity.TileEntityContainerBlock;
|
2013-08-27 00:28:55 +02:00
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
import net.minecraft.inventory.Container;
|
2013-11-30 01:11:07 +01:00
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-08-27 00:28:55 +02:00
|
|
|
|
|
|
|
public abstract class GuiMekanism extends GuiContainer
|
|
|
|
{
|
|
|
|
public Set<GuiElement> guiElements = new HashSet<GuiElement>();
|
|
|
|
|
2013-11-30 01:11:07 +01:00
|
|
|
private TileEntityContainerBlock tileEntity;
|
|
|
|
|
2013-08-27 00:28:55 +02:00
|
|
|
public GuiMekanism(Container container)
|
|
|
|
{
|
|
|
|
super(container);
|
|
|
|
}
|
|
|
|
|
2013-11-30 01:11:07 +01:00
|
|
|
public GuiMekanism(TileEntityContainerBlock tile, Container container)
|
|
|
|
{
|
|
|
|
super(container);
|
|
|
|
tileEntity = tile;
|
|
|
|
}
|
|
|
|
|
2013-08-27 00:28:55 +02:00
|
|
|
@Override
|
|
|
|
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
|
|
|
|
{
|
|
|
|
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
|
|
|
|
|
|
|
int xAxis = (mouseX - (width - xSize) / 2);
|
|
|
|
int yAxis = (mouseY - (height - ySize) / 2);
|
|
|
|
|
|
|
|
for(GuiElement element : guiElements)
|
|
|
|
{
|
|
|
|
element.renderForeground(xAxis, yAxis);
|
|
|
|
}
|
2013-11-30 01:11:07 +01:00
|
|
|
|
|
|
|
if(tileEntity != null)
|
|
|
|
{
|
|
|
|
Slot hovering = null;
|
|
|
|
|
|
|
|
for(int i = 0; i < inventorySlots.inventorySlots.size(); i++)
|
|
|
|
{
|
|
|
|
Slot slot = (Slot)inventorySlots.inventorySlots.get(i);
|
|
|
|
|
|
|
|
if(isMouseOverSlot(slot, mouseX, mouseY))
|
|
|
|
{
|
|
|
|
hovering = slot;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack stack = mc.thePlayer.inventory.getItemStack();
|
|
|
|
|
|
|
|
if(stack != null && stack.getItem() instanceof ItemConfigurator && hovering != null)
|
|
|
|
{
|
|
|
|
SideData data = getFromSlot(hovering);
|
|
|
|
|
|
|
|
if(data != null)
|
|
|
|
{
|
|
|
|
drawCreativeTabHoveringText(data.color.getName(), xAxis, yAxis);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-27 00:28:55 +02:00
|
|
|
}
|
2013-11-30 01:11:07 +01:00
|
|
|
|
|
|
|
private SideData getFromSlot(Slot slot)
|
|
|
|
{
|
|
|
|
if(slot.slotNumber < tileEntity.getSizeInventory())
|
|
|
|
{
|
2013-11-30 18:29:49 +01:00
|
|
|
IInvConfiguration config = (IInvConfiguration)tileEntity;
|
2013-11-30 01:11:07 +01:00
|
|
|
|
|
|
|
for(SideData data : config.getSideData())
|
|
|
|
{
|
|
|
|
for(int id : data.availableSlots)
|
|
|
|
{
|
|
|
|
if(id == slot.getSlotIndex())
|
|
|
|
{
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean isMouseOverSlot(Slot slot, int mouseX, int mouseY)
|
|
|
|
{
|
|
|
|
return isPointInRegion(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY);
|
|
|
|
}
|
2013-08-27 00:28:55 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
|
|
|
|
{
|
|
|
|
int guiWidth = (width - xSize) / 2;
|
|
|
|
int guiHeight = (height - ySize) / 2;
|
|
|
|
|
|
|
|
int xAxis = mouseX - guiWidth;
|
|
|
|
int yAxis = mouseY - guiHeight;
|
|
|
|
|
|
|
|
for(GuiElement element : guiElements)
|
|
|
|
{
|
|
|
|
element.renderBackground(xAxis, yAxis, guiWidth, guiHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void mouseClicked(int mouseX, int mouseY, int button)
|
|
|
|
{
|
|
|
|
int xAxis = (mouseX - (width - xSize) / 2);
|
|
|
|
int yAxis = (mouseY - (height - ySize) / 2);
|
|
|
|
|
|
|
|
for(GuiElement element : guiElements)
|
|
|
|
{
|
|
|
|
element.preMouseClicked(xAxis, yAxis, button);
|
|
|
|
}
|
|
|
|
|
|
|
|
super.mouseClicked(mouseX, mouseY, button);
|
|
|
|
|
|
|
|
for(GuiElement element : guiElements)
|
|
|
|
{
|
|
|
|
element.mouseClicked(xAxis, yAxis, button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|