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 else if (var1.get(2) + 1 == 10 && var1.get(5) == 31) 144 { 145 this.splashText = "OOoooOOOoooo! Spooky!"; 146 } 147 148 StringTranslate var2 = StringTranslate.getInstance(); 149 int var4 = this.height / 4 + 48; 150 151 if (this.mc.isDemo()) 152 { 153 this.addDemoButtons(var4, 24, var2); 154 } 155 else 156 { 157 this.addSingleplayerMultiplayerButtons(var4, 24, var2); 158 } 159 160 this.controlList.add(new GuiButton(3, this.width / 2 - 100, var4 + 48, 98, 20, var2.translateKey("menu.mods"))); 161 this.controlList.add(new GuiButton(6, this.width / 2 + 2, var4 + 48, 98, 20, "Mods")); 162 163 if (this.mc.hideQuitButton) 164 { 165 this.controlList.add(new GuiButton(0, this.width / 2 - 100, var4 + 72, var2.translateKey("menu.options"))); 166 } 167 else 168 { 169 this.controlList.add(new GuiButton(0, this.width / 2 - 100, var4 + 72 + 12, 98, 20, var2.translateKey("menu.options"))); 170 this.controlList.add(new GuiButton(4, this.width / 2 + 2, var4 + 72 + 12, 98, 20, var2.translateKey("menu.quit"))); 171 } 172 173 this.controlList.add(new GuiButtonLanguage(5, this.width / 2 - 124, var4 + 72 + 12)); 174 } 175 176 /** 177 * Adds Singleplayer and Multiplayer buttons on Main Menu for players who have bought the game. 178 */ 179 private void addSingleplayerMultiplayerButtons(int par1, int par2, StringTranslate par3StringTranslate) 180 { 181 this.controlList.add(new GuiButton(1, this.width / 2 - 100, par1, par3StringTranslate.translateKey("menu.singleplayer"))); 182 this.controlList.add(new GuiButton(2, this.width / 2 - 100, par1 + par2 * 1, par3StringTranslate.translateKey("menu.multiplayer"))); 183 } 184 185 /** 186 * Adds Demo buttons on Main Menu for players who are playing Demo. 187 */ 188 private void addDemoButtons(int par1, int par2, StringTranslate par3StringTranslate) 189 { 190 this.controlList.add(new GuiButton(11, this.width / 2 - 100, par1, par3StringTranslate.translateKey("menu.playdemo"))); 191 this.controlList.add(this.buttonResetDemo = new GuiButton(12, this.width / 2 - 100, par1 + par2 * 1, par3StringTranslate.translateKey("menu.resetdemo"))); 192 ISaveFormat var4 = this.mc.getSaveLoader(); 193 WorldInfo var5 = var4.getWorldInfo("Demo_World"); 194 195 if (var5 == null) 196 { 197 this.buttonResetDemo.enabled = false; 198 } 199 } 200 201 /** 202 * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e). 203 */ 204 protected void actionPerformed(GuiButton par1GuiButton) 205 { 206 if (par1GuiButton.id == 0) 207 { 208 this.mc.displayGuiScreen(new GuiOptions(this, this.mc.gameSettings)); 209 } 210 211 if (par1GuiButton.id == 5) 212 { 213 this.mc.displayGuiScreen(new GuiLanguage(this, this.mc.gameSettings)); 214 } 215 216 if (par1GuiButton.id == 1) 217 { 218 this.mc.displayGuiScreen(new GuiSelectWorld(this)); 219 } 220 221 if (par1GuiButton.id == 2) 222 { 223 this.mc.displayGuiScreen(new GuiMultiplayer(this)); 224 } 225 226 if (par1GuiButton.id == 3) 227 { 228 this.mc.displayGuiScreen(new GuiTexturePacks(this)); 229 } 230 231 if (par1GuiButton.id == 4) 232 { 233 this.mc.shutdown(); 234 } 235 236 if (par1GuiButton.id == 6) 237 { 238 this.mc.displayGuiScreen(new GuiModList(this)); 239 } 240 241 if (par1GuiButton.id == 11) 242 { 243 this.mc.launchIntegratedServer("Demo_World", "Demo_World", DemoWorldServer.demoWorldSettings); 244 } 245 246 if (par1GuiButton.id == 12) 247 { 248 ISaveFormat var2 = this.mc.getSaveLoader(); 249 WorldInfo var3 = var2.getWorldInfo("Demo_World"); 250 251 if (var3 != null) 252 { 253 GuiYesNo var4 = GuiSelectWorld.getDeleteWorldScreen(this, var3.getWorldName(), 12); 254 this.mc.displayGuiScreen(var4); 255 } 256 } 257 } 258 259 public void confirmClicked(boolean par1, int par2) 260 { 261 if (par1 && par2 == 12) 262 { 263 ISaveFormat var3 = this.mc.getSaveLoader(); 264 var3.flushCache(); 265 var3.deleteWorldDirectory("Demo_World"); 266 this.mc.displayGuiScreen(this); 267 } 268 } 269 270 /** 271 * Draws the main menu panorama 272 */ 273 private void drawPanorama(int par1, int par2, float par3) 274 { 275 Tessellator var4 = Tessellator.instance; 276 GL11.glMatrixMode(GL11.GL_PROJECTION); 277 GL11.glPushMatrix(); 278 GL11.glLoadIdentity(); 279 GLU.gluPerspective(120.0F, 1.0F, 0.05F, 10.0F); 280 GL11.glMatrixMode(GL11.GL_MODELVIEW); 281 GL11.glPushMatrix(); 282 GL11.glLoadIdentity(); 283 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); 284 GL11.glRotatef(180.0F, 1.0F, 0.0F, 0.0F); 285 GL11.glEnable(GL11.GL_BLEND); 286 GL11.glDisable(GL11.GL_ALPHA_TEST); 287 GL11.glDisable(GL11.GL_CULL_FACE); 288 GL11.glDepthMask(false); 289 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); 290 byte var5 = 8; 291 292 for (int var6 = 0; var6 < var5 * var5; ++var6) 293 { 294 GL11.glPushMatrix(); 295 float var7 = ((float)(var6 % var5) / (float)var5 - 0.5F) / 64.0F; 296 float var8 = ((float)(var6 / var5) / (float)var5 - 0.5F) / 64.0F; 297 float var9 = 0.0F; 298 GL11.glTranslatef(var7, var8, var9); 299 GL11.glRotatef(MathHelper.sin(((float)this.panoramaTimer + par3) / 400.0F) * 25.0F + 20.0F, 1.0F, 0.0F, 0.0F); 300 GL11.glRotatef(-((float)this.panoramaTimer + par3) * 0.1F, 0.0F, 1.0F, 0.0F); 301 302 for (int var10 = 0; var10 < 6; ++var10) 303 { 304 GL11.glPushMatrix(); 305 306 if (var10 == 1) 307 { 308 GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); 309 } 310 311 if (var10 == 2) 312 { 313 GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F); 314 } 315 316 if (var10 == 3) 317 { 318 GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); 319 } 320 321 if (var10 == 4) 322 { 323 GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F); 324 } 325 326 if (var10 == 5) 327 { 328 GL11.glRotatef(-90.0F, 1.0F, 0.0F, 0.0F); 329 } 330 331 GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture(titlePanoramaPaths[var10])); 332 var4.startDrawingQuads(); 333 var4.setColorRGBA_I(16777215, 255 / (var6 + 1)); 334 float var11 = 0.0F; 335 var4.addVertexWithUV(-1.0D, -1.0D, 1.0D, (double)(0.0F + var11), (double)(0.0F + var11)); 336 var4.addVertexWithUV(1.0D, -1.0D, 1.0D, (double)(1.0F - var11), (double)(0.0F + var11)); 337 var4.addVertexWithUV(1.0D, 1.0D, 1.0D, (double)(1.0F - var11), (double)(1.0F - var11)); 338 var4.addVertexWithUV(-1.0D, 1.0D, 1.0D, (double)(0.0F + var11), (double)(1.0F - var11)); 339 var4.draw(); 340 GL11.glPopMatrix(); 341 } 342 343 GL11.glPopMatrix(); 344 GL11.glColorMask(true, true, true, false); 345 } 346 347 var4.setTranslation(0.0D, 0.0D, 0.0D); 348 GL11.glColorMask(true, true, true, true); 349 GL11.glMatrixMode(GL11.GL_PROJECTION); 350 GL11.glPopMatrix(); 351 GL11.glMatrixMode(GL11.GL_MODELVIEW); 352 GL11.glPopMatrix(); 353 GL11.glDepthMask(true); 354 GL11.glEnable(GL11.GL_CULL_FACE); 355 GL11.glEnable(GL11.GL_ALPHA_TEST); 356 GL11.glEnable(GL11.GL_DEPTH_TEST); 357 } 358 359 /** 360 * Rotate and blurs the skybox view in the main menu 361 */ 362 private void rotateAndBlurSkybox(float par1) 363 { 364 GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.viewportTexture); 365 GL11.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, 256, 256); 366 GL11.glEnable(GL11.GL_BLEND); 367 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); 368 GL11.glColorMask(true, true, true, false); 369 Tessellator var2 = Tessellator.instance; 370 var2.startDrawingQuads(); 371 byte var3 = 3; 372 373 for (int var4 = 0; var4 < var3; ++var4) 374 { 375 var2.setColorRGBA_F(1.0F, 1.0F, 1.0F, 1.0F / (float)(var4 + 1)); 376 int var5 = this.width; 377 int var6 = this.height; 378 float var7 = (float)(var4 - var3 / 2) / 256.0F; 379 var2.addVertexWithUV((double)var5, (double)var6, (double)this.zLevel, (double)(0.0F + var7), 0.0D); 380 var2.addVertexWithUV((double)var5, 0.0D, (double)this.zLevel, (double)(1.0F + var7), 0.0D); 381 var2.addVertexWithUV(0.0D, 0.0D, (double)this.zLevel, (double)(1.0F + var7), 1.0D); 382 var2.addVertexWithUV(0.0D, (double)var6, (double)this.zLevel, (double)(0.0F + var7), 1.0D); 383 } 384 385 var2.draw(); 386 GL11.glColorMask(true, true, true, true); 387 } 388 389 /** 390 * Renders the skybox in the main menu 391 */ 392 private void renderSkybox(int par1, int par2, float par3) 393 { 394 GL11.glViewport(0, 0, 256, 256); 395 this.drawPanorama(par1, par2, par3); 396 GL11.glDisable(GL11.GL_TEXTURE_2D); 397 GL11.glEnable(GL11.GL_TEXTURE_2D); 398 this.rotateAndBlurSkybox(par3); 399 this.rotateAndBlurSkybox(par3); 400 this.rotateAndBlurSkybox(par3); 401 this.rotateAndBlurSkybox(par3); 402 this.rotateAndBlurSkybox(par3); 403 this.rotateAndBlurSkybox(par3); 404 this.rotateAndBlurSkybox(par3); 405 this.rotateAndBlurSkybox(par3); 406 GL11.glViewport(0, 0, this.mc.displayWidth, this.mc.displayHeight); 407 Tessellator var4 = Tessellator.instance; 408 var4.startDrawingQuads(); 409 float var5 = this.width > this.height ? 120.0F / (float)this.width : 120.0F / (float)this.height; 410 float var6 = (float)this.height * var5 / 256.0F; 411 float var7 = (float)this.width * var5 / 256.0F; 412 GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); 413 GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); 414 var4.setColorRGBA_F(1.0F, 1.0F, 1.0F, 1.0F); 415 int var8 = this.width; 416 int var9 = this.height; 417 var4.addVertexWithUV(0.0D, (double)var9, (double)this.zLevel, (double)(0.5F - var6), (double)(0.5F + var7)); 418 var4.addVertexWithUV((double)var8, (double)var9, (double)this.zLevel, (double)(0.5F - var6), (double)(0.5F - var7)); 419 var4.addVertexWithUV((double)var8, 0.0D, (double)this.zLevel, (double)(0.5F + var6), (double)(0.5F - var7)); 420 var4.addVertexWithUV(0.0D, 0.0D, (double)this.zLevel, (double)(0.5F + var6), (double)(0.5F + var7)); 421 var4.draw(); 422 } 423 424 /** 425 * Draws the screen and all the components in it. 426 */ 427 public void drawScreen(int par1, int par2, float par3) 428 { 429 this.renderSkybox(par1, par2, par3); 430 Tessellator var4 = Tessellator.instance; 431 short var5 = 274; 432 int var6 = this.width / 2 - var5 / 2; 433 byte var7 = 30; 434 this.drawGradientRect(0, 0, this.width, this.height, -2130706433, 16777215); 435 this.drawGradientRect(0, 0, this.width, this.height, 0, Integer.MIN_VALUE); 436 GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/title/mclogo.png")); 437 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); 438 439 if ((double)this.updateCounter < 1.0E-4D) 440 { 441 this.drawTexturedModalRect(var6 + 0, var7 + 0, 0, 0, 99, 44); 442 this.drawTexturedModalRect(var6 + 99, var7 + 0, 129, 0, 27, 44); 443 this.drawTexturedModalRect(var6 + 99 + 26, var7 + 0, 126, 0, 3, 44); 444 this.drawTexturedModalRect(var6 + 99 + 26 + 3, var7 + 0, 99, 0, 26, 44); 445 this.drawTexturedModalRect(var6 + 155, var7 + 0, 0, 45, 155, 44); 446 } 447 else 448 { 449 this.drawTexturedModalRect(var6 + 0, var7 + 0, 0, 0, 155, 44); 450 this.drawTexturedModalRect(var6 + 155, var7 + 0, 0, 45, 155, 44); 451 } 452 453 var4.setColorOpaque_I(16777215); 454 GL11.glPushMatrix(); 455 GL11.glTranslatef((float)(this.width / 2 + 90), 70.0F, 0.0F); 456 GL11.glRotatef(-20.0F, 0.0F, 0.0F, 1.0F); 457 float var8 = 1.8F - MathHelper.abs(MathHelper.sin((float)(Minecraft.getSystemTime() % 1000L) / 1000.0F * (float)Math.PI * 2.0F) * 0.1F); 458 var8 = var8 * 100.0F / (float)(this.fontRenderer.getStringWidth(this.splashText) + 32); 459 GL11.glScalef(var8, var8, var8); 460 this.drawCenteredString(this.fontRenderer, this.splashText, 0, -8, 16776960); 461 GL11.glPopMatrix(); 462 String var9 = "Minecraft 1.4.1"; 463 464 if (this.mc.isDemo()) 465 { 466 var9 = var9 + " Demo"; 467 } 468 469 List<String> brandings=Lists.reverse(FMLCommonHandler.instance().getBrandings()); 470 for (int i=0; i<brandings.size(); i++) { 471 String brd = brandings.get(i); 472 if (!Strings.isNullOrEmpty(brd)) 473 { 474 this.drawString(this.fontRenderer, brd, 2, this.height - ( 10 + i * (this.fontRenderer.FONT_HEIGHT + 1)), 16777215); 475 } 476 } 477 String var10 = "Copyright Mojang AB. Do not distribute!"; 478 this.drawString(this.fontRenderer, var10, this.width - this.fontRenderer.getStringWidth(var10) - 2, this.height - 10, 16777215); 479 super.drawScreen(par1, par2, par3); 480 } 481 }