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.Minecraft;
007import net.minecraft.client.mco.ExceptionMcoService;
008import net.minecraft.client.mco.McoClient;
009import net.minecraft.client.mco.McoServer;
010import net.minecraft.util.StringTranslate;
011import org.lwjgl.input.Keyboard;
012
013@SideOnly(Side.CLIENT)
014public class GuiScreenConfigureWorld extends GuiScreen
015{
016    private final GuiScreen field_96285_a;
017    private McoServer field_96280_b;
018    private SelectionListInvited field_96282_c;
019    private int field_96277_d;
020    private int field_96286_n;
021    private int field_96287_o;
022    private int field_96284_p = -1;
023    private String field_96283_q;
024    private GuiButton field_96281_r;
025    private GuiButton field_96279_s;
026    private GuiButton field_96278_t;
027    private GuiButton field_96276_u;
028    private GuiButton field_98128_v;
029    private GuiButton field_98127_w;
030    private GuiButton field_98129_x;
031
032    public GuiScreenConfigureWorld(GuiScreen par1, McoServer par2)
033    {
034        this.field_96285_a = par1;
035        this.field_96280_b = par2;
036    }
037
038    /**
039     * Called from the main game loop to update the screen.
040     */
041    public void updateScreen() {}
042
043    /**
044     * Adds the buttons (and other controls) to the screen in question.
045     */
046    public void initGui()
047    {
048        StringTranslate stringtranslate = StringTranslate.getInstance();
049        this.field_96277_d = this.width / 2 - 200;
050        this.field_96286_n = 180;
051        this.field_96287_o = this.width / 2;
052        Keyboard.enableRepeatEvents(true);
053        this.buttonList.clear();
054
055        if (this.field_96280_b.field_96404_d.equals("CLOSED"))
056        {
057            this.buttonList.add(this.field_96281_r = new GuiButton(0, this.field_96277_d, this.func_96264_a(12), this.field_96286_n / 2 - 2, 20, stringtranslate.translateKey("mco.configure.world.buttons.open")));
058            this.field_96281_r.enabled = !this.field_96280_b.field_98166_h;
059        }
060        else
061        {
062            this.buttonList.add(this.field_96279_s = new GuiButton(1, this.field_96277_d, this.func_96264_a(12), this.field_96286_n / 2 - 2, 20, stringtranslate.translateKey("mco.configure.world.buttons.close")));
063            this.field_96279_s.enabled = !this.field_96280_b.field_98166_h;
064        }
065
066        this.buttonList.add(this.field_98129_x = new GuiButton(7, this.field_96277_d + this.field_96286_n / 2 + 2, this.func_96264_a(12), this.field_96286_n / 2 - 2, 20, stringtranslate.translateKey("mco.configure.world.buttons.subscription")));
067        this.buttonList.add(this.field_96278_t = new GuiButton(5, this.field_96277_d, this.func_96264_a(10), this.field_96286_n / 2 - 2, 20, stringtranslate.translateKey("mco.configure.world.buttons.edit")));
068        this.buttonList.add(this.field_96276_u = new GuiButton(6, this.field_96277_d + this.field_96286_n / 2 + 2, this.func_96264_a(10), this.field_96286_n / 2 - 2, 20, stringtranslate.translateKey("mco.configure.world.buttons.reset")));
069        this.buttonList.add(this.field_98128_v = new GuiButton(4, this.field_96287_o, this.func_96264_a(10), this.field_96286_n / 2 - 2, 20, stringtranslate.translateKey("mco.configure.world.buttons.invite")));
070        this.buttonList.add(this.field_98127_w = new GuiButton(3, this.field_96287_o + this.field_96286_n / 2 + 2, this.func_96264_a(10), this.field_96286_n / 2 - 2, 20, stringtranslate.translateKey("mco.configure.world.buttons.uninvite")));
071        this.buttonList.add(new GuiButton(10, this.field_96287_o, this.func_96264_a(12), this.field_96286_n, 20, stringtranslate.translateKey("gui.back")));
072        this.field_96282_c = new SelectionListInvited(this);
073        this.field_96278_t.enabled = !this.field_96280_b.field_98166_h;
074        this.field_96276_u.enabled = !this.field_96280_b.field_98166_h;
075        this.field_98128_v.enabled = !this.field_96280_b.field_98166_h;
076        this.field_98127_w.enabled = !this.field_96280_b.field_98166_h;
077    }
078
079    private int func_96264_a(int par1)
080    {
081        return 40 + par1 * 13;
082    }
083
084    /**
085     * Called when the screen is unloaded. Used to disable keyboard repeat events
086     */
087    public void onGuiClosed()
088    {
089        Keyboard.enableRepeatEvents(false);
090    }
091
092    /**
093     * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
094     */
095    protected void actionPerformed(GuiButton par1GuiButton)
096    {
097        if (par1GuiButton.enabled)
098        {
099            if (par1GuiButton.id == 10)
100            {
101                this.mc.displayGuiScreen(this.field_96285_a);
102            }
103            else if (par1GuiButton.id == 5)
104            {
105                this.mc.displayGuiScreen(new GuiScreenEditOnlineWorld(this, this.field_96285_a, this.field_96280_b));
106            }
107            else if (par1GuiButton.id == 1)
108            {
109                StringTranslate stringtranslate = StringTranslate.getInstance();
110                String s = stringtranslate.translateKey("mco.configure.world.close.question.line1");
111                String s1 = stringtranslate.translateKey("mco.configure.world.close.question.line2");
112                this.mc.displayGuiScreen(new GuiScreenConfirmation(this, "Warning!", s, s1, 1));
113            }
114            else if (par1GuiButton.id == 0)
115            {
116                this.func_96268_g();
117            }
118            else if (par1GuiButton.id == 4)
119            {
120                this.mc.displayGuiScreen(new GuiScreenInvite(this.field_96285_a, this, this.field_96280_b));
121            }
122            else if (par1GuiButton.id == 3)
123            {
124                this.func_96272_i();
125            }
126            else if (par1GuiButton.id == 6)
127            {
128                this.mc.displayGuiScreen(new GuiScreenResetWorld(this, this.field_96280_b));
129            }
130            else if (par1GuiButton.id == 7)
131            {
132                this.mc.displayGuiScreen(new GuiScreenSubscription(this, this.field_96280_b));
133            }
134        }
135    }
136
137    private void func_96268_g()
138    {
139        McoClient mcoclient = new McoClient(this.mc.session);
140
141        try
142        {
143            Boolean obool = mcoclient.func_96383_b(this.field_96280_b.field_96408_a);
144
145            if (obool.booleanValue())
146            {
147                this.field_96280_b.field_96404_d = "OPEN";
148                this.initGui();
149            }
150        }
151        catch (ExceptionMcoService exceptionmcoservice)
152        {
153            ;
154        }
155        catch (IOException ioexception)
156        {
157            ;
158        }
159    }
160
161    private void func_96275_h()
162    {
163        McoClient mcoclient = new McoClient(this.mc.session);
164
165        try
166        {
167            boolean flag = mcoclient.func_96378_c(this.field_96280_b.field_96408_a).booleanValue();
168
169            if (flag)
170            {
171                this.field_96280_b.field_96404_d = "CLOSED";
172                this.initGui();
173            }
174        }
175        catch (ExceptionMcoService exceptionmcoservice)
176        {
177            ;
178        }
179        catch (IOException ioexception)
180        {
181            ;
182        }
183    }
184
185    private void func_96272_i()
186    {
187        if (this.field_96284_p >= 0 && this.field_96284_p < this.field_96280_b.field_96402_f.size())
188        {
189            this.field_96283_q = (String)this.field_96280_b.field_96402_f.get(this.field_96284_p);
190            StringTranslate stringtranslate = StringTranslate.getInstance();
191            GuiYesNo guiyesno = new GuiYesNo(this, "Warning!", stringtranslate.translateKey("mco.configure.world.uninvite.question") + " \'" + this.field_96283_q + "\'", 3);
192            this.mc.displayGuiScreen(guiyesno);
193        }
194    }
195
196    public void confirmClicked(boolean par1, int par2)
197    {
198        if (par2 == 3)
199        {
200            if (par1)
201            {
202                McoClient mcoclient = new McoClient(this.mc.session);
203
204                try
205                {
206                    mcoclient.func_96381_a(this.field_96280_b.field_96408_a, this.field_96283_q);
207                }
208                catch (ExceptionMcoService exceptionmcoservice)
209                {
210                    System.err.println("Could not uninvite the selected user");
211                }
212
213                this.func_96267_d(this.field_96284_p);
214            }
215
216            this.mc.displayGuiScreen(new GuiScreenConfigureWorld(this.field_96285_a, this.field_96280_b));
217        }
218
219        if (par2 == 1)
220        {
221            if (par1)
222            {
223                this.func_96275_h();
224            }
225
226            this.mc.displayGuiScreen(this);
227        }
228    }
229
230    private void func_96267_d(int par1)
231    {
232        this.field_96280_b.field_96402_f.remove(par1);
233    }
234
235    /**
236     * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
237     */
238    protected void keyTyped(char par1, int par2) {}
239
240    /**
241     * Called when the mouse is clicked.
242     */
243    protected void mouseClicked(int par1, int par2, int par3)
244    {
245        super.mouseClicked(par1, par2, par3);
246    }
247
248    /**
249     * Draws the screen and all the components in it.
250     */
251    public void drawScreen(int par1, int par2, float par3)
252    {
253        StringTranslate stringtranslate = StringTranslate.getInstance();
254        this.drawDefaultBackground();
255        this.field_96282_c.func_96612_a(par1, par2, par3);
256        this.drawCenteredString(this.fontRenderer, stringtranslate.translateKey("mco.configure.world.title"), this.width / 2, 17, 16777215);
257        this.drawString(this.fontRenderer, stringtranslate.translateKey("mco.configure.world.name"), this.field_96277_d, this.func_96264_a(1), 10526880);
258        this.drawString(this.fontRenderer, this.field_96280_b.func_96398_b(), this.field_96277_d, this.func_96264_a(2), 16777215);
259        this.drawString(this.fontRenderer, stringtranslate.translateKey("mco.configure.world.description"), this.field_96277_d, this.func_96264_a(4), 10526880);
260        this.drawString(this.fontRenderer, this.field_96280_b.func_96397_a(), this.field_96277_d, this.func_96264_a(5), 16777215);
261        this.drawString(this.fontRenderer, stringtranslate.translateKey("mco.configure.world.invited"), this.field_96287_o, this.func_96264_a(1), 10526880);
262        super.drawScreen(par1, par2, par3);
263    }
264
265    static Minecraft func_96265_a(GuiScreenConfigureWorld par0GuiScreenConfigureWorld)
266    {
267        return par0GuiScreenConfigureWorld.mc;
268    }
269
270    static int func_96271_b(GuiScreenConfigureWorld par0GuiScreenConfigureWorld)
271    {
272        return par0GuiScreenConfigureWorld.field_96287_o;
273    }
274
275    static int func_96274_a(GuiScreenConfigureWorld par0GuiScreenConfigureWorld, int par1)
276    {
277        return par0GuiScreenConfigureWorld.func_96264_a(par1);
278    }
279
280    static int func_96269_c(GuiScreenConfigureWorld par0GuiScreenConfigureWorld)
281    {
282        return par0GuiScreenConfigureWorld.field_96286_n;
283    }
284
285    static McoServer func_96266_d(GuiScreenConfigureWorld par0GuiScreenConfigureWorld)
286    {
287        return par0GuiScreenConfigureWorld.field_96280_b;
288    }
289
290    static int func_96270_b(GuiScreenConfigureWorld par0GuiScreenConfigureWorld, int par1)
291    {
292        return par0GuiScreenConfigureWorld.field_96284_p = par1;
293    }
294
295    static int func_96263_e(GuiScreenConfigureWorld par0GuiScreenConfigureWorld)
296    {
297        return par0GuiScreenConfigureWorld.field_96284_p;
298    }
299
300    static FontRenderer func_96273_f(GuiScreenConfigureWorld par0GuiScreenConfigureWorld)
301    {
302        return par0GuiScreenConfigureWorld.fontRenderer;
303    }
304}