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
* http : //github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https : //github.com/Ellpeck/ActuallyAdditions
*
* <EFBFBD> 2015 Ellpeck
* /
2015-08-29 23:01:13 +02:00
package ellpeck.actuallyadditions.booklet ;
2015-08-28 21:17:09 +02:00
import cpw.mods.fml.relauncher.Side ;
import cpw.mods.fml.relauncher.SideOnly ;
2015-09-10 21:25:34 +02:00
import ellpeck.actuallyadditions.booklet.page.BookletPage ;
2015-08-28 21:17:09 +02:00
import ellpeck.actuallyadditions.config.GuiConfiguration ;
2015-09-02 20:06:34 +02:00
import ellpeck.actuallyadditions.update.UpdateChecker ;
2015-08-31 06:15:06 +02:00
import ellpeck.actuallyadditions.util.* ;
2015-08-28 21:17:09 +02:00
import net.minecraft.client.Minecraft ;
import net.minecraft.client.gui.FontRenderer ;
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 ;
2015-08-28 21:17:09 +02:00
import net.minecraft.client.renderer.OpenGlHelper ;
import net.minecraft.item.ItemStack ;
2015-08-30 01:19:03 +02:00
import net.minecraft.util.EnumChatFormatting ;
2015-08-28 21:17:09 +02:00
import net.minecraft.util.ResourceLocation ;
import org.lwjgl.opengl.GL11 ;
2015-08-30 05:11:05 +02:00
import java.awt.* ;
import java.net.URI ;
2015-08-29 15:40:12 +02:00
import java.util.ArrayList ;
2015-08-28 21:17:09 +02:00
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 )
public class GuiBooklet extends GuiScreen {
public static final ResourceLocation resLoc = AssetUtil . getGuiLocation ( " guiBooklet " ) ;
public FontRenderer unicodeRenderer ;
public int xSize ;
public int ySize ;
public int guiLeft ;
public int guiTop ;
2015-09-10 21:25:34 +02:00
public BookletPage currentPage ;
2015-08-28 21:17:09 +02:00
public BookletChapter currentChapter ;
public BookletIndexEntry currentIndexEntry ;
2015-08-29 10:59:03 +02:00
public int pageOpenInIndex ;
public int indexPageAmount ;
2015-08-28 21:17:09 +02:00
2015-08-29 15:40:12 +02:00
private GuiTextField searchField ;
2015-08-28 21:17:09 +02:00
private static final int BUTTON_FORWARD_ID = 0 ;
private static final int BUTTON_BACK_ID = 1 ;
private static final int BUTTON_RETURN_ID = 2 ;
private static final int CHAPTER_BUTTONS_START = 3 ;
2015-09-06 23:18:50 +02:00
2015-09-05 00:15:11 +02:00
public static final int BUTTONS_PER_PAGE = 13 ;
2015-09-06 23:18:50 +02:00
private static final int TOOLTIP_SPLIT_LENGTH = 160 ;
2015-08-30 01:19:03 +02:00
2015-09-02 20:06:34 +02:00
private static final int BUTTON_UPDATE_ID = CHAPTER_BUTTONS_START + BUTTONS_PER_PAGE ;
private static final int BUTTON_TWITTER_ID = BUTTON_UPDATE_ID + 1 ;
private static final int BUTTON_FORUM_ID = BUTTON_TWITTER_ID + 1 ;
private static final int BUTTON_ACHIEVEMENTS_ID = BUTTON_FORUM_ID + 1 ;
private static final int BUTTON_CONFIG_ID = BUTTON_ACHIEVEMENTS_ID + 1 ;
private int cursorCounter ;
2015-08-31 02:05:41 +02:00
private boolean mouseClicked ;
2015-08-30 19:10:10 +02:00
2015-08-31 02:05:41 +02:00
public GuiBooklet ( ) {
2015-08-28 21:17:09 +02:00
this . xSize = 146 ;
this . ySize = 180 ;
}
2015-08-29 15:40:12 +02:00
@Override
public void updateScreen ( ) {
super . updateScreen ( ) ;
this . searchField . updateCursorCounter ( ) ;
2015-09-02 20:06:34 +02:00
boolean buttonThere = UpdateChecker . doneChecking & & UpdateChecker . updateVersion > UpdateChecker . clientVersion ;
this . getButton ( BUTTON_UPDATE_ID ) . visible = buttonThere ;
if ( buttonThere ) {
this . cursorCounter + + ;
if ( this . cursorCounter % 8 = = 0 ) {
TexturedButton button = ( TexturedButton ) this . getButton ( BUTTON_UPDATE_ID ) ;
button . setTexturePos ( 245 , button . texturePosY = = 0 ? 22 : 0 ) ;
}
}
2015-08-29 15:40:12 +02:00
}
@SuppressWarnings ( " unchecked " )
@Override
public void keyTyped ( char theChar , int key ) {
if ( key ! = 1 & & this . searchField . isFocused ( ) ) {
this . searchField . textboxKeyTyped ( theChar , key ) ;
2015-08-29 17:32:39 +02:00
if ( this . currentIndexEntry instanceof BookletEntryAllSearch ) {
2015-08-29 15:40:12 +02:00
BookletEntryAllSearch currentEntry = ( BookletEntryAllSearch ) this . currentIndexEntry ;
if ( this . searchField . getText ( ) ! = null & & ! this . searchField . getText ( ) . isEmpty ( ) ) {
currentEntry . chapters . clear ( ) ;
for ( BookletChapter chapter : currentEntry . allChapters ) {
if ( chapter . getLocalizedName ( ) . toLowerCase ( ) . contains ( this . searchField . getText ( ) . toLowerCase ( ) ) ) {
currentEntry . chapters . add ( chapter ) ;
}
}
}
else {
currentEntry . chapters = ( ArrayList < BookletChapter > ) currentEntry . allChapters . clone ( ) ;
}
this . openIndexEntry ( this . currentIndexEntry , this . pageOpenInIndex , false ) ;
}
}
else {
super . keyTyped ( theChar , key ) ;
}
}
2015-08-30 19:10:10 +02:00
@Override
public void onGuiClosed ( ) {
PersistantVariables . saveBookPage ( this . currentIndexEntry , this . currentChapter , this . currentPage , this . pageOpenInIndex ) ;
}
2015-08-29 15:40:12 +02:00
@Override
protected void mouseClicked ( int par1 , int par2 , int par3 ) {
this . searchField . mouseClicked ( par1 , par2 , par3 ) ;
2015-08-31 02:09:34 +02:00
if ( par3 = = 0 & & this . currentChapter ! = null ) {
2015-08-31 02:05:41 +02:00
this . mouseClicked = true ;
}
2015-08-29 15:40:12 +02:00
super . mouseClicked ( par1 , par2 , par3 ) ;
}
2015-08-28 21:17:09 +02:00
@SuppressWarnings ( " unchecked " )
@Override
public void initGui ( ) {
this . guiLeft = ( this . width - this . xSize ) / 2 ;
this . guiTop = ( this . height - this . ySize ) / 2 ;
this . unicodeRenderer = new FontRenderer ( this . mc . gameSettings , new ResourceLocation ( " textures/font/ascii.png " ) , this . mc . renderEngine , true ) ;
2015-09-02 20:06:34 +02:00
this . addButton ( new TexturedButton ( BUTTON_FORWARD_ID , this . guiLeft + this . xSize , this . guiTop + this . ySize + 2 , 164 , 0 , 18 , 10 ) ) ;
this . addButton ( new TexturedButton ( BUTTON_BACK_ID , this . guiLeft - 18 , this . guiTop + this . ySize + 2 , 146 , 0 , 18 , 10 ) ) ;
this . addButton ( new TexturedButton ( BUTTON_RETURN_ID , this . guiLeft + this . xSize / 2 - 7 , this . guiTop + this . ySize + 2 , 182 , 0 , 15 , 10 ) ) ;
2015-08-28 21:17:09 +02:00
2015-08-30 01:19:03 +02:00
for ( int i = 0 ; i < BUTTONS_PER_PAGE ; i + + ) {
2015-09-10 21:25:34 +02:00
this . addButton ( new IndexButton ( CHAPTER_BUTTONS_START + i , guiLeft + 15 , guiTop + 10 + ( i * 12 ) , 110 , 10 , " " , this ) ) ;
2015-08-28 21:17:09 +02:00
}
2015-09-02 20:06:34 +02:00
this . addButton ( new TexturedButton ( BUTTON_UPDATE_ID , this . guiLeft - 11 , this . guiTop - 11 , 245 , 0 , 11 , 11 ) ) ;
this . getButton ( BUTTON_UPDATE_ID ) . visible = UpdateChecker . doneChecking & & UpdateChecker . updateVersion > UpdateChecker . clientVersion ;
this . addButton ( new TexturedButton ( BUTTON_TWITTER_ID , this . guiLeft , this . guiTop , 213 , 0 , 8 , 8 ) ) ;
this . addButton ( new TexturedButton ( BUTTON_FORUM_ID , this . guiLeft , this . guiTop + 10 , 221 , 0 , 8 , 8 ) ) ;
this . addButton ( new TexturedButton ( BUTTON_ACHIEVEMENTS_ID , this . guiLeft + 138 , this . guiTop , 205 , 0 , 8 , 8 ) ) ;
this . addButton ( new TexturedButton ( BUTTON_CONFIG_ID , this . guiLeft + 138 , this . guiTop + 10 , 197 , 0 , 8 , 8 ) ) ;
2015-08-28 21:17:09 +02:00
2015-08-29 15:40:12 +02:00
this . searchField = new GuiTextField ( this . unicodeRenderer , guiLeft + 148 , guiTop + 162 , 66 , 10 ) ;
this . searchField . setMaxStringLength ( 30 ) ;
this . searchField . setEnableBackgroundDrawing ( false ) ;
2015-08-28 21:17:09 +02:00
this . currentPage = null ;
this . currentChapter = null ;
this . currentIndexEntry = null ;
2015-08-29 15:40:12 +02:00
2015-08-30 19:10:10 +02:00
if ( ! PersistantVariables . getBoolean ( " BookAlreadyOpened " ) ) {
this . openIndexEntry ( InitBooklet . chapterIntro . entry , 1 , true ) ;
this . openChapter ( InitBooklet . chapterIntro , null ) ;
PersistantVariables . setBoolean ( " BookAlreadyOpened " , true ) ;
}
else {
PersistantVariables . openLastBookPage ( this ) ;
}
2015-08-28 21:17:09 +02:00
}
2015-09-02 20:06:34 +02:00
@SuppressWarnings ( " unchecked " )
private void addButton ( GuiButton button ) {
if ( this . buttonList . size ( ) > button . id ) {
this . buttonList . set ( button . id , button ) ;
}
else {
this . buttonList . add ( button . id , button ) ;
}
}
2015-09-06 23:18:50 +02:00
@Override
public boolean doesGuiPauseGame ( ) {
return false ;
}
2015-08-28 21:17:09 +02:00
private GuiButton getButton ( int id ) {
return ( GuiButton ) this . buttonList . get ( id ) ;
}
@Override
public void renderToolTip ( ItemStack stack , int x , int y ) {
super . renderToolTip ( stack , x , y ) ;
}
2015-08-29 17:32:39 +02:00
public void drawHoveringText ( List list , int x , int y ) {
super . func_146283_a ( list , x , y ) ;
}
2015-08-31 11:48:15 +02:00
@SuppressWarnings ( " unchecked " )
2015-08-28 21:17:09 +02:00
@Override
public void drawScreen ( int x , int y , float f ) {
GL11 . glColor4f ( 1 . 0F , 1 . 0F , 1 . 0F , 1 . 0F ) ;
this . mc . getTextureManager ( ) . bindTexture ( resLoc ) ;
2015-08-31 06:15:06 +02:00
this . drawTexturedModalRect ( this . guiLeft , this . guiTop , 0 , 0 , this . isGimmicky ( ) ? 256 : this . xSize , this . isGimmicky ( ) ? 256 : this . ySize ) ;
2015-08-28 21:17:09 +02:00
2015-08-29 17:32:39 +02:00
if ( this . currentIndexEntry instanceof BookletEntryAllSearch & & this . currentChapter = = null ) {
2015-08-29 15:40:12 +02:00
this . drawTexturedModalRect ( this . guiLeft + 146 , this . guiTop + 160 , 146 , 80 , 70 , 14 ) ;
}
2015-08-28 21:17:09 +02:00
if ( this . currentIndexEntry ! = null ) {
if ( this . currentChapter = = null ) {
this . drawCenteredString ( this . fontRendererObj , this . currentIndexEntry . getLocalizedName ( ) , this . guiLeft + this . xSize / 2 , this . guiTop - 8 , StringUtil . DECIMAL_COLOR_WHITE ) ;
}
2015-08-29 10:59:03 +02:00
else {
2015-08-28 21:17:09 +02:00
this . drawCenteredString ( this . fontRendererObj , this . currentChapter . getLocalizedName ( ) , this . guiLeft + this . xSize / 2 , this . guiTop - 8 , StringUtil . DECIMAL_COLOR_WHITE ) ;
2015-08-29 10:59:03 +02:00
}
2015-08-28 21:17:09 +02:00
}
2015-08-29 10:59:03 +02:00
else {
2015-08-28 21:17:09 +02:00
this . drawCenteredString ( this . fontRendererObj , StringUtil . localize ( " itemGroup. " + ModUtil . MOD_ID_LOWER ) , this . guiLeft + this . xSize / 2 , this . guiTop - 8 , StringUtil . DECIMAL_COLOR_WHITE ) ;
2015-08-29 10:59:03 +02:00
}
2015-08-28 21:17:09 +02:00
2015-08-29 10:59:03 +02:00
if ( this . currentIndexEntry ! = null ) {
if ( this . currentChapter ! = null & & this . currentPage ! = null ) {
this . drawCenteredString ( this . unicodeRenderer , this . currentPage . getID ( ) + " / " + this . currentChapter . pages . length , this . guiLeft + this . xSize / 2 , this . guiTop + 172 , StringUtil . DECIMAL_COLOR_WHITE ) ;
2015-08-31 02:05:41 +02:00
this . currentPage . renderPre ( this , x , y , this . mouseClicked ) ;
2015-08-29 10:59:03 +02:00
}
else {
this . drawCenteredString ( this . unicodeRenderer , this . pageOpenInIndex + " / " + this . indexPageAmount , this . guiLeft + this . xSize / 2 , this . guiTop + 172 , StringUtil . DECIMAL_COLOR_WHITE ) ;
}
2015-08-28 21:17:09 +02:00
}
2015-08-31 06:15:06 +02:00
if ( this . isGimmicky ( ) ) {
2015-09-12 20:35:43 +02:00
this . unicodeRenderer . drawSplitString ( " This book looks a lot like the one from Botania, doesn't it? Well, I think it does, too, and I'm kind of annoyed by it to be honest. Wasn't really meant to be that way. I guess I just kind of had the design of the Botania Book in mind when designing this. Well. I made the Code on my own, so I don't really care. Also: How did you find this gimmick? :P -Peck " , this . guiLeft - 80 - 3 , this . guiTop + 25 , 80 , StringUtil . DECIMAL_COLOR_WHITE ) ;
2015-08-31 06:15:06 +02:00
String strg = " Click this! I need followaz #Pathetic #DontTakeSeriously -> " ;
this . unicodeRenderer . drawString ( strg , this . guiLeft - this . unicodeRenderer . getStringWidth ( strg ) - 3 , this . guiTop , StringUtil . DECIMAL_COLOR_WHITE ) ;
if ( this . currentChapter = = InitBooklet . chapterIntro & & this . currentPage = = InitBooklet . chapterIntro . pages [ 1 ] ) {
strg = " Hey Hose, I kind of hate you a bit for that Ellopecko thing. (Not really! It's fun and games and stuff! :D) " ;
this . unicodeRenderer . drawString ( strg , this . guiLeft + this . xSize / 2 - this . unicodeRenderer . getStringWidth ( strg ) / 2 , this . guiTop - 20 , StringUtil . DECIMAL_COLOR_WHITE ) ;
}
}
2015-09-12 20:35:43 +02:00
else {
//TODO WIP Text
this . unicodeRenderer . drawSplitString ( ! KeyUtil . isShiftPressed ( ) ? EnumChatFormatting . ITALIC + " Press Shift! " : EnumChatFormatting . UNDERLINE + " WIP INFO: " + EnumChatFormatting . RESET + " \ nThis book is not completely finished yet! \ nThings still to come: \ n-Items for a Crafting Recipe shown in the book getting automatically put into a Crafting Table On A Stick through a button \ n-Seeing an Item's page by clicking a keybind while the item is getting hovered over in the player's inventory " , this . guiLeft + this . xSize + 3 , this . guiTop + 3 , 80 , StringUtil . DECIMAL_COLOR_WHITE ) ;
}
2015-08-31 06:15:06 +02:00
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-08-31 11:48:15 +02:00
if ( this . currentIndexEntry ! = null & & this . currentChapter ! = null & & this . currentPage ! = null ) {
this . currentPage . render ( this , x , y , this . mouseClicked ) ;
}
2015-08-28 21:17:09 +02:00
//Achievements Hover Text
2015-08-28 22:18:46 +02:00
if ( x > = this . guiLeft + 138 & & x < = this . guiLeft + 138 + 7 & & y > = this . guiTop & & y < = this . guiTop + 7 ) {
2015-08-31 11:48:15 +02:00
this . func_146283_a ( Collections . singletonList ( EnumChatFormatting . GOLD + " Show Achievements " ) , x , y ) ;
2015-08-28 21:17:09 +02:00
}
//Config Hover Text
2015-08-28 22:18:46 +02:00
if ( x > = this . guiLeft + 138 & & x < = this . guiLeft + 138 + 7 & & y > = this . guiTop + 10 & & y < = this . guiTop + 10 + 7 ) {
2015-08-31 11:48:15 +02:00
ArrayList list = new ArrayList ( ) ;
list . add ( EnumChatFormatting . GOLD + " Show Configuration GUI " ) ;
2015-09-06 23:18:50 +02:00
list . addAll ( this . fontRendererObj . listFormattedStringToWidth ( " It is highly recommended that you restart your game after changing anything as that prevents possible bugs occuring! " , TOOLTIP_SPLIT_LENGTH ) ) ;
2015-08-31 11:48:15 +02:00
this . func_146283_a ( list , x , y ) ;
2015-08-28 21:17:09 +02:00
}
2015-08-30 05:11:05 +02:00
//Twitter Hover Text
if ( x > = this . guiLeft & & x < = this . guiLeft + 7 & & y > = this . guiTop & & y < = this . guiTop + 7 ) {
2015-08-31 11:48:15 +02:00
this . func_146283_a ( Collections . singletonList ( EnumChatFormatting . GOLD + " Open @ActAddMod on Twitter in Browser " ) , x , y ) ;
2015-08-30 05:11:05 +02:00
}
//Forum Hover Text
if ( x > = this . guiLeft & & x < = this . guiLeft + 7 & & y > = this . guiTop + 10 & & y < = this . guiTop + 10 + 7 ) {
2015-08-31 11:48:15 +02:00
this . func_146283_a ( Collections . singletonList ( EnumChatFormatting . GOLD + " Open Minecraft Forum Post in Browser " ) , x , y ) ;
2015-08-28 22:18:46 +02:00
}
2015-09-02 20:06:34 +02:00
//Update Checker Hover Text
if ( x > = this . guiLeft - 11 & & x < = this . guiLeft - 11 + 10 & & y > = this . guiTop - 11 & & y < = this . guiTop - 11 + 10 ) {
if ( UpdateChecker . doneChecking & & UpdateChecker . updateVersion > UpdateChecker . clientVersion ) {
ArrayList list = new ArrayList ( ) ;
list . add ( EnumChatFormatting . GOLD + " There is an Update available! " ) ;
list . add ( EnumChatFormatting . ITALIC + " You have: " + ModUtil . VERSION + " , Newest: " + UpdateChecker . updateVersionS ) ;
2015-09-06 23:18:50 +02:00
list . addAll ( this . fontRendererObj . listFormattedStringToWidth ( EnumChatFormatting . ITALIC + " Updates include: " + UpdateChecker . changelog , TOOLTIP_SPLIT_LENGTH ) ) ;
list . add ( EnumChatFormatting . GRAY + " Click this button to visit the download page! " ) ;
2015-09-02 20:06:34 +02:00
this . func_146283_a ( list , x , y ) ;
}
}
2015-08-31 02:05:41 +02:00
if ( this . mouseClicked ) this . mouseClicked = false ;
2015-08-28 21:17:09 +02:00
}
2015-08-31 06:15:06 +02:00
private boolean isGimmicky ( ) {
return KeyUtil . isControlPressed ( ) & & KeyUtil . isShiftPressed ( ) & & KeyUtil . isAltPressed ( ) ;
}
2015-09-10 21:25:34 +02:00
private BookletPage getNextPage ( BookletChapter chapter , BookletPage currentPage ) {
2015-08-28 21:17:09 +02:00
for ( int i = 0 ; i < chapter . pages . length ; i + + ) {
if ( chapter . pages [ i ] = = currentPage ) {
if ( i + 1 < chapter . pages . length ) {
return chapter . pages [ i + 1 ] ;
}
}
}
return null ;
}
2015-09-10 21:25:34 +02:00
private BookletPage getPrevPage ( BookletChapter chapter , BookletPage currentPage ) {
2015-08-28 21:17:09 +02:00
for ( int i = 0 ; i < chapter . pages . length ; i + + ) {
if ( chapter . pages [ i ] = = currentPage ) {
if ( i - 1 > = 0 ) {
return chapter . pages [ i - 1 ] ;
}
}
}
return null ;
}
@Override
public void actionPerformed ( GuiButton button ) {
2015-09-02 20:06:34 +02:00
if ( button . id = = BUTTON_UPDATE_ID ) {
if ( UpdateChecker . doneChecking & & UpdateChecker . updateVersion > UpdateChecker . clientVersion ) {
try {
if ( Desktop . isDesktopSupported ( ) ) {
Desktop . getDesktop ( ) . browse ( new URI ( UpdateChecker . DOWNLOAD_LINK ) ) ;
}
}
catch ( Exception e ) {
ModUtil . LOGGER . error ( " Something bad happened when trying to open a URL! " , e ) ;
}
}
}
else if ( button . id = = BUTTON_TWITTER_ID ) {
2015-08-30 05:11:05 +02:00
try {
if ( Desktop . isDesktopSupported ( ) ) {
2015-09-02 20:06:34 +02:00
Desktop . getDesktop ( ) . browse ( new URI ( " http://twitter.com/ActAddMod " ) ) ;
2015-08-30 05:11:05 +02:00
}
}
catch ( Exception e ) {
2015-09-02 20:06:34 +02:00
ModUtil . LOGGER . error ( " Something bad happened when trying to open a URL! " , e ) ;
2015-08-30 05:11:05 +02:00
}
}
else if ( button . id = = BUTTON_FORUM_ID ) {
try {
if ( Desktop . isDesktopSupported ( ) ) {
Desktop . getDesktop ( ) . browse ( new URI ( " http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/wip-mods/2374910-actually-additions-a-bunch-of-awesome-gadgets " ) ) ;
}
}
catch ( Exception e ) {
2015-09-02 20:06:34 +02:00
ModUtil . LOGGER . error ( " Something bad happened when trying to open a URL! " , e ) ;
2015-08-30 05:11:05 +02:00
}
}
else if ( button . id = = BUTTON_CONFIG_ID ) {
2015-08-28 21:17:09 +02:00
mc . displayGuiScreen ( new GuiConfiguration ( this ) ) ;
}
else if ( button . id = = BUTTON_ACHIEVEMENTS_ID ) {
mc . displayGuiScreen ( new GuiAAAchievements ( this , mc . thePlayer . getStatFileWriter ( ) ) ) ;
}
else if ( button . id = = BUTTON_FORWARD_ID ) {
2015-08-29 10:59:03 +02:00
if ( this . currentIndexEntry ! = null ) {
if ( this . currentPage ! = null ) {
2015-09-10 21:25:34 +02:00
BookletPage page = this . getNextPage ( this . currentChapter , this . currentPage ) ;
2015-08-29 10:59:03 +02:00
if ( page ! = null ) this . currentPage = page ;
}
else {
2015-09-09 23:44:53 +02:00
this . openIndexEntry ( this . currentIndexEntry , this . pageOpenInIndex + 1 , ! ( this . currentIndexEntry instanceof BookletEntryAllSearch ) ) ;
2015-08-29 10:59:03 +02:00
}
}
2015-08-28 21:17:09 +02:00
}
else if ( button . id = = BUTTON_BACK_ID ) {
2015-08-29 10:59:03 +02:00
if ( this . currentIndexEntry ! = null ) {
if ( this . currentPage ! = null ) {
2015-09-10 21:25:34 +02:00
BookletPage page = this . getPrevPage ( this . currentChapter , this . currentPage ) ;
2015-08-29 10:59:03 +02:00
if ( page ! = null ) this . currentPage = page ;
}
else {
2015-09-09 23:44:53 +02:00
this . openIndexEntry ( this . currentIndexEntry , this . pageOpenInIndex - 1 , ! ( this . currentIndexEntry instanceof BookletEntryAllSearch ) ) ;
2015-08-29 10:59:03 +02:00
}
}
2015-08-28 21:17:09 +02:00
}
else if ( button . id = = BUTTON_RETURN_ID ) {
2015-08-30 19:10:10 +02:00
if ( this . currentChapter ! = null & & this . currentChapter ! = InitBooklet . chapterIntro ) {
2015-08-29 15:40:12 +02:00
this . openIndexEntry ( this . currentIndexEntry , this . pageOpenInIndex , true ) ;
2015-08-29 10:59:03 +02:00
}
else {
2015-08-29 15:40:12 +02:00
this . openIndexEntry ( null , 1 , true ) ;
2015-08-28 21:17:09 +02:00
}
}
else if ( button . id > = CHAPTER_BUTTONS_START ) {
int actualButton = button . id - CHAPTER_BUTTONS_START ;
if ( this . currentIndexEntry ! = null ) {
if ( this . currentChapter = = null ) {
2015-08-29 01:09:09 +02:00
if ( actualButton < this . currentIndexEntry . chapters . size ( ) ) {
2015-08-30 01:19:03 +02:00
BookletChapter chap = currentIndexEntry . chapters . get ( actualButton + ( BUTTONS_PER_PAGE * this . pageOpenInIndex - BUTTONS_PER_PAGE ) ) ;
2015-08-29 17:32:39 +02:00
this . openChapter ( chap , chap . pages [ 0 ] ) ;
2015-08-28 21:17:09 +02:00
}
}
}
else {
if ( actualButton < InitBooklet . entries . size ( ) ) {
2015-08-29 15:40:12 +02:00
this . openIndexEntry ( InitBooklet . entries . get ( actualButton ) , 1 , true ) ;
2015-08-28 21:17:09 +02:00
}
}
}
if ( button . id = = BUTTON_FORWARD_ID | | button . id = = BUTTON_BACK_ID ) {
2015-08-29 10:59:03 +02:00
if ( this . currentChapter ! = null & & this . currentIndexEntry ! = null ) {
if ( this . currentPage ! = null ) {
this . getButton ( BUTTON_FORWARD_ID ) . visible = this . getNextPage ( this . currentChapter , this . currentPage ) ! = null ;
this . getButton ( BUTTON_BACK_ID ) . visible = this . getPrevPage ( this . currentChapter , this . currentPage ) ! = null ;
}
}
2015-08-28 21:17:09 +02:00
}
}
2015-08-29 15:40:12 +02:00
@SuppressWarnings ( " unchecked " )
2015-08-30 19:10:10 +02:00
public void openIndexEntry ( BookletIndexEntry entry , int page , boolean resetTextField ) {
2015-08-29 15:40:12 +02:00
if ( resetTextField ) {
2015-08-29 17:32:39 +02:00
this . searchField . setVisible ( entry instanceof BookletEntryAllSearch ) ;
this . searchField . setFocused ( entry instanceof BookletEntryAllSearch ) ;
2015-08-29 15:40:12 +02:00
this . searchField . setText ( " " ) ;
2015-08-29 17:32:39 +02:00
if ( entry instanceof BookletEntryAllSearch ) {
2015-08-29 15:40:12 +02:00
entry . chapters = ( ArrayList < BookletChapter > ) ( ( BookletEntryAllSearch ) entry ) . allChapters . clone ( ) ;
}
}
2015-08-29 10:59:03 +02:00
this . currentPage = null ;
this . currentChapter = null ;
2015-08-28 21:17:09 +02:00
this . currentIndexEntry = entry ;
2015-08-30 01:19:03 +02:00
this . indexPageAmount = entry = = null ? 1 : entry . chapters . size ( ) / BUTTONS_PER_PAGE + 1 ;
2015-09-05 00:15:11 +02:00
this . pageOpenInIndex = entry = = null ? 1 : ( this . indexPageAmount < = page | | page < = 0 ? this . indexPageAmount : page ) ;
2015-08-28 21:17:09 +02:00
this . getButton ( BUTTON_RETURN_ID ) . visible = entry ! = null ;
2015-08-29 10:59:03 +02:00
this . getButton ( BUTTON_FORWARD_ID ) . visible = this . pageOpenInIndex < this . indexPageAmount ;
this . getButton ( BUTTON_BACK_ID ) . visible = this . pageOpenInIndex > 1 ;
2015-08-28 21:17:09 +02:00
2015-08-30 04:02:28 +02:00
for ( int i = 0 ; i < BUTTONS_PER_PAGE ; i + + ) {
2015-09-10 21:25:34 +02:00
IndexButton button = ( IndexButton ) this . getButton ( CHAPTER_BUTTONS_START + i ) ;
2015-08-28 21:17:09 +02:00
if ( entry = = null ) {
2015-08-30 01:19:03 +02:00
boolean entryExists = InitBooklet . entries . size ( ) > i + ( BUTTONS_PER_PAGE * this . pageOpenInIndex - BUTTONS_PER_PAGE ) ;
2015-08-28 21:17:09 +02:00
button . visible = entryExists ;
2015-08-29 10:59:03 +02:00
if ( entryExists ) {
2015-08-30 01:19:03 +02:00
button . displayString = InitBooklet . entries . get ( i + ( BUTTONS_PER_PAGE * this . pageOpenInIndex - BUTTONS_PER_PAGE ) ) . getLocalizedName ( ) ;
2015-09-10 21:25:34 +02:00
button . chap = null ;
2015-08-29 10:59:03 +02:00
}
2015-08-28 21:17:09 +02:00
}
else {
2015-08-30 01:19:03 +02:00
boolean entryExists = entry . chapters . size ( ) > i + ( BUTTONS_PER_PAGE * this . pageOpenInIndex - BUTTONS_PER_PAGE ) ;
2015-08-28 21:17:09 +02:00
button . visible = entryExists ;
2015-08-29 15:40:12 +02:00
if ( entryExists ) {
2015-09-10 21:25:34 +02:00
BookletChapter chap = entry . chapters . get ( i + ( BUTTONS_PER_PAGE * this . pageOpenInIndex - BUTTONS_PER_PAGE ) ) ;
button . displayString = chap . getLocalizedName ( ) ;
button . chap = chap ;
2015-08-29 15:40:12 +02:00
}
2015-08-28 21:17:09 +02:00
}
}
}
2015-09-10 21:25:34 +02:00
public void openChapter ( BookletChapter chapter , BookletPage page ) {
2015-08-28 21:17:09 +02:00
if ( chapter = = null ) return ;
2015-08-29 15:40:12 +02:00
this . searchField . setVisible ( false ) ;
this . searchField . setFocused ( false ) ;
this . searchField . setText ( " " ) ;
2015-08-28 21:17:09 +02:00
this . currentChapter = chapter ;
2015-08-29 17:32:39 +02:00
this . currentPage = page ! = null & & this . hasPage ( chapter , page ) ? page : chapter . pages [ 0 ] ;
2015-08-28 21:17:09 +02:00
2015-08-29 17:32:39 +02:00
this . getButton ( BUTTON_FORWARD_ID ) . visible = this . getNextPage ( chapter , this . currentPage ) ! = null ;
2015-08-30 01:19:03 +02:00
this . getButton ( BUTTON_BACK_ID ) . visible = this . getPrevPage ( chapter , this . currentPage ) ! = null ;
2015-08-28 21:17:09 +02:00
2015-08-30 01:19:03 +02:00
for ( int i = 0 ; i < BUTTONS_PER_PAGE ; i + + ) {
2015-08-28 21:17:09 +02:00
GuiButton button = this . getButton ( CHAPTER_BUTTONS_START + i ) ;
button . visible = false ;
}
}
2015-09-10 21:25:34 +02:00
private boolean hasPage ( BookletChapter chapter , BookletPage page ) {
for ( BookletPage aPage : chapter . pages ) {
2015-08-29 17:32:39 +02:00
if ( aPage = = page ) {
return true ;
}
}
return false ;
}
2015-08-28 21:17:09 +02:00
private static class IndexButton extends GuiButton {
2015-09-10 21:25:34 +02:00
private GuiBooklet gui ;
public BookletChapter chap ;
2015-08-28 21:17:09 +02:00
2015-09-10 21:25:34 +02:00
public IndexButton ( int id , int x , int y , int width , int height , String text , GuiBooklet gui ) {
2015-08-28 21:17:09 +02:00
super ( id , x , y , width , height , text ) ;
2015-09-10 21:25:34 +02:00
this . gui = gui ;
2015-08-28 21:17:09 +02:00
}
@Override
public void drawButton ( Minecraft minecraft , int mouseX , int mouseY ) {
if ( this . visible ) {
GL11 . glColor4f ( 1 . 0F , 1 . 0F , 1 . 0F , 1 . 0F ) ;
this . field_146123_n = mouseX > = this . xPosition & & mouseY > = this . yPosition & & mouseX < this . xPosition + this . width & & mouseY < this . yPosition + this . height ;
GL11 . glEnable ( GL11 . GL_BLEND ) ;
OpenGlHelper . glBlendFunc ( 770 , 771 , 1 , 0 ) ;
GL11 . glBlendFunc ( GL11 . GL_SRC_ALPHA , GL11 . GL_ONE_MINUS_SRC_ALPHA ) ;
this . mouseDragged ( minecraft , mouseX , mouseY ) ;
int color = 0 ;
if ( this . field_146123_n ) {
color = 38144 ;
}
2015-09-10 21:25:34 +02:00
int textOffsetX = 0 ;
if ( this . chap ! = null ) {
if ( this . chap . displayStack ! = null ) {
GL11 . glPushMatrix ( ) ;
BookletPage . renderItem ( this . gui , this . chap . displayStack , this . xPosition - 5 , this . yPosition , 0 . 725F ) ;
GL11 . glPopMatrix ( ) ;
textOffsetX = 8 ;
}
}
this . gui . unicodeRenderer . drawString ( ( this . field_146123_n ? EnumChatFormatting . UNDERLINE : " " ) + this . displayString , this . xPosition + textOffsetX , this . yPosition + ( this . height - 8 ) / 2 , color ) ;
2015-08-28 21:17:09 +02:00
}
}
}
private static class TexturedButton extends GuiButton {
2015-09-02 20:06:34 +02:00
public int texturePosX ;
public int texturePosY ;
2015-08-28 21:17:09 +02:00
public TexturedButton ( int id , int x , int y , int texturePosX , int texturePosY , int width , int height ) {
super ( id , x , y , width , height , " " ) ;
this . texturePosX = texturePosX ;
this . texturePosY = texturePosY ;
}
2015-09-02 20:06:34 +02:00
public void setTexturePos ( int x , int y ) {
this . texturePosX = x ;
this . texturePosY = y ;
}
2015-08-28 21:17:09 +02:00
@Override
public void drawButton ( Minecraft minecraft , int x , int y ) {
if ( this . visible ) {
minecraft . getTextureManager ( ) . bindTexture ( resLoc ) ;
GL11 . glColor4f ( 1 . 0F , 1 . 0F , 1 . 0F , 1 . 0F ) ;
this . field_146123_n = x > = this . xPosition & & y > = this . yPosition & & x < this . xPosition + this . width & & y < this . yPosition + this . height ;
int k = this . getHoverState ( this . field_146123_n ) ;
2015-09-02 20:06:34 +02:00
if ( k = = 0 ) k = 1 ;
2015-08-28 21:17:09 +02:00
GL11 . glEnable ( GL11 . GL_BLEND ) ;
OpenGlHelper . glBlendFunc ( 770 , 771 , 1 , 0 ) ;
GL11 . glBlendFunc ( GL11 . GL_SRC_ALPHA , GL11 . GL_ONE_MINUS_SRC_ALPHA ) ;
this . drawTexturedModalRect ( this . xPosition , this . yPosition , this . texturePosX , this . texturePosY - this . height + k * this . height , this . width , this . height ) ;
this . mouseDragged ( minecraft , x , y ) ;
}
}
}
}