Search in sources :

Example 1 with GuiButtonCompendiumLink

use of am2.guis.controls.GuiButtonCompendiumLink in project ArsMagica2 by Mithion.

the class GuiCompendiumIndex method initSubItemButtonsForEntry.

private int initSubItemButtonsForEntry(CompendiumEntry entry, int idCount, String category) {
    int l = (width - xSize) / 2;
    int i1 = (height - ySize) / 2;
    boolean entryHasDescription = !entry.getDescription().equals("");
    int buttonXStart = entryHasDescription ? l + 185 : l + 40;
    int buttonX = buttonXStart;
    int buttonY = i1 + 35;
    int numPages = 0;
    for (CompendiumEntry subItem : entry.getSubItems()) {
        if (!checkSCMLimit(subItem))
            continue;
        String newCategory = category + ":" + entry.getID();
        GuiButtonCompendiumLink link = new GuiButtonCompendiumLink(idCount++, buttonX, buttonY, fontRendererObj, subItem.getName(), subItem.getID(), newCategory, subItem.hasSubItems(), numPages);
        if (entryHasDescription && entry.getSubItems().length < maxLines)
            link.setShowOnAllPages();
        link.visible = false;
        buttonY += 12;
        if (buttonY > i1 + (ySize) - 25) {
            if (buttonX > l + 40) {
                numPages++;
                buttonX = buttonXStart;
            } else {
                buttonX += 145;
            }
            buttonY = i1 + 30;
        }
        this.buttonList.add(link);
        if (subItem.hasSubItems()) {
            idCount = initSubItemButtonsForEntry(subItem, idCount, category);
        }
    }
    this.pagingData.put(category, numPages);
    return idCount;
}
Also used : GuiButtonCompendiumLink(am2.guis.controls.GuiButtonCompendiumLink)

Example 2 with GuiButtonCompendiumLink

use of am2.guis.controls.GuiButtonCompendiumLink in project ArsMagica2 by Mithion.

the class GuiCompendiumIndex method actionPerformed.

@Override
protected void actionPerformed(GuiButton buttonClicked) {
    if (buttonClicked.id == backToIndex.id) {
        CompendiumBreadcrumb crumb = AMGuiHelper.instance.popCompendiumBreadcrumb();
        Minecraft.getMinecraft().displayGuiScreen(new GuiCompendiumIndex(crumb));
        return;
    }
    if (buttonClicked instanceof GuiButtonCompendiumTab) {
        this.currentParentEntry = null;
        this.currentParentEntryName = null;
        this.activeCategory = ((GuiButtonCompendiumTab) buttonClicked).displayString;
        activeCategoryID = ((GuiButtonCompendiumTab) buttonClicked).categoryID;
        int visibleButtons = 0;
        for (Object button : this.buttonList) {
            if (button instanceof GuiButtonCompendiumTab) {
                ((GuiButtonCompendiumTab) button).setActive(false);
            } else if (button instanceof GuiButtonCompendiumLink) {
                if (((GuiButtonCompendiumLink) button).getCategory().equals(activeCategoryID) && ((GuiButtonCompendiumLink) button).getPageNum() == 0) {
                    ((GuiButtonCompendiumLink) button).visible = true;
                    visibleButtons++;
                } else {
                    ((GuiButtonCompendiumLink) button).visible = false;
                }
            }
        }
        if (visibleButtons == 0) {
            String zeroItemText = ArcaneCompendium.instance.getZeroItemText(activeCategoryID);
            lines = GuiArcaneCompendium.splitStringToLines(fontRendererObj, zeroItemText, lineWidth, maxLines);
        } else {
            lines = null;
        }
        ((GuiButtonCompendiumTab) buttonClicked).setActive(true);
        page = 0;
        prevPage.visible = false;
        if (getNumPages() > 0) {
            nextPage.visible = true;
        } else {
            nextPage.visible = false;
        }
    } else if (buttonClicked instanceof GuiButtonCompendiumLink) {
        this.currentParentEntry = null;
        if (((GuiButtonCompendiumLink) buttonClicked).hasSubItems()) {
            storeBreadcrumb();
            for (Object btn : this.buttonList) {
                if (btn instanceof GuiButtonCompendiumTab) {
                    ((GuiButtonCompendiumTab) btn).visible = false;
                }
            }
            backToIndex.visible = true;
            this.currentParentEntryName = ((GuiButtonCompendiumLink) buttonClicked).getEntryID();
            this.currentParentEntry = ArcaneCompendium.instance.getEntry(currentParentEntryName);
            this.activeCategoryID = this.activeCategoryID + ":" + this.currentParentEntryName;
            currentParentEntry.setIsNew(false);
            switchCategoryAndPage();
        } else {
            CompendiumEntry entry = ArcaneCompendium.instance.getEntry(((GuiButtonCompendiumLink) buttonClicked).getEntryID());
            if (entry != null) {
                storeBreadcrumb();
                GuiArcaneCompendium gui = entry.getCompendiumGui(((GuiButtonCompendiumLink) buttonClicked).getEntryID());
                if (gui != null) {
                    Minecraft.getMinecraft().displayGuiScreen(gui);
                }
            }
        }
    }
    if (getNumPages() > 0) {
        if (buttonClicked.id == nextPage.id && page < getNumPages()) {
            page++;
            switchCategoryAndPage();
            if (page == getNumPages()) {
                nextPage.visible = false;
            }
            prevPage.visible = true;
        } else if (buttonClicked.id == prevPage.id && page > 0) {
            page--;
            switchCategoryAndPage();
            if (page == 0) {
                prevPage.visible = false;
            }
            nextPage.visible = true;
        }
    }
}
Also used : CompendiumBreadcrumb(am2.guis.AMGuiHelper.CompendiumBreadcrumb) GuiButtonCompendiumLink(am2.guis.controls.GuiButtonCompendiumLink) GuiButtonCompendiumTab(am2.guis.controls.GuiButtonCompendiumTab)

