use of binnie.core.gui.controls.core.Control in project Binnie by ForestryMC.
the class PageSpeciesFlowerGenome method onValueChanged.
@Override
public void onValueChanged(IAlleleSpecies species) {
deleteAllChildren();
IAllele[] template = BotanyAPI.flowerRoot.getTemplate(species.getUID());
if (template == null) {
return;
}
IFlower flower = BotanyAPI.flowerRoot.templateAsIndividual(template);
IFlowerGenome genome = flower.getGenome();
IAlleleFlowerSpecies flowerSpecies = 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 + ".temp"), TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), flowerSpecies.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), EnumHelper.getLocalisedName(flowerSpecies.getMoisture(), 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), EnumHelper.getLocalisedName(flowerSpecies.getPH(), 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() == flowerSpecies) {
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.getSize().xPos(), y));
scrollable.setScrollableContent(contents);
}
use of binnie.core.gui.controls.core.Control in project Binnie by ForestryMC.
the class WindowAnalyst method initialiseClient.
@Override
@SideOnly(Side.CLIENT)
public void initialiseClient() {
setTitle(isDatabase ? (isMaster ? I18N.localise("genetics.gui.registry.master.title") : I18N.localise("genetics.gui.registry.title")) : I18N.localise("genetics.gui.analyst.title"));
getWindowInventory().createSlot(0);
baseWidget = new Widget(this);
int x = 16;
int y = 28;
Collection<IBreedingSystem> activeSystems = Binnie.GENETICS.getActiveSystems();
if (isDatabase) {
for (IBreedingSystem syst : activeSystems) {
new ControlSystemButton(x, y, this, syst);
x += 22;
}
} else {
new ControlSlot.Builder(this, x, y + 1).assign(InventoryType.WINDOW, 0);
x += 22;
new ControlSlot.Builder(this, x, y + 1).assign(InventoryType.WINDOW, 1);
x += 26;
setupValidators();
}
tabBar = new Control(this, x, 28, getWidth() - 16 - x, 20);
analystPanel = new AnalystPanel(this);
if (!isDatabase) {
slideUpInv = new ControlSlide(this, (getSize().xPos() - 244) / 2, getSize().yPos() - 80 + 1, 244, 80, Alignment.BOTTOM);
new ControlPlayerInventory(slideUpInv, true);
slideUpInv.setSlide(false);
}
addEventHandler(EventKey.Down.class, event -> {
if (event.getKey() == 205) {
shiftPages(true);
}
if (event.getKey() == 203) {
shiftPages(false);
}
});
if (!isDatabase) {
analystNone = new AnalystNoneControl(this);
}
setIndividual(null);
IBreedingSystem first = Binnie.GENETICS.getFirstActiveSystem();
setSystem(first);
}
use of binnie.core.gui.controls.core.Control in project Binnie by ForestryMC.
the class WindowAnalyst method setPage.
public void setPage(ControlScrollableContent side, @Nullable IWidget page) {
Control existingPage = (Control) side.getContent();
if (existingPage != null) {
existingPage.hide();
side.setScrollableContent(null);
}
if (page != null) {
page.show();
side.setScrollableContent(page);
side.setPercentageIndex(0);
page.setPosition(side.getPosition().add(1, 1));
}
}
use of binnie.core.gui.controls.core.Control in project Binnie by ForestryMC.
the class PageSpeciesTreeGenome method onValueChanged.
// TODO: unused ?
/*public static String tolerated(final boolean t) {
if (t) {
return I18N.localise("binniecore.gui.tolerated");
}
return I18N.localise("binniecore.gui.nottolerated");
}*/
@Override
public void onValueChanged(final IAlleleSpecies species) {
this.deleteAllChildren();
final IAllele[] template = TreeManager.treeRoot.getTemplate(species.getUID());
if (template == null) {
return;
}
final ITree tree = TreeManager.treeRoot.templateAsIndividual(template);
final ITreeGenome genome = tree.getGenome();
final IAlleleTreeSpecies treeSpecies = genome.getPrimary();
final int w = 144;
final int h = 176;
new ControlText(this, new Area(0, 4, w, 16), this.getValue().toString(), TextJustification.MIDDLE_CENTER);
final ControlScrollableContent scrollable = new ControlScrollableContent(this, 4, 20, w - 8, h - 8 - 16, 12);
final Control contents = new Control(scrollable, 0, 0, w - 8 - 12, h - 8 - 16);
final int tw = w - 8 - 12;
final int w2 = 65;
final int w3 = tw - 50;
int y = 0;
final int th = 14;
final int th2 = 18;
final IBreedingSystem syst = Binnie.GENETICS.getSystem(TreeManager.treeRoot);
new ControlText(contents, new Area(w2, y, w3, th), treeSpecies.getPlantType().toString(), TextJustification.MIDDLE_LEFT);
y += th;
new ControlText(contents, new Area(0, y, w2, th), I18N.localise("binniecore.gui.temperature.short") + " : ", TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), treeSpecies.getTemperature().getName(), TextJustification.MIDDLE_LEFT);
y += th;
Minecraft minecraft = Minecraft.getMinecraft();
World world = minecraft.world;
TextureMap map = minecraft.getTextureMapBlocks();
ILeafSpriteProvider spriteProvider = treeSpecies.getLeafSpriteProvider();
TextureAtlasSprite leaf = map.getAtlasSprite(spriteProvider.getSprite(false, false).toString());
int leafColour = spriteProvider.getColor(false);
new ControlText(contents, new Area(0, y, w2, th2), I18N.localise("extratrees.gui.database.leaves") + " : ", TextJustification.MIDDLE_RIGHT);
new ControlBlockIconDisplay(contents, w2, y, leaf).setColor(leafColour);
IFruitProvider fruitProvider = genome.getFruitProvider();
ResourceLocation fruitSprite = fruitProvider.getSprite(genome, world, BlockPos.ORIGIN, 100);
if (fruitSprite != null && !treeSpecies.getUID().equals("forestry.treeOak")) {
TextureAtlasSprite fruit = map.getAtlasSprite(fruitSprite.toString());
int fruitColour = fruitProvider.getColour(genome, world, BlockPos.ORIGIN, 100);
new ControlBlockIconDisplay(contents, w2, y, fruit).setColor(fruitColour);
}
y += th2;
Map<ItemStack, Float> products = fruitProvider.getProducts();
ItemStack log = treeSpecies.getWoodProvider().getWoodStack();
if (log.isEmpty()) {
new ControlText(contents, new Area(0, y, w2, th2), I18N.localise("extratrees.gui.database.log") + " : ", TextJustification.MIDDLE_RIGHT);
final ControlItemDisplay display = new ControlItemDisplay(contents, w2, y);
display.setItemStack(log);
display.setTooltip();
y += th2;
}
new ControlText(contents, new Area(0, y, w2, th), syst.getChromosomeShortName(EnumTreeChromosome.HEIGHT) + " : ", TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), genome.getHeight() + "x", TextJustification.MIDDLE_LEFT);
y += th;
new ControlText(contents, new Area(0, y, w2, th), syst.getChromosomeShortName(EnumTreeChromosome.FERTILITY) + " : ", TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), genome.getFertility() + "x", TextJustification.MIDDLE_LEFT);
y += th;
List<ItemStack> fruits = new ArrayList<>(products.keySet());
if (!fruits.isEmpty()) {
new ControlText(contents, new Area(0, y, w2, th2), syst.getChromosomeShortName(EnumTreeChromosome.FRUITS) + " : ", TextJustification.MIDDLE_RIGHT);
for (ItemStack fruitw : fruits) {
final ControlItemDisplay display2 = new ControlItemDisplay(contents, w2, y);
display2.setItemStack(fruitw);
display2.setTooltip();
y += th2;
}
}
new ControlText(contents, new Area(0, y, w2, th), syst.getChromosomeShortName(EnumTreeChromosome.YIELD) + " : ", TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), genome.getYield() + "x", TextJustification.MIDDLE_LEFT);
y += th;
new ControlText(contents, new Area(0, y, w2, th), syst.getChromosomeShortName(EnumTreeChromosome.SAPPINESS) + " : ", TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), genome.getSappiness() + "x", TextJustification.MIDDLE_LEFT);
y += th;
new ControlText(contents, new Area(0, y, w2, th), syst.getChromosomeShortName(EnumTreeChromosome.MATURATION) + " : ", TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), genome.getMaturationTime() + "x", TextJustification.MIDDLE_LEFT);
y += th;
new ControlText(contents, new Area(0, y, w2, th), syst.getChromosomeShortName(EnumTreeChromosome.GIRTH) + " : ", TextJustification.MIDDLE_RIGHT);
new ControlText(contents, new Area(w2, y, w3, th), genome.getGirth() + "x" + genome.getGirth(), TextJustification.MIDDLE_LEFT);
y += th;
contents.setSize(new Point(contents.getSize().xPos(), y));
scrollable.setScrollableContent(contents);
}
use of binnie.core.gui.controls.core.Control in project Binnie by ForestryMC.
the class WindowCompartment method initialiseClient.
// TODO: Clean Up, Localise
@Override
@SideOnly(Side.CLIENT)
public void initialiseClient() {
IInventory inventory = this.getInventory();
IMachine machine = Machine.getMachine(inventory);
MachinePackage machinePackage = machine.getPackage();
this.setTitle(machinePackage.getDisplayName());
int x = 16;
final int y = 32;
final ComponentCompartmentInventory inv = machine.getInterface(ComponentCompartmentInventory.class);
Integer[] tabs1 = new Integer[0];
Integer[] tabs2 = new Integer[0];
if (inv.getTabCount() == 4) {
tabs1 = new Integer[] { 0, 1 };
tabs2 = new Integer[] { 2, 3 };
}
if (inv.getTabCount() == 6) {
tabs1 = new Integer[] { 0, 1, 2 };
tabs2 = new Integer[] { 3, 4, 5 };
}
if (inv.getTabCount() == 8) {
tabs1 = new Integer[] { 0, 1, 2, 3 };
tabs2 = new Integer[] { 4, 5, 6, 7 };
}
final boolean doubleTabbed = tabs2.length > 0;
final int compartmentPageWidth = 16 + 18 * inv.getPageSize() / 5;
final int compartmentPageHeight = 106;
final int compartmentWidth = compartmentPageWidth + (doubleTabbed ? 48 : 24);
final int compartmentHeight = compartmentPageHeight;
final Control controlCompartment = new Control(this, x, y, compartmentWidth, compartmentHeight);
final ControlTabBar<Integer> tab = new ControlTabBar<>(controlCompartment, 0, 0, 24, compartmentPageHeight, Alignment.LEFT, Arrays.asList(tabs1), (x1, y1, w, h, value) -> {
return new CompartmentTabIcon(this, x1, y1, w, h, value);
});
final String[] tabHelp = { "Compartment Tab", "Tabs that divide the inventory into sections. Each one can be labelled seperately." };
tab.addHelp(tabHelp);
tab.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, tab, event -> {
if (event.getValue() == null) {
return;
}
final NBTTagCompound nbt = new NBTTagCompound();
final int i = (Integer) event.getValue();
nbt.setByte("i", (byte) i);
Window.get(tab).sendClientAction("tab-change", nbt);
WindowCompartment.this.currentTab = i;
});
x += 24;
final ControlPages<Integer> compartmentPages = new ControlPages<>(controlCompartment, 24, 0, compartmentPageWidth, compartmentPageHeight);
final ControlPage[] page = new ControlPage[inv.getTabCount()];
for (int p = 0; p < inv.getTabCount(); ++p) {
page[p] = new ControlPage<>(compartmentPages, p);
}
CraftGUIUtil.linkWidgets(tab, compartmentPages);
int i = 0;
for (int p2 = 0; p2 < inv.getTabCount(); ++p2) {
final ControlPage thisPage = page[p2];
final Panel panel = new CompartmentCenterPanel(this, thisPage);
this.panels.put(panel, p2);
final int[] slotsIDs = new int[inv.getPageSize()];
for (int k = 0; k < inv.getPageSize(); ++k) {
slotsIDs[k] = i++;
}
new ControlSlotArray.Builder(thisPage, 8, 8, inv.getPageSize() / 5, 5).create(slotsIDs);
}
x += compartmentPageWidth;
if (tabs2.length > 0) {
final ControlTabBar<Integer> tab2 = new ControlTabBar<>(controlCompartment, 24 + compartmentPageWidth, 0, 24, compartmentPageHeight, Alignment.RIGHT, Arrays.asList(tabs2), (x1, y1, w, h, value) -> {
return new CompartmentTabIcon(this, x1, y1, w, h, value);
});
tab2.setValue(tabs1[0]);
tab2.addHelp(tabHelp);
tab2.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, tab2, event -> {
if (event.getValue() == null) {
return;
}
final NBTTagCompound nbt = new NBTTagCompound();
final int iVal = (Integer) event.getValue();
nbt.setByte("i", (byte) iVal);
Window.get(tab).sendClientAction("tab-change", nbt);
WindowCompartment.this.currentTab = iVal;
});
CraftGUIUtil.linkWidgets(tab2, compartmentPages);
x += 24;
}
x += 16;
this.setSize(new Point(Math.max(32 + compartmentWidth, 252), this.getHeight()));
controlCompartment.setPosition(new Point((this.getWidth() - controlCompartment.getWidth()) / 2, controlCompartment.getYPos()));
final ControlPlayerInventory invent = new ControlPlayerInventory(this, true);
final ControlSlide slide = new ControlSlide(this, 0, 134, 136, 92, Alignment.LEFT);
slide.setLabel("Tab Properties");
slide.setSlide(false);
slide.addHelp("Tab Properties");
slide.addHelp("The label, colour and icon of the Tab can be altered here. Clicking on the icon with a held item will change it.");
final Panel tabPropertyPanel = new Panel(slide, 16, 8, 112, 76, MinecraftGUI.PanelType.GRAY);
int y2 = 4;
new ControlText(tabPropertyPanel, new Point(4, y2), "Tab Name:");
final Panel parent = tabPropertyPanel;
final int x2 = 4;
y2 += 12;
(this.tabName = new ControlTextEdit(parent, x2, y2, 104, 12)).addEventHandler(EventTextEdit.class, EventHandlerOrigin.SELF, this.tabName, event -> {
final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab();
currentTab.setName(event.getValue());
final NBTTagCompound nbt = new NBTTagCompound();
currentTab.writeToNBT(nbt);
WindowCompartment.this.sendClientAction("comp-change-tab", nbt);
});
y2 += 20;
new ControlText(tabPropertyPanel, new Point(4, y2), "Tab Icon: ");
(this.tabIcon = new ControlItemDisplay(tabPropertyPanel, 58, y2 - 4)).setItemStack(new ItemStack(Items.PAPER));
this.tabIcon.addAttribute(Attribute.MOUSE_OVER);
this.tabIcon.addSelfEventHandler(EventMouse.Down.class, event -> {
if (WindowCompartment.this.getHeldItemStack().isEmpty()) {
return;
}
final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab();
final ItemStack stack = WindowCompartment.this.getHeldItemStack().copy();
stack.setCount(1);
currentTab.setIcon(stack);
final NBTTagCompound nbt = new NBTTagCompound();
currentTab.writeToNBT(nbt);
WindowCompartment.this.sendClientAction("comp-change-tab", nbt);
});
this.tabColour = new ControlColourSelector(tabPropertyPanel, 82, y2 - 4, 16, 16, EnumColor.WHITE);
this.tabIcon.addHelp("Icon for Current Tab");
this.tabIcon.addHelp("Click here with an item to change");
y2 += 20;
new ControlText(tabPropertyPanel, new Point(4, y2), "Colour: ");
final int cw = 8;
final Panel panelColour = new Panel(tabPropertyPanel, 40, y2 - 4, cw * 8 + 2, cw * 2 + 1, MinecraftGUI.PanelType.GRAY);
for (int cc = 0; cc < 16; ++cc) {
final ControlColourSelector color = new ControlColourSelector(panelColour, 1 + cw * (cc % 8), 1 + cw * (cc / 8), cw, cw, EnumColor.values()[cc]);
color.addSelfEventHandler(EventMouse.Down.class, event -> {
final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab();
currentTab.setColor(color.getValue());
final NBTTagCompound nbt = new NBTTagCompound();
currentTab.writeToNBT(nbt);
WindowCompartment.this.sendClientAction("comp-change-tab", nbt);
});
color.addHelp("Colour Selector");
color.addHelp("Select a colour to highlight the current tab");
}
y2 += 20;
final ControlButton searchButton = new SearchButton(this, controlCompartment, compartmentWidth, compartmentPageHeight);
searchButton.addHelp("Search Button");
searchButton.addHelp("Clicking this will open the Search dialog. This allows you to search the inventory for specific items.");
}
Aggregations