Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.00 KB | None | 0 0
  1. @SideOnly(Side.CLIENT)
  2. public class GUILoreBook extends GuiScreen {
  3.    
  4.    
  5.     private final int bookImageHeight = 210;
  6.     private final int bookImageWidth = 256;
  7.     private int currPage = 0;
  8.    
  9.     Random rand;
  10.     private GuiButton buttonDone;
  11.     private VolumeSelctor VolSelectorLS;
  12.     private VolumeSelctor VolSelectorG;
  13.     private VolumeSelctor VolSelectorA;
  14.     private NextPageButton buttonNextPage;
  15.     private NextPageButton buttonPreviousPage;
  16.     private static ResourceLocation next_buttons = new ResourceLocation(Reference.MOD_ID + ":textures/gui/lore/page_c.png");
  17.     private static ResourceLocation index = new ResourceLocation(Reference.MOD_ID + ":textures/gui/lore/volume_lost_sea_ls.png");
  18.     private static final ResourceLocation BOOK_GUI_TEXTURES = new ResourceLocation(Reference.MOD_ID + ":textures/gui/lore/book_turn_test.png");
  19.    
  20.     //Rnd Rips
  21.     private static ResourceLocation rip_1 = new ResourceLocation(Reference.MOD_ID + ":textures/gui/lore/rips/rip.png");
  22.     private static ResourceLocation rip_2 = new ResourceLocation(Reference.MOD_ID + ":textures/gui/lore/rips/rip2.png");
  23.     private static ResourceLocation rip_3 = new ResourceLocation(Reference.MOD_ID + ":textures/gui/lore/rips/rip3.png");
  24.    
  25.     private static final int bookTotalPages = 120;
  26.     private boolean pageUnlocked[] = new boolean[bookTotalPages + 1];
  27.     private boolean pageRipped[] = new boolean[bookTotalPages + 1];
  28.     private static ResourceLocation[] bookPageTextures = new ResourceLocation[bookTotalPages];
  29.     private static String[] stringPageText = new String[bookTotalPages];
  30.     private static String[] stringPageText2 = new String[bookTotalPages];
  31.    
  32.     private ItemStack stack;
  33.     public GUILoreBook(ItemStack stack)
  34.     {
  35.        
  36.         this.stack = stack;
  37.         bookPageTextures[0] = new ResourceLocation(Reference.MOD_ID + ":textures/gui/lore/lore_book_base_front.png");
  38.         bookPageTextures[1] = new ResourceLocation(Reference.MOD_ID + ":textures/gui/lore/lore_book_base.png");
  39.        
  40.         bookPageTextures[2] = new ResourceLocation(Reference.MOD_ID + ":textures/gui/lore/lore_book_vol1.png");
  41.         bookPageTextures[3] = new ResourceLocation(Reference.MOD_ID + ":textures/gui/lore/lore_book_vol2.png");
  42.         bookPageTextures[4] = new ResourceLocation(Reference.MOD_ID + ":textures/gui/lore/lore_book_vol3.png");
  43.         stringPageText[0] = "Introduction";
  44.         stringPageText[1] = "There are many many places in The Lost Sea, most of them I probably haven't even seen.. ,"
  45.                 + "anyways here a some of these locations I have seen in this vast sea.";
  46.         stringPageText[2] = "* - Pirate Cove"
  47.                 + "         * - Siren Caves"
  48.                 + "         * - Skull Island"
  49.                 + "         * - Dwarka Village"
  50.                 + "       * - The Great Trench"
  51.                 + "  * - Brine Seas"
  52.                 + "          * - Atlantis"
  53.                 + "               * - Aegean Sea"
  54.                 + "          * - Aegaeon Tower"
  55.                 + "      * - King's Garden"
  56.                 + "      * - Tasma's Dwelling";
  57.         stringPageText[3] = "The siren caves are a place some should not go, the creatures in this cave can really, extend your piston, heh if you get me. Anyways it's a decent sized cave filled with some water and it has rocks where these creatures known as Sirens live.";
  58.         stringPageText2[0] = "The sirens are basically the mythical creature you know as a mermaid, except it's much worse. My only tip for you, don't fall for them.                                Seriously though, they will eat you...";
  59.        
  60.         //Page 4
  61.         stringPageText[4] = "Skull island, even if it does exist that is, here are some things I know about it. I've never personally been there but ol' swashblocker says he has. It's apparently a island with a huge cave shaped as a skull, heh says the name.";
  62.         stringPageText2[1] = "Swashblocker is the only one who knows what is looks like because apparently his other crew members died in the storms near the island. Apparently these are no normal storms, they are hurricane like. He says there is also a great treasure in the cave";
  63.    
  64.         stringPageText[5] = "Dwarka village probably has to be the most peaceful place in the sea. It's a village that has a spell cast around it to prevent monsters from getting in, It also has a few Atlanteans that survived the invasion of Atlantis living in the village.";
  65.         stringPageText2[2] = "There are many powerful and ancient people there, including a mighty wizard who claims to have made the guardians. His name is Dromonar, the great Warlock. It's said he started the rebellion against the guardians. Nobody's seen him ever since he put up that shield.";
  66.        
  67.         //Page 5
  68.         stringPageText[6] = "";
  69.         stringPageText2[3] = "";
  70.    
  71.     }
  72.    
  73.    
  74.    
  75.     /**
  76.      * Adds the buttons (and other controls) to the screen in question.
  77.      */
  78.     @Override
  79.     public void initGui()
  80.     {
  81.        
  82.         NBTTagCompound nbt = stack.getTagCompound();
  83.        
  84.         if(nbt == null) {
  85.             nbt = new NBTTagCompound();
  86.         }
  87.         nbt = nbt.getCompoundTag("pages");
  88.         int unlocked_pages = 0;
  89.         if(nbt.hasKey("unlocked_pages"))
  90.         {
  91.             unlocked_pages = nbt.getInteger("unlocked_pages");
  92.         }
  93.         //System.out.println(unlocked_pages);
  94.         for(int i = 1; i <= bookTotalPages; i++)
  95.         {
  96.             pageUnlocked[i] = false;
  97.             if(nbt.hasKey("page_" + i))
  98.             {
  99.                 if(nbt.getBoolean("page_" + i));
  100.                 {
  101.                     pageUnlocked[i] = true;    
  102.                 }
  103.             }
  104.             //System.out.println(i + ":" + pageUnlocked[i]); //ONLY THIS LINE
  105.         }
  106.             buttonList.clear();
  107.             Keyboard.enableRepeatEvents(true);
  108.            
  109.             buttonDone = new GuiButton(0, width / 2 - 49, -25 + bookImageHeight, 98, 20, I18n.format("gui.done", new Object[0])) {
  110.                
  111.                 @Override
  112.                 public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
  113.                 {
  114.                     GL11.glColor4f(7.0F, 1.0F, 1.0F, 1.0F);
  115.                     super.drawButton(mc, mouseX, mouseY, partialTicks);
  116.                 }
  117.                
  118.                 @Override
  119.                 public void playPressSound(SoundHandler soundHandlerIn)
  120.                 {
  121.                     soundHandlerIn.playSound(PositionedSoundRecord.getMasterRecord(TLSSounds.BOOK_CLOSE, 1.0F));
  122.                 }
  123.             };
  124.            
  125.             buttonList.add(buttonDone);
  126.            
  127.             int offsetFromScreenLeft = (width - bookImageWidth) / 2;
  128.             buttonList.add(buttonNextPage = new NextPageButton(1,
  129.                   offsetFromScreenLeft + 215, 156, true));
  130.             buttonList.add(buttonPreviousPage = new NextPageButton(2,
  131.                   offsetFromScreenLeft + 16, 156, false));
  132.            
  133. //          //Volumes
  134. //          buttonList.add(VolSelectorLS = new VolumeSelctor(2,
  135. //                    offsetFromScreenLeft + 38, 156, false));
  136. //          buttonList.add(VolSelectorG = new VolumeSelctor(2,
  137. //                    offsetFromScreenLeft + 38, 156, false));
  138. //          buttonList.add(VolSelectorA = new VolumeSelctor(2,
  139. //                    offsetFromScreenLeft + 38, 156, false));
  140.     }
  141.     /**
  142.      * Called from the main game loop to update the screen.
  143.      */
  144.     @Override
  145.     public void updateScreen()
  146.     {
  147.         buttonNextPage.visible = (currPage < bookTotalPages - 1);
  148.         buttonPreviousPage.visible = currPage > 0;
  149.         //System.out.println(currPage);
  150.         //System.out.println(bookTotalPages);  
  151.        
  152.         //VolSelectorLS.visible = currPage == 0;
  153.         //VolSelectorG.visible = currPage == 0;
  154.         //VolSelectorA.visible = currPage == 0;
  155.     }
  156.     /**
  157.      * Draws the screen and all the components in it.
  158.      */
  159.     @Override
  160.     public void drawScreen(int parWidth, int parHeight, float p_73863_3_)
  161.     {
  162.         int offsetFromScreenLeft = (width - bookImageWidth ) / 2;
  163.         int topLeftStart = (bookImageWidth/2);
  164.         int widthOfString;
  165.        
  166.        
  167.        
  168.         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  169.         if(pageUnlocked[currPage] && currPage != 1 && currPage != 45 && currPage != 75) {
  170.            mc.getTextureManager().bindTexture(bookPageTextures[1]);
  171.         }
  172.         else if(currPage == 0) {
  173.             mc.getTextureManager().bindTexture(bookPageTextures[0]);
  174.         }
  175.         else if(currPage == 1) {
  176.            mc.getTextureManager().bindTexture(bookPageTextures[2]);
  177.         }
  178.         else if(currPage == 45) {
  179.                mc.getTextureManager().bindTexture(bookPageTextures[3]);
  180.             }
  181.         else if(currPage == 75) {
  182.                mc.getTextureManager().bindTexture(bookPageTextures[4]);
  183.             }
  184.         else
  185.         {
  186.             if(rand.nextInt(2) == 1) {
  187.                 mc.getTextureManager().bindTexture(rip_1);
  188.             }else {
  189.                 mc.getTextureManager().bindTexture(rip_2);
  190.             }
  191.            
  192.         }
  193.        
  194.         drawTexturedModalRect(offsetFromScreenLeft, 2, 0, 0, bookImageWidth, bookImageHeight);
  195.       if(currPage == 0) {
  196.         this.fontRenderer.drawString("Index", (163F), (50), 000000, false);
  197.        
  198.         this.fontRenderer.drawString("A Lost Sea", (150F), (70), 000000, false);
  199.         this.fontRenderer.drawString("The Guardians", (141.5F), (106), 000000, false);
  200.         this.fontRenderer.drawString("Atlantis", (158F), (141.5F), 000000, false);
  201.        
  202.         //Right
  203.         this.fontRenderer.drawSplitString(stringPageText[currPage], 270, 40, 116, 0);
  204.        
  205.         this.fontRenderer.drawSplitString("§nVolume I: A Lost Sea§r", 250, 55, 116, 5592575);
  206.         this.fontRenderer.drawString("About the mystical sea", (244F), (69F), 000000, false);
  207.        
  208.         this.fontRenderer.drawSplitString("§nVolume II: The Guardians§r", 250, 90, 116, 16755200);
  209.         this.fontRenderer.drawString("The Guardians story", (245F), (114F), 000000, false);
  210.        
  211.         this.fontRenderer.drawSplitString("§nVolume III: Atlantis§r", 250, 135, 116, 11115264);
  212.         this.fontRenderer.drawString("Lost Underwater City..", (243F), (146F), 000000, false);
  213.        
  214.       }else if(currPage == 1) {
  215.           this.fontRenderer.drawSplitString(stringPageText[1], 242, 45, 116, 0);
  216.           this.fontRenderer.drawSplitString("-------------------", 242, 118, 116, 0);
  217.          
  218.           this.fontRenderer.drawSplitString("* - Places on next page(s)", 245, 135, 116, 0);
  219.       }else if(currPage == 2) {
  220.          
  221.           this.fontRenderer.drawString("Known Locations", (138F), (43F), 000000, false);
  222.           this.fontRenderer.drawString("Pirate Cove", (272F), (43F), 65280, true);
  223.           this.fontRenderer.drawSplitString(stringPageText[2], 129, 55, 116, 0);
  224.           this.fontRenderer.drawSplitString("Ah yes, Pirate Cove, it's pirate cove alright. It's a secluded island with a pirate crew that lives there. It's said that the pirates hide on that island far away from Skull Island which is where the Ghost Pirates apparently live.", 250, 52, 105, 0);
  225.       }else if(currPage == 3) {
  226.           this.fontRenderer.drawString("Siren Caves", (145F), (43F), 3120639, true);
  227.           this.fontRenderer.drawSplitString(stringPageText[3], 129, 52, 110, 0);
  228.          
  229.           this.fontRenderer.drawSplitString(stringPageText2[0], 250, 52, 105, 0);
  230.       }else if(currPage == 4) {
  231.           this.fontRenderer.drawString("Skull Island", (145F), (43F), 16722176, true);
  232.           this.fontRenderer.drawSplitString(stringPageText[4], 129, 52, 110, 0);
  233.          
  234.           this.fontRenderer.drawSplitString(stringPageText2[1], 250, 46, 105, 0);
  235.       }else if(currPage == 5) {
  236.           this.fontRenderer.drawString("Dwarka Village", (145F), (43F), 65504, true);
  237.          
  238.           this.fontRenderer.drawSplitString(stringPageText[5], 129, 52, 110, 0);
  239.          
  240.           this.fontRenderer.drawSplitString(stringPageText2[2], 250, 36, 105, 0);
  241.       }
  242.       else if(currPage == 6) {
  243.           this.fontRenderer.drawString("The Great Trench", (135F), (43F), 10092720, true);
  244.          
  245.           this.fontRenderer.drawSplitString(stringPageText[6], 129, 52, 110, 0);
  246.          
  247.           this.fontRenderer.drawSplitString(stringPageText2[3], 250, 36, 105, 0);
  248.       }
  249.       super.drawScreen(parWidth, parHeight, p_73863_3_);
  250.    
  251.     }
  252.     @Override
  253.     protected void mouseClickMove(int parMouseX, int parMouseY, int parLastButtonClicked, long parTimeSinceMouseClick)
  254.     {
  255.     }
  256.  
  257.     @Override
  258.     protected void actionPerformed(GuiButton parButton)
  259.     {
  260.      if (parButton == buttonDone)
  261.      {
  262.          // You can send a packet to server here if you need server to do
  263.          // something
  264.          mc.displayGuiScreen((GuiScreen)null);
  265.      }
  266.         else if (parButton == buttonNextPage)
  267.         {
  268.             if (currPage < bookTotalPages - 1)
  269.             {
  270.                 ++currPage;
  271.             }
  272.         }
  273.         else if (parButton == buttonPreviousPage)
  274.         {
  275.             if (currPage > 0)
  276.             {
  277.                 --currPage;
  278.             }
  279.         }
  280.    }
  281.     @Override
  282.     public void onGuiClosed()
  283.     {
  284.     }
  285.     /**
  286.      * Returns true if this GUI should pause the game when it is displayed in
  287.      * single-player
  288.      */
  289.     @Override
  290.     public boolean doesGuiPauseGame()
  291.     {
  292.         return false;
  293.     }
  294.    
  295.    
  296.    
  297.     @SideOnly(Side.CLIENT)
  298.     static class NextPageButton extends GuiButton
  299.     {
  300.         private final boolean isNextButton;
  301.  
  302.         public NextPageButton(int parButtonId, int parPosX, int parPosY, boolean parIsNextButton)
  303.         {
  304.             super(parButtonId, parPosX, parPosY, 23, 13, "");
  305.             isNextButton = parIsNextButton;
  306.         }
  307.        
  308.         @Override
  309.         public void playPressSound(SoundHandler soundHandlerIn)
  310.         {
  311.            soundHandlerIn.playSound(PositionedSoundRecord.getMasterRecord(TLSSounds.PAGE_FLIP , 1.2F));
  312.         }
  313.  
  314.         /**
  315.          * Draws this button to the screen.
  316.          */
  317.         @Override
  318.         public void drawButton(Minecraft mc, int parX, int parY, float partial)
  319.         {
  320.             if (visible)
  321.             {
  322.                 boolean isButtonPressed = (parX >= x && parY >= y && parX < x + width && parY < y + height);
  323.                 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  324.                 mc.getTextureManager().bindTexture(BOOK_GUI_TEXTURES);
  325.                 int i = 0;
  326.                 int j = 192;
  327.  
  328.                 if (isButtonPressed)
  329.                 {
  330.                     i += 23;
  331.                 }
  332.  
  333.                 if (!isNextButton)
  334.                 {
  335.                     j += 13;
  336.                 }
  337.  
  338.                 this.drawTexturedModalRect(this.x, this.y, i, j, 23, 13);
  339.             }
  340.         }
  341.     }
  342.    
  343.     @SideOnly(Side.CLIENT)
  344.     static class VolumeSelctor extends GuiButton
  345.     {
  346.         private final boolean isNextButton;
  347.  
  348.         public VolumeSelctor(int parButtonId, int parPosX, int parPosY, boolean parIsNextButton)
  349.         {
  350.             super(parButtonId, parPosX, parPosY, 23, 13, "");
  351.             isNextButton = parIsNextButton;
  352.         }
  353.  
  354.         /**
  355.          * Draws this button to the screen.
  356.          */
  357.         @Override
  358.         public void drawButton(Minecraft mc, int parX, int parY, float partial)
  359.         {
  360.             if (visible)
  361.             {
  362.                 boolean isButtonPressed = (parX >= x
  363.                       && parY >= y
  364.                       && parX < x + width
  365.                       && parY < y + height);
  366.                 int textureX = 16;
  367.                 int textureY = 16;
  368.  
  369.                 if (isButtonPressed)
  370.                 {
  371.                     textureX += 23;
  372.                 }
  373.  
  374.                 if (!isNextButton)
  375.                 {
  376.                     textureY += 13;
  377.                 }
  378.  
  379.                 drawTexturedModalRect(x, y,
  380.                       textureX, textureY,
  381.                       23, 13);
  382.             }
  383.         }
  384.     }
  385. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement