From 13351e498e4811865d1c386043ad7307787adcb5 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 1 Nov 2016 12:00:49 +0100 Subject: [PATCH] Made the booklet always show the search bar and just put you into the all items section --- .../api/ActuallyAdditionsAPI.java | 4 ++ .../mod/booklet/BookletUtils.java | 46 +++++++++++-------- .../mod/booklet/GuiBooklet.java | 9 ++-- .../mod/booklet/InitBooklet.java | 4 ++ .../mod/booklet/entry/BookletEntry.java | 3 +- .../booklet/entry/BookletEntryAllSearch.java | 18 -------- .../assets/actuallyadditions/lang/en_US.lang | 4 +- 7 files changed, 42 insertions(+), 46 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index e68aaf884..6ea55b04e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -11,6 +11,7 @@ package de.ellpeck.actuallyadditions.api; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; +import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter; import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry; import de.ellpeck.actuallyadditions.api.internal.IMethodHandler; import de.ellpeck.actuallyadditions.api.laser.ILaserRelayConnectionHandler; @@ -42,6 +43,9 @@ public final class ActuallyAdditionsAPI{ public static final List COMPOST_RECIPES = new ArrayList(); public static final Map OIL_GENERATOR_RECIPES = new HashMap(); public static final List BOOKLET_ENTRIES = new ArrayList(); + //This is added to automatically, you don't need to add anything to this list + public static final List ALL_CHAPTERS = new ArrayList(); + //This is added to automatically, you don't need to add anything to this list public static final List BOOKLET_PAGES_WITH_ITEM_OR_FLUID_DATA = new ArrayList(); public static final List STONE_ORES = new ArrayList(); public static final List NETHERRACK_ORES = new ArrayList(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/BookletUtils.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/BookletUtils.java index 4c91c3783..a2cf8e949 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/BookletUtils.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/BookletUtils.java @@ -233,22 +233,34 @@ public final class BookletUtils{ */ @SideOnly(Side.CLIENT) public static void updateSearchBar(GuiBooklet booklet){ - if(booklet.currentEntrySet.getCurrentEntry() instanceof BookletEntryAllSearch){ - BookletEntryAllSearch currentEntry = (BookletEntryAllSearch)booklet.currentEntrySet.getCurrentEntry(); - if(booklet.searchField.getText() != null && !booklet.searchField.getText().isEmpty()){ - currentEntry.chapters.clear(); + boolean change = false; - for(IBookletChapter chapter : currentEntry.allChapters){ - String searchFieldText = booklet.searchField.getText().toLowerCase(Locale.ROOT); - if(chapter.getLocalizedName().toLowerCase(Locale.ROOT).contains(searchFieldText) || getChapterStacksContainString(searchFieldText, chapter)){ - currentEntry.chapters.add(chapter); - } + IBookletEntry current = booklet.currentEntrySet.getCurrentEntry(); + boolean isAllSearch = current instanceof BookletEntryAllSearch; + + if(booklet.searchField.getText() != null && !booklet.searchField.getText().isEmpty()){ + if(!isAllSearch){ + openIndexEntry(booklet, ActuallyAdditionsAPI.allAndSearch, 1, false); + current = booklet.currentEntrySet.getCurrentEntry(); + } + + current.getChapters().clear(); + for(IBookletChapter chapter : ActuallyAdditionsAPI.ALL_CHAPTERS){ + String searchFieldText = booklet.searchField.getText().toLowerCase(Locale.ROOT); + if(chapter.getLocalizedName().toLowerCase(Locale.ROOT).contains(searchFieldText) || getChapterStacksContainString(searchFieldText, chapter)){ + current.getChapters().add(chapter); } } - else{ - currentEntry.setChapters((ArrayList)currentEntry.allChapters.clone()); - } - openIndexEntry(booklet, booklet.currentEntrySet.getCurrentEntry(), booklet.currentEntrySet.getPageInIndex(), false); + + change = true; + } + else if(isAllSearch){ + current.setChapters(ActuallyAdditionsAPI.ALL_CHAPTERS); + change = true; + } + + if(change){ + openIndexEntry(booklet, current, booklet.currentEntrySet.getPageInIndex(), false); } } @@ -294,12 +306,10 @@ public final class BookletUtils{ @SideOnly(Side.CLIENT) public static void openIndexEntry(GuiBooklet booklet, IBookletEntry entry, int page, boolean resetTextField){ - booklet.searchField.setVisible(entry instanceof BookletEntryAllSearch); - booklet.searchField.setFocused(entry instanceof BookletEntryAllSearch); if(resetTextField){ booklet.searchField.setText(""); if(entry instanceof BookletEntryAllSearch){ - entry.setChapters((List)((BookletEntryAllSearch)entry).allChapters.clone()); + entry.setChapters(ActuallyAdditionsAPI.ALL_CHAPTERS); } } @@ -381,10 +391,6 @@ public final class BookletUtils{ return; } - booklet.searchField.setVisible(false); - booklet.searchField.setFocused(false); - booklet.searchField.setText(""); - booklet.currentEntrySet.setChapter(chapter); if(booklet.currentEntrySet.getCurrentPage() != null){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java index 9a542cea4..7bebf949d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java @@ -18,7 +18,6 @@ import de.ellpeck.actuallyadditions.api.internal.IEntrySet; import de.ellpeck.actuallyadditions.mod.booklet.button.BookmarkButton; import de.ellpeck.actuallyadditions.mod.booklet.button.IndexButton; import de.ellpeck.actuallyadditions.mod.booklet.button.TexturedButton; -import de.ellpeck.actuallyadditions.mod.booklet.entry.BookletEntryAllSearch; import de.ellpeck.actuallyadditions.mod.booklet.entry.EntrySet; import de.ellpeck.actuallyadditions.mod.config.GuiConfiguration; import de.ellpeck.actuallyadditions.mod.data.PlayerData; @@ -131,8 +130,9 @@ public class GuiBooklet extends GuiScreen implements IBookletGui{ this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); //Draws the search bar - if(this.currentEntrySet.getCurrentEntry() instanceof BookletEntryAllSearch && this.currentEntrySet.getCurrentChapter() == null){ - this.drawTexturedModalRect(this.guiLeft+146, this.guiTop+160, 146, 80, 70, 14); + this.drawTexturedModalRect(this.guiLeft+146, this.guiTop+160, 146, 80, 70, 14); + if(!this.searchField.isFocused() && (this.searchField.getText() == null || this.searchField.getText().isEmpty())){ + this.drawString(this.fontRendererObj, TextFormatting.ITALIC+"Click to search...", this.guiLeft+148, this.guiTop+162, 0xFFFFFF); } //Draws Achievement Info @@ -373,10 +373,9 @@ public class GuiBooklet extends GuiScreen implements IBookletGui{ this.buttonList.add(this.bookmarkButtons[i]); } - this.searchField = new GuiTextField(4500, this.fontRendererObj, this.guiLeft+148, this.guiTop+162, 66, 10); + this.searchField = new GuiTextField(4500, this.fontRendererObj, this.guiLeft+148, this.guiTop+162, 70, 10); this.searchField.setMaxStringLength(30); this.searchField.setEnableBackgroundDrawing(false); - this.searchField.setCanLoseFocus(false); this.currentEntrySet.removeEntry(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java index bd27a6ad0..74c57ec93 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java @@ -68,6 +68,10 @@ public final class InitBooklet{ int count = 0; for(IBookletEntry entry : ActuallyAdditionsAPI.BOOKLET_ENTRIES){ for(IBookletChapter chapter : entry.getChapters()){ + if(!ActuallyAdditionsAPI.ALL_CHAPTERS.contains(chapter)){ + ActuallyAdditionsAPI.ALL_CHAPTERS.add(chapter); + } + for(BookletPage page : chapter.getPages()){ ItemStack[] items = page.getItemStacksForPage(); FluidStack[] fluids = page.getFluidStacksForPage(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/BookletEntry.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/BookletEntry.java index 5760af45b..e2e67f6bc 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/BookletEntry.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/BookletEntry.java @@ -40,7 +40,8 @@ public class BookletEntry implements IBookletEntry{ @Override public void setChapters(List chapters){ - this.chapters = chapters; + this.chapters.clear(); + this.chapters.addAll(chapters); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/BookletEntryAllSearch.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/BookletEntryAllSearch.java index cfcd4a0e1..76da4e361 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/BookletEntryAllSearch.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/entry/BookletEntryAllSearch.java @@ -10,28 +10,10 @@ package de.ellpeck.actuallyadditions.mod.booklet.entry; -import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter; - -import java.util.ArrayList; -import java.util.List; - public class BookletEntryAllSearch extends BookletEntry{ - public ArrayList allChapters = new ArrayList(); - public BookletEntryAllSearch(String unlocalizedName){ super(unlocalizedName); } - @Override - public void setChapters(List chapters){ - this.allChapters = (ArrayList)chapters; - this.chapters = (ArrayList)this.allChapters.clone(); - } - - @Override - public void addChapter(IBookletChapter chapter){ - this.allChapters.add(chapter); - this.chapters = (ArrayList)this.allChapters.clone(); - } } diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index 445aa880d..d8c444948 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -729,7 +729,7 @@ booklet.actuallyadditions.indexEntry.gettingStarted.name=Getting Started booklet.actuallyadditions.indexEntry.misc.name=Miscellaneous booklet.actuallyadditions.indexEntry.crossover.name=Mod Crossover booklet.actuallyadditions.indexEntry.functionalNoRF.name=Blocks that don't use RF -booklet.actuallyadditions.indexEntry.allAndSearch.name=All Items and Search +booklet.actuallyadditions.indexEntry.allAndSearch.name=A list of everything booklet.actuallyadditions.indexEntry.functionalRF.name=Blocks that use RF booklet.actuallyadditions.indexEntry.generatingRF.name=Blocks that generate RF booklet.actuallyadditions.indexEntry.itemsNoRF.name=Items that don't use RF @@ -921,7 +921,7 @@ booklet.actuallyadditions.chapter.crystals.name=Crystals and Reconstructor booklet.actuallyadditions.chapter.crystals.text.1=The Atomic Reconstructor is used to craft Crystals, which are the main crafting ingredient in most items from Actually Additions. Upon being supplied with power, it shoots out a Laser. When the Laser hits a block, it will convert all surrounding items and blocks, provided they can be converted. When shooting a laser, it uses RF, but additional rates vary depending on the conversion. booklet.actuallyadditions.chapter.crystals.text.2=There are various Lenses that can be attached to the Reconstructor that don't all follow the default behavior of the Reconstructor and are able to do some neat things. See the Reconstruction section in the booklet for more information. When right-clicking the Reconstructor with a Redstone Torch in hand, it will change between a mode where it gets deactivated by Redstone and a mode where it responds to pulses. booklet.actuallyadditions.chapter.crystals.text.3=It should be noted that any recipes listed without information about Lenses don't use one. I thought that was obvious. -booklet.actuallyadditions.chapter.crystals.text.5=When you have crafted a couple of items, you might want to find a way to automate this. There is a very simple way to do accomplish this: Place the Atomic Reconstructor down facing into a Precision Dropper (to find it, look it up in the All Items and Search Entry!). Next, place a Ranged Collector in the area that has the converted items set as a whitelist. Now you can just chuck your raw materials into the Dropper to convert them! +booklet.actuallyadditions.chapter.crystals.text.5=When you have crafted a couple of items, you might want to find a way to automate this. There is a very simple way to do accomplish this: Place the Atomic Reconstructor down facing into a Precision Dropper (to find it, look it up in the All Items Entry!). Next, place a Ranged Collector in the area that has the converted items set as a whitelist. Now you can just chuck your raw materials into the Dropper to convert them! booklet.actuallyadditions.chapter.crystals.text.6=Molecular Transformilator booklet.actuallyadditions.chapter.bookTutorial.name=Intro to the Manual