From f9a9ee4dc6ba86896a5f7f0cf29b5122e8ad3a48 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 11 Nov 2015 18:51:20 +0100 Subject: [PATCH] Moving stuff from the booklet gui to a Util class so that it isn't that cluttered, added comments and explanatations --- .../booklet/BookletUtils.java | 419 +++++++++++++++++ .../actuallyadditions/booklet/GuiBooklet.java | 431 +++--------------- .../booklet/InitBooklet.java | 23 +- .../booklet/{ => chapter}/BookletChapter.java | 8 +- .../{ => chapter}/BookletChapterCoffee.java | 5 +- .../{ => chapter}/BookletChapterCrusher.java | 5 +- .../BookletEntry.java} | 12 +- .../{ => entry}/BookletEntryAllSearch.java | 6 +- .../booklet/page/BookletPage.java | 7 +- .../nei/BookletInfoRecipeHandler.java | 2 +- .../nei/NeiScreenEvents.java | 9 +- .../util/playerdata/PersistentClientData.java | 17 +- 12 files changed, 538 insertions(+), 406 deletions(-) create mode 100644 src/main/java/ellpeck/actuallyadditions/booklet/BookletUtils.java rename src/main/java/ellpeck/actuallyadditions/booklet/{ => chapter}/BookletChapter.java (84%) rename src/main/java/ellpeck/actuallyadditions/booklet/{ => chapter}/BookletChapterCoffee.java (85%) rename src/main/java/ellpeck/actuallyadditions/booklet/{ => chapter}/BookletChapterCrusher.java (89%) rename src/main/java/ellpeck/actuallyadditions/booklet/{BookletIndexEntry.java => entry/BookletEntry.java} (81%) rename src/main/java/ellpeck/actuallyadditions/booklet/{ => entry}/BookletEntryAllSearch.java (82%) diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/BookletUtils.java b/src/main/java/ellpeck/actuallyadditions/booklet/BookletUtils.java new file mode 100644 index 000000000..d7e8577e4 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/booklet/BookletUtils.java @@ -0,0 +1,419 @@ +/* + * This file ("BookletUtils.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.booklet; + +import ellpeck.actuallyadditions.booklet.chapter.BookletChapter; +import ellpeck.actuallyadditions.booklet.entry.BookletEntry; +import ellpeck.actuallyadditions.booklet.entry.BookletEntryAllSearch; +import ellpeck.actuallyadditions.booklet.page.BookletPage; +import ellpeck.actuallyadditions.update.UpdateChecker; +import ellpeck.actuallyadditions.util.*; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IChatComponent; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Locale; + +public class BookletUtils{ + + /** + * Tries to open a URL in the Browser + * @param url The URL + * @param shiftUrl The URL to open when Shift is held + */ + public static void openBrowser(String url, String shiftUrl){ + try{ + if(Desktop.isDesktopSupported()){ + if(shiftUrl.equals(url) || KeyUtil.isShiftPressed()){ + Desktop.getDesktop().browse(new URI(shiftUrl)); + } + else{ + Desktop.getDesktop().browse(new URI(url)); + } + } + } + catch(Exception e){ + ModUtil.LOGGER.error("Something bad happened when trying to open a URL!", e); + } + } + + /** + * Tries to open a URL in the Browser + */ + public static void openBrowser(String url){ + openBrowser(url, url); + } + + /** + * Draws the Title of the current chapter, current index entry or just "Actually Additions" if neither is present + */ + public static void drawTitle(GuiBooklet booklet){ + if(booklet.currentIndexEntry != null){ + if(booklet.currentChapter == null){ + booklet.drawCenteredString(booklet.getFontRenderer(), booklet.currentIndexEntry.getLocalizedName(), booklet.guiLeft+booklet.xSize/2, booklet.guiTop-8, StringUtil.DECIMAL_COLOR_WHITE); + } + else{ + booklet.drawCenteredString(booklet.getFontRenderer(), booklet.currentChapter.getLocalizedName(), booklet.guiLeft+booklet.xSize/2, booklet.guiTop-8, StringUtil.DECIMAL_COLOR_WHITE); + } + } + else{ + booklet.drawCenteredString(booklet.getFontRenderer(), StringUtil.localize("itemGroup."+ModUtil.MOD_ID_LOWER), booklet.guiLeft+booklet.xSize/2, booklet.guiTop-8, StringUtil.DECIMAL_COLOR_WHITE); + } + } + + /** + * Pre-renders the booklet page, including + * -the number of a page and its content (text, crafting recipe etc.) + * -the number of a page in a chapter + * -the amount of words in the index + */ + public static void renderPre(GuiBooklet booklet, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){ + if(booklet.currentIndexEntry != null){ + //Renders Booklet Page Number and Content + if(booklet.currentChapter != null && booklet.currentPage != null){ + booklet.drawCenteredString(booklet.getFontRenderer(), booklet.currentPage.getID()+"/"+booklet.currentChapter.pages.length, booklet.guiLeft+booklet.xSize/2, booklet.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE); + booklet.currentPage.renderPre(booklet, mouseX, mouseY, ticksElapsed, mousePressed); + } + //Renders Chapter Page Number + else{ + booklet.drawCenteredString(booklet.getFontRenderer(), booklet.pageOpenInIndex+"/"+booklet.indexPageAmount, booklet.guiLeft+booklet.xSize/2, booklet.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE); + } + } + //Renders the amount of words the book has + else{ + String wordCountString = StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".amountOfWords", InitBooklet.wordCount); + booklet.getFontRenderer().drawString(EnumChatFormatting.ITALIC+wordCountString, booklet.guiLeft+booklet.xSize-booklet.getFontRenderer().getStringWidth(wordCountString)-15, booklet.guiTop+booklet.ySize-18, 0); + } + } + + /** + * Draws all of the hovering texts for the buttons that need explanation in the booklet + */ + @SuppressWarnings("unchecked") + public static void doHoverTexts(GuiBooklet booklet, int mouseX, int mouseY){ + //Achievements Hover Text + if(mouseX >= booklet.guiLeft+138 && mouseX <= booklet.guiLeft+138+7 && mouseY >= booklet.guiTop && mouseY <= booklet.guiTop+7){ + booklet.drawHoveringText(Collections.singletonList(EnumChatFormatting.GOLD+"Show Achievements"), mouseX, mouseY); + } + //Config Hover Text + if(mouseX >= booklet.guiLeft+138 && mouseX <= booklet.guiLeft+138+7 && mouseY >= booklet.guiTop+10 && mouseY <= booklet.guiTop+10+7){ + ArrayList list = new ArrayList(); + list.add(EnumChatFormatting.GOLD+"Show Configuration GUI"); + list.addAll(booklet.getFontRenderer().listFormattedStringToWidth("It is highly recommended that you restart your game after changing anything as that prevents possible bugs occuring!", GuiBooklet.TOOLTIP_SPLIT_LENGTH)); + booklet.drawHoveringText(list, mouseX, mouseY); + + } + //Twitter Hover Text + if(mouseX >= booklet.guiLeft && mouseX <= booklet.guiLeft+7 && mouseY >= booklet.guiTop && mouseY <= booklet.guiTop+7){ + booklet.drawHoveringText(Collections.singletonList(EnumChatFormatting.GOLD+"Open @ActAddMod on Twitter in Browser"), mouseX, mouseY); + } + //Forum Hover Text + if(mouseX >= booklet.guiLeft && mouseX <= booklet.guiLeft+7 && mouseY >= booklet.guiTop+10 && mouseY <= booklet.guiTop+10+7){ + booklet.drawHoveringText(Collections.singletonList(EnumChatFormatting.GOLD+"Open Minecraft Forum Post in Browser"), mouseX, mouseY); + } + //Update Checker Hover Text + if(mouseX >= booklet.guiLeft-11 && mouseX <= booklet.guiLeft-11+10 && mouseY >= booklet.guiTop-11 && mouseY <= booklet.guiTop-11+10){ + ArrayList list = new ArrayList(); + if(UpdateChecker.checkFailed){ + list.add(IChatComponent.Serializer.func_150699_a(StringUtil.localize("info."+ModUtil.MOD_ID_LOWER+".update.failed")).getFormattedText()); + } + else if(UpdateChecker.needsUpdateNotify){ + list.add(IChatComponent.Serializer.func_150699_a(StringUtil.localize("info."+ModUtil.MOD_ID_LOWER+".update.generic")).getFormattedText()); + list.add(IChatComponent.Serializer.func_150699_a(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID_LOWER+".update.versionCompare", ModUtil.VERSION, UpdateChecker.updateVersion)).getFormattedText()); + list.add(StringUtil.localize("info."+ModUtil.MOD_ID_LOWER+".update.buttonOptions")); + } + booklet.drawHoveringText(list, mouseX, mouseY); + } + } + + /** + * Updates the search bar, should be called when it is getting typed into + */ + @SuppressWarnings("unchecked") + public static void updateSearchBar(GuiBooklet booklet){ + if(booklet.currentIndexEntry instanceof BookletEntryAllSearch){ + BookletEntryAllSearch currentEntry = (BookletEntryAllSearch)booklet.currentIndexEntry; + if(booklet.searchField.getText() != null && !booklet.searchField.getText().isEmpty()){ + currentEntry.chapters.clear(); + + for(BookletChapter chapter : currentEntry.allChapters){ + if(chapter.getLocalizedName().toLowerCase(Locale.ROOT).contains(booklet.searchField.getText().toLowerCase(Locale.ROOT))){ + currentEntry.chapters.add(chapter); + } + } + } + else{ + currentEntry.chapters = (ArrayList)currentEntry.allChapters.clone(); + } + openIndexEntry(booklet, booklet.currentIndexEntry, booklet.pageOpenInIndex, false); + } + } + + /** + * Called when one of the buttons to open an index or a chapter is pressed + */ + public static void handleChapterButtonClick(GuiBooklet booklet, GuiButton button){ + int place = Util.arrayContains(booklet.chapterButtons, button); + if(place >= 0){ + if(booklet.currentIndexEntry != null){ + if(booklet.currentChapter == null){ + if(place < booklet.currentIndexEntry.chapters.size()){ + BookletChapter chap = booklet.currentIndexEntry.chapters.get(place+(booklet.chapterButtons.length*booklet.pageOpenInIndex-booklet.chapterButtons.length)); + openChapter(booklet, chap, chap.pages[0]); + } + } + } + else{ + if(place < InitBooklet.entries.size()){ + openIndexEntry(booklet, InitBooklet.entries.get(place), 1, true); + } + } + } + } + + /** + * Called when the "next page"-button is pressed + */ + public static void handleNextPage(GuiBooklet booklet){ + if(booklet.currentIndexEntry != null){ + if(booklet.currentPage != null){ + BookletPage page = getNextPage(booklet.currentChapter, booklet.currentPage); + if(page != null){ + booklet.currentPage = page; + } + + booklet.buttonForward.visible = getNextPage(booklet.currentChapter, booklet.currentPage) != null; + booklet.buttonBackward.visible = getPrevPage(booklet.currentChapter, booklet.currentPage) != null; + } + else{ + openIndexEntry(booklet, booklet.currentIndexEntry, booklet.pageOpenInIndex+1, !(booklet.currentIndexEntry instanceof BookletEntryAllSearch)); + } + } + } + + /** + * Called when the "previous page"-button is pressed + */ + public static void handlePreviousPage(GuiBooklet booklet){ + if(booklet.currentIndexEntry != null){ + if(booklet.currentPage != null){ + BookletPage page = getPrevPage(booklet.currentChapter, booklet.currentPage); + if(page != null){ + booklet.currentPage = page; + } + + booklet.buttonForward.visible = getNextPage(booklet.currentChapter, booklet.currentPage) != null; + booklet.buttonBackward.visible = getPrevPage(booklet.currentChapter, booklet.currentPage) != null; + } + else{ + openIndexEntry(booklet, booklet.currentIndexEntry, booklet.pageOpenInIndex-1, !(booklet.currentIndexEntry instanceof BookletEntryAllSearch)); + } + } + } + + /** + * Gets the next available page in the booklet (or null if there is none) + */ + private static BookletPage getNextPage(BookletChapter chapter, BookletPage currentPage){ + for(int i = 0; i < chapter.pages.length; i++){ + if(chapter.pages[i] == currentPage){ + if(i+1 < chapter.pages.length){ + return chapter.pages[i+1]; + } + } + } + return null; + } + + /** + * Gets the previous available page in the booklet (or null if there is none) + */ + private static BookletPage getPrevPage(BookletChapter chapter, BookletPage currentPage){ + for(int i = 0; i < chapter.pages.length; i++){ + if(chapter.pages[i] == currentPage){ + if(i-1 >= 0){ + return chapter.pages[i-1]; + } + } + } + return null; + } + + /** + * Opens a chapter in the booklet. + * Can only be done when the chapter is not null and an index entry is opened in the booklet + */ + public static void openChapter(GuiBooklet booklet, BookletChapter chapter, BookletPage page){ + if(chapter == null || booklet.currentIndexEntry == null){ + return; + } + + booklet.searchField.setVisible(false); + booklet.searchField.setFocused(false); + booklet.searchField.setText(""); + + booklet.currentChapter = chapter; + booklet.currentPage = page != null && doesChapterHavePage(chapter, page) ? page : chapter.pages[0]; + + booklet.buttonForward.visible = getNextPage(chapter, booklet.currentPage) != null; + booklet.buttonBackward.visible = getPrevPage(chapter, booklet.currentPage) != null; + booklet.buttonPreviousScreen.visible = true; + booklet.buttonPreviouslyOpenedGui.visible = booklet.parentScreen != null; + + for(GuiButton chapterButton : booklet.chapterButtons){ + chapterButton.visible = false; + } + } + + /** + * Checks if a chapter has a certain page + */ + private static boolean doesChapterHavePage(BookletChapter chapter, BookletPage page){ + for(BookletPage aPage : chapter.pages){ + if(aPage == page){ + return true; + } + } + return false; + } + + /** + * Opens an index entry in the booklet. + * @param resetTextField will clear the text in the searchField and reset the search entry's data + */ + @SuppressWarnings("unchecked") + public static void openIndexEntry(GuiBooklet booklet, BookletEntry 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.chapters = (ArrayList)((BookletEntryAllSearch)entry).allChapters.clone(); + } + } + + booklet.currentPage = null; + booklet.currentChapter = null; + + booklet.currentIndexEntry = entry; + booklet.indexPageAmount = entry == null ? 1 : entry.chapters.size()/booklet.chapterButtons.length+1; + booklet.pageOpenInIndex = entry == null ? 1 : (booklet.indexPageAmount <= page || page <= 0 ? booklet.indexPageAmount : page); + + booklet.buttonPreviousScreen.visible = entry != null; + booklet.buttonForward.visible = booklet.pageOpenInIndex < booklet.indexPageAmount; + booklet.buttonBackward.visible = booklet.pageOpenInIndex > 1; + booklet.buttonPreviouslyOpenedGui.visible = booklet.parentScreen != null; + + for(int i = 0; i < booklet.chapterButtons.length; i++){ + IndexButton button = (IndexButton)booklet.chapterButtons[i]; + if(entry == null){ + boolean entryExists = InitBooklet.entries.size() > i; + button.visible = entryExists; + if(entryExists){ + button.displayString = InitBooklet.entries.get(i).getNameWithColor(); + button.chap = null; + } + } + else{ + boolean entryExists = entry.chapters.size() > i+(booklet.chapterButtons.length*booklet.pageOpenInIndex-booklet.chapterButtons.length); + button.visible = entryExists; + if(entryExists){ + BookletChapter chap = entry.chapters.get(i+(booklet.chapterButtons.length*booklet.pageOpenInIndex-booklet.chapterButtons.length)); + button.displayString = chap.getNameWithColor(); + button.chap = chap; + } + } + } + } + + public static class IndexButton extends GuiButton{ + + public BookletChapter chap; + private GuiBooklet gui; + + public IndexButton(int id, int x, int y, int width, int height, String text, GuiBooklet gui){ + super(id, x, y, width, height, text); + this.gui = gui; + } + + @Override + public void drawButton(Minecraft minecraft, int mouseX, int mouseY){ + if(this.visible){ + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition+this.width && mouseY < this.yPosition+this.height; + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + this.mouseDragged(minecraft, mouseX, mouseY); + + int textOffsetX = 0; + if(this.chap != null){ + if(this.chap.displayStack != null){ + GL11.glPushMatrix(); + BookletPage.renderItem(this.gui, this.chap.displayStack, this.xPosition-4, this.yPosition, 0.725F); + GL11.glPopMatrix(); + textOffsetX = 10; + } + } + + if(this.field_146123_n){ + GL11.glPushMatrix(); + AssetUtil.drawHorizontalGradientRect(this.xPosition+textOffsetX-1, this.yPosition+this.height-1, this.xPosition+this.gui.getFontRenderer().getStringWidth(this.displayString)+textOffsetX+1, this.yPosition+this.height, 0x80 << 24 | 22271, 22271); + GL11.glPopMatrix(); + } + + this.gui.getFontRenderer().drawString(this.displayString, this.xPosition+textOffsetX, this.yPosition+(this.height-8)/2, 0); + } + } + } + + public static class TexturedButton extends GuiButton{ + + public int texturePosX; + public int texturePosY; + + public TexturedButton(int id, int x, int y, int texturePosX, int texturePosY, int width, int height){ + super(id, x, y, width, height, ""); + this.texturePosX = texturePosX; + this.texturePosY = texturePosY; + } + + public void setTexturePos(int x, int y){ + this.texturePosX = x; + this.texturePosY = y; + } + + @Override + public void drawButton(Minecraft minecraft, int x, int y){ + if(this.visible){ + minecraft.getTextureManager().bindTexture(GuiBooklet.resLoc); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.field_146123_n = x >= this.xPosition && y >= this.yPosition && x < this.xPosition+this.width && y < this.yPosition+this.height; + int k = this.getHoverState(this.field_146123_n); + if(k == 0){ + k = 1; + } + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + this.drawTexturedModalRect(this.xPosition, this.yPosition, this.texturePosX, this.texturePosY-this.height+k*this.height, this.width, this.height); + this.mouseDragged(minecraft, x, y); + } + } + } +} diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/GuiBooklet.java b/src/main/java/ellpeck/actuallyadditions/booklet/GuiBooklet.java index d84746425..a44fed2d4 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/GuiBooklet.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/GuiBooklet.java @@ -12,28 +12,23 @@ package ellpeck.actuallyadditions.booklet; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.booklet.chapter.BookletChapter; +import ellpeck.actuallyadditions.booklet.entry.BookletEntry; +import ellpeck.actuallyadditions.booklet.entry.BookletEntryAllSearch; import ellpeck.actuallyadditions.booklet.page.BookletPage; import ellpeck.actuallyadditions.config.GuiConfiguration; import ellpeck.actuallyadditions.proxy.ClientProxy; import ellpeck.actuallyadditions.update.UpdateChecker; -import ellpeck.actuallyadditions.util.*; +import ellpeck.actuallyadditions.util.AssetUtil; import ellpeck.actuallyadditions.util.playerdata.PersistentClientData; -import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.IChatComponent; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; -import java.awt.*; -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Locale; @SideOnly(Side.CLIENT) public class GuiBooklet extends GuiScreen{ @@ -50,24 +45,24 @@ public class GuiBooklet extends GuiScreen{ public int guiTop; public BookletPage currentPage; public BookletChapter currentChapter; - public BookletIndexEntry currentIndexEntry; + public BookletEntry currentIndexEntry; public int pageOpenInIndex; public int indexPageAmount; - 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 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]; public GuiTextField searchField; private int ticksElapsed; private boolean mousePressed; - private GuiScreen parentScreen; + public GuiScreen parentScreen; public GuiBooklet(GuiScreen parentScreen){ this.xSize = 146; @@ -79,93 +74,50 @@ public class GuiBooklet extends GuiScreen{ super.func_146283_a(list, x, y); } - @SuppressWarnings("unchecked") + public FontRenderer getFontRenderer(){ + return this.fontRendererObj; + } + @Override public void drawScreen(int x, int y, float f){ + //Fixes Unicode flag boolean unicodeBefore = this.fontRendererObj.getUnicodeFlag(); this.fontRendererObj.setUnicodeFlag(true); + //Draws the Background GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(ClientProxy.jingleAllTheWay ? resLocChristmas : (ClientProxy.pumpkinBlurPumpkinBlur ? resLocHalloween : (ClientProxy.bulletForMyValentine ? resLocValentine : resLoc))); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); this.mc.getTextureManager().bindTexture(resLoc); + //Draws the search bar if(this.currentIndexEntry instanceof BookletEntryAllSearch && this.currentChapter == null){ this.drawTexturedModalRect(this.guiLeft+146, this.guiTop+160, 146, 80, 70, 14); } + //Draws the title this.fontRendererObj.setUnicodeFlag(false); - if(this.currentIndexEntry != null){ - if(this.currentChapter == null){ - this.drawCenteredString(this.fontRendererObj, this.currentIndexEntry.getLocalizedName(), this.guiLeft+this.xSize/2, this.guiTop-8, StringUtil.DECIMAL_COLOR_WHITE); - } - else{ - this.drawCenteredString(this.fontRendererObj, this.currentChapter.getLocalizedName(), this.guiLeft+this.xSize/2, this.guiTop-8, StringUtil.DECIMAL_COLOR_WHITE); - } - } - else{ - this.drawCenteredString(this.fontRendererObj, StringUtil.localize("itemGroup."+ModUtil.MOD_ID_LOWER), this.guiLeft+this.xSize/2, this.guiTop-8, StringUtil.DECIMAL_COLOR_WHITE); - } + BookletUtils.drawTitle(this); this.fontRendererObj.setUnicodeFlag(true); - if(this.currentIndexEntry != null){ - if(this.currentChapter != null && this.currentPage != null){ - this.drawCenteredString(this.fontRendererObj, this.currentPage.getID()+"/"+this.currentChapter.pages.length, this.guiLeft+this.xSize/2, this.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE); - this.currentPage.renderPre(this, x, y, this.ticksElapsed, this.mousePressed); - } - else{ - this.drawCenteredString(this.fontRendererObj, this.pageOpenInIndex+"/"+this.indexPageAmount, this.guiLeft+this.xSize/2, this.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE); - } - } - else{ - String wordCountString = StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".amountOfWords", InitBooklet.wordCount); - this.fontRendererObj.drawString(EnumChatFormatting.ITALIC+wordCountString, this.guiLeft+this.xSize-this.fontRendererObj.getStringWidth(wordCountString)-15, this.guiTop+this.ySize-18, 0); - } + //Pre-Renders the current page's content etc. + BookletUtils.renderPre(this, x, y, this.ticksElapsed, this.mousePressed); + //Does vanilla drawing stuff super.drawScreen(x, y, f); this.searchField.drawTextBox(); + //Renders the current page's content if(this.currentIndexEntry != null && this.currentChapter != null && this.currentPage != null){ this.currentPage.render(this, x, y, this.ticksElapsed, this.mousePressed); } + //Draws hovering texts for buttons this.fontRendererObj.setUnicodeFlag(false); - //Achievements Hover Text - if(x >= this.guiLeft+138 && x <= this.guiLeft+138+7 && y >= this.guiTop && y <= this.guiTop+7){ - this.func_146283_a(Collections.singletonList(EnumChatFormatting.GOLD+"Show Achievements"), x, y); - } - //Config Hover Text - if(x >= this.guiLeft+138 && x <= this.guiLeft+138+7 && y >= this.guiTop+10 && y <= this.guiTop+10+7){ - ArrayList list = new ArrayList(); - list.add(EnumChatFormatting.GOLD+"Show Configuration GUI"); - list.addAll(this.fontRendererObj.listFormattedStringToWidth("It is highly recommended that you restart your game after changing anything as that prevents possible bugs occuring!", TOOLTIP_SPLIT_LENGTH)); - this.func_146283_a(list, x, y); - - } - //Twitter Hover Text - if(x >= this.guiLeft && x <= this.guiLeft+7 && y >= this.guiTop && y <= this.guiTop+7){ - this.func_146283_a(Collections.singletonList(EnumChatFormatting.GOLD+"Open @ActAddMod on Twitter in Browser"), x, y); - } - //Forum Hover Text - if(x >= this.guiLeft && x <= this.guiLeft+7 && y >= this.guiTop+10 && y <= this.guiTop+10+7){ - this.func_146283_a(Collections.singletonList(EnumChatFormatting.GOLD+"Open Minecraft Forum Post in Browser"), x, y); - } - //Update Checker Hover Text - if(x >= this.guiLeft-11 && x <= this.guiLeft-11+10 && y >= this.guiTop-11 && y <= this.guiTop-11+10){ - ArrayList list = new ArrayList(); - if(UpdateChecker.checkFailed){ - list.add(IChatComponent.Serializer.func_150699_a(StringUtil.localize("info."+ModUtil.MOD_ID_LOWER+".update.failed")).getFormattedText()); - } - else if(UpdateChecker.needsUpdateNotify){ - list.add(IChatComponent.Serializer.func_150699_a(StringUtil.localize("info."+ModUtil.MOD_ID_LOWER+".update.generic")).getFormattedText()); - list.add(IChatComponent.Serializer.func_150699_a(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID_LOWER+".update.versionCompare", ModUtil.VERSION, UpdateChecker.updateVersion)).getFormattedText()); - list.add(StringUtil.localize("info."+ModUtil.MOD_ID_LOWER+".update.buttonOptions")); - } - this.func_146283_a(list, x, y); - } - + BookletUtils.doHoverTexts(this, x, y); this.fontRendererObj.setUnicodeFlag(unicodeBefore); + //Resets mouse if(this.mousePressed){ this.mousePressed = false; } @@ -175,151 +127,70 @@ public class GuiBooklet extends GuiScreen{ public void keyTyped(char theChar, int key){ if(key != 1 && this.searchField.isFocused()){ this.searchField.textboxKeyTyped(theChar, key); - this.updateSearchBar(); + BookletUtils.updateSearchBar(this); } 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(Locale.ROOT).contains(this.searchField.getText().toLowerCase(Locale.ROOT))){ - currentEntry.chapters.add(chapter); - } - } - } - else{ - currentEntry.chapters = (ArrayList)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); - + //Notifys the booklet of the mouse being pressed if(par3 == 0 && this.currentChapter != null){ this.mousePressed = true; } - super.mouseClicked(par1, par2, par3); } @Override public void actionPerformed(GuiButton button){ + //Handles going to the parent GUI if(button == this.buttonPreviouslyOpenedGui){ if(this.parentScreen != null){ mc.displayGuiScreen(this.parentScreen); } } + //Handles update else if(button == this.buttonUpdate){ if(UpdateChecker.needsUpdateNotify){ - try{ - if(Desktop.isDesktopSupported()){ - if(KeyUtil.isShiftPressed()){ - Desktop.getDesktop().browse(new URI(UpdateChecker.DOWNLOAD_LINK)); - } - else{ - Desktop.getDesktop().browse(new URI(UpdateChecker.CHANGELOG_LINK)); - } - } - } - catch(Exception e){ - ModUtil.LOGGER.error("Something bad happened when trying to open a URL!", e); - } + BookletUtils.openBrowser(UpdateChecker.CHANGELOG_LINK, UpdateChecker.DOWNLOAD_LINK); } } + //Handles Twitter else if(button == this.buttonTwitter){ - try{ - if(Desktop.isDesktopSupported()){ - Desktop.getDesktop().browse(new URI("http://twitter.com/ActAddMod")); - } - } - catch(Exception e){ - ModUtil.LOGGER.error("Something bad happened when trying to open a URL!", e); - } + BookletUtils.openBrowser("http://twitter.com/ActAddMod"); } + //Handles forum else if(button == this.buttonForum){ - try{ - if(Desktop.isDesktopSupported()){ - Desktop.getDesktop().browse(new URI("http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2551118")); - } - } - catch(Exception e){ - ModUtil.LOGGER.error("Something bad happened when trying to open a URL!", e); - } + BookletUtils.openBrowser("http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2551118"); } + //Handles config else if(button == this.buttonConfig){ mc.displayGuiScreen(new GuiConfiguration(this)); } + //Handles achievements else if(button == this.buttonAchievements){ mc.displayGuiScreen(new GuiAAAchievements(this, mc.thePlayer.getStatFileWriter())); } else if(button == this.buttonForward){ - if(this.currentIndexEntry != null){ - if(this.currentPage != null){ - BookletPage page = this.getNextPage(this.currentChapter, this.currentPage); - if(page != null){ - this.currentPage = page; - } - - this.buttonForward.visible = this.getNextPage(this.currentChapter, this.currentPage) != null; - this.buttonBackward.visible = this.getPrevPage(this.currentChapter, this.currentPage) != null; - } - else{ - this.openIndexEntry(this.currentIndexEntry, this.pageOpenInIndex+1, !(this.currentIndexEntry instanceof BookletEntryAllSearch)); - } - } + BookletUtils.handleNextPage(this); } else if(button == this.buttonBackward){ - if(this.currentIndexEntry != null){ - if(this.currentPage != null){ - BookletPage page = this.getPrevPage(this.currentChapter, this.currentPage); - if(page != null){ - this.currentPage = page; - } - - this.buttonForward.visible = this.getNextPage(this.currentChapter, this.currentPage) != null; - this.buttonBackward.visible = this.getPrevPage(this.currentChapter, this.currentPage) != null; - } - else{ - this.openIndexEntry(this.currentIndexEntry, this.pageOpenInIndex-1, !(this.currentIndexEntry instanceof BookletEntryAllSearch)); - } - } + BookletUtils.handlePreviousPage(this); } + //Handles gonig from page to chapter or from chapter to index else if(button == this.buttonPreviousScreen){ if(this.currentChapter != null && this.currentChapter != InitBooklet.chapterIntro){ - this.openIndexEntry(this.currentIndexEntry, this.pageOpenInIndex, true); + BookletUtils.openIndexEntry(this, this.currentIndexEntry, this.pageOpenInIndex, true); } else{ - this.openIndexEntry(null, 1, true); + BookletUtils.openIndexEntry(this, null, 1, true); } } else{ - int place = Util.arrayContains(this.chapterButtons, button); - if(place >= 0){ - if(this.currentIndexEntry != null){ - if(this.currentChapter == null){ - if(place < this.currentIndexEntry.chapters.size()){ - BookletChapter chap = currentIndexEntry.chapters.get(place+(this.chapterButtons.length*this.pageOpenInIndex-this.chapterButtons.length)); - this.openChapter(chap, chap.pages[0]); - } - } - } - else{ - if(place < InitBooklet.entries.size()){ - this.openIndexEntry(InitBooklet.entries.get(place), 1, true); - } - } - } + BookletUtils.handleChapterButtonClick(this, button); } } @@ -329,36 +200,36 @@ public class GuiBooklet extends GuiScreen{ this.guiLeft = (this.width-this.xSize)/2; this.guiTop = (this.height-this.ySize)/2; - this.buttonForward = new TexturedButton(0, this.guiLeft+this.xSize, this.guiTop+this.ySize+2, 164, 0, 18, 10); + this.buttonForward = new BookletUtils.TexturedButton(0, this.guiLeft+this.xSize, this.guiTop+this.ySize+2, 164, 0, 18, 10); this.buttonList.add(this.buttonForward); - this.buttonBackward = new TexturedButton(1, this.guiLeft-18, this.guiTop+this.ySize+2, 146, 0, 18, 10); + this.buttonBackward = new BookletUtils.TexturedButton(1, this.guiLeft-18, this.guiTop+this.ySize+2, 146, 0, 18, 10); this.buttonList.add(this.buttonBackward); - this.buttonPreviousScreen = new TexturedButton(2, this.guiLeft+this.xSize/2-7, this.guiTop+this.ySize+2, 182, 0, 15, 10); + this.buttonPreviousScreen = new BookletUtils.TexturedButton(2, this.guiLeft+this.xSize/2-7, this.guiTop+this.ySize+2, 182, 0, 15, 10); this.buttonList.add(this.buttonPreviousScreen); - this.buttonPreviouslyOpenedGui = new TexturedButton(3, this.guiLeft+this.xSize/3, this.guiTop+this.ySize+2, 245, 44, 11, 15); + this.buttonPreviouslyOpenedGui = new BookletUtils.TexturedButton(3, this.guiLeft+this.xSize/3, this.guiTop+this.ySize+2, 245, 44, 11, 15); this.buttonList.add(this.buttonPreviouslyOpenedGui); - this.buttonUpdate = new TexturedButton(4, this.guiLeft-11, this.guiTop-11, 245, 0, 11, 11); + this.buttonUpdate = new BookletUtils.TexturedButton(4, this.guiLeft-11, this.guiTop-11, 245, 0, 11, 11); this.buttonUpdate.visible = UpdateChecker.needsUpdateNotify; this.buttonList.add(this.buttonUpdate); - this.buttonTwitter = new TexturedButton(5, this.guiLeft, this.guiTop, 213, 0, 8, 8); + this.buttonTwitter = new BookletUtils.TexturedButton(5, this.guiLeft, this.guiTop, 213, 0, 8, 8); this.buttonList.add(this.buttonTwitter); - this.buttonForum = new TexturedButton(6, this.guiLeft, this.guiTop+10, 221, 0, 8, 8); + this.buttonForum = new BookletUtils.TexturedButton(6, this.guiLeft, this.guiTop+10, 221, 0, 8, 8); this.buttonList.add(this.buttonForum); - this.buttonAchievements = new TexturedButton(7, this.guiLeft+138, this.guiTop, 205, 0, 8, 8); + this.buttonAchievements = new BookletUtils.TexturedButton(7, this.guiLeft+138, this.guiTop, 205, 0, 8, 8); this.buttonList.add(this.buttonAchievements); - this.buttonConfig = new TexturedButton(8, this.guiLeft+138, this.guiTop+10, 197, 0, 8, 8); + this.buttonConfig = new BookletUtils.TexturedButton(8, this.guiLeft+138, this.guiTop+10, 197, 0, 8, 8); this.buttonList.add(this.buttonConfig); for(int i = 0; i < this.chapterButtons.length; i++){ - this.chapterButtons[i] = new IndexButton(9+i, guiLeft+15, guiTop+10+(i*12), 115, 10, "", this); + this.chapterButtons[i] = new BookletUtils.IndexButton(9+i, guiLeft+15, guiTop+10+(i*12), 115, 10, "", this); this.buttonList.add(this.chapterButtons[i]); } @@ -371,10 +242,10 @@ public class GuiBooklet extends GuiScreen{ this.currentChapter = null; this.currentIndexEntry = null; - //So that the First Page will still open if used via something like NEI before + // So that the First Page will still open if used via something like NEI before if(this.parentScreen == null && !PersistentClientData.getBoolean("BookAlreadyOpened")){ - this.openIndexEntry(InitBooklet.chapterIntro.entry, 1, true); - this.openChapter(InitBooklet.chapterIntro, null); + BookletUtils.openIndexEntry(this, InitBooklet.chapterIntro.entry, 1, true); + BookletUtils.openChapter(this, InitBooklet.chapterIntro, null); PersistentClientData.setBoolean("BookAlreadyOpened", true); } @@ -396,7 +267,7 @@ public class GuiBooklet extends GuiScreen{ this.buttonUpdate.visible = buttonThere; if(buttonThere){ if(this.ticksElapsed%8 == 0){ - TexturedButton button = (TexturedButton)this.buttonUpdate; + BookletUtils.TexturedButton button = (BookletUtils.TexturedButton)this.buttonUpdate; button.setTexturePos(245, button.texturePosY == 0 ? 22 : 0); } } @@ -413,178 +284,4 @@ public class GuiBooklet extends GuiScreen{ public boolean doesGuiPauseGame(){ return false; } - - private BookletPage getNextPage(BookletChapter chapter, BookletPage currentPage){ - for(int i = 0; i < chapter.pages.length; i++){ - if(chapter.pages[i] == currentPage){ - if(i+1 < chapter.pages.length){ - return chapter.pages[i+1]; - } - } - } - return null; - } - - private BookletPage getPrevPage(BookletChapter chapter, BookletPage currentPage){ - for(int i = 0; i < chapter.pages.length; i++){ - if(chapter.pages[i] == currentPage){ - if(i-1 >= 0){ - return chapter.pages[i-1]; - } - } - } - return null; - } - - public void openChapter(BookletChapter chapter, BookletPage page){ - if(chapter == null){ - return; - } - - this.searchField.setVisible(false); - this.searchField.setFocused(false); - this.searchField.setText(""); - - this.currentChapter = chapter; - this.currentPage = page != null && this.hasPage(chapter, page) ? page : chapter.pages[0]; - - this.buttonForward.visible = this.getNextPage(chapter, this.currentPage) != null; - this.buttonBackward.visible = this.getPrevPage(chapter, this.currentPage) != null; - this.buttonPreviousScreen.visible = true; - this.buttonPreviouslyOpenedGui.visible = this.parentScreen != null; - - for(GuiButton chapterButton : this.chapterButtons){ - chapterButton.visible = false; - } - } - - private boolean hasPage(BookletChapter chapter, BookletPage page){ - for(BookletPage aPage : chapter.pages){ - if(aPage == page){ - return true; - } - } - return false; - } - - @SuppressWarnings("unchecked") - public void openIndexEntry(BookletIndexEntry entry, int page, boolean resetTextField){ - this.searchField.setVisible(entry instanceof BookletEntryAllSearch); - this.searchField.setFocused(entry instanceof BookletEntryAllSearch); - if(resetTextField){ - this.searchField.setText(""); - if(entry instanceof BookletEntryAllSearch){ - entry.chapters = (ArrayList)((BookletEntryAllSearch)entry).allChapters.clone(); - } - } - - this.currentPage = null; - this.currentChapter = null; - - this.currentIndexEntry = entry; - this.indexPageAmount = entry == null ? 1 : entry.chapters.size()/this.chapterButtons.length+1; - this.pageOpenInIndex = entry == null ? 1 : (this.indexPageAmount <= page || page <= 0 ? this.indexPageAmount : page); - - this.buttonPreviousScreen.visible = entry != null; - this.buttonForward.visible = this.pageOpenInIndex < this.indexPageAmount; - this.buttonBackward.visible = this.pageOpenInIndex > 1; - this.buttonPreviouslyOpenedGui.visible = this.parentScreen != null; - - for(int i = 0; i < this.chapterButtons.length; i++){ - IndexButton button = (IndexButton)this.chapterButtons[i]; - if(entry == null){ - boolean entryExists = InitBooklet.entries.size() > i; - button.visible = entryExists; - if(entryExists){ - button.displayString = InitBooklet.entries.get(i).getNameWithColor(); - button.chap = null; - } - } - else{ - boolean entryExists = entry.chapters.size() > i+(this.chapterButtons.length*this.pageOpenInIndex-this.chapterButtons.length); - button.visible = entryExists; - if(entryExists){ - BookletChapter chap = entry.chapters.get(i+(this.chapterButtons.length*this.pageOpenInIndex-this.chapterButtons.length)); - button.displayString = chap.getNameWithColor(); - button.chap = chap; - } - } - } - } - - private static class IndexButton extends GuiButton{ - - public BookletChapter chap; - private GuiBooklet gui; - - public IndexButton(int id, int x, int y, int width, int height, String text, GuiBooklet gui){ - super(id, x, y, width, height, text); - this.gui = gui; - } - - @Override - public void drawButton(Minecraft minecraft, int mouseX, int mouseY){ - if(this.visible){ - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition+this.width && mouseY < this.yPosition+this.height; - GL11.glEnable(GL11.GL_BLEND); - OpenGlHelper.glBlendFunc(770, 771, 1, 0); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - this.mouseDragged(minecraft, mouseX, mouseY); - - int textOffsetX = 0; - if(this.chap != null){ - if(this.chap.displayStack != null){ - GL11.glPushMatrix(); - BookletPage.renderItem(this.gui, this.chap.displayStack, this.xPosition-4, this.yPosition, 0.725F); - GL11.glPopMatrix(); - textOffsetX = 10; - } - } - - if(this.field_146123_n){ - GL11.glPushMatrix(); - AssetUtil.drawHorizontalGradientRect(this.xPosition+textOffsetX-1, this.yPosition+this.height-1, this.xPosition+this.gui.fontRendererObj.getStringWidth(this.displayString)+textOffsetX+1, this.yPosition+this.height, 0x80 << 24 | 22271, 22271); - GL11.glPopMatrix(); - } - - this.gui.fontRendererObj.drawString(this.displayString, this.xPosition+textOffsetX, this.yPosition+(this.height-8)/2, 0); - } - } - } - - public static class TexturedButton extends GuiButton{ - - public int texturePosX; - public int texturePosY; - - public TexturedButton(int id, int x, int y, int texturePosX, int texturePosY, int width, int height){ - super(id, x, y, width, height, ""); - this.texturePosX = texturePosX; - this.texturePosY = texturePosY; - } - - public void setTexturePos(int x, int y){ - this.texturePosX = x; - this.texturePosY = y; - } - - @Override - public void drawButton(Minecraft minecraft, int x, int y){ - if(this.visible){ - minecraft.getTextureManager().bindTexture(resLoc); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.field_146123_n = x >= this.xPosition && y >= this.yPosition && x < this.xPosition+this.width && y < this.yPosition+this.height; - int k = this.getHoverState(this.field_146123_n); - if(k == 0){ - k = 1; - } - GL11.glEnable(GL11.GL_BLEND); - OpenGlHelper.glBlendFunc(770, 771, 1, 0); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - this.drawTexturedModalRect(this.xPosition, this.yPosition, this.texturePosX, this.texturePosY-this.height+k*this.height, this.width, this.height); - this.mouseDragged(minecraft, x, y); - } - } - } } \ No newline at end of file diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/InitBooklet.java b/src/main/java/ellpeck/actuallyadditions/booklet/InitBooklet.java index f111e3fb9..2b997f754 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/InitBooklet.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/InitBooklet.java @@ -13,6 +13,11 @@ package ellpeck.actuallyadditions.booklet; import ellpeck.actuallyadditions.blocks.InitBlocks; import ellpeck.actuallyadditions.blocks.metalists.TheColoredLampColors; import ellpeck.actuallyadditions.blocks.metalists.TheMiscBlocks; +import ellpeck.actuallyadditions.booklet.chapter.BookletChapter; +import ellpeck.actuallyadditions.booklet.chapter.BookletChapterCoffee; +import ellpeck.actuallyadditions.booklet.chapter.BookletChapterCrusher; +import ellpeck.actuallyadditions.booklet.entry.BookletEntry; +import ellpeck.actuallyadditions.booklet.entry.BookletEntryAllSearch; import ellpeck.actuallyadditions.booklet.page.*; import ellpeck.actuallyadditions.config.values.ConfigIntValues; import ellpeck.actuallyadditions.crafting.*; @@ -28,19 +33,19 @@ import java.util.ArrayList; public class InitBooklet{ - public static ArrayList entries = new ArrayList(); + public static ArrayList entries = new ArrayList(); public static ArrayList pagesWithItemStackData = new ArrayList(); public static int wordCount; public static BookletChapter chapterIntro; - public static BookletIndexEntry entryFunctionalNonRF = new BookletIndexEntry("functionalNoRF"); - public static BookletIndexEntry entryFunctionalRF = new BookletIndexEntry("functionalRF").setSpecial(); - public static BookletIndexEntry entryGeneratingRF = new BookletIndexEntry("generatingRF").setSpecial(); - public static BookletIndexEntry entryItemsNonRF = new BookletIndexEntry("itemsNoRF"); - public static BookletIndexEntry entryItemsRF = new BookletIndexEntry("itemsRF").setSpecial(); - public static BookletIndexEntry entryMisc = new BookletIndexEntry("misc"); - public static BookletIndexEntry allAndSearch = new BookletEntryAllSearch("allAndSearch").setImportant(); + public static BookletEntry entryFunctionalNonRF = new BookletEntry("functionalNoRF"); + public static BookletEntry entryFunctionalRF = new BookletEntry("functionalRF").setSpecial(); + public static BookletEntry entryGeneratingRF = new BookletEntry("generatingRF").setSpecial(); + public static BookletEntry entryItemsNonRF = new BookletEntry("itemsNoRF"); + public static BookletEntry entryItemsRF = new BookletEntry("itemsRF").setSpecial(); + public static BookletEntry entryMisc = new BookletEntry("misc"); + public static BookletEntry allAndSearch = new BookletEntryAllSearch("allAndSearch").setImportant(); private static void initChapters(){ chapterIntro = new BookletChapter("intro", entryMisc, new ItemStack(InitItems.itemLexicon), new PageTextOnly(1), new PageTextOnly(2), new PageTextOnly(3), new PageCrafting(4, ItemCrafting.recipeBook)).setImportant(); @@ -128,7 +133,7 @@ public class InitBooklet{ } private static void countWords(){ - for(BookletIndexEntry entry : entries){ + for(BookletEntry entry : entries){ for(BookletChapter chapter : entry.chapters){ for(BookletPage page : chapter.pages){ if(page.getText() != null){ diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/BookletChapter.java b/src/main/java/ellpeck/actuallyadditions/booklet/chapter/BookletChapter.java similarity index 84% rename from src/main/java/ellpeck/actuallyadditions/booklet/BookletChapter.java rename to src/main/java/ellpeck/actuallyadditions/booklet/chapter/BookletChapter.java index 64878d8f3..0ccc972cb 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/BookletChapter.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/chapter/BookletChapter.java @@ -8,8 +8,10 @@ * © 2015 Ellpeck */ -package ellpeck.actuallyadditions.booklet; +package ellpeck.actuallyadditions.booklet.chapter; +import ellpeck.actuallyadditions.booklet.InitBooklet; +import ellpeck.actuallyadditions.booklet.entry.BookletEntry; import ellpeck.actuallyadditions.booklet.page.BookletPage; import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.StringUtil; @@ -19,12 +21,12 @@ import net.minecraft.util.EnumChatFormatting; public class BookletChapter{ public final BookletPage[] pages; - public final BookletIndexEntry entry; + public final BookletEntry entry; public final ItemStack displayStack; private final String unlocalizedName; public EnumChatFormatting color; - public BookletChapter(String unlocalizedName, BookletIndexEntry entry, ItemStack displayStack, BookletPage... pages){ + public BookletChapter(String unlocalizedName, BookletEntry entry, ItemStack displayStack, BookletPage... pages){ this.pages = pages.clone(); this.unlocalizedName = unlocalizedName; diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/BookletChapterCoffee.java b/src/main/java/ellpeck/actuallyadditions/booklet/chapter/BookletChapterCoffee.java similarity index 85% rename from src/main/java/ellpeck/actuallyadditions/booklet/BookletChapterCoffee.java rename to src/main/java/ellpeck/actuallyadditions/booklet/chapter/BookletChapterCoffee.java index 9e7ef8677..d69a2effd 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/BookletChapterCoffee.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/chapter/BookletChapterCoffee.java @@ -8,8 +8,9 @@ * © 2015 Ellpeck */ -package ellpeck.actuallyadditions.booklet; +package ellpeck.actuallyadditions.booklet.chapter; +import ellpeck.actuallyadditions.booklet.entry.BookletEntry; import ellpeck.actuallyadditions.booklet.page.BookletPage; import ellpeck.actuallyadditions.booklet.page.PageCoffeeRecipe; import ellpeck.actuallyadditions.items.ItemCoffee; @@ -20,7 +21,7 @@ import java.util.Arrays; public class BookletChapterCoffee extends BookletChapter{ - public BookletChapterCoffee(String unlocalizedName, BookletIndexEntry entry, ItemStack displayStack, BookletPage... pages){ + public BookletChapterCoffee(String unlocalizedName, BookletEntry entry, ItemStack displayStack, BookletPage... pages){ super(unlocalizedName, entry, displayStack, getPages(pages)); } diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/BookletChapterCrusher.java b/src/main/java/ellpeck/actuallyadditions/booklet/chapter/BookletChapterCrusher.java similarity index 89% rename from src/main/java/ellpeck/actuallyadditions/booklet/BookletChapterCrusher.java rename to src/main/java/ellpeck/actuallyadditions/booklet/chapter/BookletChapterCrusher.java index 1e5db8aef..ee93f5d65 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/BookletChapterCrusher.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/chapter/BookletChapterCrusher.java @@ -8,8 +8,9 @@ * © 2015 Ellpeck */ -package ellpeck.actuallyadditions.booklet; +package ellpeck.actuallyadditions.booklet.chapter; +import ellpeck.actuallyadditions.booklet.entry.BookletEntry; import ellpeck.actuallyadditions.booklet.page.BookletPage; import ellpeck.actuallyadditions.booklet.page.PageCrusherRecipe; import ellpeck.actuallyadditions.crafting.CrusherCrafting; @@ -21,7 +22,7 @@ import java.util.Arrays; public class BookletChapterCrusher extends BookletChapter{ - public BookletChapterCrusher(String unlocalizedName, BookletIndexEntry entry, ItemStack displayStack, BookletPage... pages){ + public BookletChapterCrusher(String unlocalizedName, BookletEntry entry, ItemStack displayStack, BookletPage... pages){ super(unlocalizedName, entry, displayStack, getPages(pages)); } diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/BookletIndexEntry.java b/src/main/java/ellpeck/actuallyadditions/booklet/entry/BookletEntry.java similarity index 81% rename from src/main/java/ellpeck/actuallyadditions/booklet/BookletIndexEntry.java rename to src/main/java/ellpeck/actuallyadditions/booklet/entry/BookletEntry.java index 493df8d20..f6f243a28 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/BookletIndexEntry.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/entry/BookletEntry.java @@ -8,21 +8,23 @@ * © 2015 Ellpeck */ -package ellpeck.actuallyadditions.booklet; +package ellpeck.actuallyadditions.booklet.entry; +import ellpeck.actuallyadditions.booklet.InitBooklet; +import ellpeck.actuallyadditions.booklet.chapter.BookletChapter; import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.StringUtil; import net.minecraft.util.EnumChatFormatting; import java.util.ArrayList; -public class BookletIndexEntry{ +public class BookletEntry{ private final String unlocalizedName; public ArrayList chapters = new ArrayList(); private EnumChatFormatting color; - public BookletIndexEntry(String unlocalizedName){ + public BookletEntry(String unlocalizedName){ this.unlocalizedName = unlocalizedName; InitBooklet.entries.add(this); @@ -45,12 +47,12 @@ public class BookletIndexEntry{ return StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".indexEntry."+this.unlocalizedName+".name"); } - public BookletIndexEntry setImportant(){ + public BookletEntry setImportant(){ this.color = EnumChatFormatting.DARK_GREEN; return this; } - public BookletIndexEntry setSpecial(){ + public BookletEntry setSpecial(){ this.color = EnumChatFormatting.DARK_PURPLE; return this; } diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/BookletEntryAllSearch.java b/src/main/java/ellpeck/actuallyadditions/booklet/entry/BookletEntryAllSearch.java similarity index 82% rename from src/main/java/ellpeck/actuallyadditions/booklet/BookletEntryAllSearch.java rename to src/main/java/ellpeck/actuallyadditions/booklet/entry/BookletEntryAllSearch.java index 41152f432..1753793eb 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/BookletEntryAllSearch.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/entry/BookletEntryAllSearch.java @@ -8,11 +8,13 @@ * © 2015 Ellpeck */ -package ellpeck.actuallyadditions.booklet; +package ellpeck.actuallyadditions.booklet.entry; + +import ellpeck.actuallyadditions.booklet.chapter.BookletChapter; import java.util.ArrayList; -public class BookletEntryAllSearch extends BookletIndexEntry{ +public class BookletEntryAllSearch extends BookletEntry{ public ArrayList allChapters = new ArrayList(); diff --git a/src/main/java/ellpeck/actuallyadditions/booklet/page/BookletPage.java b/src/main/java/ellpeck/actuallyadditions/booklet/page/BookletPage.java index a19d97253..25e709f90 100644 --- a/src/main/java/ellpeck/actuallyadditions/booklet/page/BookletPage.java +++ b/src/main/java/ellpeck/actuallyadditions/booklet/page/BookletPage.java @@ -10,9 +10,10 @@ package ellpeck.actuallyadditions.booklet.page; -import ellpeck.actuallyadditions.booklet.BookletChapter; +import ellpeck.actuallyadditions.booklet.BookletUtils; import ellpeck.actuallyadditions.booklet.GuiBooklet; import ellpeck.actuallyadditions.booklet.InitBooklet; +import ellpeck.actuallyadditions.booklet.chapter.BookletChapter; import ellpeck.actuallyadditions.util.ItemUtil; import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.StringUtil; @@ -144,8 +145,8 @@ public class BookletPage{ list.add(EnumChatFormatting.GOLD+StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".clickToSeeRecipe")); if(mousePressed){ - gui.openIndexEntry(page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1, true); - gui.openChapter(page.getChapter(), page); + BookletUtils.openIndexEntry(gui, page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1, true); + BookletUtils.openChapter(gui, page.getChapter(), page); Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); } diff --git a/src/main/java/ellpeck/actuallyadditions/nei/BookletInfoRecipeHandler.java b/src/main/java/ellpeck/actuallyadditions/nei/BookletInfoRecipeHandler.java index fe46a335b..13a18d5ae 100644 --- a/src/main/java/ellpeck/actuallyadditions/nei/BookletInfoRecipeHandler.java +++ b/src/main/java/ellpeck/actuallyadditions/nei/BookletInfoRecipeHandler.java @@ -14,8 +14,8 @@ import codechicken.lib.gui.GuiDraw; import codechicken.nei.PositionedStack; import codechicken.nei.recipe.RecipeInfo; import codechicken.nei.recipe.TemplateRecipeHandler; -import ellpeck.actuallyadditions.booklet.BookletChapter; import ellpeck.actuallyadditions.booklet.InitBooklet; +import ellpeck.actuallyadditions.booklet.chapter.BookletChapter; import ellpeck.actuallyadditions.booklet.page.BookletPage; import ellpeck.actuallyadditions.booklet.page.PagePicture; import ellpeck.actuallyadditions.util.ItemUtil; diff --git a/src/main/java/ellpeck/actuallyadditions/nei/NeiScreenEvents.java b/src/main/java/ellpeck/actuallyadditions/nei/NeiScreenEvents.java index 734386c48..6a68ea51d 100644 --- a/src/main/java/ellpeck/actuallyadditions/nei/NeiScreenEvents.java +++ b/src/main/java/ellpeck/actuallyadditions/nei/NeiScreenEvents.java @@ -13,6 +13,7 @@ package ellpeck.actuallyadditions.nei; import codechicken.nei.recipe.GuiRecipe; import codechicken.nei.recipe.IRecipeHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import ellpeck.actuallyadditions.booklet.BookletUtils; import ellpeck.actuallyadditions.booklet.GuiBooklet; import ellpeck.actuallyadditions.booklet.InitBooklet; import ellpeck.actuallyadditions.booklet.page.BookletPage; @@ -25,7 +26,7 @@ import net.minecraftforge.client.event.GuiScreenEvent; public class NeiScreenEvents{ private static final int NEI_BUTTON_ID = 123782; - private GuiBooklet.TexturedButton neiButton; + private BookletUtils.TexturedButton neiButton; @SuppressWarnings("unchecked") @SubscribeEvent @@ -38,7 +39,7 @@ public class NeiScreenEvents{ int guiLeft = (event.gui.width-xSize)/2; int guiTop = (event.gui.height-ySize)/2; - this.neiButton = new GuiBooklet.TexturedButton(NEI_BUTTON_ID, guiLeft+xSize-24, guiTop+127, 146, 154, 20, 20){ + this.neiButton = new BookletUtils.TexturedButton(NEI_BUTTON_ID, guiLeft+xSize-24, guiTop+127, 146, 154, 20, 20){ @Override public void drawButton(Minecraft minecraft, int x, int y){ super.drawButton(minecraft, x, y); @@ -69,8 +70,8 @@ public class NeiScreenEvents{ if(ItemUtil.contains(page.getItemStacksForPage(), ((INeiRecipeHandler)handler).getStackForInfo(theGui.page), true)){ GuiBooklet book = new GuiBooklet(Minecraft.getMinecraft().currentScreen); Minecraft.getMinecraft().displayGuiScreen(book); - book.openIndexEntry(page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1, true); - book.openChapter(page.getChapter(), page); + BookletUtils.openIndexEntry(book, page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.CHAPTER_BUTTONS_AMOUNT+1, true); + BookletUtils.openChapter(book, page.getChapter(), page); } } } diff --git a/src/main/java/ellpeck/actuallyadditions/util/playerdata/PersistentClientData.java b/src/main/java/ellpeck/actuallyadditions/util/playerdata/PersistentClientData.java index 58d1d6b72..82b504767 100644 --- a/src/main/java/ellpeck/actuallyadditions/util/playerdata/PersistentClientData.java +++ b/src/main/java/ellpeck/actuallyadditions/util/playerdata/PersistentClientData.java @@ -12,10 +12,11 @@ package ellpeck.actuallyadditions.util.playerdata; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import ellpeck.actuallyadditions.booklet.BookletChapter; -import ellpeck.actuallyadditions.booklet.BookletIndexEntry; +import ellpeck.actuallyadditions.booklet.BookletUtils; import ellpeck.actuallyadditions.booklet.GuiBooklet; import ellpeck.actuallyadditions.booklet.InitBooklet; +import ellpeck.actuallyadditions.booklet.chapter.BookletChapter; +import ellpeck.actuallyadditions.booklet.entry.BookletEntry; import ellpeck.actuallyadditions.booklet.page.BookletPage; import ellpeck.actuallyadditions.util.ModUtil; import net.minecraft.client.Minecraft; @@ -31,7 +32,7 @@ public class PersistentClientData{ private static File theFile; - public static void saveBookPage(BookletIndexEntry entry, BookletChapter chapter, BookletPage page, int pageInIndex, String searchWord){ + public static void saveBookPage(BookletEntry entry, BookletChapter chapter, BookletPage page, int pageInIndex, String searchWord){ NBTTagCompound baseCompound = getBaseCompound(); NBTTagCompound worldCompound = getCompoundForWorld(baseCompound); if(worldCompound != null){ @@ -97,25 +98,25 @@ public class PersistentClientData{ int chapter = worldCompound.getInteger("Chapter"); int page = worldCompound.getInteger("Page"); - BookletIndexEntry currentIndexEntry = entry == -1 ? null : InitBooklet.entries.get(entry); + BookletEntry 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); + BookletUtils.openIndexEntry(gui, currentIndexEntry, pageInIndex, true); if(currentChapter != null){ - gui.openChapter(currentChapter, currentPage); + BookletUtils.openChapter(gui, currentChapter, currentPage); } String searchText = worldCompound.getString("SearchWord"); if(!searchText.isEmpty()){ gui.searchField.setText(searchText); - gui.updateSearchBar(); + BookletUtils.updateSearchBar(gui); } } else{ //If everything fails, initialize the front page - gui.openIndexEntry(null, 1, true); + BookletUtils.openIndexEntry(gui, null, 1, true); } }