package shadersmod.client;

import java.util.ArrayList;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiSlot;
import net.minecraft.client.renderer.Tessellator;

class GuiSlotShaders extends GuiSlot
{
    private ArrayList shaderslist;
    private int selectedIndex;

    final GuiShaders shadersGui;

    public GuiSlotShaders(GuiShaders par1GuiShaders)
    {
        //super(par1GuiShaders.getMc(), par1GuiShaders.width / 2 + 20, par1GuiShaders.height, 40, par1GuiShaders.height - 70, 16);
        super(par1GuiShaders.getMc(), par1GuiShaders.width / 2 + 20, par1GuiShaders.height, 40, par1GuiShaders.height - 70, 16);
        this.shadersGui = par1GuiShaders;
        this.updateList();
    }

	public void updateList()
    {
    	this.shaderslist = Shaders.listofShaders();
        selectedIndex = 0;
    	for (int i=0,n=this.shaderslist.size(); i<n; ++i) {
    		if (((String)this.shaderslist.get(i)).equals(Shaders.currentshadername)) {
    			selectedIndex = i;
    			break;
    		}
    	}
    }

	@Override
	/** getSize */
	protected int getSize() {
		return this.shaderslist.size();
	}

	@Override
	/** elementClicked */
	protected void elementClicked(int index, boolean doubleClicked, int mouseX, int mouseY) {
		selectedIndex = index;
		Shaders.setShaderPack((String)shaderslist.get(index));
    	shadersGui.needReinit = false;
    	Shaders.loadShaderPack();
    	Shaders.uninit();
	}

	@Override
	/** isSelected */
	protected boolean isSelected(int index) {
		return index==selectedIndex;
	}

	@Override
	/** getScrollBarX */
	protected int getScrollBarX() {
		return this.width - 6;
	}

    @Override
    /** getContentHeight */
	protected int getContentHeight() {
    	return this.getSize() * 18;
	}
    
	@Override
	/** drawBackground */
	protected void drawBackground() {
		//this.shadersGui.drawDefaultBackground();
	}

	@Override
	/** drawSlot */
	protected void func_192637_a(int index, int posX, int posY, int contentY, int mouseX, int mouseY, float p_192637_7_) {
        this.shadersGui.drawCenteredString((String)this.shaderslist.get(index), this.shadersGui.width / 4 + 10, posY + 1, 0xffffff);
	}
}
