Search in sources :

Example 1 with PageIconLinkElement

use of slimeknights.tconstruct.library.client.book.elements.PageIconLinkElement in project TinkersConstruct by SlimeKnights.

the class ContentPageIconList method build.

@Override
public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) {
    int yOff = 0;
    if (this.title != null) {
        this.addTitle(list, this.title, false);
        yOff = getTitleHeight();
    }
    if (this.subText != null) {
        int height = this.addText(list, this.subText, false, 0, yOff);
        yOff = height + 16;
    }
    int offset = 15;
    int x = offset;
    int y = yOff;
    int pageW = BookScreen.PAGE_WIDTH - 2 * offset;
    int pageH = BookScreen.PAGE_HEIGHT - yOff;
    float scale = this.maxScale;
    int scaledWidth = this.width;
    int scaledHeight = this.height;
    boolean fits = false;
    while (!fits && scale > 1f) {
        scale -= 0.25f;
        scaledWidth = (int) (this.width * scale);
        scaledHeight = (int) (this.height * scale);
        int rows = pageW / scaledWidth;
        int cols = pageH / scaledHeight;
        fits = rows * cols >= this.elements.size();
    }
    for (PageIconLinkElement element : this.elements) {
        element.x = x;
        element.y = y;
        element.displayElement.x = x + (int) (scale * (this.width - element.displayElement.width) / 2);
        element.displayElement.y = y + (int) (scale * (this.height - element.displayElement.height) / 2);
        element.width = scaledWidth;
        element.height = scaledHeight;
        if (element.displayElement instanceof ItemElement) {
            ((ItemElement) element.displayElement).scale = scale;
        }
        list.add(element);
        x += scaledWidth;
        if (x > BookScreen.PAGE_WIDTH - offset - scaledWidth) {
            x = offset;
            y += scaledHeight;
            // do not draw over the page
            if (y > BookScreen.PAGE_HEIGHT - scaledHeight) {
                break;
            }
        }
    }
}
Also used : PageIconLinkElement(slimeknights.tconstruct.library.client.book.elements.PageIconLinkElement) ItemElement(slimeknights.mantle.client.screen.book.element.ItemElement)

Aggregations

ItemElement (slimeknights.mantle.client.screen.book.element.ItemElement)1 PageIconLinkElement (slimeknights.tconstruct.library.client.book.elements.PageIconLinkElement)1