Files
TinkersConstruct/src/main/java/tconstruct/tools/gui/StencilTableGui.java
T

138 lines
4.8 KiB
Java
Raw Normal View History

package tconstruct.tools.gui;
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-02-05 10:28:54 -05:00
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
2014-02-05 10:28:54 -05:00
import org.lwjgl.opengl.GL11;
2014-02-05 10:28:54 -05:00
2014-02-01 17:28:41 +11:00
import tconstruct.TConstruct;
2014-08-20 22:23:12 +02:00
import tconstruct.library.client.StencilGuiElement;
import tconstruct.library.client.TConstructClientRegistry;
import tconstruct.library.client.ToolGuiElement;
import tconstruct.library.crafting.StencilBuilder;
2014-06-04 21:44:48 -08:00
import tconstruct.tools.TinkerTools;
import tconstruct.tools.inventory.PatternShaperContainer;
import tconstruct.tools.logic.StencilTableLogic;
2014-07-21 12:52:39 -08:00
import tconstruct.util.network.PatternTablePacket;
public class StencilTableGui extends GuiContainer
{
StencilTableLogic logic;
2014-08-20 22:23:12 +02:00
int activeButton;
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;
}
2014-02-17 00:31:43 -05:00
@Override
2014-02-05 08:28:53 -05:00
public void onGuiClosed ()
{
2014-02-05 08:28:53 -05:00
super.onGuiClosed();
}
@Override
2014-02-05 08:28:53 -05:00
protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
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-08-31 05:13:31 -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)
{
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);
if (!logic.isStackInSlot(0))
{
this.drawTexturedModalRect(cornerX + 47, cornerY + 34, 176, 0, 18, 18);
}
}
2014-02-17 00:31:43 -05:00
@Override
public void initGui ()
{
super.initGui();
2014-08-20 22:23:12 +02:00
int bpr = 4; // buttons per row!
int cornerX = this.guiLeft - 22*bpr;
int cornerY = this.guiTop + 2;
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);
if(element.stencilIndex == -1)
continue;
GuiButtonStencil button = new GuiButtonStencil(id++, cornerX + 22 * (iter % bpr), cornerY + 22 * (iter / bpr), element.buttonIconX, element.buttonIconY, element.domain, element.texture,
element);
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);
if(element.stencilIndex == -1)
continue;
GuiButtonStencil button = new GuiButtonStencil(id++, cornerX + 22 * (iter % bpr), cornerY + 22 * (iter / bpr), element.buttonIconX, element.buttonIconY, element.domain, element.texture,
element);
this.buttonList.add(button);
}
// get the correct setting :I
if(logic.getStackInSlot(1) != null)
activeButton = StencilBuilder.getIndex(logic.getStackInSlot(1));
setActiveButton(activeButton);
}
2014-02-17 00:31:43 -05:00
@Override
protected void actionPerformed (GuiButton button)
{
ItemStack pattern = logic.getStackInSlot(0);
if (pattern != null && StencilBuilder.isBlank(pattern))
{
2014-08-20 22:23:12 +02:00
int id = ((GuiButtonStencil)button).element.stencilIndex;
ItemStack stack = StencilBuilder.getStencil(id);
if(stack != null)
2014-02-17 01:27:15 -05:00
{
2014-08-20 22:23:12 +02:00
logic.setInventorySlotContents(1, stack);
updateServer(stack);
}
}
2014-08-20 22:23:12 +02:00
setActiveButton(button.id);
}
2014-08-20 22:23:12 +02:00
private void setActiveButton(int id)
{
2014-08-20 22:23:12 +02:00
// deactivate old button
((GuiButton)this.buttonList.get(activeButton)).enabled = true;
// update active button
activeButton = id;
// activate the button
((GuiButton)this.buttonList.get(activeButton)).enabled = false;
}
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));
}
2014-02-15 00:29:24 -05:00
}