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