Guest User

Untitled

a guest
Nov 9th, 2016
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. package com.lemonade.mod.gui.type;
  2.  
  3. import org.lwjgl.opengl.GL11;
  4.  
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.client.gui.GuiButton;
  7. import net.minecraft.client.gui.GuiScreen;
  8. import net.minecraft.client.gui.GuiScreenBook;
  9. import net.minecraft.client.renderer.GlStateManager;
  10. import net.minecraft.client.resources.I18n;
  11. import net.minecraft.util.ResourceLocation;
  12. import net.minecraftforge.fml.relauncher.Side;
  13. import net.minecraftforge.fml.relauncher.SideOnly;
  14. import net.lemonade.mod.Reference;
  15.  
  16. public class GuiItemE extends GuiScreen {
  17. private final int bookImageHeight = 192;
  18. private final int bookImageWidth = 245;
  19. private int currPage = 0;
  20.  
  21. private static final ResourceLocation bookGuiTextures = new ResourceLocation(Reference.MOD_ID + ":textures/gui/book.png");
  22.  
  23. private static final int bookTotalPages = 4;
  24.  
  25. private static ResourceLocation[] bookPageTextures = new ResourceLocation[bookTotalPages];
  26. private static String[] stringPageText = new String[bookTotalPages];
  27. private NextPageButton buttonNextPage;
  28. private BackPageButton buttonPreviousPage;
  29.  
  30. public GuiItemE() {
  31. bookPageTextures[0] = new ResourceLocation(Reference.MOD_ID + ":textures/gui/ItemBook/Home.png");
  32. bookPageTextures[1] = new ResourceLocation(Reference.MOD_ID + ":textures/gui/ItemBook/Page1.png");
  33. bookPageTextures[2] = new ResourceLocation(Reference.MOD_ID + ":textures/gui/ItemBook/Page2.png");
  34. bookPageTextures[3] = new ResourceLocation(Reference.MOD_ID + ":textures/gui/ItemBook/Page3.png");
  35.  
  36. }
  37.  
  38. @Override
  39. public void initGui() {
  40. buttonList.clear();
  41. int offsetFromScreenLeft = (width - bookImageWidth) / 2;
  42. buttonList.add(buttonNextPage = new NextPageButton(1, offsetFromScreenLeft + 201, 225, true));
  43. buttonList.add(buttonPreviousPage = new BackPageButton(2, offsetFromScreenLeft + 24, 225, false));
  44. }
  45.  
  46. @Override
  47. public void updateScreen() {
  48. buttonNextPage.visible = (currPage < bookTotalPages - 1);
  49. buttonPreviousPage.visible = currPage > 0;
  50. }
  51.  
  52. @Override
  53. public void drawScreen(int parWidth, int parHeight, float p_73863_3_) {
  54. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  55. if (currPage == 0) {
  56. mc.getTextureManager().bindTexture(bookPageTextures[0]);
  57. }else if (currPage == 1) {
  58. mc.getTextureManager().bindTexture(bookPageTextures[1]);
  59. }else if (currPage == 2) {
  60. mc.getTextureManager().bindTexture(bookPageTextures[2]);
  61. }else if (currPage == 3) {
  62. mc.getTextureManager().bindTexture(bookPageTextures[3]);
  63. }
  64. int offsetFromScreenLeft = (int) ((width - bookImageWidth) / 2.0F);
  65. drawTexturedModalRect(offsetFromScreenLeft, -1, 0, 0, 254, 257);
  66. int widthOfString;
  67. String stringPageIndicator = I18n.format("book.pageIndicator", new Object[] { Integer.valueOf(currPage + 1), bookTotalPages });
  68. widthOfString = fontRendererObj.getStringWidth(stringPageIndicator);
  69. fontRendererObj.drawString(stringPageIndicator, offsetFromScreenLeft - widthOfString + bookImageWidth - 3, 11, 0);
  70. super.drawScreen(parWidth, parHeight, p_73863_3_);
  71.  
  72. }
  73.  
  74. @Override
  75. protected void mouseClickMove(int parMouseX, int parMouseY, int parLastButtonClicked, long parTimeSinceMouseClick) {
  76.  
  77. }
  78.  
  79. @Override
  80. protected void actionPerformed(GuiButton parButton) {
  81. if (parButton == buttonNextPage) {
  82. if (currPage < bookTotalPages - 1) {
  83. ++currPage;
  84. }
  85. } else if (parButton == buttonPreviousPage) {
  86. if (currPage > 0) {
  87. --currPage;
  88. }
  89. }
  90. }
  91.  
  92. @Override
  93. public void onGuiClosed() {
  94.  
  95. }
  96.  
  97. @Override
  98. public boolean doesGuiPauseGame() {
  99. return false;
  100. }
  101.  
  102. @SideOnly(Side.CLIENT)
  103. static class NextPageButton extends GuiButton
  104. {
  105. private final boolean field_146151_o;
  106.  
  107. public NextPageButton(int p_i46316_1_, int p_i46316_2_, int p_i46316_3_, boolean p_i46316_4_)
  108. {
  109. super(p_i46316_1_, p_i46316_2_, p_i46316_3_, 23, 13, "");
  110. this.field_146151_o = p_i46316_4_;
  111. }
  112.  
  113. public void drawButton(Minecraft mc, int mouseX, int mouseY)
  114. {
  115. if (this.visible)
  116. {
  117. boolean flag = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
  118. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  119. mc.getTextureManager().bindTexture(bookGuiTextures);
  120. int k = 0;
  121. int l = 192;
  122.  
  123. if (flag)
  124. {
  125. k += 23;
  126. }
  127.  
  128. if (!this.field_146151_o)
  129. {
  130. l += 13;
  131. }
  132.  
  133. this.drawTexturedModalRect(this.xPosition, this.yPosition, k, l, 23, 13);
  134. }
  135. }
  136. }
  137.  
  138. @SideOnly(Side.CLIENT)
  139. static class BackPageButton extends GuiButton
  140. {
  141. private final boolean field_146151_o;
  142.  
  143. public BackPageButton(int p_i46316_1_, int p_i46316_2_, int p_i46316_3_, boolean p_i46316_4_)
  144. {
  145. super(p_i46316_1_, p_i46316_2_, p_i46316_3_, 23, 13, "");
  146. this.field_146151_o = p_i46316_4_;
  147. }
  148.  
  149. public void drawButton(Minecraft mc, int mouseX, int mouseY)
  150. {
  151. if (this.visible)
  152. {
  153. boolean flag = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
  154. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  155. mc.getTextureManager().bindTexture(bookGuiTextures);
  156. int k = 0;
  157. int l = 192;
  158.  
  159. if (flag)
  160. {
  161. k += 23;
  162. }
  163.  
  164. if (!this.field_146151_o)
  165. {
  166. l += 13;
  167. }
  168.  
  169. this.drawTexturedModalRect(this.xPosition, this.yPosition, k, l, 23, 13);
  170. }
  171. }
  172. }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment