mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 23:28:35 +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 BookletIndexEntry currentIndexEntry;
|
||||||
public int pageOpenInIndex;
|
public int pageOpenInIndex;
|
||||||
public int indexPageAmount;
|
public int indexPageAmount;
|
||||||
public GuiButton buttonForward;
|
private GuiButton buttonForward;
|
||||||
public GuiButton buttonBackward;
|
private GuiButton buttonBackward;
|
||||||
public GuiButton buttonPreviousScreen;
|
private GuiButton buttonPreviousScreen;
|
||||||
public GuiButton buttonPreviouslyOpenedGui;
|
private GuiButton buttonPreviouslyOpenedGui;
|
||||||
public GuiButton buttonUpdate;
|
private GuiButton buttonUpdate;
|
||||||
public GuiButton buttonTwitter;
|
private GuiButton buttonTwitter;
|
||||||
public GuiButton buttonForum;
|
private GuiButton buttonForum;
|
||||||
public GuiButton buttonAchievements;
|
private GuiButton buttonAchievements;
|
||||||
public GuiButton buttonConfig;
|
private GuiButton buttonConfig;
|
||||||
public GuiButton[] chapterButtons = new GuiButton[CHAPTER_BUTTONS_AMOUNT];
|
private GuiButton[] chapterButtons = new GuiButton[CHAPTER_BUTTONS_AMOUNT];
|
||||||
private GuiTextField searchField;
|
public GuiTextField searchField;
|
||||||
private int ticksElapsed;
|
private int ticksElapsed;
|
||||||
private boolean mousePressed;
|
private boolean mousePressed;
|
||||||
|
|
||||||
|
@ -166,12 +166,19 @@ public class GuiBooklet extends GuiScreen{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(char theChar, int key){
|
public void keyTyped(char theChar, int key){
|
||||||
if(key != 1 && this.searchField.isFocused()){
|
if(key != 1 && this.searchField.isFocused()){
|
||||||
this.searchField.textboxKeyTyped(theChar, key);
|
this.searchField.textboxKeyTyped(theChar, key);
|
||||||
|
this.updateSearchBar();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
super.keyTyped(theChar, key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void updateSearchBar(){
|
||||||
if(this.currentIndexEntry instanceof BookletEntryAllSearch){
|
if(this.currentIndexEntry instanceof BookletEntryAllSearch){
|
||||||
BookletEntryAllSearch currentEntry = (BookletEntryAllSearch)this.currentIndexEntry;
|
BookletEntryAllSearch currentEntry = (BookletEntryAllSearch)this.currentIndexEntry;
|
||||||
if(this.searchField.getText() != null && !this.searchField.getText().isEmpty()){
|
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);
|
this.openIndexEntry(this.currentIndexEntry, this.pageOpenInIndex, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
super.keyTyped(theChar, key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void mouseClicked(int par1, int par2, int par3){
|
protected void mouseClicked(int par1, int par2, int par3){
|
||||||
|
@ -398,7 +401,7 @@ public class GuiBooklet extends GuiScreen{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuiClosed(){
|
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
|
@Override
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class PersistentClientData{
|
||||||
|
|
||||||
private static File theFile;
|
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 baseCompound = getBaseCompound();
|
||||||
NBTTagCompound worldCompound = getCompoundForWorld(baseCompound);
|
NBTTagCompound worldCompound = getCompoundForWorld(baseCompound);
|
||||||
if(worldCompound != null){
|
if(worldCompound != null){
|
||||||
|
@ -39,6 +39,7 @@ public class PersistentClientData{
|
||||||
worldCompound.setInteger("Chapter", entry == null || chapter == null ? -1 : entry.chapters.indexOf(chapter));
|
worldCompound.setInteger("Chapter", entry == null || chapter == null ? -1 : entry.chapters.indexOf(chapter));
|
||||||
worldCompound.setInteger("Page", page == null ? -1 : page.getID());
|
worldCompound.setInteger("Page", page == null ? -1 : page.getID());
|
||||||
worldCompound.setInteger("PageInIndex", pageInIndex);
|
worldCompound.setInteger("PageInIndex", pageInIndex);
|
||||||
|
worldCompound.setString("SearchWord", searchWord);
|
||||||
writeCompound(baseCompound, worldCompound);
|
writeCompound(baseCompound, worldCompound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,8 +89,7 @@ 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){
|
if(worldCompound != null && worldCompound.hasKey("Entry")){
|
||||||
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");
|
||||||
|
@ -103,12 +103,18 @@ public class PersistentClientData{
|
||||||
if(currentChapter != null){
|
if(currentChapter != null){
|
||||||
gui.openChapter(currentChapter, currentPage);
|
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
|
//If everything fails, initialize the front page
|
||||||
gui.openIndexEntry(null, 1, true);
|
gui.openIndexEntry(null, 1, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void setBoolean(String name, boolean bool){
|
public static void setBoolean(String name, boolean bool){
|
||||||
NBTTagCompound baseCompound = getBaseCompound();
|
NBTTagCompound baseCompound = getBaseCompound();
|
||||||
|
|
Loading…
Reference in a new issue