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