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 GuiScreenAddServer extends GuiScreen 009 { 010 /** This GUI's parent GUI. */ 011 private GuiScreen parentGui; 012 private GuiTextField serverAddress; 013 private GuiTextField serverName; 014 015 /** ServerData to be modified by this GUI */ 016 private ServerData newServerData; 017 018 public GuiScreenAddServer(GuiScreen par1GuiScreen, ServerData par2ServerData) 019 { 020 this.parentGui = par1GuiScreen; 021 this.newServerData = par2ServerData; 022 } 023 024 /** 025 * Called from the main game loop to update the screen. 026 */ 027 public void updateScreen() 028 { 029 this.serverName.updateCursorCounter(); 030 this.serverAddress.updateCursorCounter(); 031 } 032 033 /** 034 * Adds the buttons (and other controls) to the screen in question. 035 */ 036 public void initGui() 037 { 038 StringTranslate var1 = StringTranslate.getInstance(); 039 Keyboard.enableRepeatEvents(true); 040 this.controlList.clear(); 041 this.controlList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, var1.translateKey("addServer.add"))); 042 this.controlList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12, var1.translateKey("gui.cancel"))); 043 this.controlList.add(new GuiButton(2, this.width / 2 - 100, 142, var1.translateKey("addServer.hideAddress") + ": " + (this.newServerData.isHidingAddress() ? var1.translateKey("gui.yes") : var1.translateKey("gui.no")))); 044 this.serverName = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 66, 200, 20); 045 this.serverName.setFocused(true); 046 this.serverName.setText(this.newServerData.serverName); 047 this.serverAddress = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 106, 200, 20); 048 this.serverAddress.setMaxStringLength(128); 049 this.serverAddress.setText(this.newServerData.serverIP); 050 ((GuiButton)this.controlList.get(0)).enabled = this.serverAddress.getText().length() > 0 && this.serverAddress.getText().split(":").length > 0 && this.serverName.getText().length() > 0; 051 } 052 053 /** 054 * Called when the screen is unloaded. Used to disable keyboard repeat events 055 */ 056 public void onGuiClosed() 057 { 058 Keyboard.enableRepeatEvents(false); 059 } 060 061 /** 062 * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e). 063 */ 064 protected void actionPerformed(GuiButton par1GuiButton) 065 { 066 if (par1GuiButton.enabled) 067 { 068 if (par1GuiButton.id == 1) 069 { 070 this.parentGui.confirmClicked(false, 0); 071 } 072 else if (par1GuiButton.id == 0) 073 { 074 this.newServerData.serverName = this.serverName.getText(); 075 this.newServerData.serverIP = this.serverAddress.getText(); 076 this.parentGui.confirmClicked(true, 0); 077 } 078 else if (par1GuiButton.id == 2) 079 { 080 StringTranslate var2 = StringTranslate.getInstance(); 081 this.newServerData.setHideAddress(!this.newServerData.isHidingAddress()); 082 ((GuiButton)this.controlList.get(2)).displayString = var2.translateKey("addServer.hideAddress") + ": " + (this.newServerData.isHidingAddress() ? var2.translateKey("gui.yes") : var2.translateKey("gui.no")); 083 } 084 } 085 } 086 087 /** 088 * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e). 089 */ 090 protected void keyTyped(char par1, int par2) 091 { 092 this.serverName.textboxKeyTyped(par1, par2); 093 this.serverAddress.textboxKeyTyped(par1, par2); 094 095 if (par1 == 9) 096 { 097 if (this.serverName.isFocused()) 098 { 099 this.serverName.setFocused(false); 100 this.serverAddress.setFocused(true); 101 } 102 else 103 { 104 this.serverName.setFocused(true); 105 this.serverAddress.setFocused(false); 106 } 107 } 108 109 if (par1 == 13) 110 { 111 this.actionPerformed((GuiButton)this.controlList.get(0)); 112 } 113 114 ((GuiButton)this.controlList.get(0)).enabled = this.serverAddress.getText().length() > 0 && this.serverAddress.getText().split(":").length > 0 && this.serverName.getText().length() > 0; 115 } 116 117 /** 118 * Called when the mouse is clicked. 119 */ 120 protected void mouseClicked(int par1, int par2, int par3) 121 { 122 super.mouseClicked(par1, par2, par3); 123 this.serverAddress.mouseClicked(par1, par2, par3); 124 this.serverName.mouseClicked(par1, par2, par3); 125 } 126 127 /** 128 * Draws the screen and all the components in it. 129 */ 130 public void drawScreen(int par1, int par2, float par3) 131 { 132 StringTranslate var4 = StringTranslate.getInstance(); 133 this.drawDefaultBackground(); 134 this.drawCenteredString(this.fontRenderer, var4.translateKey("addServer.title"), this.width / 2, 17, 16777215); 135 this.drawString(this.fontRenderer, var4.translateKey("addServer.enterName"), this.width / 2 - 100, 53, 10526880); 136 this.drawString(this.fontRenderer, var4.translateKey("addServer.enterIp"), this.width / 2 - 100, 94, 10526880); 137 this.serverName.drawTextBox(); 138 this.serverAddress.drawTextBox(); 139 super.drawScreen(par1, par2, par3); 140 } 141 }