mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Word in Search Bar gets saved between sessions
This commit is contained in:
parent
e404bbf783
commit
c6d14a25a4
2 changed files with 56 additions and 47 deletions
|
@ -52,17 +52,17 @@ public class GuiBooklet extends GuiScreen{
|
|||
public BookletIndexEntry currentIndexEntry;
|
||||
public int pageOpenInIndex;
|
||||
public int indexPageAmount;
|
||||
public GuiButton buttonForward;
|
||||
public GuiButton buttonBackward;
|
||||
public GuiButton buttonPreviousScreen;
|
||||
public GuiButton buttonPreviouslyOpenedGui;
|
||||
public GuiButton buttonUpdate;
|
||||
public GuiButton buttonTwitter;
|
||||
public GuiButton buttonForum;
|
||||
public GuiButton buttonAchievements;
|
||||
public GuiButton buttonConfig;
|
||||
public GuiButton[] chapterButtons = new GuiButton[CHAPTER_BUTTONS_AMOUNT];
|
||||
private GuiTextField searchField;
|
||||
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;
|
||||
private int ticksElapsed;
|
||||
private boolean mousePressed;
|
||||
|
||||
|
@ -166,34 +166,37 @@ public class GuiBooklet extends GuiScreen{
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void keyTyped(char theChar, int key){
|
||||
if(key != 1 && this.searchField.isFocused()){
|
||||
this.searchField.textboxKeyTyped(theChar, key);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
currentEntry.chapters = (ArrayList<BookletChapter>)currentEntry.allChapters.clone();
|
||||
}
|
||||
this.openIndexEntry(this.currentIndexEntry, this.pageOpenInIndex, false);
|
||||
}
|
||||
this.updateSearchBar();
|
||||
}
|
||||
else{
|
||||
super.keyTyped(theChar, key);
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
currentEntry.chapters = (ArrayList<BookletChapter>)currentEntry.allChapters.clone();
|
||||
}
|
||||
this.openIndexEntry(this.currentIndexEntry, this.pageOpenInIndex, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int par1, int par2, int par3){
|
||||
this.searchField.mouseClicked(par1, par2, par3);
|
||||
|
@ -398,7 +401,7 @@ public class GuiBooklet extends GuiScreen{
|
|||
|
||||
@Override
|
||||
public void onGuiClosed(){
|
||||
PersistentClientData.saveBookPage(this.currentIndexEntry, this.currentChapter, this.currentPage, this.pageOpenInIndex);
|
||||
PersistentClientData.saveBookPage(this.currentIndexEntry, this.currentChapter, this.currentPage, this.pageOpenInIndex, this.searchField.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,7 +31,7 @@ public class PersistentClientData{
|
|||
|
||||
private static File theFile;
|
||||
|
||||
public static void saveBookPage(BookletIndexEntry entry, BookletChapter chapter, BookletPage page, int pageInIndex){
|
||||
public static void saveBookPage(BookletIndexEntry entry, BookletChapter chapter, BookletPage page, int pageInIndex, String searchWord){
|
||||
NBTTagCompound baseCompound = getBaseCompound();
|
||||
NBTTagCompound worldCompound = getCompoundForWorld(baseCompound);
|
||||
if(worldCompound != null){
|
||||
|
@ -39,6 +39,7 @@ public class PersistentClientData{
|
|||
worldCompound.setInteger("Chapter", entry == null || chapter == null ? -1 : entry.chapters.indexOf(chapter));
|
||||
worldCompound.setInteger("Page", page == null ? -1 : page.getID());
|
||||
worldCompound.setInteger("PageInIndex", pageInIndex);
|
||||
worldCompound.setString("SearchWord", searchWord);
|
||||
writeCompound(baseCompound, worldCompound);
|
||||
}
|
||||
}
|
||||
|
@ -88,26 +89,31 @@ public class PersistentClientData{
|
|||
|
||||
public static void openLastBookPage(GuiBooklet gui){
|
||||
NBTTagCompound worldCompound = getCompoundForWorld(getBaseCompound());
|
||||
if(worldCompound != null){
|
||||
if(worldCompound.hasKey("Entry")){
|
||||
int entry = worldCompound.getInteger("Entry");
|
||||
int chapter = worldCompound.getInteger("Chapter");
|
||||
int page = worldCompound.getInteger("Page");
|
||||
if(worldCompound != null && worldCompound.hasKey("Entry")){
|
||||
int entry = worldCompound.getInteger("Entry");
|
||||
int chapter = worldCompound.getInteger("Chapter");
|
||||
int page = worldCompound.getInteger("Page");
|
||||
|
||||
BookletIndexEntry currentIndexEntry = entry == -1 ? null : InitBooklet.entries.get(entry);
|
||||
BookletChapter currentChapter = chapter == -1 || entry == -1 || currentIndexEntry.chapters.size() <= chapter ? null : currentIndexEntry.chapters.get(chapter);
|
||||
BookletPage currentPage = chapter == -1 || currentChapter == null || currentChapter.pages.length <= page-1 ? null : currentChapter.pages[page-1];
|
||||
int pageInIndex = worldCompound.getInteger("PageInIndex");
|
||||
BookletIndexEntry currentIndexEntry = entry == -1 ? null : InitBooklet.entries.get(entry);
|
||||
BookletChapter currentChapter = chapter == -1 || entry == -1 || currentIndexEntry.chapters.size() <= chapter ? null : currentIndexEntry.chapters.get(chapter);
|
||||
BookletPage currentPage = chapter == -1 || currentChapter == null || currentChapter.pages.length <= page-1 ? null : currentChapter.pages[page-1];
|
||||
int pageInIndex = worldCompound.getInteger("PageInIndex");
|
||||
|
||||
gui.openIndexEntry(currentIndexEntry, pageInIndex, true);
|
||||
if(currentChapter != null){
|
||||
gui.openChapter(currentChapter, currentPage);
|
||||
}
|
||||
return;
|
||||
gui.openIndexEntry(currentIndexEntry, pageInIndex, true);
|
||||
if(currentChapter != null){
|
||||
gui.openChapter(currentChapter, currentPage);
|
||||
}
|
||||
|
||||
String searchText = worldCompound.getString("SearchWord");
|
||||
if(!searchText.isEmpty()){
|
||||
gui.searchField.setText(searchText);
|
||||
gui.updateSearchBar();
|
||||
}
|
||||
}
|
||||
//If everything fails, initialize the front page
|
||||
gui.openIndexEntry(null, 1, true);
|
||||
else{
|
||||
//If everything fails, initialize the front page
|
||||
gui.openIndexEntry(null, 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBoolean(String name, boolean bool){
|
||||
|
|
Loading…
Reference in a new issue