package net.minecraft.src;

import org.lwjgl.input.Keyboard;

public class GuiRenameWorld extends GuiScreen {
	private GuiScreen guiScreen;
	private GuiTextField disableButton;
	private final String worldName;

	public GuiRenameWorld(GuiScreen var1, String var2) {
		this.guiScreen = var1;
		this.worldName = var2;
	}

	public void updateScreen() {
		this.disableButton.updateCursorCounter();
	}

	public void initGui() {
		StringTranslate var1 = StringTranslate.getInstance();
		Keyboard.enableRepeatEvents(true);
		this.controlList.clear();
		this.controlList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, var1.translateKey("selectWorld.renameButton")));
		this.controlList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12, var1.translateKey("gui.cancel")));
		ISaveFormat var2 = this.mc.getSaveLoader();
		WorldInfo var3 = var2.getWorldInfoForWorld(worldName); // FIX THIS SHIT
		String var4 = var3.getWorldName();
		this.disableButton = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 60, 200, 20, var4);
		this.disableButton.isFocused = true;
		this.disableButton.setMaxStringLength(32);
	}

	public void onGuiClosed() {
		Keyboard.enableRepeatEvents(false);
	}

	protected void actionPerformed(GuiButton var1) {
		if(var1.enabled) {
			if(var1.id == 1) {
				this.mc.displayGuiScreen(this.guiScreen);
			} else if(var1.id == 0) {
				ISaveFormat var2 = this.mc.getSaveLoader();
				var2.renameWorldData(this.worldName, this.disableButton.getText().trim());
				this.mc.displayGuiScreen(this.guiScreen);
			}

		}
	}

	protected void keyTyped(char var1, int var2) {
		this.disableButton.textboxKeyTyped(var1, var2);
		((GuiButton)this.controlList.get(0)).enabled = this.disableButton.getText().trim().length() > 0;
		if(var1 == 13) {
			this.actionPerformed((GuiButton)this.controlList.get(0));
		}

	}

	protected void mouseClicked(int var1, int var2, int var3) {
		super.mouseClicked(var1, var2, var3);
		this.disableButton.mouseClicked(var1, var2, var3);
	}

	public void drawScreen(int var1, int var2, float var3) {
		StringTranslate var4 = StringTranslate.getInstance();
		this.drawDefaultBackground();
		this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.renameTitle"), this.width / 2, this.height / 4 - 60 + 20, 16777215);
		this.drawString(this.fontRenderer, var4.translateKey("selectWorld.enterName"), this.width / 2 - 100, 47, 10526880);
		this.disableButton.drawTextBox();
		super.drawScreen(var1, var2, var3);
	}
}
