Clean Up Gui

This commit is contained in:
Nedelosk committed 2017-07-31 12:09:50 +02:00
1 parent 724c3d1fbd
commit 21aa0c43a6
296 files changed
+1792 -1712

No files matched your search

@@ -0,0 +1,46 @@
package binnie.botany.gui.database;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import binnie.botany.api.IFlowerColor;
import binnie.core.gui.Attribute;
import binnie.core.gui.ITooltip;
import binnie.core.gui.IWidget;
import binnie.core.gui.Tooltip;
import binnie.core.gui.controls.core.Control;
import binnie.core.gui.controls.core.IControlValue;
import binnie.core.gui.renderer.RenderUtil;
public class ControlColorDisplay extends Control implements IControlValue<IFlowerColor>, ITooltip {
private IFlowerColor value;
public ControlColorDisplay(IWidget parent, int x, int y, IFlowerColor value) {
super(parent, x, y, 16, 16);
this.value = value;
addAttribute(Attribute.MouseOver);
}
@Override
public IFlowerColor getValue() {
return value;
}
@Override
public void setValue(IFlowerColor value) {
this.value = value;
}
@Override
@SideOnly(Side.CLIENT)
public void onRenderBackground(int guiWidth, int guiHeight) {
RenderUtil.drawSolidRect(getArea(), -1);
RenderUtil.drawSolidRect(getArea().inset(1), 0xff000000 + getValue().getColor(false));
}
@Override
public void getTooltip(Tooltip tooltip) {
super.getTooltip(tooltip);
tooltip.add(value.getColorName());
}
}
@@ -0,0 +1,25 @@
package binnie.botany.gui.database;
import binnie.botany.api.IColorMix;
import binnie.core.gui.IWidget;
import binnie.core.gui.controls.listbox.ControlListBox;
public class ControlColorMixBox extends ControlListBox<IColorMix> {
private int index;
private Type type;
public ControlColorMixBox(IWidget parent, int x, int y, int width, int height, Type type) {
super(parent, x, y, width, height, 12);
this.type = type;
}
@Override
public IWidget createOption(IColorMix value, int y) {
return new ControlColorMixItem(getContent(), value, y);
}
enum Type {
RESULTANT,
FURTHER,
}
}
@@ -0,0 +1,23 @@
package binnie.botany.gui.database;
import binnie.botany.api.IColorMix;
import binnie.core.gui.controls.listbox.ControlList;
import binnie.core.gui.controls.listbox.ControlOption;
public class ControlColorMixItem extends ControlOption<IColorMix> {
private final ControlColorDisplay itemWidget1;
private final ControlColorDisplay itemWidget2;
private final ControlColorDisplay itemWidget3;
private final ControlColorMixSymbol addSymbol;
private final ControlColorMixSymbol arrowSymbol;
public ControlColorMixItem(ControlList<IColorMix> controlList, IColorMix option, int y) {
super(controlList, option, y);
IColorMix value = getValue();
itemWidget1 = new ControlColorDisplay(this, 4, 4, value.getColorFirst());
itemWidget2 = new ControlColorDisplay(this, 44, 4, value.getColorSecond());
itemWidget3 = new ControlColorDisplay(this, 104, 4, value.getResult());
addSymbol = new ControlColorMixSymbol(this, 24, 4, 0, value);
arrowSymbol = new ControlColorMixSymbol(this, 64, 4, 1, value);
}
}
@@ -0,0 +1,56 @@
package binnie.botany.gui.database;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import binnie.botany.api.IColorMix;
import binnie.core.gui.Attribute;
import binnie.core.gui.CraftGUI;
import binnie.core.gui.ITooltip;
import binnie.core.gui.IWidget;
import binnie.core.gui.Tooltip;
import binnie.core.gui.controls.core.Control;
import binnie.core.gui.database.DatabaseConstants;
import binnie.core.gui.geometry.Point;
import binnie.core.gui.resource.Texture;
import binnie.core.gui.resource.minecraft.CraftGUITextureSheet;
import binnie.core.gui.resource.minecraft.StandardTexture;
import binnie.core.util.I18N;
public class ControlColorMixSymbol extends Control implements ITooltip {
static Texture MutationPlus = new StandardTexture(2, 94, 16, 16, CraftGUITextureSheet.Controls2);
static Texture MutationArrow = new StandardTexture(20, 94, 32, 16, CraftGUITextureSheet.Controls2);
IColorMix value;
int type;
protected ControlColorMixSymbol(IWidget parent, int x, int y, int type, IColorMix value) {
super(parent, x, y, 16 + type * 16, 16);
this.value = value;
this.type = type;
addAttribute(Attribute.MouseOver);
}
@Override
@SideOnly(Side.CLIENT)
public void onRenderBackground(int guiWidth, int guiHeight) {
super.onRenderBackground(guiWidth, guiHeight);
if (type == 0) {
CraftGUI.render.texture(ControlColorMixSymbol.MutationPlus, Point.ZERO);
} else {
CraftGUI.render.texture(ControlColorMixSymbol.MutationArrow, Point.ZERO);
}
}
public void setValue(IColorMix value) {
this.value = value;
setColor(0xffffff);
}
@Override
public void getTooltip(Tooltip tooltip) {
if (type == 1) {
float chance = value.getChance();
tooltip.add(I18N.localise(DatabaseConstants.BOTANY_CONTROL_KEY + ".color_mix_symbol.chance", chance));
}
}
}
@@ -0,0 +1,32 @@
package binnie.botany.gui.database;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import binnie.botany.api.IFlowerColor;
import binnie.core.gui.Attribute;
import binnie.core.gui.CraftGUI;
import binnie.core.gui.controls.listbox.ControlList;
import binnie.core.gui.controls.listbox.ControlTextOption;
import binnie.core.gui.geometry.CraftGUIUtil;
import binnie.core.gui.geometry.Point;
@SideOnly(Side.CLIENT)
public class ControlColorOption extends ControlTextOption<IFlowerColor> {
private ControlColorDisplay controlBee;
private Point boxPosition;
public ControlColorOption(ControlList<IFlowerColor> controlList, IFlowerColor option, int y) {
super(controlList, option, option.getColorName(), y);
setSize(new Point(getSize().x(), 20));
controlBee = new ControlColorDisplay(this, 2, 2, option);
addAttribute(Attribute.MouseOver);
CraftGUIUtil.moveWidget(textWidget, new Point(22, 0));
textWidget.setSize(textWidget.getSize().sub(new Point(24, 0)));
int th = CraftGUI.render.textHeight(textWidget.getValue(), textWidget.getSize().x());
int height = Math.max(20, th + 6);
setSize(new Point(size().x(), height));
textWidget.setSize(new Point(textWidget.getSize().x(), height));
boxPosition = new Point(2, (height - 18) / 2);
}
}
@@ -0,0 +1,37 @@
package binnie.botany.gui.database;
import java.util.ArrayList;
import java.util.List;
import binnie.botany.api.IColorMix;
import binnie.botany.api.IFlowerColor;
import binnie.botany.core.BotanyCore;
import binnie.core.gui.IWidget;
import binnie.core.gui.controls.ControlText;
import binnie.core.gui.controls.ControlTextCentered;
import binnie.core.gui.database.DatabaseConstants;
import binnie.core.gui.database.DatabaseTab;
import binnie.core.gui.database.PageAbstract;
import binnie.core.util.I18N;
public class PageColorMix extends PageAbstract<IFlowerColor> {
ControlText title;
ControlColorMixBox list;
public PageColorMix(IWidget parent, DatabaseTab tab) {
super(parent, tab);
title = new ControlTextCentered(this, 8, I18N.localise(DatabaseConstants.BOTANY_PAGES_KEY + ".color_further.title"));
list = new ControlColorMixBox(this, 4, 20, 136, 152, ControlColorMixBox.Type.FURTHER);
}
@Override
public void onValueChanged(IFlowerColor colour) {
List<IColorMix> mixes = new ArrayList<>();
for (IColorMix mix : BotanyCore.getFlowerRoot().getColorMixes(false)) {
if (mix.getColorFirst() == colour || mix.getColorSecond() == colour) {
mixes.add(mix);
}
}
list.setOptions(mixes);
}
}
@@ -0,0 +1,37 @@
package binnie.botany.gui.database;
import java.util.ArrayList;
import java.util.List;
import binnie.botany.api.IColorMix;
import binnie.botany.api.IFlowerColor;
import binnie.botany.core.BotanyCore;
import binnie.core.gui.IWidget;
import binnie.core.gui.controls.ControlText;
import binnie.core.gui.controls.ControlTextCentered;
import binnie.core.gui.database.DatabaseConstants;
import binnie.core.gui.database.DatabaseTab;
import binnie.core.gui.database.PageAbstract;
import binnie.core.util.I18N;
public class PageColorMixResultant extends PageAbstract<IFlowerColor> {
ControlText pageSpeciesFurther_Title;
ControlColorMixBox pageSpeciesFurther_List;
public PageColorMixResultant(IWidget parent, DatabaseTab tab) {
super(parent, tab);
pageSpeciesFurther_Title = new ControlTextCentered(this, 8, I18N.localise(DatabaseConstants.BOTANY_PAGES_KEY + ".species_further.title"));
pageSpeciesFurther_List = new ControlColorMixBox(this, 4, 20, 136, 152, ControlColorMixBox.Type.RESULTANT);
}
@Override
public void onValueChanged(IFlowerColor colour) {
List<IColorMix> mixes = new ArrayList<>();
for (IColorMix mix : BotanyCore.getFlowerRoot().getColorMixes(false)) {
if (mix.getResult() == colour) {
mixes.add(mix);
}
}
pageSpeciesFurther_List.setOptions(mixes);
}
}
@@ -0,0 +1,112 @@
package binnie.botany.gui.database;
import net.minecraft.item.ItemStack;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IIndividual;
import binnie.Binnie;
import binnie.botany.api.EnumFlowerChromosome;
import binnie.botany.api.EnumFlowerStage;
import binnie.botany.api.IAlleleFlowerSpecies;
import binnie.botany.api.IFlower;
import binnie.botany.api.IFlowerGenome;
import binnie.botany.core.BotanyCore;
import binnie.core.gui.IWidget;
import binnie.core.gui.controls.ControlText;
import binnie.core.gui.controls.core.Control;
import binnie.core.gui.controls.scroll.ControlScrollableContent;
import binnie.core.gui.database.DatabaseConstants;
import binnie.core.gui.database.DatabaseTab;
import binnie.core.gui.database.PageSpecies;
import binnie.core.gui.geometry.Area;
import binnie.core.gui.geometry.Point;
import binnie.core.gui.geometry.TextJustification;
import binnie.core.gui.minecraft.control.ControlItemDisplay;
import binnie.core.util.I18N;
public class PageSpeciesFlowerGenome extends PageSpecies {
public PageSpeciesFlowerGenome(IWidget parent, DatabaseTab tab) {
super(parent, tab);
}
//TODO: unused ?
/*public static String tolerated(boolean t) {
if (t) {
return "Tolerated";
}
return "Not Tolerated";
}*/
@Override
public void onValueChanged(IAlleleSpecies species) {
deleteAllChildren();
IAllele[] template = Binnie.GENETICS.getFlowerRoot().getTemplate(species.getUID());
if (template == null) {
return;
}
IFlower tree = Binnie.GENETICS.getFlowerRoot().templateAsIndividual(template);
IFlowerGenome genome = tree.getGenome();
IAlleleFlowerSpecies treeSpecies = genome.getPrimary();
int w = 144;
int h = 176;
new ControlText(this, new Area(0, 4, w, 16), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".title"), TextJustification.MIDDLE_CENTER);
ControlScrollableContent scrollable = new ControlScrollableContent(this, 4, 20, w - 8, h - 8 - 16, 12);
Control contents = new Control(scrollable, 0, 0, w - 8 - 12, h - 8 - 16);
int tw = w - 8 - 12;
int w2 = 55;
int w3 = tw - 50;
int y = 0;
int th = 14;
int th2 = 18;
new ControlText(contents, new Area(0, y, w2, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + DatabaseConstants.BOTANY_GENOME_KEY + ".temp"), TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), treeSpecies.getTemperature().getName(), TextJustification.MIDDLE_LEFT);
y += th;
new ControlText(contents, new Area(0, y, w2, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".moist"), TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), treeSpecies.getMoisture().getLocalisedName(false), TextJustification.MIDDLE_LEFT);
y += th;
new ControlText(contents, new Area(0, y, w2, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".ph"), TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), treeSpecies.getPH().getLocalisedName(false), TextJustification.MIDDLE_LEFT);
y += th;
new ControlText(contents, new Area(0, y, w2, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".fertility"), TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), genome.getFertility() + "x", TextJustification.MIDDLE_LEFT);
y += th;
float lifespan = genome.getLifespan() * 68.27f / genome.getAgeChance() / 24000.0f;
String lifespanValue = String.format("%.2f", lifespan);
new ControlText(contents, new Area(0, y, w2, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".lifespan"), TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".lifespan.value", lifespanValue), TextJustification.MIDDLE_LEFT);
y += th;
new ControlText(contents, new Area(0, y, w2, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".nectar"), TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), genome.getActiveAllele(EnumFlowerChromosome.SAPPINESS).getAlleleName(), TextJustification.MIDDLE_LEFT);
y += th;
int x = w2;
int tot = 0;
for (IIndividual vid : BotanyCore.getFlowerRoot().getIndividualTemplates()) {
if (vid.getGenome().getPrimary() == treeSpecies) {
if (tot > 0 && tot % 3 == 0) {
x -= 54;
y += 18;
}
ItemStack stack = BotanyCore.getFlowerRoot().getMemberStack(vid, EnumFlowerStage.FLOWER);
ControlItemDisplay display = new ControlItemDisplay(contents, x, y);
display.setItemStack(stack);
++tot;
x += 18;
}
}
int numOfLines = 1 + (tot - 1) / 3;
new ControlText(contents, new Area(0, y - (numOfLines - 1) * 18, w2, 4 + 18 * numOfLines), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".varieties"), TextJustification.MIDDLE_RIGHT);
y += th;
contents.setSize(new Point(contents.size().x(), y));
scrollable.setScrollableContent(contents);
}
}
@@ -0,0 +1,99 @@
package binnie.botany.gui.database;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import binnie.Binnie;
import binnie.botany.Botany;
import binnie.botany.api.IFlowerColor;
import binnie.botany.genetics.EnumFlowerColor;
import binnie.core.AbstractMod;
import binnie.core.gui.IWidget;
import binnie.core.gui.controls.listbox.ControlListBox;
import binnie.core.gui.database.DatabaseConstants;
import binnie.core.gui.database.DatabaseTab;
import binnie.core.gui.database.IDatabaseMode;
import binnie.core.gui.database.PageBranchOverview;
import binnie.core.gui.database.PageBranchSpecies;
import binnie.core.gui.database.PageBreeder;
import binnie.core.gui.database.PageSpeciesClassification;
import binnie.core.gui.database.PageSpeciesMutations;
import binnie.core.gui.database.PageSpeciesOverview;
import binnie.core.gui.database.PageSpeciesResultant;
import binnie.core.gui.database.WindowAbstractDatabase;
import binnie.core.gui.geometry.Area;
import binnie.core.gui.minecraft.Window;
import binnie.core.util.I18N;
public class WindowBotanistDatabase extends WindowAbstractDatabase {
private ControlListBox<EnumFlowerColor> selectionBoxColors;
public WindowBotanistDatabase(EntityPlayer player, Side side, boolean nei) {
super(player, side, nei, Binnie.GENETICS.flowerBreedingSystem, 130);
}
public static Window create(EntityPlayer player, Side side, boolean nei) {
return new WindowBotanistDatabase(player, side, nei);
}
@Override
@SideOnly(Side.CLIENT)
protected void addTabs() {
new PageSpeciesOverview(getInfoPages(Mode.SPECIES), new DatabaseTab(Botany.instance, "species.overview", 0));
new PageSpeciesFlowerGenome(getInfoPages(Mode.SPECIES), new DatabaseTab(Botany.instance, "genome", 0));
new PageSpeciesClassification(getInfoPages(Mode.SPECIES), new DatabaseTab(Botany.instance, "species.classification", 0));
new PageSpeciesResultant(getInfoPages(Mode.SPECIES), new DatabaseTab(Botany.instance, "species.resultant", 0));
new PageSpeciesMutations(getInfoPages(Mode.SPECIES), new DatabaseTab(Botany.instance, "species.further", 0));
new PageBranchOverview(getInfoPages(Mode.BRANCHES), new DatabaseTab(Botany.instance, "branches.overview", 0));
new PageBranchSpecies(getInfoPages(Mode.BRANCHES), new DatabaseTab(Botany.instance, "branches.species", 0));
createMode(FlowerMode.Color, new FlowerColorModeWidgets());
new PageColorMixResultant(getInfoPages(FlowerMode.Color), new DatabaseTab(Botany.instance, "color.resultant", 0));
new PageColorMix(getInfoPages(FlowerMode.Color), new DatabaseTab(Botany.instance, "color.further", 0));
new PageBreeder(getInfoPages(Mode.BREEDER), getUsername(), new DatabaseTab(Botany.instance, "breeder", 0));
}
@Override
protected AbstractMod getMod() {
return Botany.instance;
}
@Override
protected String getBackgroundTextureName() {
return "FlowerDatabase";
}
enum FlowerMode implements IDatabaseMode {
Color;
@Override
public String getName() {
return I18N.localise(DatabaseConstants.BOTANY_TAB_KEY + "." + name().toLowerCase());
}
}
@SideOnly(Side.CLIENT)
private class FlowerColorModeWidgets extends ModeWidgets {
public FlowerColorModeWidgets() {
super(FlowerMode.Color, WindowBotanistDatabase.this);
}
@Override
public void createListBox(Area area) {
listBox = new ControlListBox<IFlowerColor>(modePage, area.xPos(), area.yPos(), area.width(), area.height(), 12) {
@Override
public IWidget createOption(IFlowerColor value, int y) {
return new ControlColorOption(getContent(), value, y);
}
};
List<IFlowerColor> colors = Arrays.stream(EnumFlowerColor.values()).map(c -> c.getFlowerColorAllele()).collect(Collectors.toList());
listBox.setOptions(colors);
}
}
}
@@ -0,0 +1,9 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@FieldsAreNonnullByDefault
package binnie.botany.gui.database;
import javax.annotation.ParametersAreNonnullByDefault;
import binnie.core.util.FieldsAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;