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