Changed booklet to use EntrySet to make page history coding easier

This commit is contained in:
Ellpeck 2015-12-04 18:55:50 +01:00
parent f808bcf43f
commit 0494da1fb6
15 changed files with 174 additions and 165 deletions

View file

@ -69,7 +69,7 @@ public class BookletUtils{
//Lower title //Lower title
booklet.drawTexturedModalRect(booklet.guiLeft+booklet.xSize/2-142/2, booklet.guiTop+booklet.ySize, 0, 243, 142, 13); booklet.drawTexturedModalRect(booklet.guiLeft+booklet.xSize/2-142/2, booklet.guiTop+booklet.ySize, 0, 243, 142, 13);
String strg = booklet.currentChapter == null ? (booklet.currentIndexEntry == null ? StringUtil.localize("itemGroup."+ModUtil.MOD_ID_LOWER) : booklet.currentIndexEntry.getLocalizedName()) : booklet.currentChapter.getLocalizedName(); String strg = booklet.currentEntrySet.chapter == null ? (booklet.currentEntrySet.entry == null ? StringUtil.localize("itemGroup."+ModUtil.MOD_ID_LOWER) : booklet.currentEntrySet.entry.getLocalizedName()) : booklet.currentEntrySet.chapter.getLocalizedName();
booklet.drawCenteredString(booklet.getFontRenderer(), strg, booklet.guiLeft+booklet.xSize/2, booklet.guiTop-9, StringUtil.DECIMAL_COLOR_WHITE); booklet.drawCenteredString(booklet.getFontRenderer(), strg, booklet.guiLeft+booklet.xSize/2, booklet.guiTop-9, StringUtil.DECIMAL_COLOR_WHITE);
} }
@ -79,12 +79,12 @@ public class BookletUtils{
* @param pre If the hover info texts or the icon should be drawn * @param pre If the hover info texts or the icon should be drawn
*/ */
public static void drawAchievementInfo(GuiBooklet booklet, boolean pre, int mouseX, int mouseY){ public static void drawAchievementInfo(GuiBooklet booklet, boolean pre, int mouseX, int mouseY){
if(booklet.currentChapter == null){ if(booklet.currentEntrySet.chapter == null){
return; return;
} }
ArrayList<String> infoList = null; ArrayList<String> infoList = null;
for(BookletPage page : booklet.currentChapter.pages){ for(BookletPage page : booklet.currentEntrySet.chapter.pages){
if(page != null && page.getItemStacksForPage() != null){ if(page != null && page.getItemStacksForPage() != null){
for(ItemStack stack : page.getItemStacksForPage()){ for(ItemStack stack : page.getItemStacksForPage()){
for(Achievement achievement : InitAchievements.achievementList){ for(Achievement achievement : InitAchievements.achievementList){
@ -122,15 +122,15 @@ public class BookletUtils{
* -the amount of words and chars in the index (Just for teh lulz) * -the amount of words and chars in the index (Just for teh lulz)
*/ */
public static void renderPre(GuiBooklet booklet, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){ public static void renderPre(GuiBooklet booklet, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
if(booklet.currentIndexEntry != null){ if(booklet.currentEntrySet.entry != null){
//Renders Booklet Page Number and Content //Renders Booklet Page Number and Content
if(booklet.currentChapter != null && booklet.currentPage != null){ if(booklet.currentEntrySet.chapter != null && booklet.currentEntrySet.page != null){
booklet.drawCenteredString(booklet.getFontRenderer(), booklet.currentPage.getID()+"/"+booklet.currentChapter.pages.length, booklet.guiLeft+booklet.xSize/2, booklet.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE); booklet.drawCenteredString(booklet.getFontRenderer(), booklet.currentEntrySet.page.getID()+"/"+booklet.currentEntrySet.chapter.pages.length, booklet.guiLeft+booklet.xSize/2, booklet.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE);
booklet.currentPage.renderPre(booklet, mouseX, mouseY, ticksElapsed, mousePressed); booklet.currentEntrySet.page.renderPre(booklet, mouseX, mouseY, ticksElapsed, mousePressed);
} }
//Renders Chapter Page Number //Renders Chapter Page Number
else{ else{
booklet.drawCenteredString(booklet.getFontRenderer(), booklet.pageOpenInIndex+"/"+booklet.indexPageAmount, booklet.guiLeft+booklet.xSize/2, booklet.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE); booklet.drawCenteredString(booklet.getFontRenderer(), booklet.currentEntrySet.pageInIndex+"/"+booklet.indexPageAmount, booklet.guiLeft+booklet.xSize/2, booklet.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE);
} }
} }
//Renders the amount of words and chars the book has //Renders the amount of words and chars the book has
@ -166,8 +166,8 @@ public class BookletUtils{
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static void updateSearchBar(GuiBooklet booklet){ public static void updateSearchBar(GuiBooklet booklet){
if(booklet.currentIndexEntry instanceof BookletEntryAllSearch){ if(booklet.currentEntrySet.entry instanceof BookletEntryAllSearch){
BookletEntryAllSearch currentEntry = (BookletEntryAllSearch)booklet.currentIndexEntry; BookletEntryAllSearch currentEntry = (BookletEntryAllSearch)booklet.currentEntrySet.entry;
if(booklet.searchField.getText() != null && !booklet.searchField.getText().isEmpty()){ if(booklet.searchField.getText() != null && !booklet.searchField.getText().isEmpty()){
currentEntry.chapters.clear(); currentEntry.chapters.clear();
@ -180,7 +180,7 @@ public class BookletUtils{
else{ else{
currentEntry.chapters = (ArrayList<BookletChapter>)currentEntry.allChapters.clone(); currentEntry.chapters = (ArrayList<BookletChapter>)currentEntry.allChapters.clone();
} }
openIndexEntry(booklet, booklet.currentIndexEntry, booklet.pageOpenInIndex, false); openIndexEntry(booklet, booklet.currentEntrySet.entry, booklet.currentEntrySet.pageInIndex, false);
} }
} }
@ -200,16 +200,16 @@ public class BookletUtils{
} }
} }
booklet.currentPage = null; booklet.currentEntrySet.page = null;
booklet.currentChapter = null; booklet.currentEntrySet.chapter = null;
booklet.currentIndexEntry = entry; booklet.currentEntrySet.entry = entry;
booklet.indexPageAmount = entry == null ? 1 : entry.chapters.size()/booklet.chapterButtons.length+1; booklet.indexPageAmount = entry == null ? 1 : entry.chapters.size()/booklet.chapterButtons.length+1;
booklet.pageOpenInIndex = entry == null ? 1 : (booklet.indexPageAmount <= page || page <= 0 ? booklet.indexPageAmount : page); booklet.currentEntrySet.pageInIndex = entry == null ? 1 : (booklet.indexPageAmount <= page || page <= 0 ? booklet.indexPageAmount : page);
booklet.buttonPreviousScreen.visible = entry != null; booklet.buttonPreviousScreen.visible = entry != null;
booklet.buttonForward.visible = booklet.pageOpenInIndex < booklet.indexPageAmount; booklet.buttonForward.visible = booklet.currentEntrySet.pageInIndex < booklet.indexPageAmount;
booklet.buttonBackward.visible = booklet.pageOpenInIndex > 1; booklet.buttonBackward.visible = booklet.currentEntrySet.pageInIndex > 1;
for(int i = 0; i < booklet.chapterButtons.length; i++){ for(int i = 0; i < booklet.chapterButtons.length; i++){
IndexButton button = (IndexButton)booklet.chapterButtons[i]; IndexButton button = (IndexButton)booklet.chapterButtons[i];
@ -222,10 +222,10 @@ public class BookletUtils{
} }
} }
else{ else{
boolean entryExists = entry.chapters.size() > i+(booklet.chapterButtons.length*booklet.pageOpenInIndex-booklet.chapterButtons.length); boolean entryExists = entry.chapters.size() > i+(booklet.chapterButtons.length*booklet.currentEntrySet.pageInIndex-booklet.chapterButtons.length);
button.visible = entryExists; button.visible = entryExists;
if(entryExists){ if(entryExists){
BookletChapter chap = entry.chapters.get(i+(booklet.chapterButtons.length*booklet.pageOpenInIndex-booklet.chapterButtons.length)); BookletChapter chap = entry.chapters.get(i+(booklet.chapterButtons.length*booklet.currentEntrySet.pageInIndex-booklet.chapterButtons.length));
button.displayString = chap.getNameWithColor(); button.displayString = chap.getNameWithColor();
button.chap = chap; button.chap = chap;
} }
@ -239,10 +239,10 @@ public class BookletUtils{
public static void handleChapterButtonClick(GuiBooklet booklet, GuiButton button){ public static void handleChapterButtonClick(GuiBooklet booklet, GuiButton button){
int place = Util.arrayContains(booklet.chapterButtons, button); int place = Util.arrayContains(booklet.chapterButtons, button);
if(place >= 0){ if(place >= 0){
if(booklet.currentIndexEntry != null){ if(booklet.currentEntrySet.entry != null){
if(booklet.currentChapter == null){ if(booklet.currentEntrySet.chapter == null){
if(place < booklet.currentIndexEntry.chapters.size()){ if(place < booklet.currentEntrySet.entry.chapters.size()){
BookletChapter chap = booklet.currentIndexEntry.chapters.get(place+(booklet.chapterButtons.length*booklet.pageOpenInIndex-booklet.chapterButtons.length)); BookletChapter chap = booklet.currentEntrySet.entry.chapters.get(place+(booklet.chapterButtons.length*booklet.currentEntrySet.pageInIndex-booklet.chapterButtons.length));
openChapter(booklet, chap, chap.pages[0]); openChapter(booklet, chap, chap.pages[0]);
} }
} }
@ -260,7 +260,7 @@ public class BookletUtils{
* Can only be done when the chapter is not null and an index entry is opened in the booklet * Can only be done when the chapter is not null and an index entry is opened in the booklet
*/ */
public static void openChapter(GuiBooklet booklet, BookletChapter chapter, BookletPage page){ public static void openChapter(GuiBooklet booklet, BookletChapter chapter, BookletPage page){
if(chapter == null || booklet.currentIndexEntry == null){ if(chapter == null || booklet.currentEntrySet.entry == null){
return; return;
} }
@ -268,11 +268,11 @@ public class BookletUtils{
booklet.searchField.setFocused(false); booklet.searchField.setFocused(false);
booklet.searchField.setText(""); booklet.searchField.setText("");
booklet.currentChapter = chapter; booklet.currentEntrySet.chapter = chapter;
booklet.currentPage = page != null && doesChapterHavePage(chapter, page) ? page : chapter.pages[0]; booklet.currentEntrySet.page = page != null && doesChapterHavePage(chapter, page) ? page : chapter.pages[0];
booklet.buttonForward.visible = getNextPage(chapter, booklet.currentPage) != null; booklet.buttonForward.visible = getNextPage(chapter, booklet.currentEntrySet.page) != null;
booklet.buttonBackward.visible = getPrevPage(chapter, booklet.currentPage) != null; booklet.buttonBackward.visible = getPrevPage(chapter, booklet.currentEntrySet.page) != null;
booklet.buttonPreviousScreen.visible = true; booklet.buttonPreviousScreen.visible = true;
for(GuiButton chapterButton : booklet.chapterButtons){ for(GuiButton chapterButton : booklet.chapterButtons){
@ -295,9 +295,9 @@ public class BookletUtils{
/** /**
* Gets the next available page in the booklet (or null if there is none) * Gets the next available page in the booklet (or null if there is none)
*/ */
private static BookletPage getNextPage(BookletChapter chapter, BookletPage currentPage){ private static BookletPage getNextPage(BookletChapter chapter, BookletPage page){
for(int i = 0; i < chapter.pages.length; i++){ for(int i = 0; i < chapter.pages.length; i++){
if(chapter.pages[i] == currentPage){ if(chapter.pages[i] == page){
if(i+1 < chapter.pages.length){ if(i+1 < chapter.pages.length){
return chapter.pages[i+1]; return chapter.pages[i+1];
} }
@ -309,9 +309,9 @@ public class BookletUtils{
/** /**
* Gets the previous available page in the booklet (or null if there is none) * Gets the previous available page in the booklet (or null if there is none)
*/ */
private static BookletPage getPrevPage(BookletChapter chapter, BookletPage currentPage){ private static BookletPage getPrevPage(BookletChapter chapter, BookletPage page){
for(int i = 0; i < chapter.pages.length; i++){ for(int i = 0; i < chapter.pages.length; i++){
if(chapter.pages[i] == currentPage){ if(chapter.pages[i] == page){
if(i-1 >= 0){ if(i-1 >= 0){
return chapter.pages[i-1]; return chapter.pages[i-1];
} }
@ -324,18 +324,18 @@ public class BookletUtils{
* Called when the "next page"-button is pressed * Called when the "next page"-button is pressed
*/ */
public static void handleNextPage(GuiBooklet booklet){ public static void handleNextPage(GuiBooklet booklet){
if(booklet.currentIndexEntry != null){ if(booklet.currentEntrySet.entry != null){
if(booklet.currentPage != null){ if(booklet.currentEntrySet.page != null){
BookletPage page = getNextPage(booklet.currentChapter, booklet.currentPage); BookletPage page = getNextPage(booklet.currentEntrySet.chapter, booklet.currentEntrySet.page);
if(page != null){ if(page != null){
booklet.currentPage = page; booklet.currentEntrySet.page = page;
} }
booklet.buttonForward.visible = getNextPage(booklet.currentChapter, booklet.currentPage) != null; booklet.buttonForward.visible = getNextPage(booklet.currentEntrySet.chapter, booklet.currentEntrySet.page) != null;
booklet.buttonBackward.visible = getPrevPage(booklet.currentChapter, booklet.currentPage) != null; booklet.buttonBackward.visible = getPrevPage(booklet.currentEntrySet.chapter, booklet.currentEntrySet.page) != null;
} }
else{ else{
openIndexEntry(booklet, booklet.currentIndexEntry, booklet.pageOpenInIndex+1, !(booklet.currentIndexEntry instanceof BookletEntryAllSearch)); openIndexEntry(booklet, booklet.currentEntrySet.entry, booklet.currentEntrySet.pageInIndex+1, !(booklet.currentEntrySet.entry instanceof BookletEntryAllSearch));
} }
} }
} }
@ -344,18 +344,18 @@ public class BookletUtils{
* Called when the "previous page"-button is pressed * Called when the "previous page"-button is pressed
*/ */
public static void handlePreviousPage(GuiBooklet booklet){ public static void handlePreviousPage(GuiBooklet booklet){
if(booklet.currentIndexEntry != null){ if(booklet.currentEntrySet.entry != null){
if(booklet.currentPage != null){ if(booklet.currentEntrySet.page != null){
BookletPage page = getPrevPage(booklet.currentChapter, booklet.currentPage); BookletPage page = getPrevPage(booklet.currentEntrySet.chapter, booklet.currentEntrySet.page);
if(page != null){ if(page != null){
booklet.currentPage = page; booklet.currentEntrySet.page = page;
} }
booklet.buttonForward.visible = getNextPage(booklet.currentChapter, booklet.currentPage) != null; booklet.buttonForward.visible = getNextPage(booklet.currentEntrySet.chapter, booklet.currentEntrySet.page) != null;
booklet.buttonBackward.visible = getPrevPage(booklet.currentChapter, booklet.currentPage) != null; booklet.buttonBackward.visible = getPrevPage(booklet.currentEntrySet.chapter, booklet.currentEntrySet.page) != null;
} }
else{ else{
openIndexEntry(booklet, booklet.currentIndexEntry, booklet.pageOpenInIndex-1, !(booklet.currentIndexEntry instanceof BookletEntryAllSearch)); openIndexEntry(booklet, booklet.currentEntrySet.entry, booklet.currentEntrySet.pageInIndex-1, !(booklet.currentEntrySet.entry instanceof BookletEntryAllSearch));
} }
} }
} }

View file

@ -0,0 +1,68 @@
/*
* This file ("EntrySet.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
*
* © 2015 Ellpeck
*/
package ellpeck.actuallyadditions.booklet;
import ellpeck.actuallyadditions.booklet.chapter.BookletChapter;
import ellpeck.actuallyadditions.booklet.entry.BookletEntry;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import net.minecraft.nbt.NBTTagCompound;
public class EntrySet{
public BookletPage page;
public BookletChapter chapter;
public BookletEntry entry;
public int pageInIndex;
public EntrySet(BookletPage page, BookletChapter chapter, BookletEntry entry, int pageInIndex){
this.setEntry(page, chapter, entry, pageInIndex);
}
public EntrySet(BookletEntry entry){
this(null, null, entry, 1);
}
public void removeEntry(){
this.setEntry(null, null, null, 1);
}
public void setEntry(BookletPage page, BookletChapter chapter, BookletEntry entry, int pageInIndex){
this.page = page;
this.chapter = chapter;
this.entry = entry;
this.pageInIndex = pageInIndex;
}
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("Entry", entry == null ? -1 : InitBooklet.entries.indexOf(entry));
compound.setInteger("Chapter", entry == null || chapter == null ? -1 : entry.chapters.indexOf(chapter));
compound.setInteger("Page", page == null ? -1 : page.getID());
compound.setInteger("PageInIndex", pageInIndex);
return compound;
}
public static EntrySet readFromNBT(NBTTagCompound compound){
if(compound.hasKey("Entry")){
int entry = compound.getInteger("Entry");
int chapter = compound.getInteger("Chapter");
int page = compound.getInteger("Page");
BookletEntry currentEntry = entry == -1 ? null : InitBooklet.entries.get(entry);
BookletChapter currentChapter = chapter == -1 || entry == -1 || currentEntry.chapters.size() <= chapter ? null : currentEntry.chapters.get(chapter);
BookletPage currentPage = chapter == -1 || currentChapter == null || currentChapter.pages.length <= page-1 ? null : currentChapter.pages[page-1];
int pageInIndex = compound.getInteger("PageInIndex");
return new EntrySet(currentPage, currentChapter, currentEntry, pageInIndex);
}
return null;
}
}

View file

@ -15,10 +15,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.booklet.button.BookmarkButton; import ellpeck.actuallyadditions.booklet.button.BookmarkButton;
import ellpeck.actuallyadditions.booklet.button.IndexButton; import ellpeck.actuallyadditions.booklet.button.IndexButton;
import ellpeck.actuallyadditions.booklet.button.TexturedButton; import ellpeck.actuallyadditions.booklet.button.TexturedButton;
import ellpeck.actuallyadditions.booklet.chapter.BookletChapter;
import ellpeck.actuallyadditions.booklet.entry.BookletEntry;
import ellpeck.actuallyadditions.booklet.entry.BookletEntryAllSearch; import ellpeck.actuallyadditions.booklet.entry.BookletEntryAllSearch;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.config.GuiConfiguration; import ellpeck.actuallyadditions.config.GuiConfiguration;
import ellpeck.actuallyadditions.proxy.ClientProxy; import ellpeck.actuallyadditions.proxy.ClientProxy;
import ellpeck.actuallyadditions.update.UpdateChecker; import ellpeck.actuallyadditions.update.UpdateChecker;
@ -58,11 +55,8 @@ public class GuiBooklet extends GuiScreen{
public int guiLeft; public int guiLeft;
public int guiTop; public int guiTop;
public BookletPage currentPage; public EntrySet currentEntrySet = new EntrySet(null);
public BookletChapter currentChapter;
public BookletEntry currentIndexEntry;
public int pageOpenInIndex;
public int indexPageAmount; public int indexPageAmount;
public GuiButton buttonForward; public GuiButton buttonForward;
@ -119,7 +113,7 @@ public class GuiBooklet extends GuiScreen{
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
//Draws the search bar //Draws the search bar
if(this.currentIndexEntry instanceof BookletEntryAllSearch && this.currentChapter == null){ if(this.currentEntrySet.entry instanceof BookletEntryAllSearch && this.currentEntrySet.chapter == null){
this.mc.getTextureManager().bindTexture(resLoc); this.mc.getTextureManager().bindTexture(resLoc);
this.drawTexturedModalRect(this.guiLeft+146, this.guiTop+160, 146, 80, 70, 14); this.drawTexturedModalRect(this.guiLeft+146, this.guiTop+160, 146, 80, 70, 14);
} }
@ -146,8 +140,8 @@ public class GuiBooklet extends GuiScreen{
this.fontRendererObj.setUnicodeFlag(true); this.fontRendererObj.setUnicodeFlag(true);
//Renders the current page's content //Renders the current page's content
if(this.currentIndexEntry != null && this.currentChapter != null && this.currentPage != null){ if(this.currentEntrySet.entry != null && this.currentEntrySet.chapter != null && this.currentEntrySet.page != null){
this.currentPage.render(this, x, y, this.ticksElapsed, this.mousePressed); this.currentEntrySet.page.render(this, x, y, this.ticksElapsed, this.mousePressed);
} }
this.fontRendererObj.setUnicodeFlag(unicodeBefore); this.fontRendererObj.setUnicodeFlag(unicodeBefore);
@ -162,7 +156,7 @@ public class GuiBooklet extends GuiScreen{
if(key == Keyboard.KEY_ESCAPE && this.parentScreen != null){ if(key == Keyboard.KEY_ESCAPE && this.parentScreen != null){
this.mc.displayGuiScreen(this.parentScreen); this.mc.displayGuiScreen(this.parentScreen);
} }
else if(this.searchField.isFocused()){ else if(this.searchField.isFocused() && key != Keyboard.KEY_ESCAPE){
this.searchField.textboxKeyTyped(theChar, key); this.searchField.textboxKeyTyped(theChar, key);
BookletUtils.updateSearchBar(this); BookletUtils.updateSearchBar(this);
} }
@ -188,7 +182,7 @@ public class GuiBooklet extends GuiScreen{
protected void mouseClicked(int par1, int par2, int par3){ protected void mouseClicked(int par1, int par2, int par3){
this.searchField.mouseClicked(par1, par2, par3); this.searchField.mouseClicked(par1, par2, par3);
//Notifys the booklet of the mouse being pressed //Notifys the booklet of the mouse being pressed
if(par3 == 0 && this.currentChapter != null){ if(par3 == 0 && this.currentEntrySet.chapter != null){
this.mousePressed = true; this.mousePressed = true;
} }
super.mouseClicked(par1, par2, par3); super.mouseClicked(par1, par2, par3);
@ -227,8 +221,8 @@ public class GuiBooklet extends GuiScreen{
//Handles gonig from page to chapter or from chapter to index //Handles gonig from page to chapter or from chapter to index
else if(button == this.buttonPreviousScreen){ else if(button == this.buttonPreviousScreen){
if(KeyUtil.isShiftPressed()){ if(KeyUtil.isShiftPressed()){
if(this.currentChapter != null){ if(this.currentEntrySet.chapter != null){
BookletUtils.openIndexEntry(this, this.currentIndexEntry, this.pageOpenInIndex, true); BookletUtils.openIndexEntry(this, this.currentEntrySet.entry, this.currentEntrySet.pageInIndex, true);
} }
else{ else{
BookletUtils.openIndexEntry(this, null, 1, true); BookletUtils.openIndexEntry(this, null, 1, true);
@ -310,9 +304,7 @@ public class GuiBooklet extends GuiScreen{
this.searchField.setEnableBackgroundDrawing(false); this.searchField.setEnableBackgroundDrawing(false);
this.searchField.setCanLoseFocus(false); this.searchField.setCanLoseFocus(false);
this.currentPage = null; this.currentEntrySet.removeEntry();
this.currentChapter = null;
this.currentIndexEntry = null;
if(this.tryOpenMainPage && !PersistentClientData.getBoolean("BookAlreadyOpened")){ if(this.tryOpenMainPage && !PersistentClientData.getBoolean("BookAlreadyOpened")){
BookletUtils.openIndexEntry(this, InitBooklet.chapterIntro.entry, 1, true); BookletUtils.openIndexEntry(this, InitBooklet.chapterIntro.entry, 1, true);
@ -330,8 +322,8 @@ public class GuiBooklet extends GuiScreen{
super.updateScreen(); super.updateScreen();
this.searchField.updateCursorCounter(); this.searchField.updateCursorCounter();
if(this.currentIndexEntry != null && this.currentChapter != null && this.currentPage != null){ if(this.currentEntrySet.entry != null && this.currentEntrySet.chapter != null && this.currentEntrySet.page != null){
this.currentPage.updateScreen(this.ticksElapsed); this.currentEntrySet.page.updateScreen(this.ticksElapsed);
} }
boolean buttonThere = UpdateChecker.needsUpdateNotify; boolean buttonThere = UpdateChecker.needsUpdateNotify;

View file

@ -36,7 +36,7 @@ public class GuiBookletStand extends GuiBooklet{
@Override @Override
public void actionPerformed(GuiButton button){ public void actionPerformed(GuiButton button){
if(button == this.buttonSetPage){ if(button == this.buttonSetPage){
PacketHandler.theNetwork.sendToServer(new PacketBookletStandButton(this.theStand.xCoord, this.theStand.yCoord, this.theStand.zCoord, this.theStand.getWorldObj(), Minecraft.getMinecraft().thePlayer, this.currentIndexEntry, this.currentChapter, this.currentPage, this.pageOpenInIndex)); PacketHandler.theNetwork.sendToServer(new PacketBookletStandButton(this.theStand.xCoord, this.theStand.yCoord, this.theStand.zCoord, this.theStand.getWorldObj(), Minecraft.getMinecraft().thePlayer, this.currentEntrySet));
} }
super.actionPerformed(button); super.actionPerformed(button);
} }
@ -65,7 +65,7 @@ public class GuiBookletStand extends GuiBooklet{
this.buttonSetPage.visible = Objects.equals(Minecraft.getMinecraft().thePlayer.getCommandSenderName(), this.theStand.assignedPlayer); this.buttonSetPage.visible = Objects.equals(Minecraft.getMinecraft().thePlayer.getCommandSenderName(), this.theStand.assignedPlayer);
//Open the pages the book was assigned //Open the pages the book was assigned
BookletUtils.openIndexEntry(this, this.theStand.assignedEntry, this.theStand.assignedPageInIndex, true); BookletUtils.openIndexEntry(this, this.theStand.assignedEntry.entry, this.theStand.assignedEntry.pageInIndex, true);
BookletUtils.openChapter(this, this.theStand.assignedChapter, this.theStand.assignedPage); BookletUtils.openChapter(this, this.theStand.assignedEntry.chapter, this.theStand.assignedEntry.page);
} }
} }

View file

@ -11,9 +11,8 @@
package ellpeck.actuallyadditions.booklet.button; package ellpeck.actuallyadditions.booklet.button;
import ellpeck.actuallyadditions.booklet.BookletUtils; import ellpeck.actuallyadditions.booklet.BookletUtils;
import ellpeck.actuallyadditions.booklet.EntrySet;
import ellpeck.actuallyadditions.booklet.GuiBooklet; import ellpeck.actuallyadditions.booklet.GuiBooklet;
import ellpeck.actuallyadditions.booklet.chapter.BookletChapter;
import ellpeck.actuallyadditions.booklet.entry.BookletEntry;
import ellpeck.actuallyadditions.booklet.page.BookletPage; import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.items.InitItems; import ellpeck.actuallyadditions.items.InitItems;
import ellpeck.actuallyadditions.util.KeyUtil; import ellpeck.actuallyadditions.util.KeyUtil;
@ -28,10 +27,7 @@ import java.util.ArrayList;
public class BookmarkButton extends GuiButton{ public class BookmarkButton extends GuiButton{
public BookletChapter assignedChapter; public EntrySet assignedEntry = new EntrySet(null);
public BookletPage assignedPage;
public BookletEntry assignedEntry;
public int assignedPageInIndex;
private GuiBooklet booklet; private GuiBooklet booklet;
@ -41,24 +37,18 @@ public class BookmarkButton extends GuiButton{
} }
public void onPressed(){ public void onPressed(){
if(this.assignedEntry != null){ if(this.assignedEntry.entry != null){
if(KeyUtil.isShiftPressed()){ if(KeyUtil.isShiftPressed()){
this.assignedEntry = null; this.assignedEntry.removeEntry();
this.assignedChapter = null;
this.assignedPage = null;
this.assignedPageInIndex = 1;
} }
else{ else{
BookletUtils.openIndexEntry(this.booklet, this.assignedEntry, this.assignedPageInIndex, true); BookletUtils.openIndexEntry(this.booklet, this.assignedEntry.entry, this.assignedEntry.pageInIndex, true);
BookletUtils.openChapter(this.booklet, this.assignedChapter, this.assignedPage); BookletUtils.openChapter(this.booklet, this.assignedEntry.chapter, this.assignedEntry.page);
} }
} }
else{ else{
if(this.booklet.currentIndexEntry != null){ if(this.booklet.currentEntrySet.entry != null){
this.assignedEntry = this.booklet.currentIndexEntry; this.assignedEntry.setEntry(this.booklet.currentEntrySet.page, this.booklet.currentEntrySet.chapter, this.booklet.currentEntrySet.entry, this.booklet.currentEntrySet.pageInIndex);
this.assignedChapter = this.booklet.currentChapter;
this.assignedPage = this.booklet.currentPage;
this.assignedPageInIndex = this.booklet.pageOpenInIndex;
} }
} }
} }
@ -78,12 +68,12 @@ public class BookmarkButton extends GuiButton{
OpenGlHelper.glBlendFunc(770, 771, 1, 0); OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
int renderHeight = 25; int renderHeight = 25;
this.drawTexturedModalRect(this.xPosition, this.yPosition, 146+(this.assignedEntry == null ? 0 : 16), 194-renderHeight+k*renderHeight, this.width, renderHeight); this.drawTexturedModalRect(this.xPosition, this.yPosition, 146+(this.assignedEntry.entry == null ? 0 : 16), 194-renderHeight+k*renderHeight, this.width, renderHeight);
this.mouseDragged(minecraft, x, y); this.mouseDragged(minecraft, x, y);
if(this.assignedEntry != null){ if(this.assignedEntry.entry != null){
GL11.glPushMatrix(); GL11.glPushMatrix();
BookletPage.renderItem(booklet, this.assignedChapter != null && this.assignedChapter.displayStack != null ? this.assignedChapter.displayStack : new ItemStack(InitItems.itemBooklet), this.xPosition+2, this.yPosition+1, 0.725F); BookletPage.renderItem(booklet, this.assignedEntry.chapter != null && this.assignedEntry.chapter.displayStack != null ? this.assignedEntry.chapter.displayStack : new ItemStack(InitItems.itemBooklet), this.xPosition+2, this.yPosition+1, 0.725F);
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
} }
@ -92,12 +82,12 @@ public class BookmarkButton extends GuiButton{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void drawHover(int mouseX, int mouseY){ public void drawHover(int mouseX, int mouseY){
ArrayList list = new ArrayList(); ArrayList list = new ArrayList();
if(this.assignedEntry != null){ if(this.assignedEntry.entry != null){
if(this.assignedChapter != null){ if(this.assignedEntry.chapter != null){
list.add(EnumChatFormatting.GOLD+this.assignedChapter.getLocalizedName()+", Page "+this.assignedPage.getID()); list.add(EnumChatFormatting.GOLD+this.assignedEntry.chapter.getLocalizedName()+", Page "+this.assignedEntry.page.getID());
} }
else{ else{
list.add(EnumChatFormatting.GOLD+this.assignedEntry.getLocalizedName()+", Page "+this.assignedPageInIndex); list.add(EnumChatFormatting.GOLD+this.assignedEntry.entry.getLocalizedName()+", Page "+this.assignedEntry.pageInIndex);
} }
list.add("Click to open"); list.add("Click to open");
list.add(EnumChatFormatting.ITALIC+"Shift-Click to remove"); list.add(EnumChatFormatting.ITALIC+"Shift-Click to remove");

View file

@ -43,7 +43,7 @@ public class PageCoffeeRecipe extends BookletPage{
String strg = "Coffee Machine Recipe"; String strg = "Coffee Machine Recipe";
gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+10, 0); gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+10, 0);
String text = gui.currentPage.getText(); String text = gui.currentEntrySet.page.getText();
if(text != null && !text.isEmpty()){ if(text != null && !text.isEmpty()){
gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+100, 115, 0); gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+100, 115, 0);
} }

View file

@ -91,7 +91,7 @@ public class PageCrafting extends BookletPage{
gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+10, 0); gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+10, 0);
} }
String text = gui.currentPage.getText(); String text = gui.currentEntrySet.page.getText();
if(text != null && !text.isEmpty()){ if(text != null && !text.isEmpty()){
gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+90, 115, 0); gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+90, 115, 0);
} }

View file

@ -62,7 +62,7 @@ public class PageCrusherRecipe extends BookletPage{
gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+10, 0); gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+10, 0);
} }
String text = gui.currentPage.getText(); String text = gui.currentEntrySet.page.getText();
if(text != null && !text.isEmpty()){ if(text != null && !text.isEmpty()){
gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+100, 115, 0); gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+100, 115, 0);
} }

View file

@ -66,7 +66,7 @@ public class PageFurnace extends BookletPage{
gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+10, 0); gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+10, 0);
} }
String text = gui.currentPage.getText(); String text = gui.currentEntrySet.page.getText();
if(text != null && !text.isEmpty()){ if(text != null && !text.isEmpty()){
gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+100, 115, 0); gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+100, 115, 0);
} }

View file

@ -33,7 +33,7 @@ public class PagePicture extends PageTextOnly{
gui.mc.getTextureManager().bindTexture(this.resLoc); gui.mc.getTextureManager().bindTexture(this.resLoc);
gui.drawTexturedModalRect(gui.guiLeft, gui.guiTop, 0, 0, gui.xSize, gui.ySize); gui.drawTexturedModalRect(gui.guiLeft, gui.guiTop, 0, 0, gui.xSize, gui.ySize);
String text = gui.currentPage.getText(); String text = gui.currentEntrySet.page.getText();
if(text != null && !text.isEmpty()){ if(text != null && !text.isEmpty()){
gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+textStartY, 115, 0); gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+textStartY, 115, 0);
} }

View file

@ -76,7 +76,7 @@ public class PageReconstructor extends BookletPage{
gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+10, 0); gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+10, 0);
} }
String text = gui.currentPage.getText(); String text = gui.currentEntrySet.page.getText();
if(text != null && !text.isEmpty()){ if(text != null && !text.isEmpty()){
gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+100, 115, 0); gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+100, 115, 0);
} }

View file

@ -37,7 +37,7 @@ public class PageTextOnly extends BookletPage{
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){ public void renderPre(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
String text = gui.currentPage.getText(); String text = gui.currentEntrySet.page.getText();
if(text != null && !text.isEmpty()){ if(text != null && !text.isEmpty()){
gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+9, 115, 0); gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+9, 115, 0);
} }

View file

@ -13,10 +13,8 @@ package ellpeck.actuallyadditions.network;
import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext; import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import ellpeck.actuallyadditions.booklet.EntrySet;
import ellpeck.actuallyadditions.booklet.InitBooklet; import ellpeck.actuallyadditions.booklet.InitBooklet;
import ellpeck.actuallyadditions.booklet.chapter.BookletChapter;
import ellpeck.actuallyadditions.booklet.entry.BookletEntry;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.tile.TileEntityBookletStand; import ellpeck.actuallyadditions.tile.TileEntityBookletStand;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -44,17 +42,17 @@ public class PacketBookletStandButton implements IMessage{
} }
public PacketBookletStandButton(int x, int y, int z, World world, EntityPlayer player, BookletEntry entry, BookletChapter chapter, BookletPage page, int pageInIndex){ public PacketBookletStandButton(int x, int y, int z, World world, EntityPlayer player, EntrySet set){
this.tileX = x; this.tileX = x;
this.tileY = y; this.tileY = y;
this.tileZ = z; this.tileZ = z;
this.worldID = world.provider.dimensionId; this.worldID = world.provider.dimensionId;
this.playerID = player.getEntityId(); this.playerID = player.getEntityId();
this.entryID = entry == null ? -1 : InitBooklet.entries.indexOf(entry); this.entryID = set.entry == null ? -1 : InitBooklet.entries.indexOf(set.entry);
this.chapterID = entry == null || chapter == null ? -1 : entry.chapters.indexOf(chapter); this.chapterID = set.entry == null || set.chapter == null ? -1 : set.entry.chapters.indexOf(set.chapter);
this.pageID = page == null ? -1 : page.getID(); this.pageID = set.page == null ? -1 : set.page.getID();
this.pageInIndex = pageInIndex; this.pageInIndex = set.pageInIndex;
} }
@Override @Override
@ -95,7 +93,11 @@ public class PacketBookletStandButton implements IMessage{
if(tile instanceof TileEntityBookletStand){ if(tile instanceof TileEntityBookletStand){
if(Objects.equals(player.getCommandSenderName(), ((TileEntityBookletStand)tile).assignedPlayer)){ if(Objects.equals(player.getCommandSenderName(), ((TileEntityBookletStand)tile).assignedPlayer)){
((TileEntityBookletStand)tile).setEntry(message.entryID, message.chapterID, message.pageID, message.pageInIndex); EntrySet theSet = ((TileEntityBookletStand)tile).assignedEntry;
theSet.entry = message.entryID == -1 ? null : InitBooklet.entries.get(message.entryID);
theSet.chapter = message.chapterID == -1 || message.entryID == -1 || theSet.entry.chapters.size() <= message.chapterID ? null : theSet.entry.chapters.get(message.chapterID);
theSet.page = message.chapterID == -1 || theSet.chapter == null || theSet.chapter.pages.length <= message.pageID-1 ? null : theSet.chapter.pages[message.pageID-1];
theSet.pageInIndex = message.pageInIndex;
((TileEntityBookletStand)tile).sendUpdate(); ((TileEntityBookletStand)tile).sendUpdate();
} }
} }

View file

@ -10,19 +10,12 @@
package ellpeck.actuallyadditions.tile; package ellpeck.actuallyadditions.tile;
import ellpeck.actuallyadditions.booklet.InitBooklet; import ellpeck.actuallyadditions.booklet.EntrySet;
import ellpeck.actuallyadditions.booklet.chapter.BookletChapter;
import ellpeck.actuallyadditions.booklet.entry.BookletEntry;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
public class TileEntityBookletStand extends TileEntityBase{ public class TileEntityBookletStand extends TileEntityBase{
public BookletChapter assignedChapter; public EntrySet assignedEntry = new EntrySet(null);
public BookletPage assignedPage;
public BookletEntry assignedEntry;
public int assignedPageInIndex;
public String assignedPlayer; public String assignedPlayer;
@Override @Override
@ -32,10 +25,7 @@ public class TileEntityBookletStand extends TileEntityBase{
@Override @Override
public void writeSyncableNBT(NBTTagCompound compound, boolean isForSync){ public void writeSyncableNBT(NBTTagCompound compound, boolean isForSync){
compound.setInteger("Entry", this.assignedEntry == null ? -1 : InitBooklet.entries.indexOf(this.assignedEntry)); compound.setTag("SavedEntry", this.assignedEntry.writeToNBT());
compound.setInteger("Chapter", this.assignedEntry == null || this.assignedChapter == null ? -1 : this.assignedEntry.chapters.indexOf(this.assignedChapter));
compound.setInteger("Page", this.assignedPage == null ? -1 : this.assignedPage.getID());
compound.setInteger("PageInIndex", this.assignedPageInIndex);
if(this.assignedPlayer != null){ if(this.assignedPlayer != null){
compound.setString("Player", this.assignedPlayer); compound.setString("Player", this.assignedPlayer);
@ -44,18 +34,11 @@ public class TileEntityBookletStand extends TileEntityBase{
@Override @Override
public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){ public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){
this.setEntry(compound.getInteger("Entry"), compound.getInteger("Chapter"), compound.getInteger("Page"), compound.getInteger("PageInIndex")); this.assignedEntry = EntrySet.readFromNBT(compound.getCompoundTag("SavedEntry"));
String player = compound.getString("Player"); String player = compound.getString("Player");
if(player != null){ if(player != null){
this.assignedPlayer = player; this.assignedPlayer = player;
} }
} }
public void setEntry(int entry, int chapter, int page, int pageInIndex){
this.assignedEntry = entry == -1 ? null : InitBooklet.entries.get(entry);
this.assignedChapter = chapter == -1 || entry == -1 || this.assignedEntry.chapters.size() <= chapter ? null : this.assignedEntry.chapters.get(chapter);
this.assignedPage = chapter == -1 || this.assignedChapter == null || this.assignedChapter.pages.length <= page-1 ? null : this.assignedChapter.pages[page-1];
this.assignedPageInIndex = pageInIndex;
}
} }

View file

@ -13,12 +13,9 @@ package ellpeck.actuallyadditions.util.playerdata;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.booklet.BookletUtils; import ellpeck.actuallyadditions.booklet.BookletUtils;
import ellpeck.actuallyadditions.booklet.EntrySet;
import ellpeck.actuallyadditions.booklet.GuiBooklet; import ellpeck.actuallyadditions.booklet.GuiBooklet;
import ellpeck.actuallyadditions.booklet.InitBooklet;
import ellpeck.actuallyadditions.booklet.button.BookmarkButton; import ellpeck.actuallyadditions.booklet.button.BookmarkButton;
import ellpeck.actuallyadditions.booklet.chapter.BookletChapter;
import ellpeck.actuallyadditions.booklet.entry.BookletEntry;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.ModUtil;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.CompressedStreamTools;
@ -39,10 +36,7 @@ public class PersistentClientData{
NBTTagCompound worldCompound = getCompoundForWorld(baseCompound); NBTTagCompound worldCompound = getCompoundForWorld(baseCompound);
//Save Entry etc. //Save Entry etc.
if(worldCompound != null){ if(worldCompound != null){
worldCompound.setInteger("Entry", gui.currentIndexEntry == null ? -1 : InitBooklet.entries.indexOf(gui.currentIndexEntry)); worldCompound.setTag("SavedEntry", gui.currentEntrySet.writeToNBT());
worldCompound.setInteger("Chapter", gui.currentIndexEntry == null || gui.currentChapter == null ? -1 : gui.currentIndexEntry.chapters.indexOf(gui.currentChapter));
worldCompound.setInteger("Page", gui.currentPage == null ? -1 : gui.currentPage.getID());
worldCompound.setInteger("PageInIndex", gui.pageOpenInIndex);
worldCompound.setString("SearchWord", gui.searchField.getText()); worldCompound.setString("SearchWord", gui.searchField.getText());
} }
@ -51,12 +45,7 @@ public class PersistentClientData{
for(int i = 0; i < gui.bookmarkButtons.length; i++){ for(int i = 0; i < gui.bookmarkButtons.length; i++){
BookmarkButton button = (BookmarkButton)gui.bookmarkButtons[i]; BookmarkButton button = (BookmarkButton)gui.bookmarkButtons[i];
NBTTagCompound compound = new NBTTagCompound(); list.appendTag(button.assignedEntry.writeToNBT());
compound.setInteger("Entry", button.assignedEntry == null ? -1 : InitBooklet.entries.indexOf(button.assignedEntry));
compound.setInteger("Chapter", button.assignedEntry == null || button.assignedChapter == null ? -1 : button.assignedEntry.chapters.indexOf(button.assignedChapter));
compound.setInteger("Page", button.assignedPage == null ? -1 : button.assignedPage.getID());
compound.setInteger("PageInIndex", button.assignedPageInIndex);
list.appendTag(compound);
} }
worldCompound.setTag("Bookmarks", list); worldCompound.setTag("Bookmarks", list);
@ -115,19 +104,12 @@ public class PersistentClientData{
NBTTagCompound worldCompound = getCompoundForWorld(getBaseCompound()); NBTTagCompound worldCompound = getCompoundForWorld(getBaseCompound());
if(worldCompound != null){ if(worldCompound != null){
//Open Entry etc. //Open Entry etc.
if(worldCompound.hasKey("Entry")){ EntrySet set = EntrySet.readFromNBT(worldCompound.getCompoundTag("SavedEntry"));
int entry = worldCompound.getInteger("Entry"); if(set != null){
int chapter = worldCompound.getInteger("Chapter");
int page = worldCompound.getInteger("Page");
BookletEntry currentIndexEntry = entry == -1 ? null : InitBooklet.entries.get(entry); BookletUtils.openIndexEntry(gui, set.entry, set.pageInIndex, true);
BookletChapter currentChapter = chapter == -1 || entry == -1 || currentIndexEntry.chapters.size() <= chapter ? null : currentIndexEntry.chapters.get(chapter); if(set.chapter != null){
BookletPage currentPage = chapter == -1 || currentChapter == null || currentChapter.pages.length <= page-1 ? null : currentChapter.pages[page-1]; BookletUtils.openChapter(gui, set.chapter, set.page);
int pageInIndex = worldCompound.getInteger("PageInIndex");
BookletUtils.openIndexEntry(gui, currentIndexEntry, pageInIndex, true);
if(currentChapter != null){
BookletUtils.openChapter(gui, currentChapter, currentPage);
} }
String searchText = worldCompound.getString("SearchWord"); String searchText = worldCompound.getString("SearchWord");
@ -147,15 +129,7 @@ public class PersistentClientData{
for(int i = 0; i < list.tagCount(); i++){ for(int i = 0; i < list.tagCount(); i++){
BookmarkButton button = (BookmarkButton)gui.bookmarkButtons[i]; BookmarkButton button = (BookmarkButton)gui.bookmarkButtons[i];
NBTTagCompound compound = list.getCompoundTagAt(i); NBTTagCompound compound = list.getCompoundTagAt(i);
button.assignedEntry = EntrySet.readFromNBT(compound);
int entry = compound.getInteger("Entry");
int chapter = compound.getInteger("Chapter");
int page = compound.getInteger("Page");
button.assignedEntry = entry == -1 ? null : InitBooklet.entries.get(entry);
button.assignedChapter = chapter == -1 || entry == -1 || button.assignedEntry.chapters.size() <= chapter ? null : button.assignedEntry.chapters.get(chapter);
button.assignedPage = chapter == -1 || button.assignedChapter == null || button.assignedChapter.pages.length <= page-1 ? null : button.assignedChapter.pages[page-1];
button.assignedPageInIndex = compound.getInteger("PageInIndex");
} }
} }
} }