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