2015-11-11 18:51:20 +01:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("BookletUtils.java") is part of the Actually Additions mod for Minecraft.
|
2015-11-11 18:51:20 +01:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-11-11 18:51:20 +01:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-11-11 18:51:20 +01:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.booklet;
|
2015-11-11 18:51:20 +01:00
|
|
|
|
2016-01-05 14:57:50 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
|
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
|
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements;
|
|
|
|
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;
|
2016-01-16 23:14:10 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.proxy.ClientProxy;
|
2016-03-18 15:42:06 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
2015-12-17 21:58:59 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2015-11-11 18:51:20 +01:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
2016-03-18 15:42:06 +01:00
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2015-11-13 21:40:38 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.stats.Achievement;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2015-11-11 18:51:20 +01:00
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.util.ArrayList;
|
2016-01-05 14:57:50 +01:00
|
|
|
import java.util.List;
|
2015-11-11 18:51:20 +01:00
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
public class BookletUtils{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tries to open a URL in the Browser
|
2015-12-01 19:48:09 +01:00
|
|
|
*/
|
|
|
|
public static void openBrowser(String url){
|
|
|
|
openBrowser(url, url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tries to open a URL in the Browser
|
|
|
|
*
|
|
|
|
* @param url The URL
|
2015-11-11 18:51:20 +01:00
|
|
|
* @param shiftUrl The URL to open when Shift is held
|
|
|
|
*/
|
|
|
|
public static void openBrowser(String url, String shiftUrl){
|
|
|
|
try{
|
|
|
|
if(Desktop.isDesktopSupported()){
|
2016-03-18 15:42:06 +01:00
|
|
|
if(shiftUrl.equals(url) || GuiScreen.isShiftKeyDown()){
|
2015-11-11 18:51:20 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the Title of the current chapter, current index entry or just "Actually Additions" if neither is present
|
|
|
|
*/
|
|
|
|
public static void drawTitle(GuiBooklet booklet){
|
2015-12-06 01:01:18 +01:00
|
|
|
booklet.mc.getTextureManager().bindTexture(GuiBooklet.resLoc);
|
2015-11-16 22:21:29 +01:00
|
|
|
//Upper title
|
2015-11-16 19:03:29 +01:00
|
|
|
booklet.drawTexturedModalRect(booklet.guiLeft+booklet.xSize/2-142/2, booklet.guiTop-12, 0, 240, 142, 12);
|
2015-11-16 22:21:29 +01:00
|
|
|
//Lower title
|
|
|
|
booklet.drawTexturedModalRect(booklet.guiLeft+booklet.xSize/2-142/2, booklet.guiTop+booklet.ySize, 0, 243, 142, 13);
|
2015-11-16 19:03:29 +01:00
|
|
|
|
2015-12-17 21:58:59 +01:00
|
|
|
//Draw No Entry title
|
2016-05-14 13:51:18 +02:00
|
|
|
if(booklet.currentEntrySet.getCurrentEntry() == null){
|
2016-04-20 21:39:03 +02:00
|
|
|
String strg = TextFormatting.DARK_GREEN+StringUtil.localize("info."+ModUtil.MOD_ID+".booklet.manualName.1");
|
2015-12-17 21:58:59 +01:00
|
|
|
booklet.getFontRenderer().drawString(strg, booklet.guiLeft+booklet.xSize/2-booklet.getFontRenderer().getStringWidth(strg)/2-3, booklet.guiTop+12, 0);
|
2016-04-20 21:39:03 +02:00
|
|
|
strg = TextFormatting.DARK_GREEN+StringUtil.localize("info."+ModUtil.MOD_ID+".booklet.manualName.2");
|
2015-12-17 21:58:59 +01:00
|
|
|
booklet.getFontRenderer().drawString(strg, booklet.guiLeft+booklet.xSize/2-booklet.getFontRenderer().getStringWidth(strg)/2-3, booklet.guiTop+12+booklet.getFontRenderer().FONT_HEIGHT, 0);
|
|
|
|
|
|
|
|
String version;
|
2016-01-08 08:10:55 +01:00
|
|
|
String playerName = Minecraft.getMinecraft().thePlayer.getName();
|
2015-12-18 15:46:38 +01:00
|
|
|
if(playerName.equals("dqmhose")){
|
2015-12-17 21:58:59 +01:00
|
|
|
version = "Pants Edition";
|
|
|
|
}
|
2015-12-27 17:24:13 +01:00
|
|
|
else if(playerName.equals("TwoOfEight")){
|
|
|
|
version = "Illustrator's Edition";
|
|
|
|
}
|
2015-12-18 15:46:38 +01:00
|
|
|
else if(playerName.equals("KittyVanCat")){
|
2015-12-17 21:58:59 +01:00
|
|
|
version = "Cat's Edition";
|
|
|
|
}
|
2016-03-08 00:05:34 +01:00
|
|
|
else if(playerName.equals("canitzp")){
|
|
|
|
version = "P's Edition";
|
|
|
|
}
|
2015-12-18 15:46:38 +01:00
|
|
|
else if(playerName.equals("Ellpeck") || Util.isDevVersion()){
|
2015-12-17 21:58:59 +01:00
|
|
|
version = "Dev's Edition";
|
|
|
|
}
|
|
|
|
else{
|
2016-04-20 21:39:03 +02:00
|
|
|
version = StringUtil.localize("info."+ModUtil.MOD_ID+".booklet.edition")+" "+ModUtil.VERSION.substring(ModUtil.VERSION.indexOf("r")+1);
|
2015-12-17 21:58:59 +01:00
|
|
|
}
|
2016-03-18 23:47:22 +01:00
|
|
|
strg = TextFormatting.GOLD+TextFormatting.ITALIC.toString()+"-"+version+"-";
|
2015-12-17 21:58:59 +01:00
|
|
|
booklet.getFontRenderer().drawString(strg, booklet.guiLeft+booklet.xSize/2-booklet.getFontRenderer().getStringWidth(strg)/2-3, booklet.guiTop+33, 0);
|
|
|
|
}
|
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
String strg = booklet.currentEntrySet.getCurrentChapter() == null ? (booklet.currentEntrySet.getCurrentEntry() == null ? StringUtil.localize("itemGroup."+ModUtil.MOD_ID) : booklet.currentEntrySet.getCurrentEntry().getLocalizedName()) : booklet.currentEntrySet.getCurrentChapter().getLocalizedName();
|
2015-11-16 19:03:29 +01:00
|
|
|
booklet.drawCenteredString(booklet.getFontRenderer(), strg, booklet.guiLeft+booklet.xSize/2, booklet.guiTop-9, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
|
2015-11-13 21:40:38 +01:00
|
|
|
/**
|
|
|
|
* Draws an Achievement Info if the page has items that trigger achievements
|
2015-12-01 19:48:09 +01:00
|
|
|
*
|
2015-11-13 21:40:38 +01:00
|
|
|
* @param pre If the hover info texts or the icon should be drawn
|
|
|
|
*/
|
|
|
|
public static void drawAchievementInfo(GuiBooklet booklet, boolean pre, int mouseX, int mouseY){
|
2016-05-14 13:51:18 +02:00
|
|
|
if(booklet.currentEntrySet.getCurrentChapter() == null){
|
2015-11-13 21:40:38 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-14 01:18:37 +01:00
|
|
|
ArrayList<String> infoList = null;
|
2016-05-14 13:51:18 +02:00
|
|
|
for(BookletPage page : booklet.currentEntrySet.getCurrentChapter().getPages()){
|
2015-11-16 19:57:46 +01:00
|
|
|
if(page != null && page.getItemStacksForPage() != null){
|
|
|
|
for(ItemStack stack : page.getItemStacksForPage()){
|
2016-01-03 19:16:43 +01:00
|
|
|
if(stack != null){
|
|
|
|
for(Achievement achievement : InitAchievements.achievementList){
|
|
|
|
if(achievement.theItemStack != null && ItemUtil.areItemsEqual(stack, achievement.theItemStack, true)){
|
|
|
|
if(pre){
|
|
|
|
booklet.mc.getTextureManager().bindTexture(GuiBooklet.resLoc);
|
|
|
|
booklet.drawTexturedModalRect(booklet.guiLeft+booklet.xSize+1, booklet.guiTop-18, 166, 154, 22, 21);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(mouseX >= booklet.guiLeft+booklet.xSize+1 && mouseX < booklet.guiLeft+booklet.xSize+1+22 && mouseY >= booklet.guiTop-18 && mouseY < booklet.guiTop-18+21){
|
|
|
|
if(infoList == null){
|
|
|
|
infoList = new ArrayList<String>();
|
2016-03-18 23:47:22 +01:00
|
|
|
infoList.add(TextFormatting.GOLD+"Achievements related to this chapter:");
|
2016-01-03 19:16:43 +01:00
|
|
|
}
|
|
|
|
infoList.add("-"+StringUtil.localize(achievement.statId));
|
2016-03-18 23:47:22 +01:00
|
|
|
infoList.add(TextFormatting.GRAY+"("+achievement.getDescription()+")");
|
2015-11-16 19:57:46 +01:00
|
|
|
}
|
2015-11-14 01:18:37 +01:00
|
|
|
}
|
2015-11-13 21:40:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-14 01:18:37 +01:00
|
|
|
if(infoList != null){
|
|
|
|
booklet.drawHoveringText(infoList, mouseX, mouseY);
|
2015-11-13 21:40:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-11 18:51:20 +01:00
|
|
|
/**
|
|
|
|
* 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
|
2015-11-11 19:01:19 +01:00
|
|
|
* -the amount of words and chars in the index (Just for teh lulz)
|
2015-11-11 18:51:20 +01:00
|
|
|
*/
|
|
|
|
public static void renderPre(GuiBooklet booklet, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
|
2016-05-14 13:51:18 +02:00
|
|
|
if(booklet.currentEntrySet.getCurrentEntry() != null){
|
2015-11-11 18:51:20 +01:00
|
|
|
//Renders Booklet Page Number and Content
|
2016-05-14 13:51:18 +02:00
|
|
|
if(booklet.currentEntrySet.getCurrentChapter() != null && booklet.currentEntrySet.getCurrentPage() != null){
|
|
|
|
booklet.drawCenteredString(booklet.getFontRenderer(), booklet.currentEntrySet.getCurrentPage().getID()+"/"+booklet.currentEntrySet.getCurrentChapter().getPages().length, booklet.guiLeft+booklet.xSize/2, booklet.guiTop+171, StringUtil.DECIMAL_COLOR_WHITE);
|
|
|
|
booklet.currentEntrySet.getCurrentPage().renderPre(booklet, mouseX, mouseY, ticksElapsed, mousePressed);
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
//Renders Chapter Page Number
|
|
|
|
else{
|
2016-05-14 13:51:18 +02:00
|
|
|
booklet.drawCenteredString(booklet.getFontRenderer(), booklet.currentEntrySet.getPageInIndex()+"/"+booklet.indexPageAmount, booklet.guiLeft+booklet.xSize/2, booklet.guiTop+171, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
2015-11-11 19:01:19 +01:00
|
|
|
//Renders the amount of words and chars the book has
|
2015-11-11 18:51:20 +01:00
|
|
|
else{
|
2016-04-20 21:39:03 +02:00
|
|
|
String wordCountString = StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID+".amountOfWords", ClientProxy.bookletWordCount);
|
2016-03-18 23:47:22 +01:00
|
|
|
booklet.getFontRenderer().drawString(TextFormatting.ITALIC+wordCountString, booklet.guiLeft+booklet.xSize-booklet.getFontRenderer().getStringWidth(wordCountString)-15, booklet.guiTop+booklet.ySize-18-booklet.getFontRenderer().FONT_HEIGHT, 0);
|
2015-11-11 19:01:19 +01:00
|
|
|
|
2016-04-20 21:39:03 +02:00
|
|
|
String charCountString = StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID+".amountOfChars", ClientProxy.bookletCharCount);
|
2016-03-18 23:47:22 +01:00
|
|
|
booklet.getFontRenderer().drawString(TextFormatting.ITALIC+charCountString, booklet.guiLeft+booklet.xSize-booklet.getFontRenderer().getStringWidth(charCountString)-15, booklet.guiTop+booklet.ySize-18, 0);
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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){
|
2015-12-04 18:14:03 +01:00
|
|
|
//Update all of the buttons' hovering texts
|
|
|
|
for(Object button : booklet.getButtonList()){
|
2016-01-08 08:10:55 +01:00
|
|
|
if(button instanceof GuiButton && ((GuiButton)button).visible && ((GuiButton)button).isMouseOver()){
|
2015-12-04 18:14:03 +01:00
|
|
|
if(button instanceof BookmarkButton){
|
2015-11-16 19:57:46 +01:00
|
|
|
((BookmarkButton)button).drawHover(mouseX, mouseY);
|
|
|
|
}
|
2015-12-04 18:14:03 +01:00
|
|
|
else if(button instanceof TexturedButton){
|
|
|
|
booklet.drawHoveringText(((TexturedButton)button).textList, mouseX, mouseY);
|
|
|
|
}
|
2016-01-09 17:53:06 +01:00
|
|
|
else if(button instanceof IndexButton){
|
|
|
|
((IndexButton)button).drawHover(mouseX, mouseY);
|
|
|
|
}
|
2015-11-16 19:57:46 +01:00
|
|
|
}
|
|
|
|
}
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the search bar, should be called when it is getting typed into
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public static void updateSearchBar(GuiBooklet booklet){
|
2016-05-14 13:51:18 +02:00
|
|
|
if(booklet.currentEntrySet.getCurrentEntry() instanceof BookletEntryAllSearch){
|
|
|
|
BookletEntryAllSearch currentEntry = (BookletEntryAllSearch)booklet.currentEntrySet.getCurrentEntry();
|
2015-11-11 18:51:20 +01:00
|
|
|
if(booklet.searchField.getText() != null && !booklet.searchField.getText().isEmpty()){
|
|
|
|
currentEntry.chapters.clear();
|
|
|
|
|
2016-01-05 14:57:50 +01:00
|
|
|
for(IBookletChapter chapter : currentEntry.allChapters){
|
2016-01-08 21:55:39 +01:00
|
|
|
String searchFieldText = booklet.searchField.getText().toLowerCase(Locale.ROOT);
|
|
|
|
if(chapter.getLocalizedName().toLowerCase(Locale.ROOT).contains(searchFieldText) || getChapterStacksContainString(searchFieldText, chapter)){
|
2015-11-11 18:51:20 +01:00
|
|
|
currentEntry.chapters.add(chapter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2016-01-05 14:57:50 +01:00
|
|
|
currentEntry.setChapters((ArrayList<IBookletChapter>)currentEntry.allChapters.clone());
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
2016-05-14 13:51:18 +02:00
|
|
|
openIndexEntry(booklet, booklet.currentEntrySet.getCurrentEntry(), booklet.currentEntrySet.getPageInIndex(), false);
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-08 21:55:39 +01:00
|
|
|
private static boolean getChapterStacksContainString(String text, IBookletChapter chapter){
|
|
|
|
for(BookletPage page : chapter.getPages()){
|
|
|
|
ItemStack[] pageStacks = page.getItemStacksForPage();
|
|
|
|
if(pageStacks != null){
|
|
|
|
for(ItemStack stack : pageStacks){
|
|
|
|
if(stack.getDisplayName().toLowerCase(Locale.ROOT).contains(text)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2016-01-05 14:57:50 +01:00
|
|
|
public static void openIndexEntry(GuiBooklet booklet, IBookletEntry entry, int page, boolean resetTextField){
|
2015-12-01 19:48:09 +01:00
|
|
|
booklet.searchField.setVisible(entry instanceof BookletEntryAllSearch);
|
|
|
|
booklet.searchField.setFocused(entry instanceof BookletEntryAllSearch);
|
|
|
|
if(resetTextField){
|
|
|
|
booklet.searchField.setText("");
|
|
|
|
if(entry instanceof BookletEntryAllSearch){
|
2016-01-05 14:57:50 +01:00
|
|
|
entry.setChapters((List<IBookletChapter>)((BookletEntryAllSearch)entry).allChapters.clone());
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
booklet.currentEntrySet.setPage(null);
|
|
|
|
booklet.currentEntrySet.setChapter(null);
|
2015-12-01 19:48:09 +01:00
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
booklet.currentEntrySet.setEntry(entry);
|
2016-01-05 14:57:50 +01:00
|
|
|
booklet.indexPageAmount = entry == null ? 1 : entry.getChapters().size()/booklet.chapterButtons.length+1;
|
2016-05-14 13:51:18 +02:00
|
|
|
booklet.currentEntrySet.setPageInIndex(entry == null ? 1 : (booklet.indexPageAmount <= page || page <= 0 ? booklet.indexPageAmount : page));
|
2015-12-01 19:48:09 +01:00
|
|
|
|
|
|
|
booklet.buttonPreviousScreen.visible = entry != null;
|
2016-05-14 13:51:18 +02:00
|
|
|
booklet.buttonForward.visible = booklet.currentEntrySet.getPageInIndex() < booklet.indexPageAmount;
|
|
|
|
booklet.buttonBackward.visible = booklet.currentEntrySet.getPageInIndex() > 1;
|
2015-12-01 19:48:09 +01:00
|
|
|
|
|
|
|
for(int i = 0; i < booklet.chapterButtons.length; i++){
|
|
|
|
IndexButton button = (IndexButton)booklet.chapterButtons[i];
|
|
|
|
if(entry == null){
|
2015-12-17 21:58:59 +01:00
|
|
|
if(i >= GuiBooklet.INDEX_BUTTONS_OFFSET){
|
2016-01-05 14:57:50 +01:00
|
|
|
boolean entryExists = ActuallyAdditionsAPI.bookletEntries.size() > i-GuiBooklet.INDEX_BUTTONS_OFFSET;
|
2015-12-17 21:58:59 +01:00
|
|
|
button.visible = entryExists;
|
|
|
|
if(entryExists){
|
2016-05-14 15:07:10 +02:00
|
|
|
button.displayString = "◦ "+ActuallyAdditionsAPI.bookletEntries.get(i-GuiBooklet.INDEX_BUTTONS_OFFSET).getLocalizedNameWithFormatting();
|
2015-12-17 21:58:59 +01:00
|
|
|
button.chap = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
button.visible = false;
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2016-05-14 13:51:18 +02:00
|
|
|
boolean entryExists = entry.getChapters().size() > i+(booklet.chapterButtons.length*booklet.currentEntrySet.getPageInIndex()-booklet.chapterButtons.length);
|
2015-12-01 19:48:09 +01:00
|
|
|
button.visible = entryExists;
|
|
|
|
if(entryExists){
|
2016-05-14 13:51:18 +02:00
|
|
|
IBookletChapter chap = entry.getChapters().get(i+(booklet.chapterButtons.length*booklet.currentEntrySet.getPageInIndex()-booklet.chapterButtons.length));
|
2016-01-05 14:57:50 +01:00
|
|
|
button.displayString = chap.getLocalizedNameWithFormatting();
|
2015-12-01 19:48:09 +01:00
|
|
|
button.chap = chap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-11 18:51:20 +01:00
|
|
|
/**
|
|
|
|
* 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){
|
2016-05-14 13:51:18 +02:00
|
|
|
if(booklet.currentEntrySet.getCurrentEntry() != null){
|
|
|
|
if(booklet.currentEntrySet.getCurrentChapter() == null){
|
|
|
|
if(place < booklet.currentEntrySet.getCurrentEntry().getChapters().size()){
|
|
|
|
IBookletChapter chap = booklet.currentEntrySet.getCurrentEntry().getChapters().get(place+(booklet.chapterButtons.length*booklet.currentEntrySet.getPageInIndex()-booklet.chapterButtons.length));
|
2016-01-05 14:57:50 +01:00
|
|
|
openChapter(booklet, chap, chap.getPages()[0]);
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2016-01-05 14:57:50 +01:00
|
|
|
if(place-GuiBooklet.INDEX_BUTTONS_OFFSET < ActuallyAdditionsAPI.bookletEntries.size()){
|
|
|
|
openIndexEntry(booklet, ActuallyAdditionsAPI.bookletEntries.get(place-GuiBooklet.INDEX_BUTTONS_OFFSET), 1, true);
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-01 19:48:09 +01:00
|
|
|
* 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
|
2015-11-11 18:51:20 +01:00
|
|
|
*/
|
2016-01-05 14:57:50 +01:00
|
|
|
public static void openChapter(GuiBooklet booklet, IBookletChapter chapter, BookletPage page){
|
2016-05-14 13:51:18 +02:00
|
|
|
if(chapter == null || booklet.currentEntrySet.getCurrentEntry() == null){
|
2015-12-01 19:48:09 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-11-11 18:51:20 +01:00
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
booklet.searchField.setVisible(false);
|
|
|
|
booklet.searchField.setFocused(false);
|
|
|
|
booklet.searchField.setText("");
|
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
booklet.currentEntrySet.setChapter(chapter);
|
|
|
|
booklet.currentEntrySet.setPage(page != null && doesChapterHavePage(chapter, page) ? page : chapter.getPages()[0]);
|
2015-12-01 19:48:09 +01:00
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
booklet.buttonForward.visible = getNextPage(chapter, booklet.currentEntrySet.getCurrentPage()) != null;
|
|
|
|
booklet.buttonBackward.visible = getPrevPage(chapter, booklet.currentEntrySet.getCurrentPage()) != null;
|
2015-12-01 19:48:09 +01:00
|
|
|
booklet.buttonPreviousScreen.visible = true;
|
|
|
|
|
|
|
|
for(GuiButton chapterButton : booklet.chapterButtons){
|
|
|
|
chapterButton.visible = false;
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-01 19:48:09 +01:00
|
|
|
* Checks if a chapter has a certain page
|
2015-11-11 18:51:20 +01:00
|
|
|
*/
|
2016-01-05 14:57:50 +01:00
|
|
|
private static boolean doesChapterHavePage(IBookletChapter chapter, BookletPage page){
|
|
|
|
for(BookletPage aPage : chapter.getPages()){
|
2015-12-01 19:48:09 +01:00
|
|
|
if(aPage == page){
|
|
|
|
return true;
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-01 19:48:09 +01:00
|
|
|
return false;
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the next available page in the booklet (or null if there is none)
|
|
|
|
*/
|
2016-01-05 14:57:50 +01:00
|
|
|
private static BookletPage getNextPage(IBookletChapter chapter, BookletPage page){
|
|
|
|
for(int i = 0; i < chapter.getPages().length; i++){
|
|
|
|
if(chapter.getPages()[i] == page){
|
|
|
|
if(i+1 < chapter.getPages().length){
|
|
|
|
return chapter.getPages()[i+1];
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the previous available page in the booklet (or null if there is none)
|
|
|
|
*/
|
2016-01-05 14:57:50 +01:00
|
|
|
private static BookletPage getPrevPage(IBookletChapter chapter, BookletPage page){
|
|
|
|
for(int i = 0; i < chapter.getPages().length; i++){
|
|
|
|
if(chapter.getPages()[i] == page){
|
2015-11-11 18:51:20 +01:00
|
|
|
if(i-1 >= 0){
|
2016-01-05 14:57:50 +01:00
|
|
|
return chapter.getPages()[i-1];
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-01 19:48:09 +01:00
|
|
|
* Called when the "next page"-button is pressed
|
2015-11-11 18:51:20 +01:00
|
|
|
*/
|
2015-12-01 19:48:09 +01:00
|
|
|
public static void handleNextPage(GuiBooklet booklet){
|
2016-05-14 13:51:18 +02:00
|
|
|
if(booklet.currentEntrySet.getCurrentEntry() != null){
|
|
|
|
if(booklet.currentEntrySet.getCurrentPage() != null){
|
|
|
|
BookletPage page = getNextPage(booklet.currentEntrySet.getCurrentChapter(), booklet.currentEntrySet.getCurrentPage());
|
2015-12-01 19:48:09 +01:00
|
|
|
if(page != null){
|
2016-05-14 13:51:18 +02:00
|
|
|
booklet.currentEntrySet.setPage(page);
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
2015-11-11 18:51:20 +01:00
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
booklet.buttonForward.visible = getNextPage(booklet.currentEntrySet.getCurrentChapter(), booklet.currentEntrySet.getCurrentPage()) != null;
|
|
|
|
booklet.buttonBackward.visible = getPrevPage(booklet.currentEntrySet.getCurrentChapter(), booklet.currentEntrySet.getCurrentPage()) != null;
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
else{
|
2016-05-14 13:51:18 +02:00
|
|
|
if(booklet.currentEntrySet.getPageInIndex()+1 <= booklet.indexPageAmount){
|
|
|
|
openIndexEntry(booklet, booklet.currentEntrySet.getCurrentEntry(), booklet.currentEntrySet.getPageInIndex()+1, !(booklet.currentEntrySet.getCurrentEntry() instanceof BookletEntryAllSearch));
|
2015-12-04 19:53:55 +01:00
|
|
|
}
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-01 19:48:09 +01:00
|
|
|
* Called when the "previous page"-button is pressed
|
2015-11-11 18:51:20 +01:00
|
|
|
*/
|
2015-12-01 19:48:09 +01:00
|
|
|
public static void handlePreviousPage(GuiBooklet booklet){
|
2016-05-14 13:51:18 +02:00
|
|
|
if(booklet.currentEntrySet.getCurrentEntry() != null){
|
|
|
|
if(booklet.currentEntrySet.getCurrentPage() != null){
|
|
|
|
BookletPage page = getPrevPage(booklet.currentEntrySet.getCurrentChapter(), booklet.currentEntrySet.getCurrentPage());
|
2015-12-01 19:48:09 +01:00
|
|
|
if(page != null){
|
2016-05-14 13:51:18 +02:00
|
|
|
booklet.currentEntrySet.setPage(page);
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
2016-05-14 13:51:18 +02:00
|
|
|
booklet.buttonForward.visible = getNextPage(booklet.currentEntrySet.getCurrentChapter(), booklet.currentEntrySet.getCurrentPage()) != null;
|
|
|
|
booklet.buttonBackward.visible = getPrevPage(booklet.currentEntrySet.getCurrentChapter(), booklet.currentEntrySet.getCurrentPage()) != null;
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
else{
|
2016-05-14 13:51:18 +02:00
|
|
|
if(booklet.currentEntrySet.getPageInIndex()-1 > 0){
|
|
|
|
openIndexEntry(booklet, booklet.currentEntrySet.getCurrentEntry(), booklet.currentEntrySet.getPageInIndex()-1, !(booklet.currentEntrySet.getCurrentEntry() instanceof BookletEntryAllSearch));
|
2015-12-04 19:53:55 +01:00
|
|
|
}
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
2015-11-11 18:51:20 +01:00
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
public static BookletPage getFirstPageForStack(ItemStack stack){
|
|
|
|
ArrayList<BookletPage> pages = getPagesForStack(stack);
|
|
|
|
return pages.isEmpty() ? null : pages.get(0);
|
|
|
|
}
|
2015-11-11 18:51:20 +01:00
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
public static ArrayList<BookletPage> getPagesForStack(ItemStack stack){
|
|
|
|
ArrayList<BookletPage> possiblePages = new ArrayList<BookletPage>();
|
2016-01-05 14:57:50 +01:00
|
|
|
for(BookletPage page : ActuallyAdditionsAPI.bookletPagesWithItemStackData){
|
2015-12-22 20:43:41 +01:00
|
|
|
if(ItemUtil.contains(page.getItemStacksForPage(), stack, page.arePageStacksWildcard)){
|
2015-12-01 19:48:09 +01:00
|
|
|
possiblePages.add(page);
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-01 19:48:09 +01:00
|
|
|
return possiblePages;
|
2015-11-11 18:51:20 +01:00
|
|
|
}
|
|
|
|
}
|