2014-07-05 21:08:58 -08:00
|
|
|
package tconstruct.tools.gui;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-09-09 18:30:15 +10:00
|
|
|
import net.minecraft.util.*;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
2014-02-01 17:28:41 +11:00
|
|
|
import tconstruct.TConstruct;
|
2014-09-09 18:30:15 +10:00
|
|
|
import tconstruct.library.client.*;
|
2014-08-20 19:15:16 +02:00
|
|
|
import tconstruct.library.crafting.StencilBuilder;
|
2014-06-04 21:44:48 -08:00
|
|
|
import tconstruct.tools.inventory.PatternShaperContainer;
|
|
|
|
|
import tconstruct.tools.logic.StencilTableLogic;
|
2014-07-21 12:52:39 -08:00
|
|
|
import tconstruct.util.network.PatternTablePacket;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
public class StencilTableGui extends GuiContainer
|
|
|
|
|
{
|
|
|
|
|
StencilTableLogic logic;
|
2014-08-20 22:23:12 +02:00
|
|
|
int activeButton;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
public StencilTableGui(InventoryPlayer inventoryplayer, StencilTableLogic shaper, World world, int x, int y, int z)
|
|
|
|
|
{
|
|
|
|
|
super(new PatternShaperContainer(inventoryplayer, shaper));
|
|
|
|
|
logic = shaper;
|
2014-08-20 22:23:12 +02:00
|
|
|
activeButton = 0;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public void onGuiClosed ()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
super.onGuiClosed();
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
protected void drawGuiContainerForegroundLayer (int par1, int par2)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
fontRendererObj.drawString(StatCollector.translateToLocal("crafters.PatternShaper"), 50, 6, 0x404040);
|
|
|
|
|
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, (ySize - 96) + 2, 0x404040);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
2013-08-31 05:13:31 -07:00
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/patternshaper.png");
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
protected void drawGuiContainerBackgroundLayer (float par1, int par2, int par3)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
2014-02-05 08:28:53 -05:00
|
|
|
this.mc.getTextureManager().bindTexture(background);
|
|
|
|
|
int cornerX = (this.width - this.xSize) / 2;
|
|
|
|
|
int cornerY = (this.height - this.ySize) / 2;
|
|
|
|
|
this.drawTexturedModalRect(cornerX, cornerY, 0, 0, this.xSize, this.ySize);
|
2013-07-26 21:18:53 -07:00
|
|
|
if (!logic.isStackInSlot(0))
|
|
|
|
|
{
|
|
|
|
|
this.drawTexturedModalRect(cornerX + 47, cornerY + 34, 176, 0, 18, 18);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
public void initGui ()
|
|
|
|
|
{
|
|
|
|
|
super.initGui();
|
2014-08-20 22:23:12 +02:00
|
|
|
|
|
|
|
|
int bpr = 4; // buttons per row!
|
2014-09-09 18:30:15 +10:00
|
|
|
int cornerX = this.guiLeft - 22 * bpr;
|
2014-08-20 22:23:12 +02:00
|
|
|
int cornerY = this.guiTop + 2;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-02-05 08:28:53 -05:00
|
|
|
this.buttonList.clear();
|
2014-08-20 22:23:12 +02:00
|
|
|
|
|
|
|
|
int id = 0;
|
|
|
|
|
for (int iter = 0; iter < TConstructClientRegistry.stencilButtons.size(); iter++)
|
|
|
|
|
{
|
|
|
|
|
StencilGuiElement element = TConstructClientRegistry.stencilButtons.get(iter);
|
2014-09-09 18:30:15 +10:00
|
|
|
if (element.stencilIndex == -1)
|
2014-08-20 22:23:12 +02:00
|
|
|
continue;
|
2014-09-09 18:30:15 +10:00
|
|
|
GuiButtonStencil button = new GuiButtonStencil(id++, cornerX + 22 * (iter % bpr), cornerY + 22 * (iter / bpr), element.buttonIconX, element.buttonIconY, element.domain, element.texture, element);
|
2014-08-20 22:23:12 +02:00
|
|
|
this.buttonList.add(button);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// secondary buttons, yay!
|
|
|
|
|
// these are to use for other mods :I
|
|
|
|
|
cornerX = this.guiLeft + this.xSize + 4;
|
|
|
|
|
for (int iter = 0; iter < TConstructClientRegistry.stencilButtons2.size(); iter++)
|
|
|
|
|
{
|
|
|
|
|
StencilGuiElement element = TConstructClientRegistry.stencilButtons2.get(iter);
|
2014-09-09 18:30:15 +10:00
|
|
|
if (element.stencilIndex == -1)
|
2014-08-20 22:23:12 +02:00
|
|
|
continue;
|
2014-09-09 18:30:15 +10:00
|
|
|
GuiButtonStencil button = new GuiButtonStencil(id++, cornerX + 22 * (iter % bpr), cornerY + 22 * (iter / bpr), element.buttonIconX, element.buttonIconY, element.domain, element.texture, element);
|
2014-08-20 22:23:12 +02:00
|
|
|
this.buttonList.add(button);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get the correct setting :I
|
2014-08-29 14:44:45 +02:00
|
|
|
ItemStack stack;
|
2014-09-09 18:30:15 +10:00
|
|
|
if (logic.getStackInSlot(1) != null)
|
|
|
|
|
{
|
2014-08-20 22:23:12 +02:00
|
|
|
activeButton = StencilBuilder.getIndex(logic.getStackInSlot(1));
|
2014-08-29 14:44:45 +02:00
|
|
|
setActiveButton(activeButton);
|
|
|
|
|
stack = StencilBuilder.getStencil(((GuiButtonStencil) this.buttonList.get(activeButton)).element.stencilIndex);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
stack = null;
|
2014-08-20 22:23:12 +02:00
|
|
|
|
2014-08-24 23:09:49 +02:00
|
|
|
logic.setSelectedPattern(stack);
|
|
|
|
|
updateServer(stack);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
protected void actionPerformed (GuiButton button)
|
|
|
|
|
{
|
|
|
|
|
ItemStack pattern = logic.getStackInSlot(0);
|
2014-08-20 19:15:16 +02:00
|
|
|
if (pattern != null && StencilBuilder.isBlank(pattern))
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-09-09 18:30:15 +10:00
|
|
|
int id = ((GuiButtonStencil) button).element.stencilIndex;
|
2014-08-20 22:23:12 +02:00
|
|
|
ItemStack stack = StencilBuilder.getStencil(id);
|
2014-09-09 18:30:15 +10:00
|
|
|
if (stack != null)
|
2014-02-17 01:27:15 -05:00
|
|
|
{
|
2014-08-24 23:09:49 +02:00
|
|
|
logic.setSelectedPattern(stack);
|
2014-08-20 22:23:12 +02:00
|
|
|
updateServer(stack);
|
2014-08-20 19:15:16 +02:00
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
2014-08-20 22:23:12 +02:00
|
|
|
|
|
|
|
|
setActiveButton(button.id);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-09-09 18:30:15 +10:00
|
|
|
private void setActiveButton (int id)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-08-20 22:23:12 +02:00
|
|
|
// deactivate old button
|
2014-09-09 18:30:15 +10:00
|
|
|
((GuiButton) this.buttonList.get(activeButton)).enabled = true;
|
2014-08-20 22:23:12 +02:00
|
|
|
// update active button
|
|
|
|
|
activeButton = id;
|
|
|
|
|
// activate the button
|
2014-09-09 18:30:15 +10:00
|
|
|
((GuiButton) this.buttonList.get(activeButton)).enabled = false;
|
2014-08-20 22:23:12 +02:00
|
|
|
}
|
2014-02-17 01:27:15 -05:00
|
|
|
|
2014-08-20 22:23:12 +02:00
|
|
|
void updateServer (ItemStack stack)
|
|
|
|
|
{
|
2014-07-21 12:52:39 -08:00
|
|
|
TConstruct.packetPipeline.sendToServer(new PatternTablePacket(logic.xCoord, logic.yCoord, logic.zCoord, stack));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
2014-02-15 00:29:24 -05:00
|
|
|
}
|