package net.minecraft.src;

import org.lwjgl.opengl.GL11;

/**
 * PowerCraft crafting tool GUI
 * 
 * @author Ondrej Hruska
 * @copy (c) 2012
 */
public class PCco_GuiCraftingTool extends GuiContainer {
	private int inventoryRows;

	private GuiButton prev, next;
	private static int page = 0;
	
	@SuppressWarnings("unchecked")
	public void initGui()
    {
		prev = new GuiButton(0, width/2 - 115, height/2+30, "<<<");
		next = new GuiButton(1, width/2 + 115 - 30, height/2+30, ">>>");
		prev.width = next.width = 30;
		prev.enabled = page > 0;
		next.enabled = page < Math.ceil(((PCco_ContainerCraftingTool)inventorySlots).stacklist.size()/(13*7));
		controlList.add(prev);
		controlList.add(next);
		
		super.initGui();
    }
	
	@Override
	protected void actionPerformed(GuiButton guibutton) {
		if (!guibutton.enabled) { return; }
		
		if(guibutton.id == 0){
			page--;
		}
		
		if(guibutton.id == 1){
			page++;
		}
		
		((PCco_ContainerCraftingTool)inventorySlots).loadStacksForPage(page);
		
		prev.enabled = page > 0;
		next.enabled = page < Math.ceil(((PCco_ContainerCraftingTool)inventorySlots).stacklist.size()/(13*7));
		
	}
	
	

	/**
	 * Create Crafting tool GUI for player
	 * 
	 * @param player the player
	 */
	public PCco_GuiCraftingTool(EntityPlayer player) {
		super(new PCco_ContainerCraftingTool(player));
		inventoryRows = 0;
		allowUserInput = false;

		char c = '\336';
		int i = c - 108;
		inventoryRows = 7;
		ySize = i + inventoryRows * 18;
		xSize = 248;
	}

	@Override
	protected void drawGuiContainerForegroundLayer() {
		fontRenderer.drawString("PowerCraft's crafting tool", 8, 6, 0x404040);
		fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 100, (ySize - 96) + 2, 0x404040);
	}

	@Override
	protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
		int k = mc.renderEngine.getTexture("/PowerCraft/core/large-container.png");
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		mc.renderEngine.bindTexture(k);
		int l = (width - xSize) / 2;
		int i1 = (height - ySize) / 2;
		drawTexturedModalRect(l, i1, 0, 0, xSize, inventoryRows * 18 + 17);
		drawTexturedModalRect(l, i1 + inventoryRows * 18 + 17, 0, 144, xSize, 96);
	}
}
