001package net.minecraft.client.gui;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import java.util.ArrayList;
006import java.util.Collections;
007import java.util.List;
008import net.minecraft.client.Minecraft;
009import net.minecraft.client.mco.Location;
010import net.minecraft.util.StringTranslate;
011import org.lwjgl.input.Keyboard;
012
013@SideOnly(Side.CLIENT)
014public class GuiScreenCreateOnlineWorld extends GuiScreen
015{
016    private GuiScreen field_96260_a;
017    private GuiTextField field_96255_b;
018    private GuiTextField field_96257_c;
019    private String field_98108_c;
020    private String field_98109_n;
021    private static int field_96253_d = 0;
022    private static int field_96261_n = 1;
023    private static int field_96262_o = 2;
024    private volatile List field_96259_p;
025    private volatile Location field_96258_q = null;
026    private boolean field_96256_r = false;
027    private String field_96254_s = "You must enter a name!";
028
029    public GuiScreenCreateOnlineWorld(GuiScreen par1GuiScreen)
030    {
031        super.buttonList = Collections.synchronizedList(new ArrayList());
032        this.field_96260_a = par1GuiScreen;
033    }
034
035    /**
036     * Called from the main game loop to update the screen.
037     */
038    public void updateScreen()
039    {
040        this.field_96257_c.updateCursorCounter();
041        this.field_96255_b.updateCursorCounter();
042        this.field_98108_c = this.field_96257_c.getText();
043        this.field_98109_n = this.field_96255_b.getText();
044    }
045
046    /**
047     * Adds the buttons (and other controls) to the screen in question.
048     */
049    public void initGui()
050    {
051        StringTranslate stringtranslate = StringTranslate.getInstance();
052        Keyboard.enableRepeatEvents(true);
053        this.buttonList.clear();
054        this.buttonList.add(new GuiButton(field_96253_d, this.width / 2 - 100, this.height / 4 + 120 + 17, 97, 20, stringtranslate.translateKey("mco.create.world")));
055        this.buttonList.add(new GuiButton(field_96261_n, this.width / 2 + 5, this.height / 4 + 120 + 17, 95, 20, stringtranslate.translateKey("gui.cancel")));
056        this.field_96257_c = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 55, 200, 20);
057        this.field_96257_c.setFocused(true);
058
059        if (this.field_98108_c != null)
060        {
061            this.field_96257_c.setText(this.field_98108_c);
062        }
063
064        this.field_96255_b = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 95, 200, 20);
065        this.field_96255_b.setMaxStringLength(128);
066
067        if (this.field_98109_n != null)
068        {
069            this.field_96255_b.setText(this.field_98109_n);
070        }
071
072        this.func_96250_g();
073    }
074
075    private void func_96250_g()
076    {
077        if (this.field_96258_q == null)
078        {
079            (new ThreadCreateOnlineWorldScreen(this)).start();
080        }
081        else
082        {
083            this.buttonList.add(new GuiButton(field_96262_o, this.width / 2 - 100, 135, this.field_96258_q.field_96395_b));
084        }
085    }
086
087    /**
088     * Called when the screen is unloaded. Used to disable keyboard repeat events
089     */
090    public void onGuiClosed()
091    {
092        Keyboard.enableRepeatEvents(false);
093    }
094
095    /**
096     * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
097     */
098    protected void actionPerformed(GuiButton par1GuiButton)
099    {
100        if (par1GuiButton.enabled)
101        {
102            if (par1GuiButton.id == field_96261_n)
103            {
104                this.mc.displayGuiScreen(this.field_96260_a);
105            }
106            else if (par1GuiButton.id == field_96253_d)
107            {
108                this.func_96252_h();
109            }
110            else if (par1GuiButton.id == field_96262_o)
111            {
112                GuiScreenSelectLocation guiscreenselectlocation = new GuiScreenSelectLocation(this, this.field_96259_p, this.field_96258_q, this.field_96257_c.getText(), this.field_96255_b.getText());
113                this.mc.displayGuiScreen(guiscreenselectlocation);
114            }
115        }
116    }
117
118    private void func_96252_h()
119    {
120        if (this.func_96249_i())
121        {
122            String s = this.field_96255_b.getText() != null && !this.field_96255_b.getText().trim().equals("") ? this.field_96255_b.getText() : "Minecraft Realms Server";
123            TaskWorldCreation taskworldcreation = new TaskWorldCreation(this, this.field_96257_c.getText(), s, this.field_96258_q == null ? "NO_LOCATION" : this.field_96258_q.field_96396_a);
124            GuiScreenLongRunningTask guiscreenlongrunningtask = new GuiScreenLongRunningTask(this.mc, this.field_96260_a, taskworldcreation);
125            guiscreenlongrunningtask.func_98117_g();
126            this.mc.displayGuiScreen(guiscreenlongrunningtask);
127        }
128    }
129
130    private boolean func_96249_i()
131    {
132        this.field_96256_r = this.field_96257_c.getText() == null || this.field_96257_c.getText().trim().equals("");
133        return !this.field_96256_r;
134    }
135
136    /**
137     * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
138     */
139    protected void keyTyped(char par1, int par2)
140    {
141        this.field_96257_c.textboxKeyTyped(par1, par2);
142        this.field_96255_b.textboxKeyTyped(par1, par2);
143
144        if (par1 == 9)
145        {
146            if (this.field_96257_c.isFocused())
147            {
148                this.field_96257_c.setFocused(false);
149                this.field_96255_b.setFocused(true);
150            }
151            else
152            {
153                this.field_96257_c.setFocused(true);
154                this.field_96255_b.setFocused(false);
155            }
156        }
157
158        if (par1 == 13)
159        {
160            this.actionPerformed((GuiButton)this.buttonList.get(0));
161        }
162    }
163
164    /**
165     * Called when the mouse is clicked.
166     */
167    protected void mouseClicked(int par1, int par2, int par3)
168    {
169        super.mouseClicked(par1, par2, par3);
170        this.field_96255_b.mouseClicked(par1, par2, par3);
171        this.field_96257_c.mouseClicked(par1, par2, par3);
172    }
173
174    /**
175     * Draws the screen and all the components in it.
176     */
177    public void drawScreen(int par1, int par2, float par3)
178    {
179        StringTranslate stringtranslate = StringTranslate.getInstance();
180        this.drawDefaultBackground();
181        this.drawCenteredString(this.fontRenderer, stringtranslate.translateKey("mco.selectServer.create"), this.width / 2, 11, 16777215);
182        this.drawString(this.fontRenderer, stringtranslate.translateKey("mco.configure.world.name"), this.width / 2 - 100, 42, 10526880);
183        this.drawString(this.fontRenderer, stringtranslate.translateKey("mco.configure.world.description"), this.width / 2 - 100, 83, 10526880);
184
185        if (this.field_96258_q != null)
186        {
187            this.drawString(this.fontRenderer, stringtranslate.translateKey("mco.configure.world.location"), this.width / 2 - 100, 124, 10526880);
188        }
189
190        if (this.field_96256_r)
191        {
192            this.drawCenteredString(this.fontRenderer, this.field_96254_s, this.width / 2, 167, 16711680);
193        }
194
195        this.field_96257_c.drawTextBox();
196        this.field_96255_b.drawTextBox();
197        super.drawScreen(par1, par2, par3);
198    }
199
200    public void func_96251_a(Location par1Location, String par2Str, String par3Str)
201    {
202        this.field_96258_q = par1Location;
203        this.field_96257_c.setText(par2Str);
204        this.field_96255_b.setText(par3Str);
205    }
206
207    static Minecraft func_96248_a(GuiScreenCreateOnlineWorld par0GuiScreenCreateOnlineWorld)
208    {
209        return par0GuiScreenCreateOnlineWorld.mc;
210    }
211
212    static List func_98102_a(GuiScreenCreateOnlineWorld par0GuiScreenCreateOnlineWorld, List par1List)
213    {
214        return par0GuiScreenCreateOnlineWorld.field_96259_p = par1List;
215    }
216
217    static Location func_98100_a(GuiScreenCreateOnlineWorld par0GuiScreenCreateOnlineWorld, Location par1Location)
218    {
219        return par0GuiScreenCreateOnlineWorld.field_96258_q = par1Location;
220    }
221
222    static int func_98106_g()
223    {
224        return field_96262_o;
225    }
226
227    static Location func_98101_b(GuiScreenCreateOnlineWorld par0GuiScreenCreateOnlineWorld)
228    {
229        return par0GuiScreenCreateOnlineWorld.field_96258_q;
230    }
231
232    static List func_98103_c(GuiScreenCreateOnlineWorld par0GuiScreenCreateOnlineWorld)
233    {
234        return par0GuiScreenCreateOnlineWorld.buttonList;
235    }
236
237    static Minecraft func_98099_d(GuiScreenCreateOnlineWorld par0GuiScreenCreateOnlineWorld)
238    {
239        return par0GuiScreenCreateOnlineWorld.mc;
240    }
241
242    static GuiScreen func_96247_b(GuiScreenCreateOnlineWorld par0GuiScreenCreateOnlineWorld)
243    {
244        return par0GuiScreenCreateOnlineWorld.field_96260_a;
245    }
246
247    static Minecraft func_96246_c(GuiScreenCreateOnlineWorld par0GuiScreenCreateOnlineWorld)
248    {
249        return par0GuiScreenCreateOnlineWorld.mc;
250    }
251}