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-10-18 19:56:18 +02:00
import ellpeck.actuallyadditions.proxy.ClientProxy ;
2015-09-02 20:06:34 +02:00
import ellpeck.actuallyadditions.update.UpdateChecker ;
2015-10-28 18:28:30 +01:00
import ellpeck.actuallyadditions.util.* ;
2015-09-30 06:56:33 +02:00
import ellpeck.actuallyadditions.util.playerdata.PersistentClientData ;
2015-08-28 21:17:09 +02:00
import net.minecraft.client.Minecraft ;
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 ;
2015-08-30 01:19:03 +02:00
import net.minecraft.util.EnumChatFormatting ;
2015-10-28 18:28:30 +01:00
import net.minecraft.util.IChatComponent ;
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 {
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-10-03 10:16:18 +02:00
public static final int CHAPTER_BUTTONS_AMOUNT = 13 ;
public static final int TOOLTIP_SPLIT_LENGTH = 200 ;
2015-08-28 21:17:09 +02:00
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-10-30 23:37:20 +01:00
private GuiButton buttonForward ;
private GuiButton buttonBackward ;
private GuiButton buttonPreviousScreen ;
private GuiButton buttonPreviouslyOpenedGui ;
private GuiButton buttonUpdate ;
private GuiButton buttonTwitter ;
private GuiButton buttonForum ;
private GuiButton buttonAchievements ;
private GuiButton buttonConfig ;
private GuiButton [ ] chapterButtons = new GuiButton [ CHAPTER_BUTTONS_AMOUNT ] ;
public GuiTextField searchField ;
2015-09-28 23:39:34 +02:00
private int ticksElapsed ;
2015-10-04 13:21:07 +02:00
private boolean mousePressed ;
2015-08-30 19:10:10 +02:00
2015-09-24 23:42:03 +02:00
private GuiScreen parentScreen ;
public GuiBooklet ( GuiScreen parentScreen ) {
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-08-28 21:17:09 +02:00
}
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 ) {
2015-10-03 19:19:26 +02:00
boolean unicodeBefore = this . fontRendererObj . getUnicodeFlag ( ) ;
this . fontRendererObj . setUnicodeFlag ( true ) ;
2015-08-28 21:17:09 +02:00
GL11 . glColor4f ( 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-10-18 19:56:18 +02:00
this . mc . getTextureManager ( ) . bindTexture ( resLoc ) ;
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-10-03 19:19:26 +02:00
this . fontRendererObj . setUnicodeFlag ( false ) ;
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-10-03 19:19:26 +02:00
this . fontRendererObj . setUnicodeFlag ( true ) ;
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 ) {
2015-10-03 19:19:26 +02:00
this . drawCenteredString ( this . fontRendererObj , this . currentPage . getID ( ) + " / " + this . currentChapter . pages . length , this . guiLeft + this . xSize / 2 , this . guiTop + 172 , StringUtil . DECIMAL_COLOR_WHITE ) ;
2015-10-04 13:21:07 +02:00
this . currentPage . renderPre ( this , x , y , this . ticksElapsed , this . mousePressed ) ;
2015-08-29 10:59:03 +02:00
}
else {
2015-10-03 19:19:26 +02:00
this . drawCenteredString ( this . fontRendererObj , this . pageOpenInIndex + " / " + this . indexPageAmount , this . guiLeft + this . xSize / 2 , this . guiTop + 172 , StringUtil . DECIMAL_COLOR_WHITE ) ;
2015-08-29 10:59:03 +02:00
}
2015-08-28 21:17:09 +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 ) {
2015-10-04 13:21:07 +02:00
this . currentPage . render ( this , x , y , this . ticksElapsed , this . mousePressed ) ;
2015-08-31 11:48:15 +02:00
}
2015-10-03 19:19:26 +02:00
this . fontRendererObj . setUnicodeFlag ( false ) ;
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 ) {
2015-10-28 18:28:30 +01:00
ArrayList list = new ArrayList ( ) ;
if ( UpdateChecker . checkFailed ) {
list . add ( IChatComponent . Serializer . func_150699_a ( StringUtil . localize ( " info. " + ModUtil . MOD_ID_LOWER + " .update.failed " ) ) . getFormattedText ( ) ) ;
}
else if ( UpdateChecker . needsUpdateNotify ) {
list . add ( IChatComponent . Serializer . func_150699_a ( StringUtil . localize ( " info. " + ModUtil . MOD_ID_LOWER + " .update.generic " ) ) . getFormattedText ( ) ) ;
list . add ( IChatComponent . Serializer . func_150699_a ( StringUtil . localizeFormatted ( " info. " + ModUtil . MOD_ID_LOWER + " .update.versionCompare " , ModUtil . VERSION , UpdateChecker . updateVersion ) ) . getFormattedText ( ) ) ;
list . add ( StringUtil . localize ( " info. " + ModUtil . MOD_ID_LOWER + " .update.buttonOptions " ) ) ;
2015-09-02 20:06:34 +02:00
}
2015-10-28 18:28:30 +01:00
this . func_146283_a ( list , x , y ) ;
2015-09-02 20:06:34 +02:00
}
2015-08-31 02:05:41 +02:00
2015-10-03 19:19:26 +02:00
this . fontRendererObj . setUnicodeFlag ( unicodeBefore ) ;
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 ) {
if ( key ! = 1 & & this . searchField . isFocused ( ) ) {
this . searchField . textboxKeyTyped ( theChar , key ) ;
2015-10-30 23:37:20 +01:00
this . updateSearchBar ( ) ;
}
else {
super . keyTyped ( theChar , key ) ;
}
}
2015-08-31 06:15:06 +02:00
2015-10-30 23:37:20 +01:00
@SuppressWarnings ( " unchecked " )
public void updateSearchBar ( ) {
if ( this . currentIndexEntry instanceof BookletEntryAllSearch ) {
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 ) ;
2015-10-03 10:19:40 +02:00
}
}
2015-08-28 21:17:09 +02:00
}
2015-10-30 23:37:20 +01:00
else {
currentEntry . chapters = ( ArrayList < BookletChapter > ) currentEntry . allChapters . clone ( ) ;
}
this . openIndexEntry ( this . currentIndexEntry , this . pageOpenInIndex , false ) ;
2015-10-03 10:19:40 +02:00
}
2015-08-28 21:17:09 +02:00
}
2015-10-03 10:19:40 +02:00
@Override
protected void mouseClicked ( int par1 , int par2 , int par3 ) {
this . searchField . mouseClicked ( par1 , par2 , par3 ) ;
2015-10-04 13:21:07 +02:00
2015-10-04 15:24:11 +02:00
if ( par3 = = 0 & & this . currentChapter ! = null ) {
2015-10-04 13:21:07 +02:00
this . mousePressed = true ;
}
2015-10-03 10:19:40 +02:00
super . mouseClicked ( par1 , par2 , par3 ) ;
2015-08-28 21:17:09 +02:00
}
@Override
public void actionPerformed ( GuiButton button ) {
2015-09-30 19:18:13 +02:00
if ( button = = this . buttonPreviouslyOpenedGui ) {
2015-09-28 22:22:43 +02:00
if ( this . parentScreen ! = null ) {
mc . displayGuiScreen ( this . parentScreen ) ;
}
}
2015-09-30 19:18:13 +02:00
else if ( button = = this . buttonUpdate ) {
2015-10-28 18:28:30 +01:00
if ( UpdateChecker . needsUpdateNotify ) {
2015-09-02 20:06:34 +02:00
try {
if ( Desktop . isDesktopSupported ( ) ) {
2015-10-28 18:28:30 +01:00
if ( KeyUtil . isShiftPressed ( ) ) {
Desktop . getDesktop ( ) . browse ( new URI ( UpdateChecker . DOWNLOAD_LINK ) ) ;
}
else {
Desktop . getDesktop ( ) . browse ( new URI ( UpdateChecker . CHANGELOG_LINK ) ) ;
}
2015-09-02 20:06:34 +02:00
}
}
catch ( Exception e ) {
ModUtil . LOGGER . error ( " Something bad happened when trying to open a URL! " , e ) ;
}
}
}
2015-09-30 19:18:13 +02:00
else if ( button = = this . buttonTwitter ) {
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
}
}
2015-09-30 19:18:13 +02:00
else if ( button = = this . buttonForum ) {
2015-08-30 05:11:05 +02:00
try {
if ( Desktop . isDesktopSupported ( ) ) {
2015-10-29 21:27:56 +01:00
Desktop . getDesktop ( ) . browse ( new URI ( " http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2551118 " ) ) ;
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
}
}
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-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-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-10-03 10:16:18 +02:00
if ( page ! = null ) {
this . currentPage = page ;
}
2015-09-28 22:26:43 +02:00
2015-09-30 19:18:13 +02:00
this . buttonForward . visible = this . getNextPage ( this . currentChapter , this . currentPage ) ! = null ;
this . buttonBackward . visible = this . getPrevPage ( this . currentChapter , this . currentPage ) ! = null ;
2015-08-29 10:59:03 +02:00
}
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
}
2015-09-30 19:18:13 +02:00
else if ( button = = this . buttonBackward ) {
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-10-03 10:16:18 +02:00
if ( page ! = null ) {
this . currentPage = page ;
}
2015-09-28 22:26:43 +02:00
2015-09-30 19:18:13 +02:00
this . buttonForward . visible = this . getNextPage ( this . currentChapter , this . currentPage ) ! = null ;
this . buttonBackward . visible = this . getPrevPage ( this . currentChapter , this . currentPage ) ! = null ;
2015-08-29 10:59:03 +02:00
}
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
}
2015-09-30 19:18:13 +02:00
else if ( button = = this . buttonPreviousScreen ) {
2015-09-28 22:22:43 +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
}
}
2015-09-30 19:18:13 +02:00
else {
int place = Util . arrayContains ( this . chapterButtons , button ) ;
if ( place > = 0 ) {
if ( this . currentIndexEntry ! = null ) {
if ( this . currentChapter = = null ) {
if ( place < this . currentIndexEntry . chapters . size ( ) ) {
BookletChapter chap = currentIndexEntry . chapters . get ( place + ( this . chapterButtons . length * this . pageOpenInIndex - this . chapterButtons . length ) ) ;
this . openChapter ( chap , chap . pages [ 0 ] ) ;
}
2015-08-28 21:17:09 +02:00
}
}
2015-09-30 19:18:13 +02:00
else {
if ( place < InitBooklet . entries . size ( ) ) {
this . openIndexEntry ( InitBooklet . entries . get ( place ) , 1 , true ) ;
}
2015-08-28 21:17:09 +02:00
}
}
}
}
2015-10-03 10:19:40 +02:00
@SuppressWarnings ( " unchecked " )
@Override
public void initGui ( ) {
this . guiLeft = ( this . width - this . xSize ) / 2 ;
this . guiTop = ( this . height - this . ySize ) / 2 ;
this . buttonForward = new TexturedButton ( 0 , this . guiLeft + this . xSize , this . guiTop + this . ySize + 2 , 164 , 0 , 18 , 10 ) ;
this . buttonList . add ( this . buttonForward ) ;
this . buttonBackward = new TexturedButton ( 1 , this . guiLeft - 18 , this . guiTop + this . ySize + 2 , 146 , 0 , 18 , 10 ) ;
this . buttonList . add ( this . buttonBackward ) ;
this . buttonPreviousScreen = new TexturedButton ( 2 , this . guiLeft + this . xSize / 2 - 7 , this . guiTop + this . ySize + 2 , 182 , 0 , 15 , 10 ) ;
this . buttonList . add ( this . buttonPreviousScreen ) ;
this . buttonPreviouslyOpenedGui = new TexturedButton ( 3 , this . guiLeft + this . xSize / 3 , this . guiTop + this . ySize + 2 , 245 , 44 , 11 , 15 ) ;
this . buttonList . add ( this . buttonPreviouslyOpenedGui ) ;
this . buttonUpdate = new TexturedButton ( 4 , this . guiLeft - 11 , this . guiTop - 11 , 245 , 0 , 11 , 11 ) ;
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 ) ;
this . buttonTwitter = new TexturedButton ( 5 , this . guiLeft , this . guiTop , 213 , 0 , 8 , 8 ) ;
this . buttonList . add ( this . buttonTwitter ) ;
this . buttonForum = new TexturedButton ( 6 , this . guiLeft , this . guiTop + 10 , 221 , 0 , 8 , 8 ) ;
this . buttonList . add ( this . buttonForum ) ;
this . buttonAchievements = new TexturedButton ( 7 , this . guiLeft + 138 , this . guiTop , 205 , 0 , 8 , 8 ) ;
this . buttonList . add ( this . buttonAchievements ) ;
this . buttonConfig = new TexturedButton ( 8 , this . guiLeft + 138 , this . guiTop + 10 , 197 , 0 , 8 , 8 ) ;
this . buttonList . add ( this . buttonConfig ) ;
for ( int i = 0 ; i < this . chapterButtons . length ; i + + ) {
this . chapterButtons [ i ] = new IndexButton ( 9 + i , guiLeft + 15 , guiTop + 10 + ( i * 12 ) , 115 , 10 , " " , this ) ;
this . buttonList . add ( this . chapterButtons [ i ] ) ;
}
2015-10-03 19:19:26 +02:00
this . searchField = new GuiTextField ( 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
this . currentPage = null ;
this . currentChapter = null ;
this . currentIndexEntry = null ;
2015-10-18 15:31:01 +02:00
//So that the First Page will still open if used via something like NEI before
2015-10-13 03:43:41 +02:00
if ( this . parentScreen = = null & & ! PersistentClientData . getBoolean ( " BookAlreadyOpened " ) ) {
2015-10-03 10:19:40 +02:00
this . openIndexEntry ( InitBooklet . chapterIntro . entry , 1 , true ) ;
this . openChapter ( InitBooklet . chapterIntro , null ) ;
PersistentClientData . setBoolean ( " BookAlreadyOpened " , true ) ;
}
else {
PersistentClientData . openLastBookPage ( this ) ;
}
}
@Override
public void updateScreen ( ) {
super . updateScreen ( ) ;
this . searchField . updateCursorCounter ( ) ;
if ( this . currentIndexEntry ! = null & & this . currentChapter ! = null & & this . currentPage ! = null ) {
this . currentPage . updateScreen ( this . ticksElapsed ) ;
}
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 ) {
TexturedButton button = ( TexturedButton ) this . buttonUpdate ;
button . setTexturePos ( 245 , button . texturePosY = = 0 ? 22 : 0 ) ;
}
}
this . ticksElapsed + + ;
}
@Override
public void onGuiClosed ( ) {
2015-10-30 23:37:20 +01:00
PersistentClientData . saveBookPage ( this . currentIndexEntry , this . currentChapter , this . currentPage , this . pageOpenInIndex , this . searchField . getText ( ) ) ;
2015-10-03 10:19:40 +02:00
}
@Override
public boolean doesGuiPauseGame ( ) {
return false ;
}
2015-10-03 22:13:57 +02:00
private BookletPage getNextPage ( BookletChapter chapter , BookletPage currentPage ) {
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 ;
}
private BookletPage getPrevPage ( BookletChapter chapter , BookletPage currentPage ) {
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 ;
}
2015-10-03 10:19:40 +02:00
public void openChapter ( BookletChapter chapter , BookletPage page ) {
if ( chapter = = null ) {
return ;
}
this . searchField . setVisible ( false ) ;
this . searchField . setFocused ( false ) ;
this . searchField . setText ( " " ) ;
this . currentChapter = chapter ;
this . currentPage = page ! = null & & this . hasPage ( chapter , page ) ? page : chapter . pages [ 0 ] ;
this . buttonForward . visible = this . getNextPage ( chapter , this . currentPage ) ! = null ;
this . buttonBackward . visible = this . getPrevPage ( chapter , this . currentPage ) ! = null ;
this . buttonPreviousScreen . visible = true ;
this . buttonPreviouslyOpenedGui . visible = this . parentScreen ! = null ;
for ( GuiButton chapterButton : this . chapterButtons ) {
chapterButton . visible = false ;
}
}
private boolean hasPage ( BookletChapter chapter , BookletPage page ) {
for ( BookletPage aPage : chapter . pages ) {
if ( aPage = = page ) {
return true ;
}
}
return false ;
}
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-10-10 03:39:42 +02:00
this . searchField . setVisible ( entry instanceof BookletEntryAllSearch ) ;
this . searchField . setFocused ( entry instanceof BookletEntryAllSearch ) ;
2015-08-29 15:40:12 +02:00
if ( resetTextField ) {
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-09-30 19:18:13 +02:00
this . indexPageAmount = entry = = null ? 1 : entry . chapters . size ( ) / this . chapterButtons . length + 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
2015-09-30 19:18:13 +02:00
this . buttonPreviousScreen . visible = entry ! = null ;
this . buttonForward . visible = this . pageOpenInIndex < this . indexPageAmount ;
this . buttonBackward . visible = this . pageOpenInIndex > 1 ;
this . buttonPreviouslyOpenedGui . visible = this . parentScreen ! = null ;
2015-08-28 21:17:09 +02:00
2015-09-30 19:18:13 +02:00
for ( int i = 0 ; i < this . chapterButtons . length ; i + + ) {
IndexButton button = ( IndexButton ) this . chapterButtons [ i ] ;
2015-08-28 21:17:09 +02:00
if ( entry = = null ) {
2015-09-30 19:18:13 +02:00
boolean entryExists = InitBooklet . entries . size ( ) > i ;
2015-08-28 21:17:09 +02:00
button . visible = entryExists ;
2015-08-29 10:59:03 +02:00
if ( entryExists ) {
2015-10-23 19:05:02 +02:00
button . displayString = InitBooklet . entries . get ( i ) . getNameWithColor ( ) ;
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-09-30 19:18:13 +02:00
boolean entryExists = entry . chapters . size ( ) > i + ( this . chapterButtons . length * this . pageOpenInIndex - this . chapterButtons . length ) ;
2015-08-28 21:17:09 +02:00
button . visible = entryExists ;
2015-08-29 15:40:12 +02:00
if ( entryExists ) {
2015-09-30 19:18:13 +02:00
BookletChapter chap = entry . chapters . get ( i + ( this . chapterButtons . length * this . pageOpenInIndex - this . chapterButtons . length ) ) ;
2015-10-23 19:05:02 +02:00
button . displayString = chap . getNameWithColor ( ) ;
2015-09-10 21:25:34 +02:00
button . chap = chap ;
2015-08-29 15:40:12 +02:00
}
2015-08-28 21:17:09 +02:00
}
}
}
private static class IndexButton extends GuiButton {
2015-09-10 21:25:34 +02:00
public BookletChapter chap ;
2015-10-03 10:16:18 +02:00
private GuiBooklet gui ;
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 ) ;
2015-09-10 21:25:34 +02:00
int textOffsetX = 0 ;
if ( this . chap ! = null ) {
if ( this . chap . displayStack ! = null ) {
GL11 . glPushMatrix ( ) ;
2015-10-23 19:05:02 +02:00
BookletPage . renderItem ( this . gui , this . chap . displayStack , this . xPosition - 4 , this . yPosition , 0 . 725F ) ;
2015-09-10 21:25:34 +02:00
GL11 . glPopMatrix ( ) ;
2015-10-23 19:05:02 +02:00
textOffsetX = 10 ;
2015-09-10 21:25:34 +02:00
}
}
2015-10-23 19:05:02 +02:00
if ( this . field_146123_n ) {
GL11 . glPushMatrix ( ) ;
AssetUtil . drawHorizontalGradientRect ( this . xPosition + textOffsetX - 1 , this . yPosition + this . height - 1 , this . xPosition + this . gui . fontRendererObj . getStringWidth ( this . displayString ) + textOffsetX + 1 , this . yPosition + this . height , 0x80 < < 24 | 22271 , 22271 ) ;
GL11 . glPopMatrix ( ) ;
}
this . gui . fontRendererObj . drawString ( this . displayString , this . xPosition + textOffsetX , this . yPosition + ( this . height - 8 ) / 2 , 0 ) ;
2015-08-28 21:17:09 +02:00
}
}
}
2015-10-02 19:58:03 +02:00
public static class TexturedButton extends GuiButton {
2015-08-28 21:17:09 +02:00
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-10-03 10:16:18 +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 ) ;
}
}
}
}