Example 3 with GuiButtonCompendiumLink

use of am2.guis.controls.GuiButtonCompendiumLink in project ArsMagica2 by Mithion.

the class GuiCompendiumIndex method initButtonsForCategory.

private int initButtonsForCategory(String category, int idCount, boolean display) {
    ArrayList<CompendiumEntry> itemsInCategory = ArcaneCompendium.instance.getEntriesForCategory(category);
    int l = (width - xSize) / 2;
    int i1 = (height - ySize) / 2;
    int buttonX = l + 40;
    int buttonY = i1 + 35;
    int numPages = 0;
    for (int i = 0; i < itemsInCategory.size(); ++i) {
        CompendiumEntry entry = itemsInCategory.get(i);
        if (entry.isLocked() || !checkSCMLimit(entry))
            continue;
        String buttonLabel = entry.getName();
        while (fontRendererObj.getStringWidth(buttonLabel) > 125) {
            buttonLabel = buttonLabel.substring(0, buttonLabel.length() - 4) + "...";
        }
        GuiButtonCompendiumLink link = new GuiButtonCompendiumLink(idCount++, buttonX, buttonY, fontRendererObj, buttonLabel, entry.getID(), category, entry.hasSubItems(), numPages);
        if (entry.isNew()) {
            setCategoryHasNewItems(category, true);
            link.setNewItem();
        }
        link.visible = display && page == 0;
        buttonY += 12;
        if (buttonY > i1 + (ySize) - 25) {
            if (buttonX > l + 40) {
                numPages++;
                buttonX = l + 40;
            } else {
                buttonX += 155;
            }
            buttonY = i1 + 30;
        }
        this.buttonList.add(link);
        if (entry.hasSubItems()) {
            idCount = initSubItemButtonsForEntry(entry, idCount, category);
        }
    }
    this.pagingData.put(category, numPages);
    return idCount;
}
Also used : GuiButtonCompendiumLink(am2.guis.controls.GuiButtonCompendiumLink)

Aggregations

GuiButtonCompendiumLink (am2.guis.controls.GuiButtonCompendiumLink)3 CompendiumBreadcrumb (am2.guis.AMGuiHelper.CompendiumBreadcrumb)1 GuiButtonCompendiumTab (am2.guis.controls.GuiButtonCompendiumTab)1