mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 16:58:34 +01:00
Bookmark Saving
This commit is contained in:
parent
3ff1c50454
commit
bbb64eadba
3 changed files with 82 additions and 29 deletions
|
@ -526,9 +526,24 @@ public class BookletUtils{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void drawHover(int mouseX, int mouseY){
|
public void drawHover(int mouseX, int mouseY){
|
||||||
String strg = this.assignedChapter == null ? (this.assignedEntry == null ? "None" : (this.assignedEntry.getLocalizedName()+", Page "+this.assignedPageInIndex)) : (this.assignedChapter.getLocalizedName()+", Page "+this.assignedPage.getID());
|
ArrayList list = new ArrayList();
|
||||||
this.booklet.drawHoveringText(Collections.singletonList(strg), mouseX, mouseY);
|
if(this.assignedEntry != null){
|
||||||
|
if(this.assignedChapter != null){
|
||||||
|
list.add(EnumChatFormatting.GOLD+this.assignedChapter.getLocalizedName()+", Page "+this.assignedPage.getID());
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
list.add(EnumChatFormatting.GOLD+this.assignedEntry.getLocalizedName()+", Page "+this.assignedPageInIndex);
|
||||||
|
}
|
||||||
|
list.add("Click to open");
|
||||||
|
list.add(EnumChatFormatting.ITALIC+"Shift-Click to remove");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
list.add(EnumChatFormatting.GOLD+"None");
|
||||||
|
list.add("Click to save current page");
|
||||||
|
}
|
||||||
|
this.booklet.drawHoveringText(list, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,7 +301,7 @@ public class GuiBooklet extends GuiScreen{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuiClosed(){
|
public void onGuiClosed(){
|
||||||
PersistentClientData.saveBookPage(this.currentIndexEntry, this.currentChapter, this.currentPage, this.pageOpenInIndex, this.searchField.getText());
|
PersistentClientData.saveBookPage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,6 +22,7 @@ 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;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -32,17 +33,33 @@ public class PersistentClientData{
|
||||||
|
|
||||||
private static File theFile;
|
private static File theFile;
|
||||||
|
|
||||||
public static void saveBookPage(BookletEntry entry, BookletChapter chapter, BookletPage page, int pageInIndex, String searchWord){
|
public static void saveBookPage(GuiBooklet gui){
|
||||||
NBTTagCompound baseCompound = getBaseCompound();
|
NBTTagCompound baseCompound = getBaseCompound();
|
||||||
NBTTagCompound worldCompound = getCompoundForWorld(baseCompound);
|
NBTTagCompound worldCompound = getCompoundForWorld(baseCompound);
|
||||||
|
//Save Entry etc.
|
||||||
if(worldCompound != null){
|
if(worldCompound != null){
|
||||||
worldCompound.setInteger("Entry", entry == null ? -1 : InitBooklet.entries.indexOf(entry));
|
worldCompound.setInteger("Entry", gui.currentIndexEntry == null ? -1 : InitBooklet.entries.indexOf(gui.currentIndexEntry));
|
||||||
worldCompound.setInteger("Chapter", entry == null || chapter == null ? -1 : entry.chapters.indexOf(chapter));
|
worldCompound.setInteger("Chapter", gui.currentIndexEntry == null || gui.currentChapter == null ? -1 : gui.currentIndexEntry.chapters.indexOf(gui.currentChapter));
|
||||||
worldCompound.setInteger("Page", page == null ? -1 : page.getID());
|
worldCompound.setInteger("Page", gui.currentPage == null ? -1 : gui.currentPage.getID());
|
||||||
worldCompound.setInteger("PageInIndex", pageInIndex);
|
worldCompound.setInteger("PageInIndex", gui.pageOpenInIndex);
|
||||||
worldCompound.setString("SearchWord", searchWord);
|
worldCompound.setString("SearchWord", gui.searchField.getText());
|
||||||
writeCompound(baseCompound, worldCompound);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Save Bookmarks
|
||||||
|
NBTTagList list = new NBTTagList();
|
||||||
|
for(int i = 0; i < gui.bookmarkButtons.length; i++){
|
||||||
|
BookletUtils.BookmarkButton button = (BookletUtils.BookmarkButton)gui.bookmarkButtons[i];
|
||||||
|
|
||||||
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
|
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);
|
||||||
|
|
||||||
|
writeCompound(baseCompound, worldCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NBTTagCompound getBaseCompound(){
|
private static NBTTagCompound getBaseCompound(){
|
||||||
|
@ -93,7 +110,9 @@ public class PersistentClientData{
|
||||||
|
|
||||||
public static void openLastBookPage(GuiBooklet gui){
|
public static void openLastBookPage(GuiBooklet gui){
|
||||||
NBTTagCompound worldCompound = getCompoundForWorld(getBaseCompound());
|
NBTTagCompound worldCompound = getCompoundForWorld(getBaseCompound());
|
||||||
if(worldCompound != null && worldCompound.hasKey("Entry")){
|
if(worldCompound != null){
|
||||||
|
//Open Entry etc.
|
||||||
|
if(worldCompound.hasKey("Entry")){
|
||||||
int entry = worldCompound.getInteger("Entry");
|
int entry = worldCompound.getInteger("Entry");
|
||||||
int chapter = worldCompound.getInteger("Chapter");
|
int chapter = worldCompound.getInteger("Chapter");
|
||||||
int page = worldCompound.getInteger("Page");
|
int page = worldCompound.getInteger("Page");
|
||||||
|
@ -118,6 +137,25 @@ public class PersistentClientData{
|
||||||
//If everything fails, initialize the front page
|
//If everything fails, initialize the front page
|
||||||
BookletUtils.openIndexEntry(gui, null, 1, true);
|
BookletUtils.openIndexEntry(gui, null, 1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Load Bookmarks
|
||||||
|
NBTTagList list = worldCompound.getTagList("Bookmarks", 10);
|
||||||
|
if(list != null){
|
||||||
|
for(int i = 0; i < list.tagCount(); i++){
|
||||||
|
BookletUtils.BookmarkButton button = (BookletUtils.BookmarkButton)gui.bookmarkButtons[i];
|
||||||
|
NBTTagCompound compound = list.getCompoundTagAt(i);
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBoolean(String name, boolean bool){
|
public static void setBoolean(String name, boolean bool){
|
||||||
|
|
Loading…
Reference in a new issue