2015-08-29 14:33:25 +02:00
/ *
* This file ( " GuiBooklet.java " ) is part of the Actually Additions Mod for Minecraft .
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-01-03 16:05:51 +01:00
* http : //ellpeck.de/actaddlicense/
2015-08-29 14:33:25 +02:00
* View the source code at https : //github.com/Ellpeck/ActuallyAdditions
*
2016-01-03 16:05:51 +01:00
* © 2016 Ellpeck
2015-08-29 14:33:25 +02:00
* /
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.booklet ;
2015-08-28 21:17:09 +02:00
2016-01-05 14:57:50 +01:00
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI ;
import de.ellpeck.actuallyadditions.api.booklet.BookletPage ;
import de.ellpeck.actuallyadditions.api.internal.EntrySet ;
import de.ellpeck.actuallyadditions.api.internal.IBookletGui ;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.booklet.button.BookmarkButton ;
import de.ellpeck.actuallyadditions.mod.booklet.button.IndexButton ;
import de.ellpeck.actuallyadditions.mod.booklet.button.TexturedButton ;
import de.ellpeck.actuallyadditions.mod.booklet.entry.BookletEntryAllSearch ;
import de.ellpeck.actuallyadditions.mod.config.GuiConfiguration ;
import de.ellpeck.actuallyadditions.mod.items.ItemBooklet ;
import de.ellpeck.actuallyadditions.mod.proxy.ClientProxy ;
import de.ellpeck.actuallyadditions.mod.update.UpdateChecker ;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil ;
import de.ellpeck.actuallyadditions.mod.util.ModUtil ;
import de.ellpeck.actuallyadditions.mod.util.StringUtil ;
import de.ellpeck.actuallyadditions.mod.util.playerdata.PersistentClientData ;
2015-12-02 22:31:50 +01:00
import net.minecraft.client.Minecraft ;
import net.minecraft.client.audio.PositionedSoundRecord ;
2015-11-11 18:51:20 +01:00
import net.minecraft.client.gui.FontRenderer ;
2015-08-28 21:17:09 +02:00
import net.minecraft.client.gui.GuiButton ;
import net.minecraft.client.gui.GuiScreen ;
2015-08-29 15:40:12 +02:00
import net.minecraft.client.gui.GuiTextField ;
2016-01-08 15:21:05 +01:00
import net.minecraft.client.renderer.GlStateManager ;
2016-01-05 14:57:50 +01:00
import net.minecraft.item.ItemStack ;
2015-12-04 18:14:03 +01:00
import net.minecraft.util.EnumChatFormatting ;
import net.minecraft.util.IChatComponent ;
2015-08-28 21:17:09 +02:00
import net.minecraft.util.ResourceLocation ;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.relauncher.Side ;
import net.minecraftforge.fml.relauncher.SideOnly ;
2015-11-25 19:59:58 +01:00
import org.lwjgl.input.Keyboard ;
2015-12-04 19:53:55 +01:00
import org.lwjgl.input.Mouse ;
2015-08-28 21:17:09 +02:00
2016-01-08 08:10:55 +01:00
import java.io.IOException ;
2015-12-04 18:14:03 +01:00
import java.util.ArrayList ;
import java.util.Collections ;
2015-08-29 17:32:39 +02:00
import java.util.List ;
2015-08-28 21:17:09 +02:00
@SideOnly ( Side . CLIENT )
2016-01-05 14:57:50 +01:00
public class GuiBooklet extends GuiScreen implements IBookletGui {
2015-08-28 21:17:09 +02:00
2015-10-30 20:07:36 +01:00
public static final ResourceLocation resLoc = AssetUtil . getBookletGuiLocation ( " guiBooklet " ) ;
public static final ResourceLocation resLocHalloween = AssetUtil . getBookletGuiLocation ( " guiBookletHalloween " ) ;
public static final ResourceLocation resLocChristmas = AssetUtil . getBookletGuiLocation ( " guiBookletChristmas " ) ;
public static final ResourceLocation resLocValentine = AssetUtil . getBookletGuiLocation ( " guiBookletValentinesDay " ) ;
2015-11-16 19:57:46 +01:00
2015-10-03 10:16:18 +02:00
public static final int CHAPTER_BUTTONS_AMOUNT = 13 ;
2015-12-17 21:58:59 +01:00
public static final int INDEX_BUTTONS_OFFSET = 3 ;
2015-12-19 10:30:39 +01:00
private static final int [ ] AND_HIS_NAME_IS = new int [ ] { Keyboard . KEY_C , Keyboard . KEY_E , Keyboard . KEY_N , Keyboard . KEY_A } ;
2015-08-28 21:17:09 +02:00
public int xSize ;
public int ySize ;
public int guiLeft ;
public int guiTop ;
2015-12-04 18:55:50 +01:00
public EntrySet currentEntrySet = new EntrySet ( null ) ;
2015-08-29 10:59:03 +02:00
public int indexPageAmount ;
2015-11-11 18:51:20 +01:00
public GuiButton buttonForward ;
public GuiButton buttonBackward ;
public GuiButton buttonPreviousScreen ;
public GuiButton buttonUpdate ;
public GuiButton buttonTwitter ;
public GuiButton buttonForum ;
public GuiButton buttonAchievements ;
public GuiButton buttonConfig ;
2015-12-30 23:17:03 +01:00
public GuiButton buttonWebsite ;
2015-11-11 18:51:20 +01:00
public GuiButton [ ] chapterButtons = new GuiButton [ CHAPTER_BUTTONS_AMOUNT ] ;
2015-11-16 19:57:46 +01:00
public GuiButton [ ] bookmarkButtons = new GuiButton [ 8 ] ;
2015-10-30 23:37:20 +01:00
public GuiTextField searchField ;
2015-12-01 19:48:09 +01:00
public GuiScreen parentScreen ;
2015-09-28 23:39:34 +02:00
private int ticksElapsed ;
2015-10-04 13:21:07 +02:00
private boolean mousePressed ;
2015-11-24 17:50:27 +01:00
private boolean tryOpenMainPage ;
private boolean saveOnClose ;
2015-12-02 22:31:50 +01:00
private int hisNameIsAt ;
2015-11-24 17:50:27 +01:00
public GuiBooklet ( GuiScreen parentScreen , boolean tryOpenMainPage , boolean saveOnClose ) {
2015-08-28 21:17:09 +02:00
this . xSize = 146 ;
this . ySize = 180 ;
2015-09-24 23:42:03 +02:00
this . parentScreen = parentScreen ;
2015-11-24 17:50:27 +01:00
this . tryOpenMainPage = tryOpenMainPage ;
this . saveOnClose = saveOnClose ;
2015-08-28 21:17:09 +02:00
}
2016-01-07 23:42:42 +01:00
@Override
2015-08-29 17:32:39 +02:00
public void drawHoveringText ( List list , int x , int y ) {
2016-01-07 23:42:42 +01:00
super . drawHoveringText ( list , x , y ) ;
2015-08-29 17:32:39 +02:00
}
2015-11-11 18:51:20 +01:00
public FontRenderer getFontRenderer ( ) {
return this . fontRendererObj ;
}
2015-12-04 18:14:03 +01:00
public List getButtonList ( ) {
return this . buttonList ;
}
2015-08-28 21:17:09 +02:00
@Override
public void drawScreen ( int x , int y , float f ) {
2015-11-11 18:51:20 +01:00
//Fixes Unicode flag
2015-10-03 19:19:26 +02:00
boolean unicodeBefore = this . fontRendererObj . getUnicodeFlag ( ) ;
this . fontRendererObj . setUnicodeFlag ( true ) ;
2015-12-24 23:13:57 +01:00
//To Player:
2015-12-24 23:13:46 +01:00
//
//FastCraft's a must, definitely
//But the bigger unicode option sucks real
//It screws with my book and makes me feel ill
//So don't fuck with everything unintentionally
//
//(This fixes your fuckery)
2016-01-08 15:21:05 +01:00
GlStateManager . scale ( 1 . 0F , 1 . 0F , 1 . 0F ) ;
2015-12-24 23:13:46 +01:00
2015-11-11 18:51:20 +01:00
//Draws the Background
2016-01-08 15:21:05 +01:00
GlStateManager . color ( 1 . 0F , 1 . 0F , 1 . 0F , 1 . 0F ) ;
2015-10-23 23:08:53 +02:00
this . mc . getTextureManager ( ) . bindTexture ( ClientProxy . jingleAllTheWay ? resLocChristmas : ( ClientProxy . pumpkinBlurPumpkinBlur ? resLocHalloween : ( ClientProxy . bulletForMyValentine ? resLocValentine : resLoc ) ) ) ;
2015-10-16 22:34:58 +02:00
this . drawTexturedModalRect ( this . guiLeft , this . guiTop , 0 , 0 , this . xSize , this . ySize ) ;
2015-08-28 21:17:09 +02:00
2015-11-11 18:51:20 +01:00
//Draws the search bar
2015-12-04 18:55:50 +01:00
if ( this . currentEntrySet . entry instanceof BookletEntryAllSearch & & this . currentEntrySet . chapter = = null ) {
2015-11-14 01:18:37 +01:00
this . mc . getTextureManager ( ) . bindTexture ( resLoc ) ;
2015-08-29 15:40:12 +02:00
this . drawTexturedModalRect ( this . guiLeft + 146 , this . guiTop + 160 , 146 , 80 , 70 , 14 ) ;
}
2015-11-14 01:18:37 +01:00
//Draws Achievement Info
BookletUtils . drawAchievementInfo ( this , true , x , y ) ;
2015-11-11 18:51:20 +01:00
//Draws the title
2015-10-03 19:19:26 +02:00
this . fontRendererObj . setUnicodeFlag ( false ) ;
2015-11-11 18:51:20 +01:00
BookletUtils . drawTitle ( this ) ;
2015-10-03 19:19:26 +02:00
this . fontRendererObj . setUnicodeFlag ( true ) ;
2015-08-28 21:17:09 +02:00
2015-11-16 19:03:29 +01:00
//Pre-Renders the current page's content etc.
BookletUtils . renderPre ( this , x , y , this . ticksElapsed , this . mousePressed ) ;
2015-11-11 18:51:20 +01:00
//Does vanilla drawing stuff
2015-08-28 22:18:46 +02:00
super . drawScreen ( x , y , f ) ;
2015-08-29 15:40:12 +02:00
this . searchField . drawTextBox ( ) ;
2015-08-28 22:18:46 +02:00
2015-12-17 19:16:37 +01:00
//Renders the current page's content
if ( this . currentEntrySet . entry ! = null & & this . currentEntrySet . chapter ! = null & & this . currentEntrySet . page ! = null ) {
this . currentEntrySet . page . render ( this , x , y , this . ticksElapsed , this . mousePressed ) ;
}
2015-11-11 18:51:20 +01:00
//Draws hovering texts for buttons
2015-10-03 19:19:26 +02:00
this . fontRendererObj . setUnicodeFlag ( false ) ;
2015-11-11 18:51:20 +01:00
BookletUtils . doHoverTexts ( this , x , y ) ;
2015-11-13 21:40:38 +01:00
BookletUtils . drawAchievementInfo ( this , false , x , y ) ;
2015-11-16 19:03:29 +01:00
this . fontRendererObj . setUnicodeFlag ( true ) ;
2015-10-03 19:19:26 +02:00
this . fontRendererObj . setUnicodeFlag ( unicodeBefore ) ;
2015-10-04 13:21:07 +02:00
2015-11-11 18:51:20 +01:00
//Resets mouse
2015-10-04 13:21:07 +02:00
if ( this . mousePressed ) {
this . mousePressed = false ;
}
2015-08-28 21:17:09 +02:00
}
2015-10-03 10:19:40 +02:00
@Override
public void keyTyped ( char theChar , int key ) {
2015-12-25 00:38:16 +01:00
if ( key = = Keyboard . KEY_ESCAPE ) {
2015-12-04 22:40:36 +01:00
if ( this . parentScreen ! = null ) {
this . mc . displayGuiScreen ( this . parentScreen ) ;
}
else {
this . mc . displayGuiScreen ( null ) ;
this . mc . setIngameFocus ( ) ;
}
2015-11-25 19:59:58 +01:00
}
2015-12-04 22:40:36 +01:00
else if ( this . searchField . isFocused ( ) ) {
2015-10-03 10:19:40 +02:00
this . searchField . textboxKeyTyped ( theChar , key ) ;
2015-11-11 18:51:20 +01:00
BookletUtils . updateSearchBar ( this ) ;
2015-10-30 23:37:20 +01:00
}
else {
2015-12-02 22:31:50 +01:00
if ( AND_HIS_NAME_IS . length > this . hisNameIsAt & & AND_HIS_NAME_IS [ this . hisNameIsAt ] = = key ) {
if ( this . hisNameIsAt + 1 > = AND_HIS_NAME_IS . length ) {
2016-01-07 23:42:42 +01:00
Minecraft . getMinecraft ( ) . getSoundHandler ( ) . playSound ( PositionedSoundRecord . create ( new ResourceLocation ( ModUtil . MOD_ID_LOWER , " duhDuhDuhDuuuh " ) ) ) ;
2015-12-02 22:31:50 +01:00
ModUtil . LOGGER . info ( " AND HIS NAME IS JOHN CENA DUH DUH DUH DUUUH " ) ;
this . hisNameIsAt = 0 ;
}
else {
this . hisNameIsAt + + ;
}
}
else {
this . hisNameIsAt = 0 ;
}
2015-10-30 23:37:20 +01:00
}
}
2015-08-31 06:15:06 +02:00
2015-10-03 10:19:40 +02:00
@Override
2016-01-08 08:10:55 +01:00
protected void mouseClicked ( int par1 , int par2 , int par3 ) throws IOException {
2015-10-03 10:19:40 +02:00
this . searchField . mouseClicked ( par1 , par2 , par3 ) ;
2015-12-04 19:53:55 +01:00
//Left mouse button
2015-12-04 18:55:50 +01:00
if ( par3 = = 0 & & this . currentEntrySet . chapter ! = null ) {
2015-10-04 13:21:07 +02:00
this . mousePressed = true ;
}
2015-12-04 19:53:55 +01:00
//Right mouse button
else if ( par3 = = 1 ) {
if ( this . currentEntrySet . chapter ! = null ) {
BookletUtils . openIndexEntry ( this , this . currentEntrySet . entry , this . currentEntrySet . pageInIndex , true ) ;
}
else {
BookletUtils . openIndexEntry ( this , null , 1 , true ) ;
}
}
2016-01-08 08:10:55 +01:00
super . mouseClicked ( par1 , par2 , par3 ) ;
2015-08-28 21:17:09 +02:00
}
@Override
public void actionPerformed ( GuiButton button ) {
2015-11-11 18:51:20 +01:00
//Handles update
2015-11-25 19:59:58 +01:00
if ( button = = this . buttonUpdate ) {
2015-10-28 18:28:30 +01:00
if ( UpdateChecker . needsUpdateNotify ) {
2015-11-11 18:51:20 +01:00
BookletUtils . openBrowser ( UpdateChecker . CHANGELOG_LINK , UpdateChecker . DOWNLOAD_LINK ) ;
2015-09-02 20:06:34 +02:00
}
}
2015-12-30 23:17:03 +01:00
//Handles Website
else if ( button = = this . buttonWebsite ) {
BookletUtils . openBrowser ( " http://ellpeck.de " ) ;
}
2015-11-11 18:51:20 +01:00
//Handles Twitter
2015-09-30 19:18:13 +02:00
else if ( button = = this . buttonTwitter ) {
2015-11-11 18:51:20 +01:00
BookletUtils . openBrowser ( " http://twitter.com/ActAddMod " ) ;
2015-08-30 05:11:05 +02:00
}
2015-11-11 18:51:20 +01:00
//Handles forum
2015-09-30 19:18:13 +02:00
else if ( button = = this . buttonForum ) {
2015-11-11 18:51:20 +01:00
BookletUtils . openBrowser ( " http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2551118 " ) ;
2015-08-30 05:11:05 +02:00
}
2015-11-11 18:51:20 +01:00
//Handles config
2015-09-30 19:18:13 +02:00
else if ( button = = this . buttonConfig ) {
2015-08-28 21:17:09 +02:00
mc . displayGuiScreen ( new GuiConfiguration ( this ) ) ;
}
2015-11-11 18:51:20 +01:00
//Handles achievements
2015-09-30 19:18:13 +02:00
else if ( button = = this . buttonAchievements ) {
2015-08-28 21:17:09 +02:00
mc . displayGuiScreen ( new GuiAAAchievements ( this , mc . thePlayer . getStatFileWriter ( ) ) ) ;
}
2015-09-30 19:18:13 +02:00
else if ( button = = this . buttonForward ) {
2015-11-11 18:51:20 +01:00
BookletUtils . handleNextPage ( this ) ;
2015-08-28 21:17:09 +02:00
}
2015-09-30 19:18:13 +02:00
else if ( button = = this . buttonBackward ) {
2015-11-11 18:51:20 +01:00
BookletUtils . handlePreviousPage ( this ) ;
2015-08-28 21:17:09 +02:00
}
2015-11-11 18:51:20 +01:00
//Handles gonig from page to chapter or from chapter to index
2015-09-30 19:18:13 +02:00
else if ( button = = this . buttonPreviousScreen ) {
2015-12-04 19:53:55 +01:00
if ( this . currentEntrySet . chapter ! = null ) {
BookletUtils . openIndexEntry ( this , this . currentEntrySet . entry , this . currentEntrySet . pageInIndex , true ) ;
2015-08-29 10:59:03 +02:00
}
else {
2015-12-04 19:53:55 +01:00
BookletUtils . openIndexEntry ( this , null , 1 , true ) ;
2015-08-28 21:17:09 +02:00
}
}
2015-11-16 19:57:46 +01:00
//Handles Bookmark button
2015-12-04 18:14:03 +01:00
else if ( button instanceof BookmarkButton ) {
( ( BookmarkButton ) button ) . onPressed ( ) ;
2015-11-16 19:57:46 +01:00
}
2015-09-30 19:18:13 +02:00
else {
2015-11-11 18:51:20 +01:00
BookletUtils . handleChapterButtonClick ( this , button ) ;
2015-08-28 21:17:09 +02:00
}
}
2016-01-03 19:16:43 +01:00
@SuppressWarnings ( " unchecked " )
2015-10-03 10:19:40 +02:00
@Override
public void initGui ( ) {
this . guiLeft = ( this . width - this . xSize ) / 2 ;
this . guiTop = ( this . height - this . ySize ) / 2 ;
2015-12-04 18:14:03 +01:00
this . buttonForward = new TexturedButton ( 0 , this . guiLeft + this . xSize - 26 , this . guiTop + this . ySize + 1 , 164 , 0 , 18 , 10 , Collections . singletonList ( EnumChatFormatting . GOLD + " Next Page " ) ) ;
2015-10-03 10:19:40 +02:00
this . buttonList . add ( this . buttonForward ) ;
2015-12-04 18:14:03 +01:00
this . buttonBackward = new TexturedButton ( 1 , this . guiLeft + 8 , this . guiTop + this . ySize + 1 , 146 , 0 , 18 , 10 , Collections . singletonList ( EnumChatFormatting . GOLD + " Previous Page " ) ) ;
2015-10-03 10:19:40 +02:00
this . buttonList . add ( this . buttonBackward ) ;
2015-12-04 19:53:55 +01:00
this . buttonPreviousScreen = new TexturedButton ( 2 , this . guiLeft + this . xSize / 2 - 7 , this . guiTop + this . ySize + 1 , 182 , 0 , 15 , 10 , Collections . singletonList ( EnumChatFormatting . GOLD + " Back " ) ) ;
2015-10-03 10:19:40 +02:00
this . buttonList . add ( this . buttonPreviousScreen ) ;
2015-12-04 18:14:03 +01:00
ArrayList updateHover = new ArrayList ( ) ;
if ( UpdateChecker . checkFailed ) {
2016-01-07 23:42:42 +01:00
updateHover . add ( IChatComponent . Serializer . jsonToComponent ( StringUtil . localize ( " info. " + ModUtil . MOD_ID_LOWER + " .update.failed " ) ) . getFormattedText ( ) ) ;
2015-12-04 18:14:03 +01:00
}
else if ( UpdateChecker . needsUpdateNotify ) {
2016-01-07 23:42:42 +01:00
updateHover . add ( IChatComponent . Serializer . jsonToComponent ( StringUtil . localize ( " info. " + ModUtil . MOD_ID_LOWER + " .update.generic " ) ) . getFormattedText ( ) ) ;
updateHover . add ( IChatComponent . Serializer . jsonToComponent ( StringUtil . localizeFormatted ( " info. " + ModUtil . MOD_ID_LOWER + " .update.versionCompare " , ModUtil . VERSION , UpdateChecker . updateVersion ) ) . getFormattedText ( ) ) ;
2015-12-04 18:14:03 +01:00
updateHover . add ( StringUtil . localize ( " info. " + ModUtil . MOD_ID_LOWER + " .update.buttonOptions " ) ) ;
}
this . buttonUpdate = new TexturedButton ( 4 , this . guiLeft - 11 , this . guiTop - 11 , 245 , 0 , 11 , 11 , updateHover ) ;
2015-10-28 18:28:30 +01:00
this . buttonUpdate . visible = UpdateChecker . needsUpdateNotify ;
2015-10-03 10:19:40 +02:00
this . buttonList . add ( this . buttonUpdate ) ;
2015-12-04 18:14:03 +01:00
this . buttonTwitter = new TexturedButton ( 5 , this . guiLeft , this . guiTop , 213 , 0 , 8 , 8 , Collections . singletonList ( EnumChatFormatting . GOLD + " Open @ActAddMod on Twitter in Browser " ) ) ;
2015-10-03 10:19:40 +02:00
this . buttonList . add ( this . buttonTwitter ) ;
2015-12-04 18:14:03 +01:00
this . buttonForum = new TexturedButton ( 6 , this . guiLeft , this . guiTop + 10 , 221 , 0 , 8 , 8 , Collections . singletonList ( EnumChatFormatting . GOLD + " Open Minecraft Forum Post in Browser " ) ) ;
2015-10-03 10:19:40 +02:00
this . buttonList . add ( this . buttonForum ) ;
2015-12-04 18:14:03 +01:00
this . buttonAchievements = new TexturedButton ( 7 , this . guiLeft + 138 , this . guiTop , 205 , 0 , 8 , 8 , Collections . singletonList ( EnumChatFormatting . GOLD + " Show Achievements " ) ) ;
2015-10-03 10:19:40 +02:00
this . buttonList . add ( this . buttonAchievements ) ;
2015-12-30 23:17:03 +01:00
ArrayList websiteHover = new ArrayList ( ) ;
websiteHover . add ( EnumChatFormatting . GOLD + " Open Author's Website " ) ;
websiteHover . add ( " (There's some cool stuff there!) " ) ;
websiteHover . add ( EnumChatFormatting . GRAY + " " + EnumChatFormatting . ITALIC + " Would you call this Product Placement? " ) ;
this . buttonWebsite = new TexturedButton ( - 99 , this . guiLeft , this . guiTop + 20 , 228 , 0 , 8 , 8 , websiteHover ) ;
this . buttonList . add ( this . buttonWebsite ) ;
2015-12-04 18:14:03 +01:00
ArrayList configHover = new ArrayList ( ) ;
configHover . add ( EnumChatFormatting . GOLD + " Show Configuration GUI " ) ;
configHover . addAll ( this . fontRendererObj . listFormattedStringToWidth ( " It is highly recommended that you restart your game after changing anything as that prevents possible bugs occuring! " , 200 ) ) ;
this . buttonConfig = new TexturedButton ( 8 , this . guiLeft + 138 , this . guiTop + 10 , 197 , 0 , 8 , 8 , configHover ) ;
2015-10-03 10:19:40 +02:00
this . buttonList . add ( this . buttonConfig ) ;
for ( int i = 0 ; i < this . chapterButtons . length ; i + + ) {
2015-12-04 18:14:03 +01:00
this . chapterButtons [ i ] = new IndexButton ( 9 + i , guiLeft + 15 , guiTop + 10 + ( i * 12 ) , 115 , 10 , " " , this ) ;
2015-10-03 10:19:40 +02:00
this . buttonList . add ( this . chapterButtons [ i ] ) ;
}
2015-11-16 19:57:46 +01:00
for ( int i = 0 ; i < this . bookmarkButtons . length ; i + + ) {
int x = this . guiLeft + xSize / 2 - ( this . bookmarkButtons . length / 2 * 16 ) + ( i * 16 ) ;
2015-12-04 18:14:03 +01:00
this . bookmarkButtons [ i ] = new BookmarkButton ( this . chapterButtons [ this . chapterButtons . length - 1 ] . id + 1 + i , x , this . guiTop + this . ySize + 13 , this ) ;
2015-11-16 19:57:46 +01:00
this . buttonList . add ( this . bookmarkButtons [ i ] ) ;
}
2016-01-07 23:42:42 +01:00
this . searchField = new GuiTextField ( 4500 , this . fontRendererObj , guiLeft + 148 , guiTop + 162 , 66 , 10 ) ;
2015-10-03 10:19:40 +02:00
this . searchField . setMaxStringLength ( 30 ) ;
this . searchField . setEnableBackgroundDrawing ( false ) ;
2015-10-10 03:39:42 +02:00
this . searchField . setCanLoseFocus ( false ) ;
2015-10-03 10:19:40 +02:00
2015-12-04 18:55:50 +01:00
this . currentEntrySet . removeEntry ( ) ;
2015-10-03 10:19:40 +02:00
2015-12-22 16:08:53 +01:00
if ( ItemBooklet . forcedEntry = = null ) {
//Open last entry or introductory entry
if ( this . tryOpenMainPage & & ! PersistentClientData . getBoolean ( " BookAlreadyOpened " ) ) {
BookletUtils . openIndexEntry ( this , InitBooklet . chapterIntro . entry , 1 , true ) ;
BookletUtils . openChapter ( this , InitBooklet . chapterIntro , null ) ;
2015-10-03 10:19:40 +02:00
2015-12-22 16:08:53 +01:00
PersistentClientData . setBoolean ( " BookAlreadyOpened " , true ) ;
}
else {
PersistentClientData . openLastBookPage ( this ) ;
}
2015-10-03 10:19:40 +02:00
}
else {
2015-12-22 16:08:53 +01:00
//Open forced entry
BookletUtils . openIndexEntry ( this , ItemBooklet . forcedEntry . entry , ItemBooklet . forcedEntry . pageInIndex , true ) ;
BookletUtils . openChapter ( this , ItemBooklet . forcedEntry . chapter , ItemBooklet . forcedEntry . page ) ;
ItemBooklet . forcedEntry = null ;
2015-10-03 10:19:40 +02:00
}
}
2015-12-19 10:30:39 +01:00
@Override
//For scrolling through pages
2016-01-08 08:10:55 +01:00
public void handleMouseInput ( ) throws IOException {
2015-12-19 10:30:39 +01:00
int wheel = Mouse . getEventDWheel ( ) ;
if ( wheel ! = 0 ) {
2016-01-08 20:51:03 +01:00
if ( wheel < 0 ) {
2015-12-19 10:30:39 +01:00
BookletUtils . handleNextPage ( this ) ;
}
2016-01-08 20:51:03 +01:00
else if ( wheel > 0 ) {
2015-12-19 10:30:39 +01:00
BookletUtils . handlePreviousPage ( this ) ;
}
}
2016-01-08 08:10:55 +01:00
super . handleMouseInput ( ) ;
2015-12-19 10:30:39 +01:00
}
2015-10-03 10:19:40 +02:00
@Override
public void updateScreen ( ) {
super . updateScreen ( ) ;
this . searchField . updateCursorCounter ( ) ;
2015-12-04 18:55:50 +01:00
if ( this . currentEntrySet . entry ! = null & & this . currentEntrySet . chapter ! = null & & this . currentEntrySet . page ! = null ) {
this . currentEntrySet . page . updateScreen ( this . ticksElapsed ) ;
2015-10-03 10:19:40 +02:00
}
2015-10-28 18:28:30 +01:00
boolean buttonThere = UpdateChecker . needsUpdateNotify ;
2015-10-03 10:19:40 +02:00
this . buttonUpdate . visible = buttonThere ;
if ( buttonThere ) {
if ( this . ticksElapsed % 8 = = 0 ) {
2015-12-04 18:14:03 +01:00
TexturedButton button = ( TexturedButton ) this . buttonUpdate ;
2015-10-03 10:19:40 +02:00
button . setTexturePos ( 245 , button . texturePosY = = 0 ? 22 : 0 ) ;
}
}
this . ticksElapsed + + ;
}
@Override
public void onGuiClosed ( ) {
2015-11-24 17:50:27 +01:00
if ( this . saveOnClose ) {
PersistentClientData . saveBookPage ( this ) ;
}
2015-10-03 10:19:40 +02:00
}
@Override
public boolean doesGuiPauseGame ( ) {
return false ;
}
2016-01-05 14:57:50 +01:00
@Override
public void renderTooltipAndTransferButton ( BookletPage from , ItemStack stack , int x , int y , boolean renderTransferButton , boolean mousePressed ) {
2016-01-07 23:42:42 +01:00
boolean flagBefore = this . mc . fontRendererObj . getUnicodeFlag ( ) ;
this . mc . fontRendererObj . setUnicodeFlag ( false ) ;
2016-01-05 14:57:50 +01:00
List list = stack . getTooltip ( this . mc . thePlayer , this . mc . gameSettings . advancedItemTooltips ) ;
for ( int k = 0 ; k < list . size ( ) ; + + k ) {
if ( k = = 0 ) {
list . set ( k , stack . getRarity ( ) . rarityColor + ( String ) list . get ( k ) ) ;
}
else {
list . set ( k , EnumChatFormatting . GRAY + ( String ) list . get ( k ) ) ;
}
}
if ( renderTransferButton ) {
BookletPage page = BookletUtils . getFirstPageForStack ( stack ) ;
if ( page ! = null & & page ! = from ) {
list . add ( from . getClickToSeeRecipeString ( ) ) ;
if ( mousePressed ) {
BookletUtils . openIndexEntry ( this , page . getChapter ( ) . getEntry ( ) , ActuallyAdditionsAPI . bookletEntries . indexOf ( page . getChapter ( ) . getEntry ( ) ) / GuiBooklet . CHAPTER_BUTTONS_AMOUNT + 1 , true ) ;
BookletUtils . openChapter ( this , page . getChapter ( ) , page ) ;
2016-01-07 23:42:42 +01:00
Minecraft . getMinecraft ( ) . getSoundHandler ( ) . playSound ( PositionedSoundRecord . create ( new ResourceLocation ( " gui.button.press " ) , 1 . 0F ) ) ;
2016-01-05 14:57:50 +01:00
}
}
}
this . drawHoveringText ( list , x , y ) ;
2016-01-07 23:42:42 +01:00
this . mc . fontRendererObj . setUnicodeFlag ( flagBefore ) ;
2016-01-05 14:57:50 +01:00
}
@Override
public int getXSize ( ) {
return this . xSize ;
}
@Override
public int getYSize ( ) {
return this . ySize ;
}
@Override
public int getGuiLeft ( ) {
return this . guiLeft ;
}
@Override
public int getGuiTop ( ) {
return this . guiTop ;
}
2016-01-06 05:17:54 +01:00
@Override
public void drawRect ( int startX , int startY , int u , int v , int xSize , int ySize ) {
this . drawTexturedModalRect ( startX , startY , u , v , xSize , ySize ) ;
}
2016-01-05 14:57:50 +01:00
@Override
public EntrySet getCurrentEntrySet ( ) {
return this . currentEntrySet ;
}
2015-08-28 21:17:09 +02:00
}