    001    package net.minecraft.client.texturepacks;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.io.File;
    006    import java.io.IOException;
    007    import java.net.URI;
    008    import net.minecraft.client.Minecraft;
    009    import net.minecraft.client.gui.FontRenderer;
    010    import net.minecraft.client.gui.GuiButton;
    011    import net.minecraft.client.gui.GuiScreen;
    012    import net.minecraft.client.gui.GuiSmallButton;
    013    import net.minecraft.util.EnumOS;
    014    import net.minecraft.util.StringTranslate;
    015    import org.lwjgl.Sys;
    016
    017    @SideOnly(Side.CLIENT)
    018    public class GuiTexturePacks extends GuiScreen
    019    {
    020        protected GuiScreen guiScreen;
    021        private int refreshTimer = -1;
    022
    023        /** the absolute location of this texture pack */
    024        private String fileLocation = "";
    025
    026        /**
    027         * the GuiTexturePackSlot that contains all the texture packs and their descriptions
    028         */
    029        private GuiTexturePackSlot guiTexturePackSlot;
    030
    031        public GuiTexturePacks(GuiScreen par1GuiScreen)
    032        {
    033            this.guiScreen = par1GuiScreen;
    034        }
    035
    036        /**
    037         * Adds the buttons (and other controls) to the screen in question.
    038         */
    039        public void initGui()
    040        {
    041            StringTranslate var1 = StringTranslate.getInstance();
    042            this.controlList.add(new GuiSmallButton(5, this.width / 2 - 154, this.height - 48, var1.translateKey("texturePack.openFolder")));
    043            this.controlList.add(new GuiSmallButton(6, this.width / 2 + 4, this.height - 48, var1.translateKey("gui.done")));
    044            this.mc.texturePackList.updateAvaliableTexturePacks();
    045            this.fileLocation = (new File(Minecraft.getMinecraftDir(), "texturepacks")).getAbsolutePath();
    046            this.guiTexturePackSlot = new GuiTexturePackSlot(this);
    047            this.guiTexturePackSlot.registerScrollButtons(this.controlList, 7, 8);
    048        }
    049
    050        /**
    051         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    052         */
    053        protected void actionPerformed(GuiButton par1GuiButton)
    054        {
    055            if (par1GuiButton.enabled)
    056            {
    057                if (par1GuiButton.id == 5)
    058                {
    059                    if (Minecraft.getOs() == EnumOS.MACOS)
    060                    {
    061                        try
    062                        {
    063                            System.out.println(this.fileLocation);
    064                            Runtime.getRuntime().exec(new String[] {"/usr/bin/open", this.fileLocation});
    065                            return;
    066                        }
    067                        catch (IOException var7)
    068                        {
    069                            var7.printStackTrace();
    070                        }
    071                    }
    072                    else if (Minecraft.getOs() == EnumOS.WINDOWS)
    073                    {
    074                        String var2 = String.format("cmd.exe /C start \"Open file\" \"%s\"", new Object[] {this.fileLocation});
    075
    076                        try
    077                        {
    078                            Runtime.getRuntime().exec(var2);
    079                            return;
    080                        }
    081                        catch (IOException var6)
    082                        {
    083                            var6.printStackTrace();
    084                        }
    085                    }
    086
    087                    boolean var8 = false;
    088
    089                    try
    090                    {
    091                        Class var3 = Class.forName("java.awt.Desktop");
    092                        Object var4 = var3.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
    093                        var3.getMethod("browse", new Class[] {URI.class}).invoke(var4, new Object[] {(new File(Minecraft.getMinecraftDir(), "texturepacks")).toURI()});
    094                    }
    095                    catch (Throwable var5)
    096                    {
    097                        var5.printStackTrace();
    098                        var8 = true;
    099                    }
    100
    101                    if (var8)
    102                    {
    103                        System.out.println("Opening via system class!");
    104                        Sys.openURL("file://" + this.fileLocation);
    105                    }
    106                }
    107                else if (par1GuiButton.id == 6)
    108                {
    109                    this.mc.renderEngine.refreshTextures();
    110                    this.mc.displayGuiScreen(this.guiScreen);
    111                }
    112                else
    113                {
    114                    this.guiTexturePackSlot.actionPerformed(par1GuiButton);
    115                }
    116            }
    117        }
    118
    119        /**
    120         * Called when the mouse is clicked.
    121         */
    122        protected void mouseClicked(int par1, int par2, int par3)
    123        {
    124            super.mouseClicked(par1, par2, par3);
    125        }
    126
    127        /**
    128         * Called when the mouse is moved or a mouse button is released.  Signature: (mouseX, mouseY, which) which==-1 is
    129         * mouseMove, which==0 or which==1 is mouseUp
    130         */
    131        protected void mouseMovedOrUp(int par1, int par2, int par3)
    132        {
    133            super.mouseMovedOrUp(par1, par2, par3);
    134        }
    135
    136        /**
    137         * Draws the screen and all the components in it.
    138         */
    139        public void drawScreen(int par1, int par2, float par3)
    140        {
    141            this.guiTexturePackSlot.drawScreen(par1, par2, par3);
    142
    143            if (this.refreshTimer <= 0)
    144            {
    145                this.mc.texturePackList.updateAvaliableTexturePacks();
    146                this.refreshTimer += 20;
    147            }
    148
    149            StringTranslate var4 = StringTranslate.getInstance();
    150            this.drawCenteredString(this.fontRenderer, var4.translateKey("texturePack.title"), this.width / 2, 16, 16777215);
    151            this.drawCenteredString(this.fontRenderer, var4.translateKey("texturePack.folderInfo"), this.width / 2 - 77, this.height - 26, 8421504);
    152            super.drawScreen(par1, par2, par3);
    153        }
    154
    155        /**
    156         * Called from the main game loop to update the screen.
    157         */
    158        public void updateScreen()
    159        {
    160            super.updateScreen();
    161            --this.refreshTimer;
    162        }
    163
    164        static Minecraft func_73950_a(GuiTexturePacks par0GuiTexturePacks)
    165        {
    166            return par0GuiTexturePacks.mc;
    167        }
    168
    169        static Minecraft func_73955_b(GuiTexturePacks par0GuiTexturePacks)
    170        {
    171            return par0GuiTexturePacks.mc;
    172        }
    173
    174        static Minecraft func_73958_c(GuiTexturePacks par0GuiTexturePacks)
    175        {
    176            return par0GuiTexturePacks.mc;
    177        }
    178
    179        static Minecraft func_73951_d(GuiTexturePacks par0GuiTexturePacks)
    180        {
    181            return par0GuiTexturePacks.mc;
    182        }
    183
    184        static Minecraft func_73952_e(GuiTexturePacks par0GuiTexturePacks)
    185        {
    186            return par0GuiTexturePacks.mc;
    187        }
    188
    189        static Minecraft func_73962_f(GuiTexturePacks par0GuiTexturePacks)
    190        {
    191            return par0GuiTexturePacks.mc;
    192        }
    193
    194        static Minecraft func_73959_g(GuiTexturePacks par0GuiTexturePacks)
    195        {
    196            return par0GuiTexturePacks.mc;
    197        }
    198
    199        static Minecraft func_73957_h(GuiTexturePacks par0GuiTexturePacks)
    200        {
    201            return par0GuiTexturePacks.mc;
    202        }
    203
    204        static Minecraft func_73956_i(GuiTexturePacks par0GuiTexturePacks)
    205        {
    206            return par0GuiTexturePacks.mc;
    207        }
    208
    209        static Minecraft func_73953_j(GuiTexturePacks par0GuiTexturePacks)
    210        {
    211            return par0GuiTexturePacks.mc;
    212        }
    213
    214        static Minecraft func_73961_k(GuiTexturePacks par0GuiTexturePacks)
    215        {
    216            return par0GuiTexturePacks.mc;
    217        }
    218
    219        static FontRenderer func_73960_l(GuiTexturePacks par0GuiTexturePacks)
    220        {
    221            return par0GuiTexturePacks.fontRenderer;
    222        }
    223
    224        static FontRenderer func_73963_m(GuiTexturePacks par0GuiTexturePacks)
    225        {
    226            return par0GuiTexturePacks.fontRenderer;
    227        }
    228
    229        static FontRenderer func_73954_n(GuiTexturePacks par0GuiTexturePacks)
    230        {
    231            return par0GuiTexturePacks.fontRenderer;
    232        }
    233    }