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