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