001package net.minecraft.client.gui;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import java.io.IOException;
006import net.minecraft.client.mco.ExceptionMcoService;
007import net.minecraft.client.mco.McoClient;
008import net.minecraft.client.mco.McoServer;
009import net.minecraft.util.StringTranslate;
010import org.lwjgl.input.Keyboard;
011
012@SideOnly(Side.CLIENT)
013public class GuiScreenInvite extends GuiScreen
014{
015    private GuiTextField field_96227_a;
016    private McoServer field_96223_b;
017    private final GuiScreen field_96224_c;
018    private final GuiScreen field_96222_d;
019    private final int field_96228_n = 0;
020    private final int field_96229_o = 1;
021    private String field_96226_p = "Could not invite the provided name";
022    private boolean field_96225_q = false;
023
024    public GuiScreenInvite(GuiScreen par1GuiScreen, GuiScreen par2GuiScreen, McoServer par3McoServer)
025    {
026        this.field_96224_c = par1GuiScreen;
027        this.field_96222_d = par2GuiScreen;
028        this.field_96223_b = par3McoServer;
029    }
030
031    /**
032     * Called from the main game loop to update the screen.
033     */
034    public void updateScreen()
035    {
036        this.field_96227_a.updateCursorCounter();
037    }
038
039    /**
040     * Adds the buttons (and other controls) to the screen in question.
041     */
042    public void initGui()
043    {
044        StringTranslate stringtranslate = StringTranslate.getInstance();
045        Keyboard.enableRepeatEvents(true);
046        this.buttonList.clear();
047        this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, stringtranslate.translateKey("mco.configure.world.buttons.invite")));
048        this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12, stringtranslate.translateKey("gui.cancel")));
049        this.field_96227_a = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 66, 200, 20);
050        this.field_96227_a.setFocused(true);
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.mc.displayGuiScreen(this.field_96222_d);
071            }
072            else if (par1GuiButton.id == 0)
073            {
074                McoClient mcoclient = new McoClient(this.mc.session);
075
076                try
077                {
078                    McoServer mcoserver = mcoclient.func_96387_b(this.field_96223_b.field_96408_a, this.field_96227_a.getText());
079
080                    if (mcoserver != null)
081                    {
082                        this.field_96223_b.field_96402_f = mcoserver.field_96402_f;
083                        this.mc.displayGuiScreen(new GuiScreenConfigureWorld(this.field_96224_c, this.field_96223_b));
084                    }
085                    else
086                    {
087                        this.func_96221_a();
088                    }
089                }
090                catch (ExceptionMcoService exceptionmcoservice)
091                {
092                    this.func_96221_a();
093                }
094                catch (IOException ioexception)
095                {
096                    this.func_96221_a();
097                }
098            }
099        }
100    }
101
102    private void func_96221_a()
103    {
104        this.field_96225_q = true;
105    }
106
107    /**
108     * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
109     */
110    protected void keyTyped(char par1, int par2)
111    {
112        this.field_96227_a.textboxKeyTyped(par1, par2);
113
114        if (par1 == 9)
115        {
116            if (this.field_96227_a.isFocused())
117            {
118                this.field_96227_a.setFocused(false);
119            }
120            else
121            {
122                this.field_96227_a.setFocused(true);
123            }
124        }
125
126        if (par1 == 13)
127        {
128            this.actionPerformed((GuiButton)this.buttonList.get(0));
129        }
130    }
131
132    /**
133     * Called when the mouse is clicked.
134     */
135    protected void mouseClicked(int par1, int par2, int par3)
136    {
137        super.mouseClicked(par1, par2, par3);
138        this.field_96227_a.mouseClicked(par1, par2, par3);
139    }
140
141    /**
142     * Draws the screen and all the components in it.
143     */
144    public void drawScreen(int par1, int par2, float par3)
145    {
146        StringTranslate stringtranslate = StringTranslate.getInstance();
147        this.drawDefaultBackground();
148        this.drawCenteredString(this.fontRenderer, stringtranslate.translateKey(""), this.width / 2, 17, 16777215);
149        this.drawString(this.fontRenderer, stringtranslate.translateKey("mco.configure.world.invite.profile.name"), this.width / 2 - 100, 53, 10526880);
150
151        if (this.field_96225_q)
152        {
153            this.drawCenteredString(this.fontRenderer, this.field_96226_p, this.width / 2, 100, 16711680);
154        }
155
156        this.field_96227_a.drawTextBox();
157        super.drawScreen(par1, par2, par3);
158    }
159}