001package net.minecraft.client.multiplayer; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import net.minecraft.client.Minecraft; 006import net.minecraft.client.gui.GuiButton; 007import net.minecraft.client.gui.GuiScreen; 008import net.minecraft.util.StringTranslate; 009 010@SideOnly(Side.CLIENT) 011public class GuiConnecting extends GuiScreen 012{ 013 /** A reference to the NetClientHandler. */ 014 private NetClientHandler clientHandler; 015 016 /** True if the connection attempt has been cancelled. */ 017 private boolean cancelled = false; 018 private final GuiScreen field_98098_c; 019 020 public GuiConnecting(GuiScreen par1GuiScreen, Minecraft par2Minecraft, ServerData par3ServerData) 021 { 022 this.mc = par2Minecraft; 023 this.field_98098_c = par1GuiScreen; 024 ServerAddress serveraddress = ServerAddress.func_78860_a(par3ServerData.serverIP); 025 par2Minecraft.loadWorld((WorldClient)null); 026 par2Minecraft.setServerData(par3ServerData); 027 this.spawnNewServerThread(serveraddress.getIP(), serveraddress.getPort()); 028 } 029 030 public GuiConnecting(GuiScreen par1GuiScreen, Minecraft par2Minecraft, String par3Str, int par4) 031 { 032 this.mc = par2Minecraft; 033 this.field_98098_c = par1GuiScreen; 034 par2Minecraft.loadWorld((WorldClient)null); 035 this.spawnNewServerThread(par3Str, par4); 036 } 037 038 private void spawnNewServerThread(String par1Str, int par2) 039 { 040 this.mc.func_98033_al().func_98233_a("Connecting to " + par1Str + ", " + par2); 041 (new ThreadConnectToServer(this, par1Str, par2)).start(); 042 } 043 044 /** 045 * Called from the main game loop to update the screen. 046 */ 047 public void updateScreen() 048 { 049 if (this.clientHandler != null) 050 { 051 this.clientHandler.processReadPackets(); 052 } 053 } 054 055 /** 056 * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e). 057 */ 058 protected void keyTyped(char par1, int par2) {} 059 060 /** 061 * Adds the buttons (and other controls) to the screen in question. 062 */ 063 public void initGui() 064 { 065 StringTranslate stringtranslate = StringTranslate.getInstance(); 066 this.buttonList.clear(); 067 this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 120 + 12, stringtranslate.translateKey("gui.cancel"))); 068 } 069 070 /** 071 * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e). 072 */ 073 protected void actionPerformed(GuiButton par1GuiButton) 074 { 075 if (par1GuiButton.id == 0) 076 { 077 this.cancelled = true; 078 079 if (this.clientHandler != null) 080 { 081 this.clientHandler.disconnect(); 082 } 083 084 this.mc.displayGuiScreen(this.field_98098_c); 085 } 086 } 087 088 /** 089 * Draws the screen and all the components in it. 090 */ 091 public void drawScreen(int par1, int par2, float par3) 092 { 093 this.drawDefaultBackground(); 094 StringTranslate stringtranslate = StringTranslate.getInstance(); 095 096 if (this.clientHandler == null) 097 { 098 this.drawCenteredString(this.fontRenderer, stringtranslate.translateKey("connect.connecting"), this.width / 2, this.height / 2 - 50, 16777215); 099 this.drawCenteredString(this.fontRenderer, "", this.width / 2, this.height / 2 - 10, 16777215); 100 } 101 else 102 { 103 this.drawCenteredString(this.fontRenderer, stringtranslate.translateKey("connect.authorizing"), this.width / 2, this.height / 2 - 50, 16777215); 104 this.drawCenteredString(this.fontRenderer, this.clientHandler.field_72560_a, this.width / 2, this.height / 2 - 10, 16777215); 105 } 106 107 super.drawScreen(par1, par2, par3); 108 } 109 110 /** 111 * Sets the NetClientHandler. 112 */ 113 static NetClientHandler setNetClientHandler(GuiConnecting par0GuiConnecting, NetClientHandler par1NetClientHandler) 114 { 115 return par0GuiConnecting.clientHandler = par1NetClientHandler; 116 } 117 118 static Minecraft func_74256_a(GuiConnecting par0GuiConnecting) 119 { 120 return par0GuiConnecting.mc; 121 } 122 123 static boolean isCancelled(GuiConnecting par0GuiConnecting) 124 { 125 return par0GuiConnecting.cancelled; 126 } 127 128 static Minecraft func_74254_c(GuiConnecting par0GuiConnecting) 129 { 130 return par0GuiConnecting.mc; 131 } 132 133 /** 134 * Gets the NetClientHandler. 135 */ 136 static NetClientHandler getNetClientHandler(GuiConnecting par0GuiConnecting) 137 { 138 return par0GuiConnecting.clientHandler; 139 } 140 141 static GuiScreen func_98097_e(GuiConnecting par0GuiConnecting) 142 { 143 return par0GuiConnecting.field_98098_c; 144 } 145 146 static Minecraft func_74250_f(GuiConnecting par0GuiConnecting) 147 { 148 return par0GuiConnecting.mc; 149 } 150 151 static Minecraft func_74251_g(GuiConnecting par0GuiConnecting) 152 { 153 return par0GuiConnecting.mc; 154 } 155 156 static Minecraft func_98096_h(GuiConnecting par0GuiConnecting) 157 { 158 return par0GuiConnecting.mc; 159 } 160 161 public static void forceTermination(GuiConnecting gui) 162 { 163 gui.cancelled = true; 164 gui.clientHandler = null; 165 } 166}