    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import org.lwjgl.input.Keyboard;
    006
    007    @SideOnly(Side.CLIENT)
    008    public class GuiRenameWorld extends GuiScreen
    009    {
    010        private GuiScreen parentGuiScreen;
    011        private GuiTextField theGuiTextField;
    012        private final String worldName;
    013
    014        public GuiRenameWorld(GuiScreen par1GuiScreen, String par2Str)
    015        {
    016            this.parentGuiScreen = par1GuiScreen;
    017            this.worldName = par2Str;
    018        }
    019
    020        /**
    021         * Called from the main game loop to update the screen.
    022         */
    023        public void updateScreen()
    024        {
    025            this.theGuiTextField.updateCursorCounter();
    026        }
    027
    028        /**
    029         * Adds the buttons (and other controls) to the screen in question.
    030         */
    031        public void initGui()
    032        {
    033            StringTranslate var1 = StringTranslate.getInstance();
    034            Keyboard.enableRepeatEvents(true);
    035            this.controlList.clear();
    036            this.controlList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, var1.translateKey("selectWorld.renameButton")));
    037            this.controlList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12, var1.translateKey("gui.cancel")));
    038            ISaveFormat var2 = this.mc.getSaveLoader();
    039            WorldInfo var3 = var2.getWorldInfo(this.worldName);
    040            String var4 = var3.getWorldName();
    041            this.theGuiTextField = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 60, 200, 20);
    042            this.theGuiTextField.setFocused(true);
    043            this.theGuiTextField.setText(var4);
    044        }
    045
    046        /**
    047         * Called when the screen is unloaded. Used to disable keyboard repeat events
    048         */
    049        public void onGuiClosed()
    050        {
    051            Keyboard.enableRepeatEvents(false);
    052        }
    053
    054        /**
    055         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    056         */
    057        protected void actionPerformed(GuiButton par1GuiButton)
    058        {
    059            if (par1GuiButton.enabled)
    060            {
    061                if (par1GuiButton.id == 1)
    062                {
    063                    this.mc.displayGuiScreen(this.parentGuiScreen);
    064                }
    065                else if (par1GuiButton.id == 0)
    066                {
    067                    ISaveFormat var2 = this.mc.getSaveLoader();
    068                    var2.renameWorld(this.worldName, this.theGuiTextField.getText().trim());
    069                    this.mc.displayGuiScreen(this.parentGuiScreen);
    070                }
    071            }
    072        }
    073
    074        /**
    075         * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
    076         */
    077        protected void keyTyped(char par1, int par2)
    078        {
    079            this.theGuiTextField.textboxKeyTyped(par1, par2);
    080            ((GuiButton)this.controlList.get(0)).enabled = this.theGuiTextField.getText().trim().length() > 0;
    081
    082            if (par1 == 13)
    083            {
    084                this.actionPerformed((GuiButton)this.controlList.get(0));
    085            }
    086        }
    087
    088        /**
    089         * Called when the mouse is clicked.
    090         */
    091        protected void mouseClicked(int par1, int par2, int par3)
    092        {
    093            super.mouseClicked(par1, par2, par3);
    094            this.theGuiTextField.mouseClicked(par1, par2, par3);
    095        }
    096
    097        /**
    098         * Draws the screen and all the components in it.
    099         */
    100        public void drawScreen(int par1, int par2, float par3)
    101        {
    102            StringTranslate var4 = StringTranslate.getInstance();
    103            this.drawDefaultBackground();
    104            this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.renameTitle"), this.width / 2, this.height / 4 - 60 + 20, 16777215);
    105            this.drawString(this.fontRenderer, var4.translateKey("selectWorld.enterName"), this.width / 2 - 100, 47, 10526880);
    106            this.theGuiTextField.drawTextBox();
    107            super.drawScreen(par1, par2, par3);
    108        }
    109    }