Add Guide Book and Analyzer Screen (#2073)

This commit is contained in:
Nedelosk authored and GitHub committed 2018-04-05 21:20:16 +02:00
1 parent b5a8740e4a
commit 8ba478d758
251 files changed
+7985 -2550

No files matched your search

@@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.book;
import javax.annotation.Nullable;
import forestry.api.gui.IElementGroup;
import forestry.api.gui.IGuiElement;
import forestry.api.gui.IGuiElementFactory;
/**
* The deserialized content data of a book page. It creates a gui element at the moment the entry gets opened.
*/
public abstract class BookContent<D> {
public String type;
/**
* A data object that was deserialized from the json object of this content.
* Can be everything from an image to a crafting recipe.
*/
@Nullable
public D data = null;
/**
* The class of the data field. Used for the deserialization. If the result of this method is null the data field
* will be null too.
*/
@Nullable
public abstract Class<? extends D> getDataClass();
/**
* Called after the deserialization.
*/
public void onDeserialization() {
}
/**
* Adds the content to the page by adding a {@link IGuiElement} or at the content to the previous element.
*
* @param page The gui element that represents a book page
* @param previous The content of the previous element.
* @param previousElement The element that was previously added to the page.
* @param pageHeight The max height of the current page.
* @return True if you added an element.
*/
public abstract boolean addElements(IElementGroup page, IGuiElementFactory factory, @Nullable BookContent previous, @Nullable IGuiElement previousElement, int pageHeight);
}
@@ -3,11 +3,8 @@
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.core;
package forestry.api.book;
/**
* The alignment of the text in a text gui element.
*/
public enum GuiElementAlignment {
LEFT, CENTER, RIGHT
public class BookManager {
public static IBookLoader loader;
}
@@ -0,0 +1,80 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.book;
import javax.annotation.Nullable;
import java.util.Collection;
import net.minecraft.item.ItemStack;
public interface IBookCategory {
/**
* @return the {@link ItemStack} that represents this category at the front page.
*/
ItemStack getStack();
IBookCategory setStack(ItemStack stack);
/**
* Adds an custom entry to the category.
*/
IBookCategory addEntry(IBookEntry entry);
/**
* Adds an entry with the given name and the given icon to the category.
*
* @param name A unique name for this entry.
* @param stack The stack that will be displayed next to the entry title at the category page.
*/
IBookCategory addEntry(String name, ItemStack stack);
/**
* Creates a entry builder with the given name.
* <p>
* At the end of your creation you have to call {@link IBookEntryBuilder#addToCategory()} to add the entry to this
* category.
*
* @param name A unique name for this entry.
*/
IBookEntryBuilder createEntry(String name);
/**
* Creates a entry builder with the given name and the given icon.
* <p>
* At the end of your creation you have to call {@link IBookEntryBuilder#addToCategory()} to add the entry to this
* category.
*
* @param name A unique name for this entry.
* @param stack The stack that will be displayed next to the entry title at the category page.
*/
IBookEntryBuilder createEntry(String name, ItemStack stack);
/**
* @return a collection that contains all entries of this category.
*/
Collection<IBookEntry> getEntries();
/**
* @return the entry with the given unique name.
*/
@Nullable
IBookEntry getEntry(String name);
/**
* @return the localized name of this category.
*/
String getLocalizedName();
/**
* Currently unused
*/
String getTooltip();
/**
* @return the unique name of this category
*/
String getName();
}
@@ -0,0 +1,26 @@
package forestry.api.book;
import javax.annotation.Nullable;
import forestry.api.gui.IElementGroup;
import forestry.api.gui.IGuiElement;
import forestry.api.gui.IGuiElementFactory;
public interface IBookContent {
/**
* Called after the deserialization.
*/
default void onDeserialization() {
}
/**
* Adds the content to the page by adding a {@link IGuiElement} or at the content to the previous element.
*
* @param page The gui element that represents a book page
* @param previous The content of the previous element.
* @param previousElement The element that was previously added to the page.
* @param pageHeight The max height of the current page.
* @return True if you added an element.
*/
boolean addElements(IElementGroup page, IGuiElementFactory factory, @Nullable BookContent previous, @Nullable IGuiElement previousElement, int pageHeight);
}
@@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.book;
import javax.annotation.Nullable;
import net.minecraft.item.ItemStack;
/**
* A entry in the {@link IForesterBook}.
* <p>
* Forestry crates them with the help of json file, but you can add you own custom ones with
* {@link IBookCategory#addEntry(IBookEntry)}.
*/
public interface IBookEntry {
/**
* @return The stack that is displayed before the entry name.
*/
ItemStack getStack();
/**
* @return A unique string identifier for this entry.
*/
String getName();
/**
* @return the object that creates the book pages at the moment the bock opens.
*/
IBookPageFactory getPageFactory();
/**
* All sub entries of this entry are reachable over the buttons on the left side of the book.
*/
IBookEntry[] getSubEntries();
/**
* The parent of the entry if this entry is a sub entry. Null if the entry is no sub entry.
*/
@Nullable
IBookEntry getParent();
/**
* @return the localized title of this entry.
*/
String getTitle();
/**
* @return the content that was deserialized from the json file of this entry.
*/
BookContent[][] getContent();
}
@@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.book;
import javax.annotation.Nullable;
import net.minecraft.item.ItemStack;
public interface IBookEntryBuilder {
/**
* Sets the content of the entry.
*/
IBookEntryBuilder setContent(BookContent[][] content);
/**
* Sets the localized name of entry.
*/
IBookEntryBuilder setTitle(String title);
IBookEntryBuilder setStack(ItemStack stack);
IBookEntryBuilder setLoader(IBookPageFactory loader);
/**
* Creates a sub entry.
* <p>
* Important: You not have to call {@link #addToCategory()} at the end of the creation of the sub entry
*
* @param name The unique name of the sub entry.
* @return The entry builder of the sub entry.
*/
default IBookEntryBuilder createSubEntry(String name) {
return createSubEntry(name, ItemStack.EMPTY);
}
/**
* Creates a sub entry.
* <p>
* Important: You not have to call {@link #addToCategory()} at the end of the creation of the sub entry
*
* @param name The unique name of the sub entry.
* @param stack The stack that represents the sub entry.
* @return The entry builder of the sub entry.
*/
IBookEntryBuilder createSubEntry(String name, ItemStack stack);
IBookEntry build(@Nullable IBookEntry parent);
/**
* Builds a entry with the current information.
*/
IBookEntry build();
/**
* Builds the entry and adds it to the category.
*/
IBookCategory addToCategory();
}
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.book;
public interface IBookLoader {
/**
* Adds a content type.
*
* @param name The name of the content type.
* @param contentClass The class for the deserialization of the content.
*/
void registerContentType(String name, Class<? extends BookContent> contentClass);
void registerPageFactory(String name, IBookPageFactory factory);
IBookPageFactory getPageFactory(String name);
/**
* Loads the book if it was not loaded already or if it was invalidated. Otherwise it returns the last loaded
* instance.
*
* @return The current instance of the forestry guide book.
*/
IForesterBook loadBook();
/**
* Invalidates the current instance of the book.
* The next time {@link #loadBook()} gets called a new instance of the book will be loaded.
*/
void invalidateBook();
}
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.book;
import java.util.Collection;
import forestry.api.gui.IGuiElement;
/**
* A factory that creates book pages for a book entry.
*/
public interface IBookPageFactory {
/**
* Usually called at the moment the player opens the given entry.
* Creates a collection of gui elements that represent a page of the book.
*
* @param entry The opened book entry.
* @param leftPageHeight The height of a page on the left side of the book.
* @param rightPageHeight The height of a page on the right side of the book.
* @param pageWidth The width of a book page.
* @return A collection where every member represent a page of the book.
*/
Collection<IGuiElement> load(IBookEntry entry, int leftPageHeight, int rightPageHeight, int pageWidth);
}
@@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.book;
import javax.annotation.Nullable;
import java.util.Collection;
/**
* IForesterBook is the interface that the forestry guide book class implements.
* <p>
* You can get the current instance of the guide book from {@link IBookLoader#loadBook()}.
*/
public interface IForesterBook {
/**
* Creates a category, add it to this book and returns it.
*
* @param name A unique identifier for the category.
* @return The created category.
*/
IBookCategory addCategory(String name);
/**
* @return The category with the given unique name.
*/
@Nullable
IBookCategory getCategory(String name);
/**
* @return All categories of this book.
*/
Collection<IBookCategory> getCategories();
/**
* @return A collection that contains all unique names of the categories
*/
Collection<String> getCategoryNames();
/**
* @return A collection that contains all entries of the category with the given name.
*/
Collection<IBookEntry> getEntries(String category);
/**
* @return the entry with the given unique name.
*/
@Nullable
IBookEntry getEntry(String name);
}
@@ -0,0 +1,15 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@API(apiVersion = "5.8.1", owner = "ForestryAPI|core", provides = "ForestryAPI|book")
package forestry.api.book;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraftforge.fml.common.API;
@@ -1,43 +0,0 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.core;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IGuiElement {
int getX();
int getY();
int getWidth();
int getHeight();
void setXOffset(int xOffset);
void setYOffset(int yOffset);
@Nullable
IGuiElement getParent();
void setParent(@Nullable IGuiElement parent);
void draw(int startX, int startY);
@SideOnly(Side.CLIENT)
default List<String> getToolTip(int mouseX, int mouseY){
return Collections.emptyList();
}
@SideOnly(Side.CLIENT)
boolean isMouseOver(int mouseX, int mouseY);
}
@@ -1,98 +0,0 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.core;
import java.util.function.Function;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.core.IGuiElementLayoutHelper.LayoutFactory;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlleleInteger;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IAlleleTolerance;
import forestry.api.genetics.IBreedingTracker;
import forestry.api.genetics.IChromosomeType;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IMutation;
/**
* A helper interface to add gui elements.
*/
@SideOnly(Side.CLIENT)
public interface IGuiElementHelper {
/**
* Adds a {@link IGuiElement} to the parent of this.
*/
void add(IGuiElement element);
/**
* Centers a element to the center of the x axis of the parent element.
*
* @return the element
*/
IGuiElement centerElement(IGuiElement element);
/**
* Creates and adds an item gui element.
*/
void addItem(int x, ItemStack itemStack);
IGuiElementLayoutHelper layoutHelper(LayoutFactory layoutFactory, int width, int height);
/**
* Adds the chromosomeName and the name of the active/not active allele, of the chromosome, with {@link #addText}.
*/
void addAllele(String chromosomeName, IIndividual individual, IChromosomeType chromosome, boolean active);
/**
* Adds the chromosomeName and the result of toString with {@link #addText}.
*/
<A extends IAllele> void addAllele(String chromosomeName, Function<A, String> toString, IIndividual individual, IChromosomeType chromosome, boolean active);
void addFertilityInfo(IAlleleInteger fertilityAllele, int x, int texOffset);
void addToleranceInfo(IAlleleTolerance toleranceAllele, IAlleleSpecies species, String text);
void addMutation(int x, int y, int width, int height, IMutation mutation, IAllele species, IBreedingTracker breedingTracker);
void addMutationResultant(int x, int y, int width, int height, IMutation mutation, IBreedingTracker breedingTracker);
/**
* Adds a text element with the default color,the align {@link GuiElementAlignment#LEFT} and the height 12.
*/
void addText(String text);
/**
* Adds a text element with the align {@link GuiElementAlignment#LEFT} and the height 12.
*/
void addText(String text, int color);
/**
* Adds a text element with the default color and the height 12.
*/
void addText(String text, GuiElementAlignment align);
/**
* Adds a text element with the height 12.
*/
void addText(String text,GuiElementAlignment align, int color);
/**
* Adds a text element.
*/
void addText(int x, int height, String text, GuiElementAlignment align, int color);
/**
* @return The element to which all elements are added.
*/
IGuiElement getParent();
IGuiElementFactory factory();
}
@@ -1,67 +0,0 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.core;
import java.util.Collection;
import java.util.List;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IGuiElementLayout extends IGuiElement {
/**
* Adds a element to this layout.
*/
IGuiElementLayout addElement(IGuiElement element);
/**
* Removes a element from this layout.
*/
IGuiElementLayout removeElement(IGuiElement element);
default IGuiElementLayout addElements(IGuiElement... elements){
for(IGuiElement element : elements){
addElement(element);
}
return this;
}
default IGuiElementLayout removeElements(IGuiElement... elements){
for(IGuiElement element : elements){
removeElement(element);
}
return this;
}
default IGuiElementLayout addElements(Collection<IGuiElement> elements){
elements.forEach(element -> addElement(element));
return this;
}
default IGuiElementLayout removeElements(Collection<IGuiElement> elements){
elements.forEach(element -> removeElement(element));
return this;
}
List<IGuiElement> getElements();
IGuiElementLayout setDistance(int distance);
void addTooltip(String line);
/**
* @return The tooltip that is displayed if the mouse is over this element and no element of this layout is under it.
*/
List<String> getTooltip();
/**
* @return The distance between the different elements of this layout.
*/
int getDistance();
int getSize();
}
@@ -8,6 +8,10 @@ package forestry.api.core;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/**
* @deprecated TODO Remove in 1.13: Not needed in the api
*/
@Deprecated
public interface IStateMapperRegister {
@SideOnly(Side.CLIENT)
@@ -9,10 +9,12 @@ import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Map;
import com.mojang.authlib.GameProfile;
import forestry.api.genetics.IClassification.EnumClassLevel;
import net.minecraft.item.ItemStack;
import com.mojang.authlib.GameProfile;
import forestry.api.genetics.IClassification.EnumClassLevel;
/**
* Manages {@link ISpeciesRoot}, {@link IAllele}s, {@link IFruitFamily}s, {@link IClassification}, the blacklist and allows creation of research notes.
*
@@ -10,9 +10,12 @@ import java.util.Map;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.gui.IElementGenetic;
public interface IAlyzerPlugin {
@SideOnly(Side.CLIENT)
@@ -24,7 +27,40 @@ public interface IAlyzerPlugin {
@SideOnly(Side.CLIENT)
void drawAnalyticsPage3(GuiScreen gui, ItemStack itemStack);
/**
* Creates the first page of the alyzer.
*
* @param gui A instance of the alyzer gui.
* @param container A helper to create the gui elements.
* @param individual The individual that is currently in the alyzer slot.
*/
default void createFirstPage(GuiScreen gui, IElementGenetic container, IIndividual individual){
}
/**
* Creates the second page of the alyzer.
*
* @param gui A instance of the alyzer gui.
* @param container A helper to create the gui elements.
* @param individual The individual that is currently in the alyzer slot.
*/
default void createSecondPage(GuiScreen gui, IElementGenetic container, IIndividual individual){
}
/**
* Creates the third page of the alyzer. This page is usually used to display the products of the individual.
*
* @param gui A instance of the alyzer gui.
* @param container A helper to create the gui elements.
* @param individual The individual that is currently in the alyzer slot.
*/
default void createThirdPage(GuiScreen gui, IElementGenetic container, IIndividual individual){
}
Map<String, ItemStack> getIconStacks();
/**
* The hints that will be shown in the alyzer gui.
*/
List<String> getHints();
}
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.genetics;
import java.util.List;
import java.util.Map;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/**
* An ISpeciesPlugin provides methods that are used in the alyzer and database to display information about an
* individual.
*/
@SideOnly(Side.CLIENT)
public interface IDatabasePlugin<I extends IIndividual> {
/**
* A map that contains a {@link ItemStack} for every possible {@link IAlleleSpecies}.
* This item stack represents the species in the database and alyzer gui.
*
* The key of the map is the uid of the species.
*/
Map<String, ItemStack> getIndividualStacks();
/* ALYZER */
List<String> getHints();
IDatabaseTab[] getTabs();
}
@@ -7,7 +7,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.core.IGuiElementHelper;
import forestry.api.gui.IElementGenetic;
/**
* A tab of the database screen that shows some information about a {@link IIndividual}.
@@ -18,14 +18,11 @@ public interface IDatabaseTab<I extends IIndividual> {
* Creates the gui elements that are displayed if this tab is selected in the database.
*
* @param individual The individual that is currently in the database selected.
* @param elementHelper A helper to create the gui elements.
* @param container A helper to create the gui elements.
*/
void createElements(IGuiElementHelper elementHelper, I individual, ItemStack itemStack);
void createElements(IElementGenetic container, I individual, ItemStack itemStack);
/**
* @return The slot of this tab.
*/
EnumDatabaseTab getTab();
ItemStack getIconStack();
/**
* Can be used to give the tab a custom tooltip.
@@ -0,0 +1,43 @@
package forestry.api.genetics;
import net.minecraft.client.gui.GuiScreen;
import forestry.api.gui.IGuiElement;
public interface IGeneticAnalyzer extends IGuiElement {
IGeneticAnalyzerProvider getProvider();
/**
* @return True if the analyzer is currently visible.
*/
boolean isVisible();
void setVisible(boolean visible);
/**
* Called at the end of the constructor of the analyzer provider.
*/
void init();
/**
* Updates the displayed content of the analyzer.
*/
void update();
/**
* Draws the tooltip of the element that is under the mouse.
*/
void drawTooltip(GuiScreen gui, int mouseX, int mouseY);
/**
*
* @return
*/
IGuiElement getItemElement();
void updateSelected();
void setSelectedSlot(int selectedSlot);
int getSelected();
}
@@ -0,0 +1,18 @@
package forestry.api.genetics;
import net.minecraft.item.ItemStack;
public interface IGeneticAnalyzerProvider {
ItemStack getSpecimen(int index);
boolean onUpdateSelected();
void onSelection(int index, boolean changed);
int getSelectedSlot(int index);
int getSlotCount();
int getFirstSlot();
}
@@ -0,0 +1,5 @@
package forestry.api.genetics;
public class IGeneticPlugin {
}
@@ -0,0 +1,31 @@
package forestry.api.genetics;
import java.util.Optional;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface ISpeciesDisplayHelper {
/**
* Plugin to add information for the genetic database.
*/
Optional<IDatabasePlugin> getDatabasePlugin();
/**
* Plugin to add information for the handheld genetic analyzer.
*/
Optional<IAlyzerPlugin> getAlyzerPlugin();
/**
* Retrieves a stack that can and should only be used on the client side in a gui.
*
* @return A empty stack, if the species was not registered before the creation of this handler or if the species is
* not a species of the {@link ISpeciesRoot}.
*/
ItemStack getDisplayStack(IAlleleSpecies species, ISpeciesType type);
ItemStack getDisplayStack(IAlleleSpecies species);
}
@@ -1,107 +0,0 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.genetics;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.core.IGuiElementHelper;
/**
* An ISpeciesPlugin provides methods that are used in the alyzer and database to display information about an
* individual.
*/
@SideOnly(Side.CLIENT)
public interface ISpeciesPlugin<I extends IIndividual> {
/**
* A map that contains a {@link ItemStack} for every possible {@link IAlleleSpecies}.
* This item stack represents the species in the database and alyzer gui.
*
* The key of the map is the uid of the species.
*/
Map<String, ItemStack> getIndividualStacks();
/* ALYZER */
/**
* Creates the first page of the alyzer.
*
* @param gui A instance of the alyzer gui.
* @param elementHelper A helper to create the gui elements.
* @param individual The individual that is currently in the alyzer slot.
*/
default void createFirstPage(GuiScreen gui, IGuiElementHelper elementHelper, I individual){
}
/**
* Creates the second page of the alyzer.
*
* @param gui A instance of the alyzer gui.
* @param elementHelper A helper to create the gui elements.
* @param individual The individual that is currently in the alyzer slot.
*/
default void createSecondPage(GuiScreen gui, IGuiElementHelper elementHelper, I individual){
}
/**
* Creates the third page of the alyzer. This page is usually used to display the products of the individual.
*
* @param gui A instance of the alyzer gui.
* @param elementHelper A helper to create the gui elements.
* @param individual The individual that is currently in the alyzer slot.
*/
default void createThirdPage(GuiScreen gui, IGuiElementHelper elementHelper, I individual){
}
/**
* The hints that will be shown in the alyzer gui.
*/
List<String> getHints();
/* DATABASE */
/**
* Provides a instance of a {@link IDatabaseTab} that is used to display information about the species of a individual in the
* database.
*
* @param active True if this tab is used to display the active species of the individual.
*
* @return null if this plugin does not support the database.
*/
default IDatabaseTab<I> getSpeciesTab(boolean active){
return null;
}
/**
* Can be used to provide a custom products tab for the database.
* If this is Null forestry uses the default mutation tab to display the products.
*/
@Nullable
default IDatabaseTab<I> getProductsTab(){
return null;
}
/**
* Can be used to provide a custom mutation tab for the database.
* If this is Null forestry uses the default mutation tab to display the mutations.
*/
@Nullable
default IDatabaseTab<I> getMutationTab(){
return null;
}
/**
* A item stack that represents the database tab in the database gui.
*/
ItemStack getTabDatabaseIconItem(EnumDatabaseTab tab);
}
@@ -86,8 +86,20 @@ public interface ISpeciesRoot {
*/
ISpeciesType getIconType();
default ISpeciesType[] getTypes(){
return new ISpeciesType[0];
}
ItemStack getMemberStack(IIndividual individual, ISpeciesType type);
default ItemStack getMemberStack(IAlleleSpecies species, ISpeciesType type){
return getMemberStack(getTemplate(species), type);
}
default ItemStack getMemberStack(IAllele[] template, ISpeciesType type){
return getMemberStack(templateAsIndividual(template), type);
}
/* BREEDING TRACKER */
IBreedingTracker getBreedingTracker(World world, @Nullable GameProfile player);
@@ -148,6 +160,15 @@ public interface ISpeciesRoot {
List<? extends IIndividual> getIndividualTemplates();
/**
* The type of the species that will be used at the given position of the mutation recipe in the gui.
*
* @param position 0 = first parent, 1 = second parent, 2 = result
*/
default ISpeciesType getTypeForMutation(int position){
return getIconType();
}
/* MUTATIONS */
/**
@@ -210,18 +231,13 @@ public interface ISpeciesRoot {
*/
IAlyzerPlugin getAlyzerPlugin();
/**
* A array with the size of 4. With the database tabs of this {@link IIndividual}.
*/
//IDatabaseTab[] getDatabaseTabs();
/**
* Plugin to add information for the handheld genetic analyzer and the database.
* @since 5.7
*/
@Nullable
@SideOnly(Side.CLIENT)
default ISpeciesPlugin getSpeciesPlugin(){
default IDatabasePlugin getSpeciesPlugin(){
return null;
}
}
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.gui;
/**
* The alignment of a gui element.
*/
public enum GuiElementAlignment {
TOP_LEFT(0.0f, 0.0f),
TOP_CENTER(0.5f, 0.0f),
TOP_RIGHT(1.0f, 0.0f),
MIDDLE_LEFT(0.0f, 0.5f),
MIDDLE_CENTER(0.5f, 0.5f),
MIDDLE_RIGHT(1.0f, 0.5f),
BOTTOM_LEFT(0.0f, 1.0f),
BOTTOM_CENTER(0.5f, 1.0f),
BOTTOM_RIGHT(1.0f, 1.0f);
private final float xOffset;
private final float yOffset;
GuiElementAlignment(float xOffset, float yOffset) {
this.xOffset = xOffset;
this.yOffset = yOffset;
}
public float getXOffset() {
return xOffset;
}
public float getYOffset() {
return yOffset;
}
}
@@ -0,0 +1,37 @@
package forestry.api.gui;
import java.util.function.Function;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlleleInteger;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IAlleleTolerance;
import forestry.api.genetics.IBreedingTracker;
import forestry.api.genetics.IChromosomeType;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IMutation;
public interface IElementGenetic extends IElementGroup {
/**
* Adds the chromosomeName and the name of the active/not active allele, of the chromosome, with {@link #text}.
*/
void addAlleleRow(String chromosomeName, IIndividual individual, IChromosomeType chromosome, boolean active);
/**
* Adds the chromosomeName and the result of toString with {@link #text}.
*/
<A extends IAllele> void addAlleleRow(String chromosomeName, Function<A, String> toString, IIndividual individual, IChromosomeType chromosome, boolean active);
void addFertilityInfo(String chromosomeName, IAlleleInteger fertilityAllele, int texOffset);
void addToleranceInfo(String chromosomeName, IAlleleTolerance toleranceAllele, IAlleleSpecies species, String text);
void addMutation(int x, int y, int width, int height, IMutation mutation, IAllele species, IBreedingTracker breedingTracker);
void addMutationResultant(int x, int y, int width, int height, IMutation mutation, IBreedingTracker breedingTracker);
void addRow(String firstText, String secondText, int firstColor, int secondColor);
void addRow(String leftText, String rightText, boolean dominant);
}
@@ -0,0 +1,115 @@
package forestry.api.gui;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import net.minecraft.item.ItemStack;
public interface IElementGroup extends IGuiElement {
/**
* Adds a element to this layout.
*/
<E extends IGuiElement> E add(E element);
/**
* Removes a element from this layout.
*/
<E extends IGuiElement> E remove(E element);
default IElementGroup add(IGuiElement... elements) {
for (IGuiElement element : elements) {
add(element);
}
return this;
}
default IElementGroup remove(IGuiElement... elements) {
for (IGuiElement element : elements) {
remove(element);
}
return this;
}
default IElementGroup add(Collection<IGuiElement> elements) {
elements.forEach(this::add);
return this;
}
default IElementGroup remove(Collection<IGuiElement> elements) {
elements.forEach(this::remove);
return this;
}
void clear();
@Nullable
IGuiElement getLastElement();
/**
* @return All elements that this layout contains.
*/
List<IGuiElement> getElements();
IGuiElement item(int xPos, int yPos, ItemStack itemStack);
default IGuiElement item(ItemStack itemStack) {
return item(0, 0, itemStack);
}
/**
* Adds a text element with the default color,the align {@link GuiElementAlignment#TOP_LEFT} and the height 12.
*/
IGuiElement text(String text);
/**
* Adds a text element with the align {@link GuiElementAlignment#TOP_LEFT} and the height 12.
*/
IGuiElement text(String text, int color);
/**
* Adds a text element with the default color and the height 12.
*/
IGuiElement text(String text, GuiElementAlignment align);
IGuiElement text(String text, GuiElementAlignment align, int color, boolean unicode);
/**
* Adds a text element with the height 12.
*/
IGuiElement text(String text, GuiElementAlignment align, int color);
IGuiElement text(int x, String text, GuiElementAlignment align, int color);
/**
* Adds a text element.
*/
IGuiElement text(int x, int height, String text, GuiElementAlignment align, int color);
IGuiElement text(int x, int y, int width, int height, String text);
/**
* Adds a text element.
*/
IGuiElement text(int x, int height, String text, GuiElementAlignment align, int color, boolean unicode);
default IElementLayout vertical(int width) {
return vertical(0, 0, width);
}
IElementLayout vertical(int xPos, int yPos, int width);
IElementLayout horizontal(int xPos, int yPos, int height);
default IElementLayout horizontal(int height) {
return horizontal(0, 0, height);
}
IElementGroup panel(int xPos, int yPos, int width, int height);
default IElementGroup panel(int width, int height) {
return panel(0, 0, width, height);
}
IElementLayoutHelper layoutHelper(IElementLayoutHelper.LayoutFactory layoutFactory, int width, int height);
}
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.gui;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IElementLayout extends IElementGroup {
/**
* @param distance
* @return
*/
IElementLayout setDistance(int distance);
/**
* @return The distance between the different elements of this layout.
*/
int getDistance();
int getSize();
}
@@ -3,7 +3,7 @@
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.core;
package forestry.api.gui;
import java.util.Collection;
@@ -11,7 +11,7 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IGuiElementLayoutHelper {
public interface IElementLayoutHelper {
/**
* @return Only false if the helper has no space to add this element.
*/
@@ -23,19 +23,23 @@ public interface IGuiElementLayoutHelper {
void clear();
/**
* Adds the layouts to the parent of the {@link IGuiElementHelper}. And calls {@link #clear()}
* Adds the layouts to the parent of the {@link IElementGroup}. And calls {@link #clear()}
*/
void finish();
void finish(boolean centerX);
default void finish() {
finish(false);
}
/**
* @return All layouts that were created with the help of this helper since the last {@link #clear()} or {@link #finish()}.
*/
Collection<IGuiElementLayout> layouts();
Collection<IElementLayout> layouts();
interface LayoutFactory {
/**
* A factory method to create new layouts if the last layout is full.
*/
IGuiElementLayout createLayout(int xOffset, int yOffset);
IElementLayout createLayout(int xOffset, int yOffset);
}
}
@@ -0,0 +1,135 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.gui;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IGuiElement {
/* Position and Size*/
/**
* @return the x position of this element relative to the position of the top widget.
*/
int getX();
/**
* @return the y position of this element relative to the position of the top widget.
*/
int getY();
void setAlign(GuiElementAlignment align);
GuiElementAlignment getAlign();
int getAbsoluteX();
int getAbsoluteY();
/**
* @return the size of the element on the x-axis.
*/
int getWidth();
/**
* @return the size of the element on the y-axis.
*/
int getHeight();
void setSize(int width, int height);
void setLocation(int xPos, int yPos);
void setBounds(int xPos, int yPos, int width, int height);
/**
* Sets the x-axis offset to the original x-axis position.
*/
void setXPosition(int xPos);
/**
* Sets the y-axis offset to the original y-axis position.
*/
void setYPosition(int yPos);
/* Parent */
/**
* @return the element that contains this element and handles all events.
*/
@Nullable
IGuiElement getParent();
void setParent(@Nullable IGuiElement parent);
/* Rendering */
/**
* Draws the element and his children.
*
* @param mouseX The x position of the mouse relative to the parent of the element.
* @param mouseY The y position of the mouse relative to the parent of the element.
*/
void draw(int mouseX, int mouseY);
/**
* Draws the element itself at the current position.
*/
void drawElement(int mouseX, int mouseY);
/* Events */
/**
* @param mouseX The x position of the mouse relative to the parent of the element.
* @param mouseY The y position of the mouse relative to the parent of the element.
* @param mouseButton The pressed mouse button.
*/
void mouseClicked(int mouseX, int mouseY, int mouseButton);
/**
* @param mouseX The x position of the mouse relative to the parent of the element.
* @param mouseY The y position of the mouse relative to the parent of the element.
* @param mouseButton The pressed mouse button.
*/
void mouseReleased(int mouseX, int mouseY, int mouseButton);
void mouseClickMove(int mouseX, int mouseY, int mouseButton);
boolean keyTyped(char typedChar, int keyCode);
/**
* @param mouseX The x position of the mouse relative to the parent of the element.
* @param mouseY The y position of the mouse relative to the parent of the element.
* @return True if the mouse is currently over the element.
*/
boolean isMouseOver(int mouseX, int mouseY);
/**
* @return True if the mouse is currently over the element.
*/
boolean isMouseOver();
/* Tooltip */
IGuiElement addTooltip(String line);
IGuiElement addTooltip(Collection<String> lines);
void clearTooltip();
/**
* Returns the tooltip that this element provides at the given mouse position.
*
* @param mouseX The x position of the mouse relative to the parent of the element.
* @param mouseY The y position of the mouse relative to the parent of the element.
*/
List<String> getTooltip(int mouseX, int mouseY);
List<String> getTooltip();
@Nullable
IGuiState getGuiState();
}
@@ -3,7 +3,9 @@
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.core;
package forestry.api.gui;
import javax.annotation.Nullable;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -13,6 +15,8 @@ import forestry.api.genetics.IAlleleInteger;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IAlleleTolerance;
import forestry.api.genetics.IBreedingTracker;
import forestry.api.genetics.IGeneticAnalyzer;
import forestry.api.genetics.IGeneticAnalyzerProvider;
import forestry.api.genetics.IMutation;
/**
@@ -21,12 +25,12 @@ import forestry.api.genetics.IMutation;
@SideOnly(Side.CLIENT)
public interface IGuiElementFactory {
IGuiElementHelper createHelper(IGuiElementLayout element);
IGeneticAnalyzer createAnalyzer(int xPos, int yPos, boolean rightBoarder, IGeneticAnalyzerProvider provider);
/* GENETIC*/
/**
* @param dominant True if you want the dominant color and false if you want the recessive color.
*
* @param dominant True if you want the dominant color and false if you want the recessive color.
* @return The color code that forestry uses to show if a allele is dominant (true) or recessive (false).
*/
int getColorCoding(boolean dominant);
@@ -34,21 +38,25 @@ public interface IGuiElementFactory {
/**
* @return Null if the mutation is secret and undiscovered. {@link IMutation#isSecret()}
*/
@Nullable
IGuiElement createMutation(int x, int y, int width, int height, IMutation mutation, IAllele species, IBreedingTracker breedingTracker);
/**
* @return Null if the mutation is secret and undiscovered. {@link IMutation#isSecret()}
*/
@Nullable
IGuiElement createMutationResultant(int x, int y, int width, int height, IMutation mutation, IBreedingTracker breedingTracker);
IGuiElement createFertilityInfo(IAlleleInteger fertilityAllele, int x, int texOffset);
IGuiElement createFertilityInfo(IAlleleInteger fertilityAllele, int texOffset);
IGuiElement createToleranceInfo(IAlleleTolerance toleranceAllele, IAlleleSpecies species, String text);
IGuiElement createToleranceInfo(IAlleleTolerance toleranceAllele);
/* LAYOUTS */
IGuiElementLayout createHorizontal(int xPos, int yPos, int height);
IElementLayout createHorizontal(int xPos, int yPos, int height);
IGuiElementLayout createVertical(int xPos, int yPos, int width);
IElementLayout createVertical(int xPos, int yPos, int width);
IGuiElementLayout createPanel(int xPos, int yPos, int width, int height);
IElementGroup createPanel(int xPos, int yPos, int width, int height);
}
@@ -0,0 +1,59 @@
package forestry.api.gui;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IGuiState {
/**
* Returns the mouse position.
*/
int getMouseX();
/**
* Returns the mouse position.
*/
int getMouseY();
/**
* Returns the mouse position relative to the given element.
*/
int getRelativeMouseX(IGuiElement element);
/**
* Returns the mouse position relative to the given element.
*/
int getRelativeMouseY(IGuiElement element);
/**
* Returns the current screen width.
*/
int getScreenWidth();
/**
* Returns the current screen height.
*/
int getScreenHeight();
/**
* Returns the current gui height.
*/
int getGuiHeight();
/**
* Returns the current gui width.
*/
int getGuiWidth();
int getGuiLeft();
int getGuiTop();
TextureManager getTextureManager();
FontRenderer getFontRenderer();
}
@@ -0,0 +1,15 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@API(apiVersion = "5.8.0", owner = "ForestryAPI|core", provides = "ForestryAPI|gui")
package forestry.api.gui;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraftforge.fml.common.API;