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,12 +166,19 @@ 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);
|
||||
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()){
|
||||
|
@ -189,10 +196,6 @@ public class GuiBooklet extends GuiScreen{
|
|||
this.openIndexEntry(this.currentIndexEntry, this.pageOpenInIndex, false);
|
||||
}
|
||||
}
|
||||
else{
|
||||
super.keyTyped(theChar, key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int par1, int par2, int 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,8 +89,7 @@ public class PersistentClientData{
|
|||
|
||||
public static void openLastBookPage(GuiBooklet gui){
|
||||
NBTTagCompound worldCompound = getCompoundForWorld(getBaseCompound());
|
||||
if(worldCompound != null){
|
||||
if(worldCompound.hasKey("Entry")){
|
||||
if(worldCompound != null && worldCompound.hasKey("Entry")){
|
||||
int entry = worldCompound.getInteger("Entry");
|
||||
int chapter = worldCompound.getInteger("Chapter");
|
||||
int page = worldCompound.getInteger("Page");
|
||||
|
@ -103,12 +103,18 @@ public class PersistentClientData{
|
|||
if(currentChapter != null){
|
||||
gui.openChapter(currentChapter, currentPage);
|
||||
}
|
||||
return;
|
||||
|
||||
String searchText = worldCompound.getString("SearchWord");
|
||||
if(!searchText.isEmpty()){
|
||||
gui.searchField.setText(searchText);
|
||||
gui.updateSearchBar();
|
||||
}
|
||||
}
|
||||
else{
|
||||
//If everything fails, initialize the front page
|
||||
gui.openIndexEntry(null, 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBoolean(String name, boolean bool){
|
||||
NBTTagCompound baseCompound = getBaseCompound();
|
||||
|
|
Loading…
Reference in a new issue