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