mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-27 15:33:12 +00:00
* Optimized imports * Some code reformat * Some refactoring and code reformat * Some code reformat
141 lines
5.8 KiB
Java
141 lines
5.8 KiB
Java
package binnie.genetics.gui.flower;
|
|
|
|
import binnie.botany.Botany;
|
|
import binnie.botany.api.EnumAcidity;
|
|
import binnie.botany.api.EnumMoisture;
|
|
import binnie.botany.api.IFlower;
|
|
import binnie.botany.gardening.BlockSoil;
|
|
import binnie.core.craftgui.IWidget;
|
|
import binnie.core.craftgui.controls.ControlText;
|
|
import binnie.core.craftgui.controls.ControlTextCentered;
|
|
import binnie.core.craftgui.geometry.Area;
|
|
import binnie.core.craftgui.geometry.TextJustification;
|
|
import binnie.core.craftgui.minecraft.control.ControlItemDisplay;
|
|
import binnie.core.genetics.Tolerance;
|
|
import binnie.genetics.Genetics;
|
|
import binnie.genetics.gui.ControlAnalystPage;
|
|
import binnie.genetics.gui.ControlToleranceBar;
|
|
import forestry.api.genetics.EnumTolerance;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.text.TextFormatting;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.EnumSet;
|
|
import java.util.List;
|
|
|
|
public class AnalystPageSoil extends ControlAnalystPage {
|
|
public AnalystPageSoil(final IWidget parent, final Area area, final IFlower flower) {
|
|
super(parent, area);
|
|
this.setColour(6697728);
|
|
final EnumMoisture moisture = flower.getGenome().getPrimary().getMoisture();
|
|
final EnumTolerance moistureTol = flower.getGenome().getToleranceMoisture();
|
|
final EnumAcidity pH = flower.getGenome().getPrimary().getPH();
|
|
final EnumTolerance pHTol = flower.getGenome().getTolerancePH();
|
|
int y = 4;
|
|
new ControlTextCentered(this, y, TextFormatting.UNDERLINE + getTitle()).setColour(this.getColour());
|
|
y += 16;
|
|
new ControlText(this, new Area(4, y, this.width() - 8, 14), Genetics.proxy.localise("gui.analyst.soil.tolerance.moisture"), TextJustification.MiddleCenter).setColour(this.getColour());
|
|
y += 12;
|
|
this.createMoisture(this, (this.width() - 100) / 2, y, 100, 10, moisture, moistureTol);
|
|
y += 16;
|
|
new ControlText(this, new Area(4, y, this.width() - 8, 14), Genetics.proxy.localise("gui.analyst.soil.tolerance.ph"), TextJustification.MiddleCenter).setColour(this.getColour());
|
|
y += 12;
|
|
this.createAcidity(this, (this.width() - 100) / 2, y, 100, 10, pH, pHTol);
|
|
y += 16;
|
|
new ControlText(this, new Area(4, y, this.width() - 8, 14), Genetics.proxy.localise("gui.analyst.soil.recommended"), TextJustification.MiddleCenter).setColour(this.getColour());
|
|
y += 12;
|
|
EnumMoisture recomMoisture = EnumMoisture.NORMAL;
|
|
final boolean canTolNormal = Tolerance.canTolerate(moisture, EnumMoisture.NORMAL, moistureTol);
|
|
final boolean canTolDamp = Tolerance.canTolerate(moisture, EnumMoisture.DAMP, moistureTol);
|
|
final boolean canTolDry = Tolerance.canTolerate(moisture, EnumMoisture.DRY, moistureTol);
|
|
if (canTolNormal) {
|
|
if (canTolDamp && !canTolDry) {
|
|
recomMoisture = EnumMoisture.DAMP;
|
|
} else if (canTolDry && !canTolDamp) {
|
|
recomMoisture = EnumMoisture.DRY;
|
|
}
|
|
} else {
|
|
if (canTolDamp) {
|
|
recomMoisture = EnumMoisture.DAMP;
|
|
}
|
|
if (canTolDry) {
|
|
recomMoisture = EnumMoisture.DRY;
|
|
}
|
|
}
|
|
EnumAcidity recomPH = EnumAcidity.NEUTRAL;
|
|
final boolean canTolNeutral = Tolerance.canTolerate(pH, EnumAcidity.NEUTRAL, pHTol);
|
|
final boolean canTolAcid = Tolerance.canTolerate(pH, EnumAcidity.ACID, pHTol);
|
|
final boolean canTolAlkaline = Tolerance.canTolerate(pH, EnumAcidity.ALKALINE, pHTol);
|
|
if (canTolNeutral) {
|
|
if (canTolAcid && !canTolAlkaline) {
|
|
recomPH = EnumAcidity.ACID;
|
|
} else if (canTolAlkaline && !canTolAcid) {
|
|
recomPH = EnumAcidity.ALKALINE;
|
|
}
|
|
} else {
|
|
if (canTolAcid) {
|
|
recomPH = EnumAcidity.ACID;
|
|
}
|
|
if (canTolAlkaline) {
|
|
recomPH = EnumAcidity.ALKALINE;
|
|
}
|
|
}
|
|
final ItemStack stack = new ItemStack(Botany.soil, 1, BlockSoil.getMeta(recomPH, recomMoisture));
|
|
final ControlItemDisplay recomSoil = new ControlItemDisplay(this, (this.width() - 24) / 2, y, 24);
|
|
recomSoil.setItemStack(stack);
|
|
recomSoil.setTooltip();
|
|
y += 32;
|
|
new ControlText(this, new Area(4, y, this.width() - 8, 14), Genetics.proxy.localise("gui.analyst.soil.other"), TextJustification.MiddleCenter).setColour(this.getColour());
|
|
y += 12;
|
|
final List<ItemStack> stacks = new ArrayList<>();
|
|
for (final EnumAcidity a : EnumSet.range(EnumAcidity.ACID, EnumAcidity.ALKALINE)) {
|
|
for (final EnumMoisture b : EnumSet.range(EnumMoisture.DRY, EnumMoisture.DAMP)) {
|
|
if (Tolerance.canTolerate(pH, a, pHTol) && Tolerance.canTolerate(moisture, b, moistureTol) && (a != recomPH || b != recomMoisture)) {
|
|
stacks.add(new ItemStack(Botany.soil, 1, BlockSoil.getMeta(a, b)));
|
|
}
|
|
}
|
|
}
|
|
final int soilListWidth = 17 * stacks.size() - 1;
|
|
final int soilListX = (this.width() - soilListWidth) / 2;
|
|
int t = 0;
|
|
for (final ItemStack soilStack : stacks) {
|
|
final ControlItemDisplay display = new ControlItemDisplay(this, soilListX + 17 * t++, y);
|
|
display.setItemStack(soilStack);
|
|
display.setTooltip();
|
|
}
|
|
}
|
|
|
|
protected void createMoisture(final IWidget parent, final int x, final int y, final int w, final int h, final EnumMoisture value, final EnumTolerance tol) {
|
|
new ControlToleranceBar<EnumMoisture>(parent, x, y, w, h, EnumMoisture.class) {
|
|
@Override
|
|
protected String getName(final EnumMoisture value) {
|
|
return value.getTranslated(false);
|
|
}
|
|
|
|
@Override
|
|
protected int getColour(final EnumMoisture value) {
|
|
return (new int[]{13434828, 6737151, 3368703})[value.ordinal()];
|
|
}
|
|
}.setValues(value, tol);
|
|
}
|
|
|
|
protected void createAcidity(final IWidget parent, final int x, final int y, final int w, final int h, final EnumAcidity value, final EnumTolerance tol) {
|
|
new ControlToleranceBar<EnumAcidity>(parent, x, y, w, h, EnumAcidity.class) {
|
|
@Override
|
|
protected String getName(final EnumAcidity value) {
|
|
return value.getTranslated(false);
|
|
}
|
|
|
|
@Override
|
|
protected int getColour(final EnumAcidity value) {
|
|
return (new int[]{16711782, 65280, 26367})[value.ordinal()];
|
|
}
|
|
}.setValues(value, tol);
|
|
}
|
|
|
|
@Override
|
|
public String getTitle() {
|
|
return Genetics.proxy.localise("gui.analyst.soil.title");
|
|
}
|
|
}
|