package net.minecraft.src;

import net.minecraft.src.PC_GresTextEdit.PC_GresInputType;
import net.minecraft.src.PC_GresWidget.PC_GresAlign;

/**
 * 
 * 
 * @author MightyPork
 * @copy (c) 2012
 *
 */
public class PCma_GuiXPBank implements PC_IGresBase {

	private PCma_TileEntityXPBank xpbank;
	private PC_GresWidget buttonClose;
	private PC_GresWidget txStoragePoints;
	private PC_GresWidget txPlayerPoints;
	private PC_GresWidget txPlayerLevel;
	private PC_GresWidget editWithdraw;
	private PC_GresWidget editDeposit;

	public PCma_GuiXPBank(PCma_TileEntityXPBank tex) {
		xpbank = tex;
	}

	@Override
	public EntityPlayer getPlayer() {
		return PC_Utils.mc().thePlayer;
	}

	@Override
	public void initGui(PC_IGresGui gui) {
		PC_GresWindow w = new PC_GresWindow(PC_Lang.tr("tile.PCmaXPBank.name"));
		w.setAlignH(PC_GresAlign.CENTER);
		
		PC_GresWidget vg, hg, hg1;
		
		hg = new PC_GresLayoutH().setAlignH(PC_GresAlign.STRETCH);
		
		vg = new PC_GresLayoutV().setAlignH(PC_GresAlign.STRETCH);
		
		hg1 = new PC_GresLayoutH().setAlignH(PC_GresAlign.LEFT);
		
		int labelWidth = 0;
		labelWidth = Math.max(labelWidth, w.getStringWidth(PC_Lang.tr("pc.gui.xpbank.totalXp")));
		labelWidth = Math.max(labelWidth, w.getStringWidth(PC_Lang.tr("pc.gui.xpbank.currentPlayerPoints")));
		labelWidth = Math.max(labelWidth, w.getStringWidth(PC_Lang.tr("pc.gui.xpbank.currentPlayerLevel")));
		labelWidth = Math.max(labelWidth, w.getStringWidth(PC_Lang.tr("pc.gui.xpbank.pointsToWithdraw")));
		labelWidth = Math.max(labelWidth, w.getStringWidth(PC_Lang.tr("pc.gui.xpbank.pointsToDeposit")));
		labelWidth += 5;
		
		hg1.add(new PC_GresLabel(PC_Lang.tr("pc.gui.xpbank.totalXp")).setMinWidth(labelWidth).setAlignH(PC_GresAlign.RIGHT));
		hg1.add(txStoragePoints = new PC_GresLabel(xpbank.xp+"").setColor(PC_GresWidget.textColorEnabled, 0x009900));
		hg1.add(new PC_GresLabel(PC_Lang.tr("pc.gui.xpbank.xpUnit")));
		vg.add(hg1);		

		vg.add(new PC_GresSeparatorH(0, 5).setLineColor(0xbbbbbb));
		
		hg1 = new PC_GresLayoutH().setAlignH(PC_GresAlign.LEFT);
		hg1.add(new PC_GresLabel(PC_Lang.tr("pc.gui.xpbank.currentPlayerPoints")).setMinWidth(labelWidth).setAlignH(PC_GresAlign.RIGHT));
		hg1.add(txPlayerPoints = new PC_GresLabel(getPlayer().experienceTotal+"").setColor(PC_GresWidget.textColorEnabled, 0x000099));
		hg1.add(new PC_GresLabel(PC_Lang.tr("pc.gui.xpbank.xpUnit")));
		vg.add(hg1);
		
		hg1 = new PC_GresLayoutH().setAlignH(PC_GresAlign.LEFT);
		hg1.add(new PC_GresLabel(PC_Lang.tr("pc.gui.xpbank.currentPlayerLevel")).setMinWidth(labelWidth).setAlignH(PC_GresAlign.RIGHT));
		hg1.add(txPlayerLevel = new PC_GresLabel(getPlayer().experienceLevel+"").setColor(PC_GresWidget.textColorEnabled, 0x990099));
		hg1.add(new PC_GresLabel(PC_Lang.tr("pc.gui.xpbank.xpLevels")));
		vg.add(hg1);
		
		vg.add(new PC_GresSeparatorH(0, 5).setLineColor(0xbbbbbb));
		
		hg1 = new PC_GresLayoutH().setAlignH(PC_GresAlign.LEFT);
		hg1.add(new PC_GresLabel(PC_Lang.tr("pc.gui.xpbank.pointsToWithdraw")).setMinWidth(labelWidth).setAlignH(PC_GresAlign.RIGHT));
		hg1.add(editWithdraw = new PC_GresTextEdit(xpbank.xp+"", 8, PC_GresInputType.UNSIGNED_INT).setId(10));
		hg1.add(new PC_GresButton(PC_Lang.tr("pc.gui.xpbank.withdrawButton")).setId(11));
		vg.add(hg1);
		
		hg1 = new PC_GresLayoutH().setAlignH(PC_GresAlign.LEFT);
		hg1.add(new PC_GresLabel(PC_Lang.tr("pc.gui.xpbank.pointsToDeposit")).setMinWidth(labelWidth).setAlignH(PC_GresAlign.RIGHT));
		hg1.add(editDeposit = new PC_GresTextEdit(xpbank.xp+"", 8, PC_GresInputType.UNSIGNED_INT).setId(20));
		hg1.add(new PC_GresButton(PC_Lang.tr("pc.gui.xpbank.depositButton")).setId(21));
		vg.add(hg1);
		
		hg.add(vg);
		w.add(hg);
		
		
		hg = new PC_GresLayoutH().setAlignH(PC_GresAlign.CENTER).setWidgetMargin(3);
		hg.add(buttonClose = new PC_GresButton(PC_Lang.tr("pc.gui.ok")).setId(0));
		w.add(hg);
		
		gui.add(w);
		
	}

	@Override
	public void onGuiClosed(PC_IGresGui gui) {}

	@Override
	public void actionPerformed(PC_GresWidget widget, PC_IGresGui gui) {
		switch(widget.getId()){
			case 0:
				gui.close();
				break;
		}
	}

	@Override
	public void onEscapePressed(PC_IGresGui gui) {
		gui.close();
	}

	@Override
	public void onReturnPressed(PC_IGresGui gui) {
		gui.close();
	}

	@Override
	public void onCraftMatrixChanged(IInventory iinventory) {}

}
