Advertisement
Guest User

GuiMainMenu

a guest
Nov 12th, 2017
2,771
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.minecraft.client.gui;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.net.URI;
  7. import java.net.URL;
  8. import java.util.ArrayList;
  9. import java.util.Calendar;
  10. import java.util.Date;
  11. import java.util.Random;
  12. import net.minecraft.client.Minecraft;
  13. import net.minecraft.client.multiplayer.GuiConnecting;
  14. import net.minecraft.client.multiplayer.ServerData;
  15. import net.minecraft.client.renderer.OpenGlHelper;
  16. import net.minecraft.client.renderer.Tessellator;
  17. import net.minecraft.client.renderer.texture.DynamicTexture;
  18. import net.minecraft.client.resources.I18n;
  19. import net.minecraft.realms.RealmsBridge;
  20. import net.minecraft.util.EnumChatFormatting;
  21. import net.minecraft.util.MathHelper;
  22. import net.minecraft.util.ResourceLocation;
  23. import net.minecraft.world.demo.DemoWorldServer;
  24. import net.minecraft.world.storage.ISaveFormat;
  25. import net.minecraft.world.storage.WorldInfo;
  26. import org.apache.commons.io.Charsets;
  27. import org.apache.logging.log4j.LogManager;
  28. import org.apache.logging.log4j.Logger;
  29. import org.lwjgl.opengl.GL11;
  30. import org.lwjgl.opengl.GLContext;
  31. import org.lwjgl.util.glu.Project;
  32.  
  33. public class GuiMainMenu extends GuiScreen implements GuiYesNoCallback
  34. {
  35. private static final Logger logger = LogManager.getLogger();
  36.  
  37. /** The RNG used by the Main Menu Screen. */
  38. private static final Random rand = new Random();
  39.  
  40. /** Counts the number of screen updates. */
  41. private float updateCounter;
  42.  
  43. /** The splash message. */
  44. private String splashText;
  45. private GuiButton buttonResetDemo;
  46.  
  47. /** Timer used to rotate the panorama, increases every tick. */
  48. private int panoramaTimer;
  49.  
  50. /**
  51. * Texture allocated for the current viewport of the main menu's panorama background.
  52. */
  53. private DynamicTexture viewportTexture;
  54. private final Object field_104025_t = new Object();
  55. private String field_92025_p;
  56. private String field_146972_A;
  57. private String field_104024_v;
  58. private static final ResourceLocation splashTexts = new ResourceLocation("texts/splashes.txt");
  59. private static final ResourceLocation minecraftTitleTextures = new ResourceLocation("textures/gui/title/minecraft.png");
  60.  
  61. /** An array of all the paths to the panorama pictures. */
  62. private static final ResourceLocation[] titlePanoramaPaths = new ResourceLocation[] {new ResourceLocation("textures/gui/title/background/panorama_0.png"), new ResourceLocation("textures/gui/title/background/panorama_1.png"), new ResourceLocation("textures/gui/title/background/panorama_2.png"), new ResourceLocation("textures/gui/title/background/panorama_3.png"), new ResourceLocation("textures/gui/title/background/panorama_4.png"), new ResourceLocation("textures/gui/title/background/panorama_5.png")};
  63. public static final String field_96138_a = "Please click " + EnumChatFormatting.UNDERLINE + "here" + EnumChatFormatting.RESET + " for more information.";
  64. private int field_92024_r;
  65. private int field_92023_s;
  66. private int field_92022_t;
  67. private int field_92021_u;
  68. private int field_92020_v;
  69. private int field_92019_w;
  70. private ResourceLocation field_110351_G;
  71. private static final String __OBFID = "CL_00001154";
  72.  
  73. private static final ResourceLocation logo = new ResourceLocation("textures/gui/logo.png");
  74. private static final ResourceLocation background = new ResourceLocation("textures/gui/backgroundmenu.png");
  75. private int textPosition = 440;
  76. private String text = "§5Bienvenue sur Shandora";
  77.  
  78. public GuiMainMenu()
  79. {
  80. this.field_146972_A = field_96138_a;
  81. this.splashText = "missingno";
  82. BufferedReader var1 = null;
  83.  
  84. try
  85. {
  86. ArrayList var2 = new ArrayList();
  87. var1 = new BufferedReader(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource(splashTexts).getInputStream(), Charsets.UTF_8));
  88. String var3;
  89.  
  90. while ((var3 = var1.readLine()) != null)
  91. {
  92. var3 = var3.trim();
  93.  
  94. if (!var3.isEmpty())
  95. {
  96. var2.add(var3);
  97. }
  98. }
  99.  
  100. if (!var2.isEmpty())
  101. {
  102. do
  103. {
  104. this.splashText = (String)var2.get(rand.nextInt(var2.size()));
  105. }
  106. while (this.splashText.hashCode() == 125780783);
  107. }
  108. }
  109. catch (IOException var12)
  110. {
  111. ;
  112. }
  113. finally
  114. {
  115. if (var1 != null)
  116. {
  117. try
  118. {
  119. var1.close();
  120. }
  121. catch (IOException var11)
  122. {
  123. ;
  124. }
  125. }
  126. }
  127.  
  128. this.updateCounter = rand.nextFloat();
  129. this.field_92025_p = "";
  130.  
  131. if (!GLContext.getCapabilities().OpenGL20 && !OpenGlHelper.func_153193_b())
  132. {
  133. this.field_92025_p = I18n.format("title.oldgl1", new Object[0]);
  134. this.field_146972_A = I18n.format("title.oldgl2", new Object[0]);
  135. this.field_104024_v = "https://help.mojang.com/customer/portal/articles/325948?ref=game";
  136. }
  137. }
  138.  
  139. /**
  140. * Called from the main game loop to update the screen.
  141. */
  142. public void updateScreen()
  143. {
  144. ++this.panoramaTimer;
  145.  
  146. if (textPosition < 0 - mc.fontRenderer.getStringWidth(text))
  147. {
  148. textPosition = width / 2 + 200;
  149. }
  150. textPosition -= 3;
  151.  
  152. }
  153.  
  154. /**
  155. * Returns true if this GUI should pause the game when it is displayed in single-player
  156. */
  157. public boolean doesGuiPauseGame()
  158. {
  159. return false;
  160. }
  161.  
  162. /**
  163. * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
  164. */
  165. protected void keyTyped(char p_73869_1_, int p_73869_2_) {}
  166.  
  167. /**
  168. * Adds the buttons (and other controls) to the screen in question.
  169. */
  170. public void initGui()
  171. {
  172. this.viewportTexture = new DynamicTexture(256, 256);
  173. this.field_110351_G = this.mc.getTextureManager().getDynamicTextureLocation("background", this.viewportTexture);
  174. Calendar var1 = Calendar.getInstance();
  175. var1.setTime(new Date());
  176.  
  177. if (var1.get(2) + 1 == 11 && var1.get(5) == 9)
  178. {
  179. this.splashText = "Happy birthday, ez!";
  180. }
  181. else if (var1.get(2) + 1 == 6 && var1.get(5) == 1)
  182. {
  183. this.splashText = "Happy birthday, Notch!";
  184. }
  185. else if (var1.get(2) + 1 == 12 && var1.get(5) == 24)
  186. {
  187. this.splashText = "Merry X-mas!";
  188. }
  189. else if (var1.get(2) + 1 == 1 && var1.get(5) == 1)
  190. {
  191. this.splashText = "Happy new year!";
  192. }
  193. else if (var1.get(2) + 1 == 10 && var1.get(5) == 31)
  194. {
  195. this.splashText = "OOoooOOOoooo! Spooky!";
  196. }
  197.  
  198. boolean var2 = true;
  199. int var3 = this.height / 4 + 28;
  200.  
  201. this.addSingleplayerMultiplayerButtons(var3, 24);
  202.  
  203.  
  204. this.buttonList.add(new GuiButton(0, this.width / 2 - 100, var3 + 72 + 12, 98, 20, I18n.format(EnumChatFormatting.GOLD + "Options")));
  205. this.buttonList.add(new GuiButton(4, this.width / 2 + 2, var3 + 72 + 12, 98, 20, I18n.format(EnumChatFormatting.RED + "Quitter")));
  206.  
  207. //this.buttonList.add(new GuiButtonLanguage(5, this.width / 2 - 124, var3 + 72 + 12));
  208.  
  209. Object var4 = this.field_104025_t;
  210.  
  211. synchronized (this.field_104025_t)
  212. {
  213. this.field_92023_s = this.fontRendererObj.getStringWidth(this.field_92025_p);
  214. this.field_92024_r = this.fontRendererObj.getStringWidth(this.field_146972_A);
  215. int var5 = Math.max(this.field_92023_s, this.field_92024_r);
  216. this.field_92022_t = (this.width - var5) / 2;
  217. this.field_92021_u = ((GuiButton)this.buttonList.get(0)).field_146129_i - 24;
  218. this.field_92020_v = this.field_92022_t + var5;
  219. this.field_92019_w = this.field_92021_u + 24;
  220. }
  221. }
  222.  
  223. /**
  224. * Adds Singleplayer and Multiplayer buttons on Main Menu for players who have bought the game.
  225. */
  226. private void addSingleplayerMultiplayerButtons(int p_73969_1_, int p_73969_2_)
  227. {
  228. this.buttonList.add(new GuiButton(1, this.width / 2 -100 , p_73969_1_ + 60, 200, 20, I18n.format(EnumChatFormatting.DARK_PURPLE + "Solo")));
  229. this.buttonList.add(new GuiButton(19, this.width / 2 - 100, p_73969_1_ + 35, 200, 20, I18n.format(EnumChatFormatting.DARK_PURPLE + "Rejoindre Shandora")));
  230. }
  231.  
  232. /**
  233. * Adds Demo buttons on Main Menu for players who are playing Demo.
  234. */
  235. private void addDemoButtons(int p_73972_1_, int p_73972_2_)
  236. {
  237. this.buttonList.add(new GuiButton(11, this.width / 2 - 100, p_73972_1_, I18n.format("menu.playdemo", new Object[0])));
  238. this.buttonList.add(this.buttonResetDemo = new GuiButton(12, this.width / 2 - 100, p_73972_1_ + p_73972_2_ * 1, I18n.format("menu.resetdemo", new Object[0])));
  239. ISaveFormat var3 = this.mc.getSaveLoader();
  240. WorldInfo var4 = var3.getWorldInfo("Demo_World");
  241.  
  242. if (var4 == null)
  243. {
  244. this.buttonResetDemo.enabled = false;
  245. }
  246. }
  247.  
  248. protected void actionPerformed(GuiButton p_146284_1_)
  249. {
  250. if (p_146284_1_.id == 0)
  251. {
  252. this.mc.displayGuiScreen(new GuiOptions(this, this.mc.gameSettings));
  253. }
  254.  
  255. if (p_146284_1_.id == 5)
  256. {
  257. this.mc.displayGuiScreen(new GuiLanguage(this, this.mc.gameSettings, this.mc.getLanguageManager()));
  258. }
  259.  
  260. if (p_146284_1_.id == 1)
  261. {
  262. this.mc.displayGuiScreen(new GuiSelectWorld(this));
  263. }
  264.  
  265. if (p_146284_1_.id == 2)
  266. {
  267. this.mc.displayGuiScreen(new GuiMultiplayer(this));
  268. }
  269.  
  270. if (p_146284_1_.id == 14)
  271. {
  272. this.func_140005_i();
  273. }
  274.  
  275. if (p_146284_1_.id == 4)
  276. {
  277. this.mc.shutdown();
  278. }
  279.  
  280. if (p_146284_1_.id == 19) {
  281. this.mc.displayGuiScreen(new GuiLoadingScreen());
  282. }
  283.  
  284. if (p_146284_1_.id == 11)
  285. {
  286. this.mc.launchIntegratedServer("Demo_World", "Demo_World", DemoWorldServer.demoWorldSettings);
  287. }
  288.  
  289. if (p_146284_1_.id == 12)
  290. {
  291. ISaveFormat var2 = this.mc.getSaveLoader();
  292. WorldInfo var3 = var2.getWorldInfo("Demo_World");
  293.  
  294. if (var3 != null)
  295. {
  296. GuiYesNo var4 = GuiSelectWorld.func_152129_a(this, var3.getWorldName(), 12);
  297. this.mc.displayGuiScreen(var4);
  298. }
  299. }
  300. }
  301.  
  302. private void func_140005_i()
  303. {
  304. RealmsBridge var1 = new RealmsBridge();
  305. var1.switchToRealms(this);
  306. }
  307.  
  308. public void confirmClicked(boolean p_73878_1_, int p_73878_2_)
  309. {
  310. if (p_73878_1_ && p_73878_2_ == 12)
  311. {
  312. ISaveFormat var6 = this.mc.getSaveLoader();
  313. var6.flushCache();
  314. var6.deleteWorldDirectory("Demo_World");
  315. this.mc.displayGuiScreen(this);
  316. }
  317. else if (p_73878_2_ == 13)
  318. {
  319. if (p_73878_1_)
  320. {
  321. try
  322. {
  323. Class var3 = Class.forName("java.awt.Desktop");
  324. Object var4 = var3.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
  325. var3.getMethod("browse", new Class[] {URI.class}).invoke(var4, new Object[] {new URI(this.field_104024_v)});
  326. }
  327. catch (Throwable var5)
  328. {
  329. logger.error("Couldn\'t open link", var5);
  330. }
  331. }
  332.  
  333. this.mc.displayGuiScreen(this);
  334. }
  335. }
  336.  
  337.  
  338. public static String readFile(String url)
  339. {
  340. String text = "0";
  341. try
  342. {
  343. URL location = new URL(url);
  344. BufferedReader in = new BufferedReader(new InputStreamReader(location.openStream()));
  345. text = in.readLine();
  346. }
  347. catch (Exception e)
  348. {
  349. System.out.println(e);
  350. }
  351. return text;
  352. }
  353.  
  354. public void drawTextureWithOptionalSize(int x, int y, int u, int v, int width, int height, int uSize, int vSize)
  355. {
  356. float scaledX = (float)1/uSize;
  357. float scaledY = (float)1/vSize;
  358. Tessellator tessellator = Tessellator.instance;
  359. tessellator.startDrawingQuads();
  360. tessellator.addVertexWithUV((double)(x + 0), (double)(y + height), (double)this.zLevel, (double)((float)(u + 0) * scaledX), (double)((float)(v + height) * scaledY));
  361. tessellator.addVertexWithUV((double)(x + width), (double)(y + height), (double)this.zLevel, (double)((float)(u + width) * scaledX), (double)((float)(v + height) * scaledY));
  362. tessellator.addVertexWithUV((double)(x + width), (double)(y + 0), (double)this.zLevel, (double)((float)(u + width) * scaledX), (double)((float)(v + 0) * scaledY));
  363. tessellator.addVertexWithUV((double)(x + 0), (double)(y + 0), (double)this.zLevel, (double)((float)(u + 0) * scaledX), (double)((float)(v + 0) * scaledY));
  364. tessellator.draw();
  365. }
  366.  
  367. public void drawLogo()
  368. {
  369. GL11.glEnable(GL11.GL_BLEND);
  370. GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  371. this.mc.getTextureManager().bindTexture(logo);
  372. this.drawTextureWithOptionalSize(width / 2 - 50, height / 4 - 50, 0, 0, 100, 100, 100, 100);
  373. }
  374.  
  375. public void drawBackground()
  376. {
  377. GL11.glDisable(GL11.GL_LIGHTING);
  378. GL11.glDisable(GL11.GL_FOG);
  379. Tessellator var2 = Tessellator.instance;
  380. GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
  381. mc.getTextureManager().bindTexture(background);
  382. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  383. var2.startDrawingQuads();
  384. var2.addVertexWithUV(0.0D, height, 0.0D, 0.0D, 1.0D);
  385. var2.addVertexWithUV(width, height, 0.0D, 1.0D, 1.0D);
  386. var2.addVertexWithUV(width, 0.0D, 0.0D, 1.0D, 0.0D);
  387. var2.addVertexWithUV(0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
  388. var2.draw();
  389. }
  390.  
  391.  
  392.  
  393. /**
  394. * Draws the screen and all the components in it.
  395. */
  396. public void drawScreen(int par1, int par2, float par3)
  397. {
  398.  
  399. drawBackground();
  400. drawLogo();
  401.  
  402. //this.drawGradientRect(0, 0, width, 15, 2130706433, 2130706433);
  403. //this.drawString(this.fontRendererObj, text, this.textPosition, 4, 0xB9121B);
  404.  
  405. /*
  406. GL11.glPushMatrix();
  407. GL11.glTranslatef((float)(this.width / 2 + 90), 70.0F, 0.0F);
  408. GL11.glRotatef(-20.0F, 0.0F, 0.0F, 1.0F);
  409. float var8 = 1.8F - MathHelper.abs(MathHelper.sin((float)(Minecraft.getSystemTime() % 1000L) / 1000.0F * (float)Math.PI * 2.0F) * 0.1F);
  410. var8 = var8 * 80.0F / (float)(this.fontRendererObj.getStringWidth(this.splashText) + 32);
  411. GL11.glScalef(var8, var8, var8);
  412. this.drawCenteredString(this.fontRendererObj, "Allez viens ! On est bien !", - 10, -15, -256);
  413. GL11.glPopMatrix();*/
  414.  
  415. drawRect(0, 0, width, 12, 0x66000000);
  416. this.drawString(this.fontRendererObj, text, this.textPosition, 2, 0xFFFFFFFF);
  417. super.drawScreen(par1, par2, par3);
  418. }
  419. /**
  420. * Called when the mouse is clicked.
  421. */
  422. protected void mouseClicked(int p_73864_1_, int p_73864_2_, int p_73864_3_)
  423. {
  424. super.mouseClicked(p_73864_1_, p_73864_2_, p_73864_3_);
  425. Object var4 = this.field_104025_t;
  426.  
  427. synchronized (this.field_104025_t)
  428. {
  429. if (this.field_92025_p.length() > 0 && p_73864_1_ >= this.field_92022_t && p_73864_1_ <= this.field_92020_v && p_73864_2_ >= this.field_92021_u && p_73864_2_ <= this.field_92019_w)
  430. {
  431. GuiConfirmOpenLink var5 = new GuiConfirmOpenLink(this, this.field_104024_v, 13, true);
  432. var5.func_146358_g();
  433. this.mc.displayGuiScreen(var5);
  434. }
  435. }
  436. }
  437. }
Advertisement
RAW Paste Data Copied
Advertisement