Guest User

Untitled

a guest
Sep 12th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.58 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.io.BufferedReader;
  4. import net.minecraft.Exodus.GuiPremiumUsernameChanger;
  5. import java.io.InputStreamReader;
  6. import java.nio.charset.Charset;
  7. import java.util.ArrayList;
  8. import java.util.Calendar;
  9. import java.util.Date;
  10. import java.util.List;
  11. import java.util.Random;
  12. import net.minecraft.client.Minecraft;
  13. import org.lwjgl.opengl.GL11;
  14. import org.lwjgl.util.glu.GLU;
  15.  
  16. public class GuiMainMenu extends GuiScreen
  17. {
  18. /** The RNG used by the Main Menu Screen. */
  19. private static final Random rand = new Random();
  20.  
  21. /** Counts the number of screen updates. */
  22. private float updateCounter;
  23.  
  24. /** The splash message. */
  25. private String splashText;
  26. private GuiButton multiplayerButton;
  27.  
  28. /** Timer used to rotate the panorama, increases every tick. */
  29. private int panoramaTimer;
  30.  
  31. /**
  32. * Texture allocated for the current viewport of the main menu's panorama background.
  33. */
  34. private int viewportTexture;
  35.  
  36. public GuiMainMenu()
  37. {
  38. updateCounter = 0.0F;
  39. panoramaTimer = 0;
  40. splashText = "missingno";
  41.  
  42. try
  43. {
  44. ArrayList arraylist = new ArrayList();
  45. BufferedReader bufferedreader = new BufferedReader(new InputStreamReader((net.minecraft.src.GuiMainMenu.class).getResourceAsStream("/title/splashes.txt"), Charset.forName("UTF-8")));
  46. String s = "";
  47.  
  48. do
  49. {
  50. String s1;
  51.  
  52. if ((s1 = bufferedreader.readLine()) == null)
  53. {
  54. break;
  55. }
  56.  
  57. s1 = s1.trim();
  58.  
  59. if (s1.length() > 0)
  60. {
  61. arraylist.add(s1);
  62. }
  63. }
  64. while (true);
  65.  
  66. do
  67. {
  68. splashText = (String)arraylist.get(rand.nextInt(arraylist.size()));
  69. }
  70. while (splashText.hashCode() == 0x77f432f);
  71. }
  72. catch (Exception exception) { }
  73.  
  74. updateCounter = rand.nextFloat();
  75. }
  76.  
  77. /**
  78. * Called from the main game loop to update the screen.
  79. */
  80. public void updateScreen()
  81. {
  82. panoramaTimer++;
  83. }
  84.  
  85. /**
  86. * Returns true if this GUI should pause the game when it is displayed in single-player
  87. */
  88. public boolean doesGuiPauseGame()
  89. {
  90. return false;
  91. }
  92.  
  93. /**
  94. * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
  95. */
  96. protected void keyTyped(char c, int i)
  97. {
  98. }
  99.  
  100. /**
  101. * Adds the buttons (and other controls) to the screen in question.
  102. */
  103. public void initGui()
  104. {
  105. viewportTexture = mc.renderEngine.allocateAndSetupTexture(new java.awt.image.BufferedImage(256, 256, 2));
  106. Calendar calendar = Calendar.getInstance();
  107. calendar.setTime(new Date());
  108.  
  109. if (calendar.get(2) + 1 == 11 && calendar.get(5) == 9)
  110. {
  111. splashText = "Happy birthday, ez!";
  112. }
  113. else if (calendar.get(2) + 1 == 6 && calendar.get(5) == 1)
  114. {
  115. splashText = "Happy birthday, Notch!";
  116. }
  117. else if (calendar.get(2) + 1 == 12 && calendar.get(5) == 24)
  118. {
  119. splashText = "Merry X-mas!";
  120. }
  121. else if (calendar.get(2) + 1 == 1 && calendar.get(5) == 1)
  122. {
  123. splashText = "Happy new year!";
  124. }
  125.  
  126. StringTranslate stringtranslate = StringTranslate.getInstance();
  127. int i = height / 4 + 48;
  128. controlList.add(new GuiButton(1, width / 2 - 100, i, stringtranslate.translateKey("menu.singleplayer")));
  129. controlList.add(multiplayerButton = new GuiButton(2, width / 2 - 100, i + 24, stringtranslate.translateKey("menu.multiplayer")));
  130. controlList.add(new GuiButton(3, width / 2 - 100, i + 48, stringtranslate.translateKey("menu.mods")));
  131.  
  132. if (mc.hideQuitButton)
  133. {
  134. controlList.add(new GuiButton(0, width / 2 - 100, i + 72, stringtranslate.translateKey("menu.options")));
  135. }
  136. else
  137. {
  138. controlList.add(new GuiButton(0, width / 2 - 100, i + 72 + 12, 98, 20, stringtranslate.translateKey("menu.options")));
  139. controlList.add(new GuiButton(4, width / 2 + 2, i + 72 + 12, 98, 20, stringtranslate.translateKey("menu.quit")));
  140. }
  141.  
  142. controlList.add(new GuiButtonLanguage(5, width / 2 - 124, i + 72 + 12));
  143.  
  144. if (mc.session == null)
  145. {
  146. multiplayerButton.enabled = false;
  147. }
  148. }
  149.  
  150. /**
  151. * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
  152. */
  153. protected void actionPerformed(GuiButton par1GuiButton)
  154. {
  155. if (par1GuiButton.id == 0)
  156. {
  157. mc.displayGuiScreen(new GuiOptions(this, mc.gameSettings));
  158. }
  159.  
  160. if (par1GuiButton.id == 5)
  161. {
  162. mc.displayGuiScreen(new GuiLanguage(this, mc.gameSettings));
  163. }
  164.  
  165. if (par1GuiButton.id == 1)
  166. {
  167. mc.displayGuiScreen(new GuiSelectWorld(this));
  168. }
  169.  
  170. if (par1GuiButton.id == 2)
  171. {
  172. mc.displayGuiScreen(new GuiMultiplayer(this));
  173. }
  174.  
  175. if (par1GuiButton.id == 3)
  176. {
  177. mc.displayGuiScreen(new GuiTexturePacks(this));
  178. }
  179.  
  180. if (par1GuiButton.id == 4)
  181. {
  182. mc.shutdown();
  183. }
  184. if(GuiButton.id == 12)
  185. {
  186. mc.displayGuiScreen(new GuiPremiumUsernameChanger(mc));
  187. }
  188. }
  189.  
  190. /**
  191. * Draws the main menu panorama
  192. */
  193. private void drawPanorama(int par1, int par2, float par3)
  194. {
  195. Tessellator tessellator = Tessellator.instance;
  196. GL11.glMatrixMode(GL11.GL_PROJECTION);
  197. GL11.glPushMatrix();
  198. GL11.glLoadIdentity();
  199. GLU.gluPerspective(120F, 1.0F, 0.05F, 10F);
  200. GL11.glMatrixMode(GL11.GL_MODELVIEW);
  201. GL11.glPushMatrix();
  202. GL11.glLoadIdentity();
  203. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  204. GL11.glRotatef(180F, 1.0F, 0.0F, 0.0F);
  205. GL11.glEnable(GL11.GL_BLEND);
  206. GL11.glDisable(GL11.GL_ALPHA_TEST);
  207. GL11.glDisable(GL11.GL_CULL_FACE);
  208. GL11.glDepthMask(false);
  209. GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  210. int i = 8;
  211.  
  212. for (int j = 0; j < i * i; j++)
  213. {
  214. GL11.glPushMatrix();
  215. float f = ((float)(j % i) / (float)i - 0.5F) / 64F;
  216. float f1 = ((float)(j / i) / (float)i - 0.5F) / 64F;
  217. float f2 = 0.0F;
  218. GL11.glTranslatef(f, f1, f2);
  219. GL11.glRotatef(MathHelper.sin(((float)panoramaTimer + par3) / 400F) * 25F + 20F, 1.0F, 0.0F, 0.0F);
  220. GL11.glRotatef(-((float)panoramaTimer + par3) * 0.1F, 0.0F, 1.0F, 0.0F);
  221.  
  222. for (int k = 0; k < 6; k++)
  223. {
  224. GL11.glPushMatrix();
  225.  
  226. if (k == 1)
  227. {
  228. GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
  229. }
  230.  
  231. if (k == 2)
  232. {
  233. GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);
  234. }
  235.  
  236. if (k == 3)
  237. {
  238. GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F);
  239. }
  240.  
  241. if (k == 4)
  242. {
  243. GL11.glRotatef(90F, 1.0F, 0.0F, 0.0F);
  244. }
  245.  
  246. if (k == 5)
  247. {
  248. GL11.glRotatef(-90F, 1.0F, 0.0F, 0.0F);
  249. }
  250.  
  251. GL11.glBindTexture(GL11.GL_TEXTURE_2D, mc.renderEngine.getTexture((new StringBuilder()).append("/title/bg/panorama").append(k).append(".png").toString()));
  252. tessellator.startDrawingQuads();
  253. tessellator.setColorRGBA_I(0xffffff, 255 / (j + 1));
  254. float f3 = 0.0F;
  255. tessellator.addVertexWithUV(-1D, -1D, 1.0D, 0.0F + f3, 0.0F + f3);
  256. tessellator.addVertexWithUV(1.0D, -1D, 1.0D, 1.0F - f3, 0.0F + f3);
  257. tessellator.addVertexWithUV(1.0D, 1.0D, 1.0D, 1.0F - f3, 1.0F - f3);
  258. tessellator.addVertexWithUV(-1D, 1.0D, 1.0D, 0.0F + f3, 1.0F - f3);
  259. tessellator.draw();
  260. GL11.glPopMatrix();
  261. }
  262.  
  263. GL11.glPopMatrix();
  264. GL11.glColorMask(true, true, true, false);
  265. }
  266.  
  267. tessellator.setTranslation(0.0D, 0.0D, 0.0D);
  268. GL11.glColorMask(true, true, true, true);
  269. GL11.glMatrixMode(GL11.GL_PROJECTION);
  270. GL11.glPopMatrix();
  271. GL11.glMatrixMode(GL11.GL_MODELVIEW);
  272. GL11.glPopMatrix();
  273. GL11.glDepthMask(true);
  274. GL11.glEnable(GL11.GL_CULL_FACE);
  275. GL11.glEnable(GL11.GL_ALPHA_TEST);
  276. GL11.glEnable(GL11.GL_DEPTH_TEST);
  277. }
  278.  
  279. /**
  280. * Rotate and blurs the skybox view in the main menu
  281. */
  282. private void rotateAndBlurSkybox(float par1)
  283. {
  284. GL11.glBindTexture(GL11.GL_TEXTURE_2D, viewportTexture);
  285. GL11.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, 256, 256);
  286. GL11.glEnable(GL11.GL_BLEND);
  287. GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  288. GL11.glColorMask(true, true, true, false);
  289. Tessellator tessellator = Tessellator.instance;
  290. tessellator.startDrawingQuads();
  291. byte byte0 = 3;
  292.  
  293. for (int i = 0; i < byte0; i++)
  294. {
  295. tessellator.setColorRGBA_F(1.0F, 1.0F, 1.0F, 1.0F / (float)(i + 1));
  296. int j = width;
  297. int k = height;
  298. float f = (float)(i - byte0 / 2) / 256F;
  299. tessellator.addVertexWithUV(j, k, zLevel, 0.0F + f, 0.0D);
  300. tessellator.addVertexWithUV(j, 0.0D, zLevel, 1.0F + f, 0.0D);
  301. tessellator.addVertexWithUV(0.0D, 0.0D, zLevel, 1.0F + f, 1.0D);
  302. tessellator.addVertexWithUV(0.0D, k, zLevel, 0.0F + f, 1.0D);
  303. }
  304.  
  305. tessellator.draw();
  306. GL11.glColorMask(true, true, true, true);
  307. }
  308.  
  309. /**
  310. * Renders the skybox in the main menu
  311. */
  312. private void renderSkybox(int par1, int par2, float par3)
  313. {
  314. GL11.glViewport(0, 0, 256, 256);
  315. drawPanorama(par1, par2, par3);
  316. GL11.glDisable(GL11.GL_TEXTURE_2D);
  317. GL11.glEnable(GL11.GL_TEXTURE_2D);
  318. rotateAndBlurSkybox(par3);
  319. rotateAndBlurSkybox(par3);
  320. rotateAndBlurSkybox(par3);
  321. rotateAndBlurSkybox(par3);
  322. rotateAndBlurSkybox(par3);
  323. rotateAndBlurSkybox(par3);
  324. rotateAndBlurSkybox(par3);
  325. rotateAndBlurSkybox(par3);
  326. GL11.glViewport(0, 0, mc.displayWidth, mc.displayHeight);
  327. Tessellator tessellator = Tessellator.instance;
  328. tessellator.startDrawingQuads();
  329. float f = width <= height ? 120F / (float)height : 120F / (float)width;
  330. float f1 = ((float)height * f) / 256F;
  331. float f2 = ((float)width * f) / 256F;
  332. GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
  333. GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
  334. tessellator.setColorRGBA_F(1.0F, 1.0F, 1.0F, 1.0F);
  335. int i = width;
  336. int j = height;
  337. tessellator.addVertexWithUV(0.0D, j, zLevel, 0.5F - f1, 0.5F + f2);
  338. tessellator.addVertexWithUV(i, j, zLevel, 0.5F - f1, 0.5F - f2);
  339. tessellator.addVertexWithUV(i, 0.0D, zLevel, 0.5F + f1, 0.5F - f2);
  340. tessellator.addVertexWithUV(0.0D, 0.0D, zLevel, 0.5F + f1, 0.5F + f2);
  341. tessellator.draw();
  342. }
  343.  
  344. /**
  345. * Draws the screen and all the components in it.
  346. */
  347. public void drawScreen(int par1, int par2, float par3)
  348. {
  349. renderSkybox(par1, par2, par3);
  350. Tessellator tessellator = Tessellator.instance;
  351. char c = 274;
  352. int i = width / 2 - c / 2;
  353. byte byte0 = 30;
  354. drawGradientRect(0, 0, width, height, 0x80ffffff, 0xffffff);
  355. drawGradientRect(0, 0, width, height, 0, 0x80000000);
  356. GL11.glBindTexture(GL11.GL_TEXTURE_2D, mc.renderEngine.getTexture("/title/mclogo.png"));
  357. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  358.  
  359. if ((double)updateCounter < 0.0001D)
  360. {
  361. drawTexturedModalRect(i + 0, byte0 + 0, 0, 0, 99, 44);
  362. drawTexturedModalRect(i + 99, byte0 + 0, 129, 0, 27, 44);
  363. drawTexturedModalRect(i + 99 + 26, byte0 + 0, 126, 0, 3, 44);
  364. drawTexturedModalRect(i + 99 + 26 + 3, byte0 + 0, 99, 0, 26, 44);
  365. drawTexturedModalRect(i + 155, byte0 + 0, 0, 45, 155, 44);
  366. }
  367. else
  368. {
  369. drawTexturedModalRect(i + 0, byte0 + 0, 0, 0, 155, 44);
  370. drawTexturedModalRect(i + 155, byte0 + 0, 0, 45, 155, 44);
  371. }
  372.  
  373. tessellator.setColorOpaque_I(0xffffff);
  374. GL11.glPushMatrix();
  375. GL11.glTranslatef(width / 2 + 90, 70F, 0.0F);
  376. GL11.glRotatef(-20F, 0.0F, 0.0F, 1.0F);
  377. float f = 1.8F - MathHelper.abs(MathHelper.sin(((float)(System.currentTimeMillis() % 1000L) / 1000F) * (float)Math.PI * 2.0F) * 0.1F);
  378. f = (f * 100F) / (float)(fontRenderer.getStringWidth(splashText) + 32);
  379. GL11.glScalef(f, f, f);
  380. drawCenteredString(fontRenderer, splashText, 0, -8, 0xffff00);
  381. GL11.glPopMatrix();
  382. drawString(fontRenderer, "Minecraft 1.2.5", 2, height - 10, 0xffffff);
  383. String s = "Copyright Mojang AB. Do not distribute!";
  384. drawString(fontRenderer, s, width - fontRenderer.getStringWidth(s) - 2, height - 10, 0xffffff);
  385. super.drawScreen(par1, par2, par3);
  386. }
  387. }
Add Comment
Please, Sign In to add comment