public void addTitle(ArrayList<BookElement> list, String title) { TextData tdTitle = new TextData(title); tdTitle.underlined = true; addTitle(list, new TextData[]{tdTitle}); }
@Override public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) { int y = TITLE_HEIGHT; if(title == null || title.isEmpty()) { y = 0; } else { addTitle(list, title); } if(text != null && text.length > 0) { list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y, text)); } } }
@Override public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) { int y = 0; if(title != null && !title.trim().isEmpty()) { addTitle(list, title); y += TITLE_HEIGHT; } for(int i = 0; i < data.length; i++) { TextData text = data[i]; list.add(new ElementText(0, y + i * (int) (Minecraft .getMinecraft().fontRenderer.FONT_HEIGHT * text.scale), GuiBook.PAGE_WIDTH, Minecraft .getMinecraft().fontRenderer.FONT_HEIGHT, new TextData[]{text})); } } }
@Override public void update(GuiBook.AdvancementCache advancementCache) { pages.clear(); List<SectionData> visibleSections = parent.getVisibleSections(advancementCache); if(visibleSections.isEmpty()) { return; } visibleSections.remove(0); PageData[] pages = new PageData[(int) Math.ceil(visibleSections.size() / 9F)]; for(int i = 0; i < pages.length; i++) { pages[i] = new PageData(true); pages[i].name = "page" + (i + 1); ContentSectionList content = new ContentSectionList(); pages[i].content = content; for(int j = i * 9; j - i * 9 < 9 && j < visibleSections.size(); j++) { content.addSection(visibleSections.get(j)); } } this.pages = new ArrayList<>(Arrays.asList(pages)); } };
content = BookLoader.GSON.fromJson(data, ctype); } catch(Exception e) { content = new ContentError(ctype == null ? "Failed to create a page of type \"" + type + "\", perhaps the type is not registered?" : "Failed to create a page of type \"" + type + "\", perhaps the page file \"" + this.data + "\" is missing or invalid?", e); content = BookLoader.getPageType(type).newInstance(); } catch(InstantiationException | IllegalAccessException | NullPointerException e) { content = new ContentError("Failed to create a page of type \"" + type + "\", perhaps the type is not registered?"); content.load(); } catch(Exception e) { content = new ContentError("Failed to load page " + parent.name + "." + name + ".", e); e.printStackTrace();
@Override public void load() { if(name == null) { name = "section" + parent.unnamedSectionCounter++; } name = name.toLowerCase(); if(!data.equals("no-load")) { IResource pagesInfo = source.getResource(source.getResourceLocation(data)); if(pagesInfo != null) { String data = source.resourceToString(pagesInfo); if(!data.isEmpty()) { try { pages = new ArrayList<>(Arrays.asList(BookLoader.GSON.fromJson(data, PageData[].class))); } catch(Exception e) { pages = new ArrayList<>(); PageData pdError = new PageData(true); pdError.name = "errorrenous"; pdError.content = new ContentError("Failed to load section " + name + ".", e); pages.add(pdError); } } } } for(PageData page : pages) { page.parent = this; page.source = source; page.load(); } icon.location = source.getResourceLocation(icon.file, true); }
private void buildPages() { leftElements.clear(); rightElements.clear(); if(page == -1) { return; } if(page == 0) { PageData page = book.findPage(0, advancementCache); if(page != null) { page.content.build(book, rightElements, false); } } else { PageData leftPage = book.findPage((page - 1) * 2 + 1, advancementCache); PageData rightPage = book.findPage((page - 1) * 2 + 2, advancementCache); if(leftPage != null) { leftPage.content.build(book, leftElements, false); } if(rightPage != null) { rightPage.content.build(book, rightElements, true); } } for(BookElement element : leftElements) { element.parent = this; } for(BookElement element : rightElements) { element.parent = this; } }
@Override public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) { int y = TITLE_HEIGHT; if(title == null || title.isEmpty()) { y = 0; } else { addTitle(list, title); } if(image != null && image.location != null) { list.add(new ElementImage(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y, image)); } else { list.add(new ElementImage(ImageData.MISSING)); } } }
@Override public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) { int y = TITLE_HEIGHT; if(title == null || title.isEmpty()) { y = 0; } else { addTitle(list, title); } if(title == null || title.isEmpty()) { y = 0; } else { addTitle(list, title); } if(text != null && text.length > 0) { list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 105, text)); } if(image != null && image.location != null) { list.add(new ElementImage(0, y + GuiBook.PAGE_HEIGHT - 100, GuiBook.PAGE_WIDTH, 100 - y, image)); } else { list.add(new ElementImage(0, y + GuiBook.PAGE_HEIGHT - 100, GuiBook.PAGE_WIDTH, 100 - y, ImageData.MISSING)); } } }
@Override public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) { int y = TITLE_HEIGHT; if(title == null || title.isEmpty()) { y = 0; } else { addTitle(list, title); } if(image != null && image.location != null) { list.add(new ElementImage(0, y, GuiBook.PAGE_WIDTH, 100, image)); } else { list.add(new ElementImage(0, y, 32, 32, ImageData.MISSING)); } if(text != null && text.length > 0) { list.add(new ElementText(0, y + 105, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 105 - y, text)); } } }
@Override public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) { int y = TITLE_HEIGHT; if(title == null || title.isEmpty()) { y = 0; } else { addTitle(list, title); } if(image != null && image.location != null) { list.add(new ElementImage(0, y, 50, 50, image)); } else { list.add(new ElementImage(0, y, 50, 50, ImageData.MISSING)); } if(text1 != null && text1.length > 0) { list.add(new ElementText(55, y, GuiBook.PAGE_WIDTH - 55, 50, text1)); } if(text2 != null && text2.length > 0) { list.add(new ElementText(0, y + 55, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 55 - y, text2)); } } }
@Override public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) { int y = TITLE_HEIGHT; if(title == null || title.isEmpty()) { y = 0; } else { addTitle(list, title); } if(text1 != null && text1.length > 0) { list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH - 55, 50, text1)); } if(image != null && image.location != null) { list.add(new ElementImage(GuiBook.PAGE_WIDTH - 50, y, 50, 50, image)); } else { list.add(new ElementImage(GuiBook.PAGE_WIDTH - 50, y, 50, 50, ImageData.MISSING)); } if(text2 != null && text2.length > 0) { list.add(new ElementText(0, y + 55, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 55 - y, text2)); } } }
@Override public void load() { BookRepository repo = parent.source; if(data == null || data.isEmpty()) { return; } ResourceLocation location = repo.getResourceLocation(data); if(location != null && repo.resourceExists(location)) { ContentStructure structure = BookLoader.GSON .fromJson(repo.resourceToString(repo.getResource(location)), ContentStructure.class); structure.parent = parent; structure.load(); this.size = structure.size; this.structure = structure.structure; this.text = structure.text; } }
@Override public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) { addTitle(list, "Error"); TextData[] text = new TextData[1 + (exception != null ? 2 : 0)]; text[0] = new TextData(errorStage); text[0].color = "dark_red"; text[0].underlined = true; if(exception != null) { text[1] = new TextData("The following error has occured: "); text[1].color = "dark_red"; text[1].paragraph = true; text[2] = new TextData(exception.getMessage() != null ? exception.getMessage() : exception.getClass() .getSimpleName()); text[2].color = "dark_red"; text[2].paragraph = true; } list.add(new ElementText(0, TITLE_HEIGHT, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - TITLE_HEIGHT, text)); } }
y = 0; } else { addTitle(list, title);
@Override public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) { int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMITHING.width / 2 - 10; int y = TITLE_HEIGHT; if(title == null || title.isEmpty()) { y = 0; } else { addTitle(list, title); } list.add(new ElementImage(x, y, IMG_SMITHING.width, IMG_SMITHING.height, IMG_SMITHING, book.appearance.slotColor)); if(input != null && !input.id.equals("")) { list.add(new ElementItem(x + INPUT_X, y + INPUT_Y, ITEM_SCALE, input.getItems(), input.action)); } if(block != null && !block.id.equals("")) { list.add(new ElementItem(x + BLOCK_X, y + BLOCK_Y, BLOCK_SCALE, block.getItems(), block.action)); } if(description != null && description.length > 0) { list.add(new ElementText(0, IMG_SMITHING.height + y + 50, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - IMG_SMITHING.height - y - 50, description)); } } }
@Override public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) { int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMITHING.width / 2; int y = TITLE_HEIGHT; if(title == null || title.isEmpty()) { y = 0; } else { addTitle(list, title); } list.add(new ElementImage(x, y, IMG_SMITHING.width, IMG_SMITHING.height, IMG_SMITHING, book.appearance.slotColor)); if(input != null && !input.id.equals("")) { list.add(new ElementItem(x + INPUT_X, y + INPUT_Y, ITEM_SCALE, input.getItems(), input.action)); } if(modifier != null && !modifier.id.equals("")) { list.add(new ElementItem(x + MODIFIER_X, y + MODIFIER_Y, ITEM_SCALE, modifier.getItems(), modifier.action)); } if(result != null && !result.id.equals("")) { list.add(new ElementItem(x + RESULT_X, y + RESULT_Y, ITEM_SCALE, result.getItems(), result.action)); } if(description != null && description.length > 0) { list.add(new ElementText(0, IMG_SMITHING.height + y + 5, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - IMG_SMITHING.height - y - 5, description)); } } }
pages[i].content = new ContentTableOfContents(i == 0 ? section.getTitle() : "", text);
@Override public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) { int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMELTING.width / 2; int y = TITLE_HEIGHT; TextData tdTitle = new TextData(title); tdTitle.underlined = true; list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH, 9, new TextData[]{tdTitle})); list.add(new ElementImage(x, y, IMG_SMELTING.width, IMG_SMELTING.height, IMG_SMELTING, book.appearance.slotColor)); if(input != null && !input.id.equals("")) { list.add(new ElementItem(x + INPUT_X, y + INPUT_Y, ITEM_SCALE, input.getItems(), input.action)); } if(result != null && !result.id.equals("")) { list.add(new ElementItem(x + RESULT_X, y + RESULT_Y, ITEM_SCALE, result.getItems(), result.action)); } list.add(new ElementItem(x + FUEL_X, y + FUEL_Y, ITEM_SCALE, getFuelsList())); if(description != null && description.length > 0) { list.add(new ElementText(0, IMG_SMELTING.height + y + 5, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y - 5, description)); } }
PageData page = new PageData(true); page.name = "errorenous"; page.content = new ContentError("Failed to load repository " + repo.toString() + ".", e); error.pages.add(page); sections.add(error); PageData page = new PageData(true); page.name = "errorenous"; page.content = new ContentError("Failed to load the book due to an unexpected error.", e); section.pages.add(page); this.sections.add(section);