More work on upgrade GUI, also made SimpleGui packets send new window ID to client

This commit is contained in:
Aidan C. Brady committed 2014-07-21 19:15:27 -04:00
1 parent e778449045
commit 0b8ec37164
6 files changed
+97 -18

No files matched your search

@@ -1,8 +1,21 @@
package mekanism.client.gui;
import mekanism.api.Coord4D;
import mekanism.client.sound.SoundHandler;
import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.inventory.container.ContainerUpgradeManagement;
import mekanism.common.network.PacketSimpleGui.SimpleGuiMessage;
import mekanism.common.tile.TileEntityContainerBlock;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -11,8 +24,65 @@ public class GuiUpgradeManagement extends GuiMekanism
{
public IUpgradeTile tileEntity;
public GuiUpgradeManagement(InventoryPlayer inventory, IUpgradeTile tileEntity)
public GuiUpgradeManagement(InventoryPlayer inventory, IUpgradeTile tile)
{
super(new ContainerUpgradeManagement(inventory, tileEntity));
super(new ContainerUpgradeManagement(inventory, tile));
tileEntity = tile;
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
fontRendererObj.drawString(MekanismUtils.localize("container.inventory"), 8, (ySize - 96) + 2, 0x404040);
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY)
{
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiUpgradeManagement.png"));
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 >= 6 && xAxis <= 20 && yAxis >= 6 && yAxis <= 20)
{
drawTexturedModalRect(guiWidth + 6, guiHeight + 6, 176, 0, 14, 14);
}
else {
drawTexturedModalRect(guiWidth + 6, guiHeight + 6, 176, 14, 14, 14);
}
int displayInt = tileEntity.getComponent().getScaledUpgradeProgress(14);
drawTexturedModalRect(guiWidth + 154, guiHeight + 26, 176, 28, 10, displayInt);
super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY);
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int button)
{
super.mouseClicked(mouseX, mouseY, button);
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
TileEntity tile = (TileEntity)tileEntity;
if(button == 0)
{
if(xAxis >= 6 && xAxis <= 20 && yAxis >= 6 && yAxis <= 20)
{
int guiId = MachineType.get(tile.getBlockType(), tile.getBlockMetadata()).guiId;
SoundHandler.playSound("gui.button.press");
Mekanism.packetHandler.sendToServer(new SimpleGuiMessage(Coord4D.get(tile), guiId));
}
}
}
}
@@ -51,8 +51,6 @@ public class GuiUpgradeTab extends GuiElement
{
mc.renderEngine.bindTexture(RESOURCE);
IUpgradeTile upgradeTile = (IUpgradeTile)tileEntity;
if(xAxis >= 179 && xAxis <= 197 && yAxis >= 10 && yAxis <= 28)
{
displayTooltip(MekanismUtils.localize("gui.upgrades"), xAxis, yAxis);
@@ -33,7 +33,7 @@ public class ContainerChemicalInfuser extends Container
}
}
for(slotX = 0; slotX < 9; ++slotX)
for(slotX = 0; slotX < 9; slotX++)
{
addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142));
}
@@ -125,7 +125,7 @@ public class ContainerFactory extends Container
if(isOutputSlot(slotID))
{
if(!mergeItemStack(slotStack, tileEntity.inventory.length, inventorySlots.size(), true))
if(!mergeItemStack(slotStack, tileEntity.inventory.length-1, inventorySlots.size(), true))
{
return null;
}
@@ -139,7 +139,7 @@ public class ContainerFactory extends Container
}
else if(slotID == 2)
{
if(!mergeItemStack(slotStack, tileEntity.inventory.length, inventorySlots.size(), true))
if(!mergeItemStack(slotStack, tileEntity.inventory.length-1, inventorySlots.size(), true))
{
return null;
}
@@ -154,7 +154,7 @@ public class ContainerFactory extends Container
}
}
else {
if(!mergeItemStack(slotStack, tileEntity.inventory.length, inventorySlots.size(), true))
if(!mergeItemStack(slotStack, tileEntity.inventory.length-1, inventorySlots.size(), true))
{
return null;
}
@@ -171,7 +171,7 @@ public class ContainerFactory extends Container
}
else if(slotID == 0)
{
if(!mergeItemStack(slotStack, tileEntity.inventory.length, inventorySlots.size(), true))
if(!mergeItemStack(slotStack, tileEntity.inventory.length-1, inventorySlots.size(), true))
{
return null;
}
@@ -187,14 +187,14 @@ public class ContainerFactory extends Container
}
}
else {
if(!mergeItemStack(slotStack, tileEntity.inventory.length, inventorySlots.size(), true))
if(!mergeItemStack(slotStack, tileEntity.inventory.length-1, inventorySlots.size(), true))
{
return null;
}
}
}
else {
int slotEnd = tileEntity.inventory.length;
int slotEnd = tileEntity.inventory.length-1;
if(slotID >= slotEnd && slotID <= (slotEnd+26))
{
@@ -253,11 +253,11 @@ public class ContainerFactory extends Container
public boolean isInputSlot(int slot)
{
if(tileEntity.tier == Tier.FactoryTier.BASIC)
return slot >= 5 && slot <= 7;
return slot >= 4 && slot <= 6;
if(tileEntity.tier == Tier.FactoryTier.ADVANCED)
return slot >= 5 && slot <= 9;
return slot >= 4 && slot <= 8;
if(tileEntity.tier == Tier.FactoryTier.ELITE)
return slot >= 5 && slot <= 11;
return slot >= 4 && slot <= 10;
return false;
}
@@ -265,11 +265,11 @@ public class ContainerFactory extends Container
public boolean isOutputSlot(int slot)
{
if(tileEntity.tier == Tier.FactoryTier.BASIC)
return slot >= 8 && slot <= 10;
return slot >= 7 && slot <= 9;
if(tileEntity.tier == Tier.FactoryTier.ADVANCED)
return slot >= 10 && slot <= 14;
return slot >= 9 && slot <= 13;
if(tileEntity.tier == Tier.FactoryTier.ELITE)
return slot >= 12 && slot <= 18;
return slot >= 11 && slot <= 17;
return false;
}
@@ -40,6 +40,7 @@ public class PacketSimpleGui implements IMessageHandler<SimpleGuiMessage, IMessa
}
else {
FMLCommonHandler.instance().showGuiScreen(SimpleGuiMessage.getGui(message.guiId, player, player.worldObj, message.coord4D));
player.openContainer.windowId = message.windowId;
}
return null;
@@ -51,6 +52,8 @@ public class PacketSimpleGui implements IMessageHandler<SimpleGuiMessage, IMessa
public int guiId;
public int windowId;
public SimpleGuiMessage() {}
public SimpleGuiMessage(Coord4D coord, int gui)
@@ -58,6 +61,12 @@ public class PacketSimpleGui implements IMessageHandler<SimpleGuiMessage, IMessa
coord4D = coord;
guiId = gui;
}
public SimpleGuiMessage(Coord4D coord, int gui, int id)
{
this(coord, gui);
windowId = id;
}
public static void openServerGui(int id, EntityPlayerMP playerMP, World world, Coord4D obj)
{
@@ -66,7 +75,7 @@ public class PacketSimpleGui implements IMessageHandler<SimpleGuiMessage, IMessa
int window = playerMP.currentWindowId;
Mekanism.packetHandler.sendTo(new SimpleGuiMessage(obj, id), playerMP);
Mekanism.packetHandler.sendTo(new SimpleGuiMessage(obj, id, window), playerMP);
playerMP.openContainer = Mekanism.proxy.getServerGui(id, playerMP, world, obj.xCoord, obj.yCoord, obj.zCoord);
playerMP.openContainer.windowId = window;
@@ -89,6 +98,7 @@ public class PacketSimpleGui implements IMessageHandler<SimpleGuiMessage, IMessa
dataStream.writeInt(coord4D.dimensionId);
dataStream.writeInt(guiId);
dataStream.writeInt(windowId);
}
@Override
@@ -97,6 +107,7 @@ public class PacketSimpleGui implements IMessageHandler<SimpleGuiMessage, IMessa
coord4D = new Coord4D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
guiId = dataStream.readInt();
windowId = dataStream.readInt();
}
}
}