| 1 | package net.minecraft.client.gui;
|
| 2 |
|
| 3 | import java.io.IOException;
|
| 4 | import net.minecraft.client.resources.I18n;
|
| 5 | import net.minecraft.world.storage.ISaveFormat;
|
| 6 | import net.minecraft.world.storage.WorldInfo;
|
| 7 | import org.lwjgl.input.Keyboard;
|
| 8 |
|
| 9 | public class GuiRenameWorld extends GuiScreen
|
| 10 | {
|
| 11 | private GuiScreen parentScreen;
|
| 12 | private GuiTextField field_146583_f;
|
| 13 | private final String saveName;
|
| 14 |
|
| 15 | public GuiRenameWorld(GuiScreen parentScreenIn, String saveNameIn)
|
| 16 | {
|
| 17 | this.parentScreen = parentScreenIn;
|
| 18 | this.saveName = saveNameIn;
|
| 19 | }
|
| 20 |
|
| 21 | /**
|
| 22 | * Called from the main game loop to update the screen.
|
| 23 | */
|
| 24 | public void updateScreen()
|
| 25 | {
|
| 26 | this.field_146583_f.updateCursorCounter();
|
| 27 | }
|
| 28 |
|
| 29 | /**
|
| 30 | * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
|
| 31 | * window resizes, the buttonList is cleared beforehand.
|
| 32 | */
|
| 33 | public void initGui()
|
| 34 | {
|
| 35 | Keyboard.enableRepeatEvents(true);
|
| 36 | this.buttonList.clear();
|
| 37 | this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, I18n.format("selectWorld.renameButton", new Object[0])));
|
| 38 | this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12, I18n.format("gui.cancel", new Object[0])));
|
| 39 | ISaveFormat isaveformat = this.mc.getSaveLoader();
|
| 40 | WorldInfo worldinfo = isaveformat.getWorldInfo(this.saveName);
|
| 41 | String s = worldinfo.getWorldName();
|
| 42 | this.field_146583_f = new GuiTextField(2, this.fontRendererObj, this.width / 2 - 100, 60, 200, 20);
|
| 43 | this.field_146583_f.setFocused(true);
|
| 44 | this.field_146583_f.setText(s);
|
| 45 | }
|
| 46 |
|
| 47 | /**
|
| 48 | * Called when the screen is unloaded. Used to disable keyboard repeat events
|
| 49 | */
|
| 50 | public void onGuiClosed()
|
| 51 | {
|
| 52 | Keyboard.enableRepeatEvents(false);
|
| 53 | }
|
| 54 |
|
| 55 | /**
|
| 56 | * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
|
| 57 | */
|
| 58 | protected void actionPerformed(GuiButton button) throws IOException
|
| 59 | {
|
| 60 | if (button.enabled)
|
| 61 | {
|
| 62 | if (button.id == 1)
|
| 63 | {
|
| 64 | this.mc.displayGuiScreen(this.parentScreen);
|
| 65 | }
|
| 66 | else if (button.id == 0)
|
| 67 | {
|
| 68 | ISaveFormat isaveformat = this.mc.getSaveLoader();
|
| 69 | isaveformat.renameWorld(this.saveName, this.field_146583_f.getText().trim());
|
| 70 | this.mc.displayGuiScreen(this.parentScreen);
|
| 71 | }
|
| 72 | }
|
| 73 | }
|
| 74 |
|
| 75 | /**
|
| 76 | * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
|
| 77 | * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
|
| 78 | */
|
| 79 | protected void keyTyped(char typedChar, int keyCode) throws IOException
|
| 80 | {
|
| 81 | this.field_146583_f.textboxKeyTyped(typedChar, keyCode);
|
| 82 | ((GuiButton)this.buttonList.get(0)).enabled = this.field_146583_f.getText().trim().length() > 0;
|
| 83 |
|
| 84 | if (keyCode == 28 || keyCode == 156)
|
| 85 | {
|
| 86 | this.actionPerformed((GuiButton)this.buttonList.get(0));
|
| 87 | }
|
| 88 | }
|
| 89 |
|
| 90 | /**
|
| 91 | * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
|
| 92 | */
|
| 93 | protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
|
| 94 | {
|
| 95 | super.mouseClicked(mouseX, mouseY, mouseButton);
|
| 96 | this.field_146583_f.mouseClicked(mouseX, mouseY, mouseButton);
|
| 97 | }
|
| 98 |
|
| 99 | /**
|
| 100 | * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
|
| 101 | */
|
| 102 | public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
| 103 | {
|
| 104 | this.drawDefaultBackground();
|
| 105 | this.drawCenteredString(this.fontRendererObj, I18n.format("selectWorld.renameTitle", new Object[0]), this.width / 2, 20, 16777215);
|
| 106 | this.drawString(this.fontRendererObj, I18n.format("selectWorld.enterName", new Object[0]), this.width / 2 - 100, 47, 10526880);
|
| 107 | this.field_146583_f.drawTextBox();
|
| 108 | super.drawScreen(mouseX, mouseY, partialTicks);
|
| 109 | }
|
| 110 | }
|
| 111 |
|