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;
}
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);
}
}
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;
}
Aggregations