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_101016_p = "Could not invite the provided name";
022    private String field_96226_p;
023    private boolean field_96225_q = false;
024
025    public GuiScreenInvite(GuiScreen par1GuiScreen, GuiScreen par2GuiScreen, McoServer par3McoServer)
026    {
027        this.field_96224_c = par1GuiScreen;
028        this.field_96222_d = par2GuiScreen;
029        this.field_96223_b = par3McoServer;
030    }
031
032    /**
033     * Called from the main game loop to update the screen.
034     */
035    public void updateScreen()
036    {
037        this.field_96227_a.updateCursorCounter();
038    }
039
040    /**
041     * Adds the buttons (and other controls) to the screen in question.
042     */
043    public void initGui()
044    {
045        StringTranslate stringtranslate = StringTranslate.getInstance();
046        Keyboard.enableRepeatEvents(true);
047        this.buttonList.clear();
048        this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, stringtranslate.translateKey("mco.configure.world.buttons.invite")));
049        this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12, stringtranslate.translateKey("gui.cancel")));
050        this.field_96227_a = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 66, 200, 20);
051        this.field_96227_a.setFocused(true);
052    }
053
054    /**
055     * Called when the screen is unloaded. Used to disable keyboard repeat events
056     */
057    public void onGuiClosed()
058    {
059        Keyboard.enableRepeatEvents(false);
060    }
061
062    /**
063     * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
064     */
065    protected void actionPerformed(GuiButton par1GuiButton)
066    {
067        if (par1GuiButton.enabled)
068        {
069            if (par1GuiButton.id == 1)
070            {
071                this.mc.displayGuiScreen(this.field_96222_d);
072            }
073            else if (par1GuiButton.id == 0)
074            {
075                McoClient mcoclient = new McoClient(this.mc.session);
076
077                try
078                {
079                    McoServer mcoserver = mcoclient.func_96387_b(this.field_96223_b.field_96408_a, this.field_96227_a.getText());
080
081                    if (mcoserver != null)
082                    {
083                        this.field_96223_b.field_96402_f = mcoserver.field_96402_f;
084                        this.mc.displayGuiScreen(new GuiScreenConfigureWorld(this.field_96224_c, this.field_96223_b));
085                    }
086                    else
087                    {
088                        this.func_101015_a(this.field_101016_p);
089                    }
090                }
091                catch (ExceptionMcoService exceptionmcoservice)
092                {
093                    this.func_101015_a(exceptionmcoservice.field_96391_b);
094                }
095                catch (IOException ioexception)
096                {
097                    this.func_101015_a(this.field_101016_p);
098                }
099            }
100        }
101    }
102
103    private void func_101015_a(String par1Str)
104    {
105        this.field_96225_q = true;
106        this.field_96226_p = par1Str;
107    }
108
109    /**
110     * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
111     */
112    protected void keyTyped(char par1, int par2)
113    {
114        this.field_96227_a.textboxKeyTyped(par1, par2);
115
116        if (par1 == 9)
117        {
118            if (this.field_96227_a.isFocused())
119            {
120                this.field_96227_a.setFocused(false);
121            }
122            else
123            {
124                this.field_96227_a.setFocused(true);
125            }
126        }
127
128        if (par1 == 13)
129        {
130            this.actionPerformed((GuiButton)this.buttonList.get(0));
131        }
132    }
133
134    /**
135     * Called when the mouse is clicked.
136     */
137    protected void mouseClicked(int par1, int par2, int par3)
138    {
139        super.mouseClicked(par1, par2, par3);
140        this.field_96227_a.mouseClicked(par1, par2, par3);
141    }
142
143    /**
144     * Draws the screen and all the components in it.
145     */
146    public void drawScreen(int par1, int par2, float par3)
147    {
148        StringTranslate stringtranslate = StringTranslate.getInstance();
149        this.drawDefaultBackground();
150        this.drawCenteredString(this.fontRenderer, stringtranslate.translateKey(""), this.width / 2, 17, 16777215);
151        this.drawString(this.fontRenderer, stringtranslate.translateKey("mco.configure.world.invite.profile.name"), this.width / 2 - 100, 53, 10526880);
152
153        if (this.field_96225_q)
154        {
155            this.drawCenteredString(this.fontRenderer, this.field_96226_p, this.width / 2, 100, 16711680);
156        }
157
158        this.field_96227_a.drawTextBox();
159        super.drawScreen(par1, par2, par3);
160    }
161}