Search in sources :

Example 1 with IDatabaseTab

use of forestry.api.genetics.IDatabaseTab in project ForestryMC by ForestryMC.

the class DatabaseScreenLogic method onItemChange.

public ScreenState onItemChange(ItemStack itemStack) {
    ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(itemStack);
    // No individual, abort
    if (speciesRoot == null) {
        return ScreenState.NO_INDIVIDUAL;
    }
    IIndividual individual = speciesRoot.getMember(itemStack);
    // Check if a individual is selected and analyzed
    if (individual == null) {
        this.individual = null;
        this.itemStack = ItemStack.EMPTY;
        return ScreenState.NO_INDIVIDUAL;
    } else if (!individual.isAnalyzed()) {
        this.individual = null;
        this.itemStack = ItemStack.EMPTY;
        return ScreenState.NOT_ANALYZED;
    }
    this.individual = individual;
    this.itemStack = itemStack;
    if (speciesRoot != this.speciesRoot) {
        IDatabaseTab[] tabs = getTabs(speciesRoot);
        if (tabs == null) {
            this.tabs = new IDatabaseTab[4];
            return ScreenState.NO_PLUGIN;
        }
        this.tabs = tabs;
        // Select the first tab
        onTabChange(tabs[0]);
    } else {
        // Update the gui
        onTabChange(selectedTab);
    }
    this.speciesRoot = speciesRoot;
    return ScreenState.SUCCESS;
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) IDatabaseTab(forestry.api.genetics.IDatabaseTab)

Example 2 with IDatabaseTab

use of forestry.api.genetics.IDatabaseTab in project ForestryMC by ForestryMC.

the class WidgetDatabaseScreen method update.

private void update() {
    // reset list and layout helper
    scrollable.clear();
    scrollBar.setVisible(false);
    scrollable.updateVisibleElements(0);
    layoutHelper = new GuiElementHelper(scrollable);
    if (state == DatabaseScreenLogic.ScreenState.SUCCESS) {
        IDatabaseTab selectedTab = logic.selectedTab;
        selectedTab.createElements(layoutHelper, logic.individual, logic.itemStack);
        int invisibleElements = scrollable.getInvisibleElementCount();
        if (invisibleElements > 0) {
            scrollBar.setParameters(this, 0, invisibleElements, 1);
            scrollBar.setVisible(true);
        // scrollBar.setValue(0);
        } else {
            scrollBar.setValue(0);
        }
        scrollable.updateVisibleElements(scrollBar.getValue());
    } else {
        GuiElementHelper layoutHelper = new GuiElementHelper(scrollable);
        FontRenderer fontRenderer = manager.gui.getFontRenderer();
        String key = "for.gui.portablealyzer.help";
        if (state == DatabaseScreenLogic.ScreenState.NO_PLUGIN) {
            key = "for.gui.database.support";
        }
        List<String> lines = fontRenderer.listFormattedStringToWidth(Translator.translateToLocal(key), width - 10);
        for (String text : lines) {
            layoutHelper.addText(2, text, -1);
        }
        scrollable.updateVisibleElements(0);
    }
}
Also used : GuiElementHelper(forestry.core.gui.elements.GuiElementHelper) FontRenderer(net.minecraft.client.gui.FontRenderer) IDatabaseTab(forestry.api.genetics.IDatabaseTab)

Example 3 with IDatabaseTab

use of forestry.api.genetics.IDatabaseTab in project ForestryMC by ForestryMC.

the class DatabaseScreenLogic method getTabs.

private IDatabaseTab[] getTabs(ISpeciesRoot speciesRoot) {
    ISpeciesPlugin databasePlugin = speciesRoot.getSpeciesPlugin();
    if (databasePlugin == null) {
        // no plugin ofr this species
        return null;
    }
    this.databasePlugin = databasePlugin;
    IDatabaseTab[] tabs = new IDatabaseTab[4];
    IDatabaseTab speciesTab = databasePlugin.getSpeciesTab(true);
    if (speciesTab == null) {
        // the plugin does not support the database
        return null;
    }
    IDatabaseTab productsTab = databasePlugin.getProductsTab();
    IDatabaseTab mutationTab = databasePlugin.getMutationTab();
    if (productsTab == null) {
        productsTab = DatabaseTab.PRODUCTS;
    }
    if (mutationTab == null) {
        mutationTab = DatabaseTab.MUTATIONS;
    }
    tabs[0] = speciesTab;
    tabs[1] = databasePlugin.getSpeciesTab(false);
    tabs[2] = productsTab;
    tabs[3] = mutationTab;
    return tabs;
}
Also used : ISpeciesPlugin(forestry.api.genetics.ISpeciesPlugin) IDatabaseTab(forestry.api.genetics.IDatabaseTab)

Aggregations

IDatabaseTab (forestry.api.genetics.IDatabaseTab)3 IIndividual (forestry.api.genetics.IIndividual)1 ISpeciesPlugin (forestry.api.genetics.ISpeciesPlugin)1 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)1 GuiElementHelper (forestry.core.gui.elements.GuiElementHelper)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1