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