001    package net.minecraft.client.gui;
002    
003    import cpw.mods.fml.client.GuiModList;
004    import cpw.mods.fml.common.FMLCommonHandler;
005    import cpw.mods.fml.relauncher.Side;
006    import cpw.mods.fml.relauncher.SideOnly;
007    import java.awt.image.BufferedImage;
008    import java.io.BufferedReader;
009    import java.io.IOException;
010    import java.io.InputStreamReader;
011    import java.net.URI;
012    import java.nio.charset.Charset;
013    import java.util.ArrayList;
014    import java.util.Calendar;
015    import java.util.Date;
016    import java.util.List;
017    import java.util.Random;
018    import net.minecraft.client.Minecraft;
019    import net.minecraft.client.renderer.Tessellator;
020    import net.minecraft.client.texturepacks.GuiTexturePacks;
021    import net.minecraft.util.MathHelper;
022    import net.minecraft.util.StringTranslate;
023    import net.minecraft.world.demo.DemoWorldServer;
024    import net.minecraft.world.storage.ISaveFormat;
025    import net.minecraft.world.storage.WorldInfo;
026    import org.lwjgl.opengl.GL11;
027    import org.lwjgl.util.glu.GLU;
028    
029    import com.google.common.base.Strings;
030    import com.google.common.collect.Lists;
031    
032    @SideOnly(Side.CLIENT)
033    public class GuiMainMenu extends GuiScreen
034    {
035        /** The RNG used by the Main Menu Screen. */
036        private static final Random rand = new Random();
037    
038        /** Counts the number of screen updates. */
039        private float updateCounter = 0.0F;
040    
041        /** The splash message. */
042        private String splashText = "missingno";
043        private GuiButton buttonResetDemo;
044    
045        /** Timer used to rotate the panorama, increases every tick. */
046        private int panoramaTimer = 0;
047    
048        /**
049         * Texture allocated for the current viewport of the main menu's panorama background.
050         */
051        private int viewportTexture;
052        private String field_92025_p;
053    
054        /** An array of all the paths to the panorama pictures. */
055        private static final String[] titlePanoramaPaths = new String[] {"/title/bg/panorama0.png", "/title/bg/panorama1.png", "/title/bg/panorama2.png", "/title/bg/panorama3.png", "/title/bg/panorama4.png", "/title/bg/panorama5.png"};
056        private int field_92024_r;
057        private int field_92023_s;
058        private int field_92022_t;
059        private int field_92021_u;
060        private int field_92020_v;
061        private int field_92019_w;
062    
063        public GuiMainMenu()
064        {
065            BufferedReader var1 = null;
066    
067            try
068            {
069                ArrayList var2 = new ArrayList();
070                var1 = new BufferedReader(new InputStreamReader(GuiMainMenu.class.getResourceAsStream("/title/splashes.txt"), Charset.forName("UTF-8")));
071                String var3;
072    
073                while ((var3 = var1.readLine()) != null)
074                {
075                    var3 = var3.trim();
076    
077                    if (var3.length() > 0)
078                    {
079                        var2.add(var3);
080                    }
081                }
082    
083                do
084                {
085                    this.splashText = (String)var2.get(rand.nextInt(var2.size()));
086                }
087                while (this.splashText.hashCode() == 125780783);
088            }
089            catch (IOException var12)
090            {
091                ;
092            }
093            finally
094            {
095                if (var1 != null)
096                {
097                    try
098                    {
099                        var1.close();
100                    }
101                    catch (IOException var11)
102                    {
103                        ;
104                    }
105                }
106            }
107    
108            this.updateCounter = rand.nextFloat();
109        }
110    
111        /**
112         * Called from the main game loop to update the screen.
113         */
114        public void updateScreen()
115        {
116            ++this.panoramaTimer;
117        }
118    
119        /**
120         * Returns true if this GUI should pause the game when it is displayed in single-player
121         */
122        public boolean doesGuiPauseGame()
123        {
124            return false;
125        }
126    
127        /**
128         * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
129         */
130        protected void keyTyped(char par1, int par2) {}
131    
132        /**
133         * Adds the buttons (and other controls) to the screen in question.
134         */
135        public void initGui()
136        {
137            this.viewportTexture = this.mc.renderEngine.allocateAndSetupTexture(new BufferedImage(256, 256, 2));
138            Calendar var1 = Calendar.getInstance();
139            var1.setTime(new Date());
140    
141            if (var1.get(2) + 1 == 11 && var1.get(5) == 9)
142            {
143                this.splashText = "Happy birthday, ez!";
144            }
145            else if (var1.get(2) + 1 == 6 && var1.get(5) == 1)
146            {
147                this.splashText = "Happy birthday, Notch!";
148            }
149            else if (var1.get(2) + 1 == 12 && var1.get(5) == 24)
150            {
151                this.splashText = "Merry X-mas!";
152            }
153            else if (var1.get(2) + 1 == 1 && var1.get(5) == 1)
154            {
155                this.splashText = "Happy new year!";
156            }
157            else if (var1.get(2) + 1 == 10 && var1.get(5) == 31)
158            {
159                this.splashText = "OOoooOOOoooo! Spooky!";
160            }
161    
162            StringTranslate var2 = StringTranslate.getInstance();
163            int var4 = this.height / 4 + 48;
164    
165            if (this.mc.isDemo())
166            {
167                this.addDemoButtons(var4, 24, var2);
168            }
169            else
170            {
171                this.addSingleplayerMultiplayerButtons(var4, 24, var2);
172            }
173    
174            this.controlList.add(new GuiButton(3, this.width / 2 - 100, var4 + 48, 98, 20, var2.translateKey("menu.mods")));
175            this.controlList.add(new GuiButton(6, this.width / 2 + 2, var4 + 48, 98, 20, "Mods"));
176    
177            if (this.mc.hideQuitButton)
178            {
179                this.controlList.add(new GuiButton(0, this.width / 2 - 100, var4 + 72, var2.translateKey("menu.options")));
180            }
181            else
182            {
183                this.controlList.add(new GuiButton(0, this.width / 2 - 100, var4 + 72 + 12, 98, 20, var2.translateKey("menu.options")));
184                this.controlList.add(new GuiButton(4, this.width / 2 + 2, var4 + 72 + 12, 98, 20, var2.translateKey("menu.quit")));
185            }
186    
187            this.controlList.add(new GuiButtonLanguage(5, this.width / 2 - 124, var4 + 72 + 12));
188            this.field_92025_p = "";
189            String var5 = System.getProperty("os_architecture");
190            String var6 = System.getProperty("java_version");
191    
192            if ("ppc".equalsIgnoreCase(var5))
193            {
194                this.field_92025_p = "\u00a7lNotice!\u00a7r PowerPC compatibility will be dropped in Minecraft 1.6";
195            }
196            else if (var6 != null && var6.startsWith("1.5"))
197            {
198                this.field_92025_p = "\u00a7lNotice!\u00a7r Java 1.5 compatibility will be dropped in Minecraft 1.6";
199            }
200    
201            this.field_92023_s = this.fontRenderer.getStringWidth(this.field_92025_p);
202            this.field_92024_r = this.fontRenderer.getStringWidth("Please click \u00a7nhere\u00a7r for more information.");
203            int var7 = Math.max(this.field_92023_s, this.field_92024_r);
204            this.field_92022_t = (this.width - var7) / 2;
205            this.field_92021_u = ((GuiButton)this.controlList.get(0)).yPosition - 24;
206            this.field_92020_v = this.field_92022_t + var7;
207            this.field_92019_w = this.field_92021_u + 24;
208        }
209    
210        /**
211         * Adds Singleplayer and Multiplayer buttons on Main Menu for players who have bought the game.
212         */
213        private void addSingleplayerMultiplayerButtons(int par1, int par2, StringTranslate par3StringTranslate)
214        {
215            this.controlList.add(new GuiButton(1, this.width / 2 - 100, par1, par3StringTranslate.translateKey("menu.singleplayer")));
216            this.controlList.add(new GuiButton(2, this.width / 2 - 100, par1 + par2 * 1, par3StringTranslate.translateKey("menu.multiplayer")));
217        }
218    
219        /**
220         * Adds Demo buttons on Main Menu for players who are playing Demo.
221         */
222        private void addDemoButtons(int par1, int par2, StringTranslate par3StringTranslate)
223        {
224            this.controlList.add(new GuiButton(11, this.width / 2 - 100, par1, par3StringTranslate.translateKey("menu.playdemo")));
225            this.controlList.add(this.buttonResetDemo = new GuiButton(12, this.width / 2 - 100, par1 + par2 * 1, par3StringTranslate.translateKey("menu.resetdemo")));
226            ISaveFormat var4 = this.mc.getSaveLoader();
227            WorldInfo var5 = var4.getWorldInfo("Demo_World");
228    
229            if (var5 == null)
230            {
231                this.buttonResetDemo.enabled = false;
232            }
233        }
234    
235        /**
236         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
237         */
238        protected void actionPerformed(GuiButton par1GuiButton)
239        {
240            if (par1GuiButton.id == 0)
241            {
242                this.mc.displayGuiScreen(new GuiOptions(this, this.mc.gameSettings));
243            }
244    
245            if (par1GuiButton.id == 5)
246            {
247                this.mc.displayGuiScreen(new GuiLanguage(this, this.mc.gameSettings));
248            }
249    
250            if (par1GuiButton.id == 1)
251            {
252                this.mc.displayGuiScreen(new GuiSelectWorld(this));
253            }
254    
255            if (par1GuiButton.id == 2)
256            {
257                this.mc.displayGuiScreen(new GuiMultiplayer(this));
258            }
259    
260            if (par1GuiButton.id == 3)
261            {
262                this.mc.displayGuiScreen(new GuiTexturePacks(this));
263            }
264    
265            if (par1GuiButton.id == 4)
266            {
267                this.mc.shutdown();
268            }
269    
270            if (par1GuiButton.id == 6)
271            {
272                this.mc.displayGuiScreen(new GuiModList(this));
273            }
274    
275            if (par1GuiButton.id == 11)
276            {
277                this.mc.launchIntegratedServer("Demo_World", "Demo_World", DemoWorldServer.demoWorldSettings);
278            }
279    
280            if (par1GuiButton.id == 12)
281            {
282                ISaveFormat var2 = this.mc.getSaveLoader();
283                WorldInfo var3 = var2.getWorldInfo("Demo_World");
284    
285                if (var3 != null)
286                {
287                    GuiYesNo var4 = GuiSelectWorld.getDeleteWorldScreen(this, var3.getWorldName(), 12);
288                    this.mc.displayGuiScreen(var4);
289                }
290            }
291        }
292    
293        public void confirmClicked(boolean par1, int par2)
294        {
295            if (par1 && par2 == 12)
296            {
297                ISaveFormat var6 = this.mc.getSaveLoader();
298                var6.flushCache();
299                var6.deleteWorldDirectory("Demo_World");
300                this.mc.displayGuiScreen(this);
301            }
302            else if (par2 == 13)
303            {
304                if (par1)
305                {
306                    try
307                    {
308                        Class var3 = Class.forName("java.awt.Desktop");
309                        Object var4 = var3.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
310                        var3.getMethod("browse", new Class[] {URI.class}).invoke(var4, new Object[] {new URI("http://tinyurl.com/javappc")});
311                    }
312                    catch (Throwable var5)
313                    {
314                        var5.printStackTrace();
315                    }
316                }
317    
318                this.mc.displayGuiScreen(this);
319            }
320        }
321    
322        /**
323         * Draws the main menu panorama
324         */
325        private void drawPanorama(int par1, int par2, float par3)
326        {
327            Tessellator var4 = Tessellator.instance;
328            GL11.glMatrixMode(GL11.GL_PROJECTION);
329            GL11.glPushMatrix();
330            GL11.glLoadIdentity();
331            GLU.gluPerspective(120.0F, 1.0F, 0.05F, 10.0F);
332            GL11.glMatrixMode(GL11.GL_MODELVIEW);
333            GL11.glPushMatrix();
334            GL11.glLoadIdentity();
335            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
336            GL11.glRotatef(180.0F, 1.0F, 0.0F, 0.0F);
337            GL11.glEnable(GL11.GL_BLEND);
338            GL11.glDisable(GL11.GL_ALPHA_TEST);
339            GL11.glDisable(GL11.GL_CULL_FACE);
340            GL11.glDepthMask(false);
341            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
342            byte var5 = 8;
343    
344            for (int var6 = 0; var6 < var5 * var5; ++var6)
345            {
346                GL11.glPushMatrix();
347                float var7 = ((float)(var6 % var5) / (float)var5 - 0.5F) / 64.0F;
348                float var8 = ((float)(var6 / var5) / (float)var5 - 0.5F) / 64.0F;
349                float var9 = 0.0F;
350                GL11.glTranslatef(var7, var8, var9);
351                GL11.glRotatef(MathHelper.sin(((float)this.panoramaTimer + par3) / 400.0F) * 25.0F + 20.0F, 1.0F, 0.0F, 0.0F);
352                GL11.glRotatef(-((float)this.panoramaTimer + par3) * 0.1F, 0.0F, 1.0F, 0.0F);
353    
354                for (int var10 = 0; var10 < 6; ++var10)
355                {
356                    GL11.glPushMatrix();
357    
358                    if (var10 == 1)
359                    {
360                        GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
361                    }
362    
363                    if (var10 == 2)
364                    {
365                        GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
366                    }
367    
368                    if (var10 == 3)
369                    {
370                        GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
371                    }
372    
373                    if (var10 == 4)
374                    {
375                        GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
376                    }
377    
378                    if (var10 == 5)
379                    {
380                        GL11.glRotatef(-90.0F, 1.0F, 0.0F, 0.0F);
381                    }
382    
383                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture(titlePanoramaPaths[var10]));
384                    var4.startDrawingQuads();
385                    var4.setColorRGBA_I(16777215, 255 / (var6 + 1));
386                    float var11 = 0.0F;
387                    var4.addVertexWithUV(-1.0D, -1.0D, 1.0D, (double)(0.0F + var11), (double)(0.0F + var11));
388                    var4.addVertexWithUV(1.0D, -1.0D, 1.0D, (double)(1.0F - var11), (double)(0.0F + var11));
389                    var4.addVertexWithUV(1.0D, 1.0D, 1.0D, (double)(1.0F - var11), (double)(1.0F - var11));
390                    var4.addVertexWithUV(-1.0D, 1.0D, 1.0D, (double)(0.0F + var11), (double)(1.0F - var11));
391                    var4.draw();
392                    GL11.glPopMatrix();
393                }
394    
395                GL11.glPopMatrix();
396                GL11.glColorMask(true, true, true, false);
397            }
398    
399            var4.setTranslation(0.0D, 0.0D, 0.0D);
400            GL11.glColorMask(true, true, true, true);
401            GL11.glMatrixMode(GL11.GL_PROJECTION);
402            GL11.glPopMatrix();
403            GL11.glMatrixMode(GL11.GL_MODELVIEW);
404            GL11.glPopMatrix();
405            GL11.glDepthMask(true);
406            GL11.glEnable(GL11.GL_CULL_FACE);
407            GL11.glEnable(GL11.GL_ALPHA_TEST);
408            GL11.glEnable(GL11.GL_DEPTH_TEST);
409        }
410    
411        /**
412         * Rotate and blurs the skybox view in the main menu
413         */
414        private void rotateAndBlurSkybox(float par1)
415        {
416            GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.viewportTexture);
417            GL11.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, 256, 256);
418            GL11.glEnable(GL11.GL_BLEND);
419            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
420            GL11.glColorMask(true, true, true, false);
421            Tessellator var2 = Tessellator.instance;
422            var2.startDrawingQuads();
423            byte var3 = 3;
424    
425            for (int var4 = 0; var4 < var3; ++var4)
426            {
427                var2.setColorRGBA_F(1.0F, 1.0F, 1.0F, 1.0F / (float)(var4 + 1));
428                int var5 = this.width;
429                int var6 = this.height;
430                float var7 = (float)(var4 - var3 / 2) / 256.0F;
431                var2.addVertexWithUV((double)var5, (double)var6, (double)this.zLevel, (double)(0.0F + var7), 0.0D);
432                var2.addVertexWithUV((double)var5, 0.0D, (double)this.zLevel, (double)(1.0F + var7), 0.0D);
433                var2.addVertexWithUV(0.0D, 0.0D, (double)this.zLevel, (double)(1.0F + var7), 1.0D);
434                var2.addVertexWithUV(0.0D, (double)var6, (double)this.zLevel, (double)(0.0F + var7), 1.0D);
435            }
436    
437            var2.draw();
438            GL11.glColorMask(true, true, true, true);
439        }
440    
441        /**
442         * Renders the skybox in the main menu
443         */
444        private void renderSkybox(int par1, int par2, float par3)
445        {
446            GL11.glViewport(0, 0, 256, 256);
447            this.drawPanorama(par1, par2, par3);
448            GL11.glDisable(GL11.GL_TEXTURE_2D);
449            GL11.glEnable(GL11.GL_TEXTURE_2D);
450            this.rotateAndBlurSkybox(par3);
451            this.rotateAndBlurSkybox(par3);
452            this.rotateAndBlurSkybox(par3);
453            this.rotateAndBlurSkybox(par3);
454            this.rotateAndBlurSkybox(par3);
455            this.rotateAndBlurSkybox(par3);
456            this.rotateAndBlurSkybox(par3);
457            this.rotateAndBlurSkybox(par3);
458            GL11.glViewport(0, 0, this.mc.displayWidth, this.mc.displayHeight);
459            Tessellator var4 = Tessellator.instance;
460            var4.startDrawingQuads();
461            float var5 = this.width > this.height ? 120.0F / (float)this.width : 120.0F / (float)this.height;
462            float var6 = (float)this.height * var5 / 256.0F;
463            float var7 = (float)this.width * var5 / 256.0F;
464            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
465            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
466            var4.setColorRGBA_F(1.0F, 1.0F, 1.0F, 1.0F);
467            int var8 = this.width;
468            int var9 = this.height;
469            var4.addVertexWithUV(0.0D, (double)var9, (double)this.zLevel, (double)(0.5F - var6), (double)(0.5F + var7));
470            var4.addVertexWithUV((double)var8, (double)var9, (double)this.zLevel, (double)(0.5F - var6), (double)(0.5F - var7));
471            var4.addVertexWithUV((double)var8, 0.0D, (double)this.zLevel, (double)(0.5F + var6), (double)(0.5F - var7));
472            var4.addVertexWithUV(0.0D, 0.0D, (double)this.zLevel, (double)(0.5F + var6), (double)(0.5F + var7));
473            var4.draw();
474        }
475    
476        /**
477         * Draws the screen and all the components in it.
478         */
479        public void drawScreen(int par1, int par2, float par3)
480        {
481            this.renderSkybox(par1, par2, par3);
482            Tessellator var4 = Tessellator.instance;
483            short var5 = 274;
484            int var6 = this.width / 2 - var5 / 2;
485            byte var7 = 30;
486            this.drawGradientRect(0, 0, this.width, this.height, -2130706433, 16777215);
487            this.drawGradientRect(0, 0, this.width, this.height, 0, Integer.MIN_VALUE);
488            GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/title/mclogo.png"));
489            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
490    
491            if ((double)this.updateCounter < 1.0E-4D)
492            {
493                this.drawTexturedModalRect(var6 + 0, var7 + 0, 0, 0, 99, 44);
494                this.drawTexturedModalRect(var6 + 99, var7 + 0, 129, 0, 27, 44);
495                this.drawTexturedModalRect(var6 + 99 + 26, var7 + 0, 126, 0, 3, 44);
496                this.drawTexturedModalRect(var6 + 99 + 26 + 3, var7 + 0, 99, 0, 26, 44);
497                this.drawTexturedModalRect(var6 + 155, var7 + 0, 0, 45, 155, 44);
498            }
499            else
500            {
501                this.drawTexturedModalRect(var6 + 0, var7 + 0, 0, 0, 155, 44);
502                this.drawTexturedModalRect(var6 + 155, var7 + 0, 0, 45, 155, 44);
503            }
504    
505            var4.setColorOpaque_I(16777215);
506            GL11.glPushMatrix();
507            GL11.glTranslatef((float)(this.width / 2 + 90), 70.0F, 0.0F);
508            GL11.glRotatef(-20.0F, 0.0F, 0.0F, 1.0F);
509            float var8 = 1.8F - MathHelper.abs(MathHelper.sin((float)(Minecraft.getSystemTime() % 1000L) / 1000.0F * (float)Math.PI * 2.0F) * 0.1F);
510            var8 = var8 * 100.0F / (float)(this.fontRenderer.getStringWidth(this.splashText) + 32);
511            GL11.glScalef(var8, var8, var8);
512            this.drawCenteredString(this.fontRenderer, this.splashText, 0, -8, 16776960);
513            GL11.glPopMatrix();
514            String var9 = "Minecraft 1.4.7";
515    
516            if (this.mc.isDemo())
517            {
518                var9 = var9 + " Demo";
519            }
520    
521            List<String> brandings = Lists.reverse(FMLCommonHandler.instance().getBrandings());
522            for (int i = 0; i < brandings.size(); i++)
523            {
524                String brd = brandings.get(i);
525                if (!Strings.isNullOrEmpty(brd))
526                {
527                    this.drawString(this.fontRenderer, brd, 2, this.height - ( 10 + i * (this.fontRenderer.FONT_HEIGHT + 1)), 16777215);
528                }
529            }
530    
531            String var10 = "Copyright Mojang AB. Do not distribute!";
532            this.drawString(this.fontRenderer, var10, this.width - this.fontRenderer.getStringWidth(var10) - 2, this.height - 10, 16777215);
533    
534            if (this.field_92025_p != null && this.field_92025_p.length() > 0)
535            {
536                drawRect(this.field_92022_t - 2, this.field_92021_u - 2, this.field_92020_v + 2, this.field_92019_w - 1, 1428160512);
537                this.drawString(this.fontRenderer, this.field_92025_p, this.field_92022_t, this.field_92021_u, 16777215);
538                this.drawString(this.fontRenderer, "Please click \u00a7nhere\u00a7r for more information.", (this.width - this.field_92024_r) / 2, ((GuiButton)this.controlList.get(0)).yPosition - 12, 16777215);
539            }
540    
541            super.drawScreen(par1, par2, par3);
542        }
543    
544        /**
545         * Called when the mouse is clicked.
546         */
547        protected void mouseClicked(int par1, int par2, int par3)
548        {
549            super.mouseClicked(par1, par2, par3);
550    
551            if (this.field_92025_p.length() > 0 && par1 >= this.field_92022_t && par1 <= this.field_92020_v && par2 >= this.field_92021_u && par2 <= this.field_92019_w)
552            {
553                GuiConfirmOpenLink var4 = new GuiConfirmOpenLink(this, "http://tinyurl.com/javappc", 13);
554                var4.func_92026_h();
555                this.mc.displayGuiScreen(var4);
556            }
557        }
558    }